playerbase.c 255 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506
  1. class PlayerBase extends ManBase
  2. {
  3. const int SIMPLIFIED_SHOCK_CAP = 63;
  4. const int SHAKE_LEVEL_MAX = 7;
  5. private int m_LifeSpanState;
  6. private int m_LastShavedSeconds;
  7. private int m_BloodType;
  8. private bool m_HasBloodTypeVisible;
  9. private bool m_LiquidTendencyDrain; //client-side only - Obsolete
  10. private bool m_FlagRaisingTendency;
  11. private int m_HasBloodyHandsVisible;
  12. protected bool m_HasHeatBuffer;
  13. protected int m_HeatBufferStage;
  14. protected float m_HeatBufferDynamicMax;
  15. protected bool m_IsInColdArea;
  16. protected bool m_PlayerLoaded;
  17. protected bool m_PlayerDisconnectProcessed;
  18. protected bool m_ProcessUIWarning;
  19. protected int m_LocalRefreshAnimStateIdx;
  20. protected int m_RefreshAnimStateIdx;
  21. private int m_StoreLoadVersion;
  22. const int ACT_STORE_SAVE_VERSION = 4;
  23. protected int m_LifespanLevelLocal; //control variable for change calls
  24. protected int m_AnimCommandStarting; //signals the command that is about to start the next frame (e.g. Swim, Fall...)
  25. EUndergroundPresence m_UndergroundPresence;
  26. private PluginPlayerStatus m_ModulePlayerStatus;
  27. PluginConfigEmotesProfile m_ConfigEmotesProfile;
  28. private PluginLifespan m_ModuleLifespan;
  29. protected PluginPresenceNotifier m_PresenceNotifier;
  30. protected ref UndergroundHandlerClient m_UndergroundHandler;
  31. protected ref UndergroundBunkerHandlerClient m_UndergroundBunkerHandler;
  32. ref PlayerStats m_PlayerStats;
  33. PluginRecipesManager m_ModuleRecipesManager;
  34. ref BleedingSourcesManagerServer m_BleedingManagerServer;
  35. ref BleedingSourcesManagerRemote m_BleedingManagerRemote;
  36. ref ModifiersManager m_ModifiersManager;
  37. ref NotifiersManager m_NotifiersManager;
  38. ref protected ActionManagerBase m_ActionManager;
  39. ref PlayerAgentPool m_AgentPool;
  40. int m_Agents;
  41. ref Environment m_Environment;
  42. ref EmoteManager m_EmoteManager;
  43. ref SymptomManager m_SymptomManager;
  44. ref VirtualHud m_VirtualHud;
  45. ref StaminaHandler m_StaminaHandler;
  46. ref InjuryAnimationHandler m_InjuryHandler;
  47. ref ShockHandler m_ShockHandler; //New shock handler
  48. ref SoftSkillsManager m_SoftSkillsManager;
  49. ref StanceIndicator m_StanceIndicator;
  50. ref TransferValues m_TrasferValues;
  51. ref DebugMonitorValues m_DebugMonitorValues;
  52. const int OVERLOAD_LIMIT = 30000;
  53. float m_CargoLoad;
  54. float m_VisibilityCoef;
  55. float m_OriginalSlidePoseAngle;
  56. int m_SoundEvent;
  57. int m_SoundEventParam;
  58. int m_FliesIndex;
  59. bool m_SoundEventSent;
  60. ref Param2<float,float> m_UAProgressParam;
  61. ref Param2<int,int> m_UAParam;
  62. ref Param3<float,float,bool> m_StaminaParam;
  63. ref Param1<string> m_UAParamMessage;
  64. ref Param1<float> m_UnconParam;
  65. ref Param1<float> m_DeathDarkeningParam;
  66. ref DamageDealtEffect m_DamageDealtEffect;
  67. ref EffectRadial m_EffectRadial;
  68. ref FlashbangEffect m_FlashbangEffect;
  69. ref ShockDealtEffect m_ShockDealtEffect;
  70. ref EffectParticle m_FliesEff;
  71. ref TInputActionMap m_InputActionMap; // Backwards compatibility
  72. ref TInputActionMap m_InputActionMapControled;
  73. ref TInputActionMap m_InputActionMapAsTarget;
  74. bool m_ActionsInitialize;
  75. //ref CraftingMeta m_CraftingMeta;
  76. ref HiddenSelectionsData m_EmptyGloves;
  77. ref WeaponManager m_WeaponManager;
  78. ref CraftingManager m_CraftingManager;
  79. ref ArrowManagerPlayer m_ArrowManager;
  80. ref InventoryActionHandler m_InventoryActionHandler;
  81. ref protected QuickBarBase m_QuickBarBase;
  82. ref PlayerSoundManagerServer m_PlayerSoundManagerServer;
  83. ref PlayerSoundManagerClient m_PlayerSoundManagerClient;
  84. ref HeatComfortAnimHandler m_HCAnimHandler;
  85. ref EffectSound m_SoundFliesEffect;
  86. bool m_QuickBarHold;
  87. bool m_QuickBarFT = false;
  88. Hud m_Hud;
  89. protected int m_RecipePick;
  90. protected bool m_IsHoldingBreath;
  91. protected bool m_IsInWater;
  92. float m_LastPostFrameTickTime;
  93. //AbstractWave m_SaySoundWave;
  94. ref Timer m_DeathCheckTimer;
  95. bool m_CorpseProcessing;
  96. int m_CorpseState;
  97. protected int m_CorpseStateLocal;
  98. protected bool m_IsHeadingRestricted;
  99. protected ref HeadingRestrictData m_HeadingRestrictData;
  100. int m_PersistentFlags;
  101. int m_StaminaState;
  102. float m_UnconsciousTime;
  103. int m_ShockSimplified;
  104. float m_CurrentShock; //Used to synchronize shock between server and client, utilized by ShockHandler
  105. bool m_IsRestrained;
  106. bool m_IsRestrainedLocal;
  107. bool m_IsRestrainStarted;
  108. bool m_IsRestrainStartedLocal;
  109. bool m_IsRestrainPrelocked;
  110. bool m_ImmunityBoosted;
  111. bool m_AreHandsLocked; //Currently only used to block quickbar usage after canceling placement
  112. float m_UnconsciousVignetteTarget = 2;
  113. float m_CameraSwayModifier = 0.2;
  114. float m_LastShockHitTime;
  115. DayZPlayerCameraBase m_CurrentCamera;
  116. int m_BleedingBits;
  117. vector m_DirectionToCursor;
  118. vector m_DefaultHitPosition;
  119. int m_DiseaseCount;
  120. int m_HealingsCount;
  121. protected bool m_AllowQuickRestrain;
  122. protected bool m_AllowQuickFishing;
  123. protected int m_Shakes;
  124. protected int m_ShakesForced;
  125. int m_BreathVapour;
  126. int m_HealthLevel;
  127. int m_MixedSoundStates;
  128. int m_QuickBarBonus = 0;
  129. bool m_IsVehicleSeatDriver;
  130. float m_UnconsciousEndTime = 0;
  131. int m_BleedingSourceCount;
  132. Head_Default m_CharactersHead;
  133. EPulseType m_PulseType;
  134. PlayerBase m_CheckPulseLastTarget;
  135. int m_ForceInjuryAnimMask;
  136. bool m_HideHairAnimated;
  137. string m_DecayedTexture;
  138. protected ref array<EntityAI> m_ItemsToDelete;
  139. int m_BrokenLegState = eBrokenLegs.NO_BROKEN_LEGS; //Describe the current leg state, can go bellow 0, cannot be used directly to obtain broken legs state, use GetBrokenLegs() instead
  140. int m_LocalBrokenState = eBrokenLegs.NO_BROKEN_LEGS;
  141. bool m_BrokenLegsJunctureReceived;
  142. ref EffectSound m_BrokenLegSound;
  143. const string SOUND_BREAK_LEG = "broken_leg_SoundSet";
  144. bool m_CanPlayBrokenLegSound; //Used to check if sound has already been played
  145. static bool DEBUG_INVENTORY_ACCESS = false;
  146. static ref array<string> m_BleedingSourcesLow; //Stores all LOWER body part bleeding sources
  147. static ref array<string> m_BleedingSourcesUp; //Stores all UPPER body part bleeding sources EXCLUDING HEAD
  148. float m_UnconRefillModifier = 1;
  149. ref protected RandomGeneratorSyncManager m_RGSManager;
  150. // CONTAMINATED AREA RELATED
  151. bool m_ContaminatedAreaEffectEnabled;
  152. const string CONTAMINATED_AREA_AMBIENT = "ContaminatedArea_SoundSet";//obsolete, use EffectTrigger::GetAmbientSoundsetName() instead
  153. EffectSound m_AmbientContamination;
  154. protected int m_ContaminatedAreaCount;
  155. protected int m_EffectAreaCount;
  156. protected bool m_InsideEffectArea;
  157. protected bool m_InsideEffectAreaPrev;
  158. protected EffectTrigger m_CurrentEffectTrigger;
  159. // effect areas
  160. protected EEffectAreaType m_InEffectAreaType; // flags for identifying which area the player is in, synchronized by EffectTriggers
  161. protected ref map<EEffectAreaType, int> m_EffectAreaOverlap = new map<EEffectAreaType, int>(); // type -> how many of such areas is player currently in
  162. protected ref map<EEffectAreaType, float> m_EffectAreaTimeToTick = new map<EEffectAreaType, float>(); // type -> how long has player spent in an area since last effect tick
  163. static ref array<Man> m_ServerPlayers = new array<Man>;
  164. protected bool m_CanDisplayHitEffectPPE;
  165. protected string m_CachedPlayerName;//cached from player identity
  166. protected string m_CachedPlayerID;//cached from player identity
  167. #ifdef DIAG_DEVELOPER
  168. int m_IsInsideTrigger;
  169. bool m_CanBeTargetedDebug; //server-side only
  170. ref array<EntityAI> m_PresetItems = new array<EntityAI>;
  171. bool m_PresetSpawned;
  172. ref CameraToolsMenuClient m_CameraToolsMenuClient;
  173. protected PluginTargetTemperature m_TargetTemperatureDiag;
  174. #endif
  175. #ifdef DEVELOPER
  176. Transport m_GetInVehicleTransportDebug;
  177. #endif
  178. #ifdef DIAG_DEVELOPER
  179. ref Bot m_Bot;
  180. #endif
  181. //Temp QuickBar load
  182. ref array<ref Param2<EntityAI,int> > m_aQuickBarLoad;
  183. //hologram
  184. ref Hologram m_HologramServer;
  185. ref Hologram m_HologramLocal;
  186. vector m_LocalProjectionPosition = "0 0 0 ";
  187. vector m_LocalProjectionOrientation = "0 0 0 ";
  188. //Sheduler
  189. float m_LastTick = -1;
  190. int m_AddModifier = -1;
  191. //crafting start
  192. int m_RecipeID = -1;
  193. EntityAI m_Item1;
  194. EntityAI m_Item2;
  195. bool m_IsCraftingReady;
  196. float m_RecipeAnimLength;
  197. vector m_CraftingInitialPos;
  198. ref array<int> m_Recipes;
  199. //crafting end
  200. ref SoundParams m_SaySoundParams;
  201. ref SoundObjectBuilder m_SaySoundBuilder;
  202. ref SoundObject m_SaySoundObject;
  203. string m_SaySoundLastSetName;
  204. //input control
  205. bool m_ActionQBControl;
  206. //Action data for base building actions
  207. ref ConstructionActionData m_ConstructionActionData;
  208. //Action data for fireplace (indoor)
  209. vector m_LastFirePoint;
  210. float m_LastFirePointRot;
  211. int m_LastFirePointIndex;
  212. bool ItemToInventory;
  213. bool m_IsFighting = false;
  214. bool m_IsDrowning;//Set only via the setter SetDrowning
  215. // debug monitor
  216. int m_DebugMonitorEnabled;
  217. //map
  218. ActionUnfoldMapCB m_hac;
  219. bool m_MapOpen;
  220. bool m_MapCloseRequestProcessed; //DEPRECATED
  221. protected bool m_MapClosingSyncSent;
  222. protected float m_LastMapScale = -1.0;
  223. protected vector m_LastMapPos;
  224. protected ref MapNavigationBehaviour m_MapNavigationBehaviour;
  225. //inventory soft locking
  226. protected bool m_InventorySoftLocked; //obsolete, count should be checked instead. Left in here for legacy's sake.
  227. protected int m_InventorySoftLockCount = 0;
  228. static ref TStringArray m_QBarItems;
  229. //Analytics
  230. string m_DatabaseID;
  231. ref Timer m_AnalyticsTimer;
  232. //! melee stats
  233. protected bool m_MeleeDebug;
  234. //protected bool m_CheckMeleeItem;
  235. protected ItemBase m_CheckMeleeItem;
  236. //! user actions & symptoms
  237. protected string m_UALastMessage;
  238. protected ref Timer m_UALastMessageTimer;
  239. protected int m_PerformedAnimActionID = -1; // animated action being performed, -1 if none
  240. protected int m_ActivePrimarySymptomID = 0; // active primary symptom, 0 if none, symptom has to be overriden to allow sync
  241. bool m_WorkingNVGHeadset; //Deprecated
  242. bool m_LoweredNVGHeadset;
  243. protected ref array<int> m_ActiveNVTypes;
  244. //bool m_PreviousNVGState;
  245. int m_SyncedModifiers;
  246. int m_SyncedModifiersPrev;
  247. PluginAdminLog m_AdminLog;
  248. ref PlayerStomach m_PlayerStomach;
  249. protected static Particle m_ContaminatedAroundPlayer;
  250. protected static Particle m_ContaminatedAroundPlayerTiny;
  251. protected PlayerStat<float> m_StatWater;
  252. protected PlayerStat<float> m_StatToxicity;
  253. protected PlayerStat<float> m_StatEnergy;
  254. protected PlayerStat<float> m_StatHeatComfort;
  255. protected PlayerStat<float> m_StatTremor;
  256. protected PlayerStat<int> m_StatWet
  257. protected PlayerStat<int> m_StatBloodType
  258. protected PlayerStat<float> m_StatDiet
  259. protected PlayerStat<float> m_StatStamina
  260. protected PlayerStat<float> m_StatSpecialty
  261. protected PlayerStat<float> m_StatHeatBuffer
  262. //!effect widgets
  263. protected GameplayEffectWidgets_base m_EffectWidgets;
  264. protected ref array<int> m_ProcessAddEffectWidgets;
  265. protected ref array<int> m_ProcessRemoveEffectWidgets;
  266. //postprocess processing
  267. protected ref array<int> m_ProcessAddGlassesEffects;
  268. protected ref array<int> m_ProcessRemoveGlassesEffects;
  269. protected EMedicalDrugsType m_MedicalDrugsActive;
  270. //! invokers
  271. protected ref ScriptInvoker m_OnUnconsciousStart;
  272. protected ref ScriptInvoker m_OnUnconsciousStop;
  273. private ref map<eAgents, float> m_BloodyHandsPenaltyChancePerAgent;
  274. void PlayerBase()
  275. {
  276. Init();
  277. }
  278. void Init()
  279. {
  280. SetEventMask(EntityEvent.INIT|EntityEvent.POSTFRAME|EntityEvent.FRAME);
  281. m_StoreLoadVersion = 0;
  282. m_IsCraftingReady = false;
  283. m_Recipes = new array<int>;
  284. m_LastShavedSeconds = 0;
  285. m_BloodType = 0;
  286. m_HasBloodTypeVisible = false;
  287. m_LifeSpanState = 0;
  288. m_LifespanLevelLocal = -1;
  289. m_CorpseState = 0;
  290. m_CorpseStateLocal = 0;
  291. m_HasBloodyHandsVisible = 0;
  292. m_PlayerLoaded = false;
  293. m_PlayerSelected = false;
  294. m_ProcessUIWarning = false;
  295. m_FlagRaisingTendency = true;
  296. m_LiquidTendencyDrain = false;
  297. m_UAParamMessage = new Param1<string>("");
  298. m_UnconParam = new Param1<float>(0);
  299. m_DeathDarkeningParam = new Param1<float>(0);
  300. m_UAParam = new Param2<int,int>(0,0);
  301. m_UAProgressParam = new Param2<float,float>(0,0);
  302. m_QuickBarBase = new QuickBarBase(this);
  303. m_QuickBarBonus = Math.Max(ConfigGetInt("quickBarBonus"), 0);
  304. m_CargoLoad = 0;
  305. m_VisibilityCoef = 1.0;
  306. m_Hud = GetGame().GetMission().GetHud();
  307. m_RecipePick = 0;
  308. m_ActionQBControl = false;
  309. m_QuickBarHold = false;
  310. m_HideHairAnimated = true;
  311. m_WorkingNVGHeadset = false;
  312. m_LoweredNVGHeadset = false;
  313. m_AreHandsLocked = false;
  314. m_ItemsToDelete = new array<EntityAI>;
  315. m_AnimCommandStarting = HumanMoveCommandID.None;
  316. m_EmptyGloves = new HiddenSelectionsData(ConfigGetString("emptyGloves"));
  317. m_CanDisplayHitEffectPPE = true;
  318. m_HeadingRestrictData = new HeadingRestrictData();
  319. #ifdef DIAG_DEVELOPER
  320. m_CanBeTargetedDebug = true;
  321. //RegisterNetSyncVariableBool("m_CanBeTargetedDebug");
  322. #endif
  323. m_AnalyticsTimer = new Timer(CALL_CATEGORY_SYSTEM);
  324. m_StaminaHandler = new StaminaHandler(this);//current stamina calculation
  325. m_InjuryHandler = new InjuryAnimationHandler(this);
  326. m_ShockHandler = new ShockHandler(this); //New shock handler
  327. m_HCAnimHandler = new HeatComfortAnimHandler(this);
  328. m_PlayerStats = new PlayerStats(this);//player stats
  329. m_ArrowManager = new ArrowManagerPlayer(this);
  330. if (GetGame().IsServer())
  331. {
  332. m_PlayerStomach = new PlayerStomach(this);
  333. m_NotifiersManager = new NotifiersManager(this); // player notifiers
  334. m_AgentPool = new PlayerAgentPool(this); // agent pool manager
  335. m_BleedingManagerServer = new BleedingSourcesManagerServer(this);
  336. m_Environment = new Environment(this);//environment effects on player
  337. m_ModifiersManager = new ModifiersManager(this); // player modifiers
  338. m_PlayerSoundManagerServer = new PlayerSoundManagerServer(this);
  339. m_VirtualHud = new VirtualHud(this);
  340. m_AdminLog = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
  341. }
  342. m_SymptomManager = new SymptomManager(this); // state manager
  343. m_ModuleRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  344. m_TrasferValues = new TransferValues(this);
  345. m_EmoteManager = new EmoteManager(this);
  346. m_SoftSkillsManager = new SoftSkillsManager(this);//Soft Skills calculation
  347. m_WeaponManager = new WeaponManager(this);
  348. m_DebugMonitorValues = new DebugMonitorValues(this);
  349. m_RGSManager = new RandomGeneratorSyncManager(this);
  350. if (!GetGame().IsDedicatedServer())
  351. {
  352. m_MeleeDebug = false;
  353. m_UALastMessage = "";
  354. m_UALastMessageTimer = new Timer;
  355. m_InventoryActionHandler = new InventoryActionHandler(this);
  356. m_BleedingManagerRemote = new BleedingSourcesManagerRemote(this);
  357. m_PlayerSoundManagerClient = new PlayerSoundManagerClient(this);
  358. m_StanceIndicator = new StanceIndicator(this);
  359. m_ActionsInitialize = false;
  360. ClientData.AddPlayerBase(this);
  361. m_ProcessAddEffectWidgets = new array<int>;
  362. m_ProcessRemoveEffectWidgets = new array<int>;
  363. m_ActiveNVTypes = new array<int>;
  364. m_ProcessAddGlassesEffects = new array<int>;
  365. m_ProcessRemoveGlassesEffects = new array<int>;
  366. }
  367. m_ActionManager = NULL;
  368. m_ConfigEmotesProfile = PluginConfigEmotesProfile.Cast(GetPlugin(PluginConfigEmotesProfile));
  369. if (GetDayZGame().IsDebug())
  370. {
  371. PluginConfigDebugProfileFixed m_ConfigDebugProfileFixed = PluginConfigDebugProfileFixed.Cast(GetPlugin(PluginConfigDebugProfileFixed));
  372. PluginConfigDebugProfile m_ConfigDebugProfile = PluginConfigDebugProfile.Cast(GetPlugin(PluginConfigDebugProfile));
  373. PluginDeveloper m_Developer = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  374. PlayerBase player = this;
  375. if (m_ConfigDebugProfile)
  376. {
  377. string default_preset = m_ConfigDebugProfile.GetDefaultPreset();
  378. if (player && default_preset != "")
  379. {
  380. TStringArray preset_array = new TStringArray;
  381. m_ConfigDebugProfileFixed.GetPresetItems(default_preset, preset_array);
  382. bool is_preset_fixed = true;
  383. if (preset_array.Count() == 0)
  384. {
  385. m_ConfigDebugProfile.GetPresetItems(default_preset, preset_array);
  386. is_preset_fixed = false;
  387. }
  388. if (preset_array.Count() > 0)
  389. {
  390. m_Developer.ClearInventory(player);
  391. for (int i = 0; i < preset_array.Count(); i++)
  392. {
  393. float health = -1;
  394. int quantity = -1;
  395. if (is_preset_fixed)
  396. {
  397. health = m_ConfigDebugProfileFixed.GetItemHealth(default_preset, i);
  398. quantity = m_ConfigDebugProfileFixed.GetItemQuantity(default_preset, i);
  399. }
  400. else
  401. {
  402. health = m_ConfigDebugProfile.GetItemHealth(default_preset, i);
  403. quantity = m_ConfigDebugProfile.GetItemQuantity(default_preset, i);
  404. }
  405. m_Developer.SpawnEntityInPlayerInventory(player, preset_array.Get(i), health, quantity);
  406. }
  407. }
  408. }
  409. }
  410. }
  411. m_MedicalDrugsActive = EMedicalDrugsType.NONE;
  412. m_MapNavigationBehaviour = new MapNavigationBehaviour(this);
  413. m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
  414. m_ModuleLifespan = PluginLifespan.Cast(GetPlugin(PluginLifespan));
  415. m_BleedingSourcesLow = new array<string>;
  416. m_BleedingSourcesLow.Insert("RightToeBase");
  417. m_BleedingSourcesLow.Insert("RightFoot");
  418. m_BleedingSourcesLow.Insert("LeftToeBase");
  419. m_BleedingSourcesLow.Insert("LeftFoot");
  420. m_BleedingSourcesLow.Insert("RightUpLegRoll");
  421. m_BleedingSourcesLow.Insert("RightUpLeg");
  422. m_BleedingSourcesLow.Insert("RightLegRoll");
  423. m_BleedingSourcesLow.Insert("RightLeg");
  424. m_BleedingSourcesLow.Insert("LeftUpLegRoll");
  425. m_BleedingSourcesLow.Insert("LeftUpLeg");
  426. m_BleedingSourcesLow.Insert("LeftLegRoll");
  427. m_BleedingSourcesLow.Insert("LeftLeg");
  428. m_BleedingSourcesUp = new array<string>;
  429. m_BleedingSourcesUp.Insert("RightForeArmRoll");
  430. m_BleedingSourcesUp.Insert("LeftForeArmRoll");
  431. m_BleedingSourcesUp.Insert("RightForeArm");
  432. m_BleedingSourcesUp.Insert("RightArmRoll");
  433. m_BleedingSourcesUp.Insert("RightArm");
  434. m_BleedingSourcesUp.Insert("RightShoulder");
  435. m_BleedingSourcesUp.Insert("LeftForeArm");
  436. m_BleedingSourcesUp.Insert("LeftArmRoll");
  437. m_BleedingSourcesUp.Insert("LeftArm");
  438. m_BleedingSourcesUp.Insert("LeftShoulder");
  439. m_BleedingSourcesUp.Insert("Spine3");
  440. m_BleedingSourcesUp.Insert("Spine2");
  441. m_BleedingSourcesUp.Insert("Spine1");
  442. m_BleedingSourcesUp.Insert("Spine");
  443. m_BleedingSourcesUp.Insert("Pelvis");
  444. m_BleedingSourcesUp.Insert("Neck");
  445. RegisterNetSyncVariableInt("m_PersistentFlags", 0, 1<<(EnumTools.GetEnumSize(PersistentFlag) + 1));
  446. RegisterNetSyncVariableInt("m_LifeSpanState", LifeSpanState.BEARD_NONE, LifeSpanState.COUNT);
  447. RegisterNetSyncVariableInt("m_BloodType", 0, 128);
  448. RegisterNetSyncVariableInt("m_ShockSimplified",0, SIMPLIFIED_SHOCK_CAP);
  449. RegisterNetSyncVariableInt("m_SoundEvent",0, EPlayerSoundEventID.ENUM_COUNT - 1);
  450. RegisterNetSyncVariableInt("m_SoundEventParam", 0, ((EPlayerSoundEventParam.ENUM_COUNT - 1) * 2) - 1);
  451. RegisterNetSyncVariableInt("m_StaminaState",0, eStaminaState.COUNT - 1);
  452. RegisterNetSyncVariableInt("m_BleedingBits");
  453. RegisterNetSyncVariableInt("m_Shakes", 0, SHAKE_LEVEL_MAX);
  454. RegisterNetSyncVariableInt("m_BreathVapour", 0, BREATH_VAPOUR_LEVEL_MAX);
  455. RegisterNetSyncVariableInt("m_HealthLevel", eInjuryHandlerLevels.PRISTINE, eInjuryHandlerLevels.RUINED);
  456. RegisterNetSyncVariableInt("m_MixedSoundStates", 0, eMixedSoundStates.COUNT - 1);
  457. RegisterNetSyncVariableInt("m_CorpseState",-PlayerConstants.CORPSE_STATE_DECAYED,PlayerConstants.CORPSE_STATE_DECAYED);//do note the negative min, negative sign denotes a special meaning
  458. RegisterNetSyncVariableInt("m_RefreshAnimStateIdx",0,3);
  459. RegisterNetSyncVariableInt("m_BrokenLegState", -eBrokenLegs.BROKEN_LEGS_SPLINT, eBrokenLegs.BROKEN_LEGS_SPLINT);
  460. RegisterNetSyncVariableInt("m_SyncedModifiers", 0, ((eModifierSyncIDs.LAST_INDEX - 1) * 2) - 1);
  461. RegisterNetSyncVariableInt("m_HasBloodyHandsVisible", 0, eBloodyHandsTypes.LAST_INDEX - 1);
  462. RegisterNetSyncVariableInt("m_ActionSoundCategoryHash");
  463. RegisterNetSyncVariableInt("m_PerformedAnimActionID", -1, 2048); // generous upper limit for modding reasons
  464. RegisterNetSyncVariableInt("m_ActivePrimarySymptomID", 0, SymptomIDs.LAST_INDEX);
  465. RegisterNetSyncVariableInt("m_HeatBufferStage", 0, HeatBufferMdfr.NUMBER_OF_STAGES - 1);
  466. RegisterNetSyncVariableFloat("m_HeatBufferDynamicMax", 0.0, 1.0, 2);
  467. RegisterNetSyncVariableBool("m_IsUnconscious");
  468. RegisterNetSyncVariableBool("m_IsRestrained");
  469. RegisterNetSyncVariableBool("m_IsInWater");
  470. RegisterNetSyncVariableBool("m_InsideEffectArea");
  471. RegisterNetSyncVariableBool("m_HasBloodTypeVisible");
  472. RegisterNetSyncVariableBool("m_IsRestrainStarted");
  473. RegisterNetSyncVariableBool("m_IsRestrainPrelocked");
  474. RegisterNetSyncVariableBool("m_HasHeatBuffer");
  475. RegisterNetSyncVariableBool("m_IsInColdArea");
  476. RegisterNetSyncVariableFloat("m_CurrentShock"); //Register shock synchronized variable
  477. m_OriginalSlidePoseAngle = GetSlidePoseAngle();
  478. //! sets default hit position and cache it here (mainly for impact particles)
  479. m_DefaultHitPosition = SetDefaultHitPosition(GetDayZPlayerType().GetDefaultHitPositionComponent());
  480. m_DecayedTexture = ConfigGetString("decayedTexture");
  481. m_FliesIndex = -1;
  482. m_BloodyHandsPenaltyChancePerAgent = new map<eAgents, float>();
  483. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(this.OnPlayerLoaded);
  484. }
  485. ScriptInvoker GetOnUnconsciousStart()
  486. {
  487. if (!m_OnUnconsciousStart)
  488. m_OnUnconsciousStart = new ScriptInvoker();
  489. return m_OnUnconsciousStart;
  490. }
  491. ScriptInvoker GetOnUnconsciousStop()
  492. {
  493. if (!m_OnUnconsciousStop)
  494. m_OnUnconsciousStop = new ScriptInvoker();
  495. return m_OnUnconsciousStop;
  496. }
  497. void AddMedicalDrugsInUse(EMedicalDrugsType drugType)
  498. {
  499. if ((m_MedicalDrugsActive & drugType) != drugType)
  500. m_MedicalDrugsActive = m_MedicalDrugsActive | drugType;
  501. }
  502. void RemoveMedicalDrugsInUse(EMedicalDrugsType drugType)
  503. {
  504. if ((m_MedicalDrugsActive & drugType) == drugType)
  505. m_MedicalDrugsActive &= ~drugType;
  506. }
  507. bool IsChelationActive()
  508. {
  509. return (m_MedicalDrugsActive & EMedicalDrugsType.CHELATION) == EMedicalDrugsType.CHELATION;
  510. }
  511. bool IsAntibioticsActive()
  512. {
  513. return (m_MedicalDrugsActive & EMedicalDrugsType.ANTIBIOTICS) == EMedicalDrugsType.ANTIBIOTICS;
  514. }
  515. void SetSoundCategoryHash(int hash)
  516. {
  517. m_ActionSoundCategoryHash = hash;
  518. SetSynchDirty();
  519. }
  520. void SetPerformedActionID(int id)
  521. {
  522. m_PerformedAnimActionID = id;
  523. SetSynchDirty();
  524. }
  525. int GetPerformedActionID()
  526. {
  527. return m_PerformedAnimActionID;
  528. }
  529. void SetActivePrimarySymptomID(SymptomIDs id)
  530. {
  531. m_ActivePrimarySymptomID = id;
  532. SetSynchDirty();
  533. }
  534. SymptomIDs GetActivePrimarySymptomID()
  535. {
  536. return m_ActivePrimarySymptomID;
  537. }
  538. void RequestTriggerEffect(EffectTrigger trigger, int ppeIdx = -1, int aroundId = ParticleList.CONTAMINATED_AREA_GAS_AROUND, int tinyId = ParticleList.CONTAMINATED_AREA_GAS_TINY, string soundset = "", bool partDynaUpdate = false, int newBirthRate = 0, bool forceUpdate = false)
  539. {
  540. //do note multiple triggers can be calling this method within a single frame depending on the contaminated area setup and dynamic gameplay events(such as gas grenades being deployed)
  541. if (!m_InsideEffectArea)
  542. return;
  543. bool allow = false;
  544. if (!m_CurrentEffectTrigger)
  545. {
  546. allow = true;
  547. }
  548. else if (trigger == m_CurrentEffectTrigger && forceUpdate)
  549. {
  550. allow = true;
  551. //Print("ON Enabling effect FORCED " + trigger);
  552. }
  553. else if (trigger.GetEffectsPriority() > m_CurrentEffectTrigger.GetEffectsPriority())
  554. {
  555. RemoveCurrentEffectTrigger();
  556. allow = true;
  557. }
  558. if (allow)
  559. {
  560. /*
  561. Print("--------------------------------------------------");
  562. Print("ON Enabling effect " + trigger);
  563. Print("------------> soundset " + soundset);
  564. Print("--------------------------------------------------");
  565. */
  566. m_CurrentEffectTrigger = trigger;
  567. SetContaminatedEffectEx( true, ppeIdx, aroundId, tinyId, soundset,partDynaUpdate, newBirthRate );
  568. }
  569. }
  570. void RemoveCurrentEffectTrigger()
  571. {
  572. if (m_CurrentEffectTrigger)
  573. {
  574. /*
  575. Print("--------------------------------------------------");
  576. Print("OFF Disabling effect");
  577. Print("--------------------------------------------------");
  578. */
  579. SetContaminatedEffectEx( false, m_CurrentEffectTrigger.m_PPERequester );
  580. m_CurrentEffectTrigger = null;
  581. }
  582. }
  583. void IncreaseContaminatedAreaCount()
  584. {
  585. if (m_ContaminatedAreaCount == 0)
  586. OnContaminatedAreaEnterServer();
  587. m_ContaminatedAreaCount++;
  588. }
  589. void DecreaseContaminatedAreaCount()
  590. {
  591. m_ContaminatedAreaCount--;
  592. if (m_ContaminatedAreaCount <= 0)
  593. {
  594. m_ContaminatedAreaCount = 0;
  595. OnContaminatedAreaExitServer();
  596. }
  597. }
  598. void IncreaseEffectAreaCount()
  599. {
  600. if (m_EffectAreaCount == 0)
  601. {
  602. m_InsideEffectArea = true;
  603. SetSynchDirty();
  604. OnPlayerIsNowInsideEffectAreaBeginServer();
  605. }
  606. m_EffectAreaCount++;
  607. }
  608. void DecreaseEffectAreaCount()
  609. {
  610. m_EffectAreaCount--;
  611. if (m_EffectAreaCount <= 0)
  612. {
  613. m_EffectAreaCount = 0;
  614. m_InsideEffectArea = false;
  615. SetSynchDirty();
  616. OnPlayerIsNowInsideEffectAreaEndServer();
  617. }
  618. }
  619. void SetInEffectAreaTypeFlag(EEffectAreaType flag)
  620. {
  621. int areaCount = m_EffectAreaOverlap.Get(flag);
  622. if (areaCount > 0)
  623. m_EffectAreaOverlap.Set(flag, m_EffectAreaOverlap.Get(flag) + 1);
  624. else
  625. m_EffectAreaOverlap.Set(flag, 1);
  626. m_InEffectAreaType |= flag;
  627. }
  628. void UnsetInEffectAreaTypeFlag(EEffectAreaType flag)
  629. {
  630. int areaCount = m_EffectAreaOverlap.Get(flag);
  631. if (areaCount > 1)
  632. m_EffectAreaOverlap.Set(flag, m_EffectAreaOverlap.Get(flag) - 1);
  633. else
  634. {
  635. m_EffectAreaOverlap.Set(flag, 0);
  636. m_InEffectAreaType &= ~flag;
  637. }
  638. }
  639. bool IsInEffectArea(EEffectAreaType area)
  640. {
  641. if (m_InEffectAreaType & area)
  642. return true;
  643. return false;
  644. }
  645. // Server side update when player is present in any effect area
  646. protected void OnUpdateEffectAreaServer(float timeSlice)
  647. {
  648. float timeSpent;
  649. if (IsInEffectArea(EEffectAreaType.HOT_SPRING))
  650. {
  651. float waterLevel = GetCurrentWaterLevel();
  652. if (waterLevel > 0.5)
  653. {
  654. timeSpent = m_EffectAreaTimeToTick.Get(EEffectAreaType.HOT_SPRING);
  655. timeSpent += timeSlice;
  656. if (timeSpent > HotSpringTrigger.HEAT_DAMAGE_TICK_TIME)
  657. {
  658. m_EffectAreaTimeToTick.Set(EEffectAreaType.HOT_SPRING, 0);
  659. HotSpringTrigger.ApplyEffects(this);
  660. }
  661. else
  662. m_EffectAreaTimeToTick.Set(EEffectAreaType.HOT_SPRING, timeSpent);
  663. }
  664. }
  665. if (IsInEffectArea(EEffectAreaType.VOLCANIC))
  666. {
  667. timeSpent = m_EffectAreaTimeToTick.Get(EEffectAreaType.VOLCANIC);
  668. timeSpent += timeSlice;
  669. if (timeSpent > VolcanicTrigger.HEAT_DAMAGE_TICK_TIME)
  670. {
  671. m_EffectAreaTimeToTick.Set(EEffectAreaType.VOLCANIC, 0);
  672. VolcanicTrigger.ApplyEffects(this);
  673. }
  674. else
  675. m_EffectAreaTimeToTick.Set(EEffectAreaType.VOLCANIC, timeSpent);
  676. }
  677. }
  678. protected void OnContaminatedAreaEnterServer()
  679. {
  680. GetModifiersManager().ActivateModifier( eModifiers.MDF_AREAEXPOSURE );
  681. //Print("Contaminated ENTERED <------------------------------------------------------------- FINAL");
  682. }
  683. protected void OnContaminatedAreaExitServer()
  684. {
  685. GetModifiersManager().DeactivateModifier( eModifiers.MDF_AREAEXPOSURE );
  686. //Print("Contaminated LEFT <------------------------------------------------------------- FINAL");
  687. }
  688. protected void OnPlayerIsNowInsideEffectAreaBeginServer()
  689. {
  690. //Print("ANY EFFECT AREA ENTERED <------------------------------------------------------------- FINAL");
  691. }
  692. protected void OnPlayerIsNowInsideEffectAreaEndServer()
  693. {
  694. //Print("ANY EFFECT AREA LEFT <------------------------------------------------------------- FINAL");
  695. }
  696. protected void OnPlayerIsNowInsideEffectAreaBeginClient()
  697. {
  698. //Print("ANY EFFECT AREA ENTERED CLIENT <------------------------------------------------------------- FINAL");
  699. }
  700. protected void OnPlayerIsNowInsideEffectAreaEndClient()
  701. {
  702. RemoveCurrentEffectTrigger();
  703. //Print("ANY EFFECT AREA LEFT CLIENT <------------------------------------------------------------- FINAL");
  704. }
  705. //! Returns item that's on this player's attachment slot. Parameter slot_type should be a string from config parameter 'itemInfo[]' like "Legs", "Headgear" and so on.
  706. ItemBase GetItemOnSlot(string slot_type)
  707. {
  708. int slot_id = InventorySlots.GetSlotIdFromString(slot_type);
  709. EntityAI item_EAI = this.GetInventory().FindAttachment(slot_id);
  710. ItemBase item_IB = ItemBase.Cast(item_EAI);
  711. if (item_EAI && !item_IB)
  712. {
  713. string str = "Warning! GetItemOnSlot() >> found item on slot " + slot_type + " can't be cast to ItemBase! Found item is " + item_EAI.GetType() + " and the player is " + GetType() + "!";
  714. Error(str);
  715. return null;
  716. }
  717. return item_IB;
  718. }
  719. //! Returns item on player's head. For an example, a headtorch.
  720. ItemBase GetItemOnHead()
  721. {
  722. return GetItemOnSlot("Headgear");
  723. }
  724. override int GetQuickBarBonus()
  725. {
  726. return m_QuickBarBonus;
  727. }
  728. //--------------------------------------------------------------------------
  729. // Inventory overrides
  730. //--------------------------------------------------------------------------
  731. override bool CanDropEntity (notnull EntityAI item)
  732. {
  733. if (GetInventory().HasInventoryReservation(item, null))
  734. {
  735. return false;
  736. }
  737. if (IsRestrained())
  738. {
  739. if (GetHumanInventory().GetEntityInHands() == item)
  740. return false;
  741. }
  742. return true;
  743. }
  744. //--------------------------------------------------------------------------
  745. // PLAYER DAMAGE EVENT HANDLING
  746. //--------------------------------------------------------------------------
  747. int GetBreathVapourLevel()
  748. {
  749. return m_BreathVapour;
  750. }
  751. // adds state to and syncs sound states variable which is used to generate sound client-side
  752. void UnsetMixedSoundState(eMixedSoundStates state)
  753. {
  754. int bit_mask_remove = ~state;
  755. eMixedSoundStates new_states = m_MixedSoundStates & bit_mask_remove;
  756. if (new_states != m_MixedSoundStates)
  757. {
  758. m_MixedSoundStates = new_states;
  759. SetSynchDirty();
  760. }
  761. }
  762. // adds state to and syncs sound states variable which is used to generate sound client-side
  763. void SetMixedSoundState(eMixedSoundStates state)
  764. {
  765. eMixedSoundStates new_states = m_MixedSoundStates | state;
  766. if (new_states != m_MixedSoundStates)
  767. {
  768. m_MixedSoundStates = new_states;
  769. SetSynchDirty();
  770. }
  771. }
  772. override bool IsPlayer()
  773. {
  774. return true;
  775. }
  776. bool IsBleeding()
  777. {
  778. return (m_BleedingBits != 0);
  779. }
  780. void SetBleedingBits(int bits)
  781. {
  782. if (m_BleedingBits != bits)
  783. {
  784. if (m_BleedingBits == 0)
  785. {
  786. OnBleedingBegin();
  787. }
  788. else if (bits == 0)
  789. {
  790. OnBleedingEnd();
  791. }
  792. }
  793. m_BleedingBits = bits;
  794. SetSynchDirty();
  795. }
  796. int GetBleedingBits()
  797. {
  798. return m_BleedingBits;
  799. }
  800. void IncreaseDiseaseCount()
  801. {
  802. m_DiseaseCount++;
  803. }
  804. void DecreaseDiseaseCount()
  805. {
  806. m_DiseaseCount--;
  807. }
  808. void IncreaseHealingsCount()
  809. {
  810. m_HealingsCount++;
  811. }
  812. void DecreaseHealingsCount()
  813. {
  814. m_HealingsCount--;
  815. }
  816. bool HasHealings()
  817. {
  818. return m_HealingsCount;//0 for no healings, 1+ for healings, gets truncated to 1
  819. }
  820. bool HasDisease()
  821. {
  822. return m_DiseaseCount;//0 for no disease, 1+ for disease, gets truncated to 1
  823. }
  824. EPulseType GetPulseType()
  825. {
  826. return m_PulseType;
  827. }
  828. void SetPulseType(EPulseType pulse_type)
  829. {
  830. m_PulseType = pulse_type;
  831. }
  832. void QueueAddEffectWidget(array<int> effects)
  833. {
  834. m_ProcessAddEffectWidgets.InsertArray(effects);
  835. }
  836. void QueueRemoveEffectWidget(array<int> effects)
  837. {
  838. m_ProcessRemoveEffectWidgets.InsertArray(effects);
  839. }
  840. void QueueAddGlassesEffect(int id)
  841. {
  842. m_ProcessAddGlassesEffects.Insert(id);
  843. }
  844. void QueueRemoveGlassesEffect(int id)
  845. {
  846. m_ProcessRemoveGlassesEffects.Insert(id);
  847. }
  848. DamageDealtEffect GetDamageDealtEffect()
  849. {
  850. return m_DamageDealtEffect;
  851. }
  852. override void SpawnDamageDealtEffect()
  853. {
  854. if (m_DamageDealtEffect)
  855. {
  856. delete m_DamageDealtEffect;
  857. }
  858. if (m_CanDisplayHitEffectPPE)
  859. {
  860. m_DamageDealtEffect = new DamageDealtEffect();
  861. }
  862. }
  863. void SpawnDamageDealtEffect2(Param param1 = null, Param param2 = null)
  864. {
  865. if (m_EffectRadial)
  866. {
  867. delete m_EffectRadial;
  868. }
  869. m_EffectRadial = new EffectRadial(param1,param2);
  870. }
  871. FlashbangEffect GetFlashbangEffect()
  872. {
  873. return m_FlashbangEffect;
  874. }
  875. void SpawnFlashbangEffect(PlayerBase player, bool visual)
  876. {
  877. if (m_FlashbangEffect)
  878. {
  879. m_FlashbangEffect.Stop();
  880. delete m_FlashbangEffect;
  881. }
  882. m_FlashbangEffect = new FlashbangEffect(player, visual);
  883. }
  884. ShockDealtEffect GetShockEffect()
  885. {
  886. return m_ShockDealtEffect;
  887. }
  888. void SpawnShockEffect(float intensity_max)
  889. {
  890. if (m_ShockDealtEffect)
  891. {
  892. delete m_ShockDealtEffect;
  893. }
  894. m_ShockDealtEffect = new ShockDealtEffect(intensity_max);
  895. }
  896. override void EEKilled(Object killer)
  897. {
  898. //Print(Object.GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " event EEKilled, player has died at STS=" + GetSimulationTimeStamp());
  899. if (m_AdminLog)
  900. {
  901. m_AdminLog.PlayerKilled(this, killer);
  902. }
  903. if (GetBleedingManagerServer())
  904. delete GetBleedingManagerServer();
  905. // kill character in database
  906. if (GetHive())
  907. {
  908. GetHive().CharacterKill(this);
  909. }
  910. // disable voice communication
  911. GetGame().EnableVoN(this, false);
  912. if (!GetGame().IsDedicatedServer())
  913. ClientData.RemovePlayerBase(this);
  914. GetSymptomManager().OnPlayerKilled();
  915. if (GetEconomyProfile() && !m_CorpseProcessing && m_CorpseState == 0 && GetGame().GetMission().InsertCorpse(this))
  916. {
  917. m_CorpseProcessing = true;
  918. //Print("EEKilled - processing corpse");
  919. }
  920. if (GetGame().IsMultiplayer() && GetGame().IsServer())
  921. {
  922. if (GetGame().GetMission())
  923. {
  924. GetGame().GetMission().SyncRespawnModeInfo(GetIdentity());
  925. }
  926. }
  927. super.EEKilled(killer);
  928. }
  929. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  930. {
  931. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  932. if (m_AdminLog)
  933. {
  934. m_AdminLog.PlayerHitBy(damageResult, damageType, this, source, component, dmgZone, ammo);
  935. }
  936. if (damageResult != null && damageResult.GetDamage(dmgZone, "Shock") > 0)
  937. {
  938. m_LastShockHitTime = GetGame().GetTime();
  939. if (!IsUnconscious())
  940. {
  941. if (GetGame().ConfigIsExisting("cfgAmmo " + ammo + " unconRefillModifier"))
  942. {
  943. m_UnconRefillModifier = GetGame().ConfigGetInt("cfgAmmo " + ammo + " unconRefillModifier");
  944. }
  945. else
  946. {
  947. m_UnconRefillModifier = 1;
  948. }
  949. }
  950. }
  951. //! DamageType.EXPLOSION & FlashGrenade
  952. if (damageType == DamageType.EXPLOSION && ammo == "FlashGrenade_Ammo")
  953. {
  954. GetStaminaHandler().DepleteStamina(EStaminaModifiers.OVERALL_DRAIN);
  955. }
  956. //new bleeding computation
  957. //---------------------------------------
  958. if (damageResult != null && GetBleedingManagerServer())
  959. {
  960. float dmg = damageResult.GetDamage(dmgZone, "Blood");
  961. GetBleedingManagerServer().ProcessHit(dmg, source, component, dmgZone, ammo, modelPos);
  962. }
  963. //---------------------------------------
  964. #ifdef DIAG_DEVELOPER
  965. if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DEBUG))
  966. Print("EEHitBy() | " + GetDisplayName() + " hit by " + source.GetDisplayName() + " to " + dmgZone);
  967. PluginRemotePlayerDebugServer plugin_remote_server = PluginRemotePlayerDebugServer.Cast(GetPlugin(PluginRemotePlayerDebugServer));
  968. if (plugin_remote_server)
  969. {
  970. plugin_remote_server.OnDamageEvent(this, damageResult);
  971. }
  972. #endif
  973. if (GetGame().IsDebugMonitor())
  974. m_DebugMonitorValues.SetLastDamage(source.GetDisplayName());
  975. if (m_ActionManager)
  976. m_ActionManager.Interrupt();
  977. int transferShockToDamageCoef = g_Game.ConfigGetInt(string.Format("%1 %2 DamageApplied transferShockToDamage", CFG_AMMO, ammo));
  978. if (transferShockToDamageCoef == 1)
  979. {
  980. //Print("PlayerBase | EEHitBy | nonlethal hit");
  981. AddHealth("", "Health", -ConvertNonlethalDamage(damageResult.GetDamage(dmgZone, "Shock"), damageType));
  982. if (dmgZone != "Head")
  983. AddHealth(dmgZone, "Health", -damageResult.GetDamage(dmgZone, "Shock")); //Also deal damage to zone health, no dmg reduction
  984. }
  985. if (GetGame().IsServer())
  986. {
  987. if (GetHealth("RightLeg", "Health") <= 1 || GetHealth("LeftLeg", "Health") <= 1 || GetHealth("RightFoot", "Health") <= 1 || GetHealth("LeftFoot", "Health") <= 1)
  988. {
  989. if (GetModifiersManager().IsModifierActive(eModifiers.MDF_BROKEN_LEGS))//effectively resets the modifier
  990. {
  991. GetModifiersManager().DeactivateModifier(eModifiers.MDF_BROKEN_LEGS);
  992. }
  993. GetModifiersManager().ActivateModifier(eModifiers.MDF_BROKEN_LEGS);
  994. }
  995. if (ammo == "Bullet_CupidsBolt" && IsAlive())
  996. {
  997. DamageSystem.ResetAllZones(this);
  998. m_ModifiersManager.ResetAll();
  999. m_ModifiersManager.ActivateModifier(eModifiers.MDF_IMMUNITYBOOST);
  1000. // bleeding sources
  1001. if (m_BleedingManagerServer)
  1002. m_BleedingManagerServer.RemoveAllSources();
  1003. // Stats
  1004. if (GetPlayerStats())
  1005. {
  1006. int bloodType = GetStatBloodType().Get();
  1007. float energyValue = GetStatEnergy().Get();
  1008. float waterValue = GetStatWater().Get();
  1009. float heatBuffer = GetStatHeatBuffer().Get();
  1010. float heatComfort = GetStatHeatComfort().Get();
  1011. GetPlayerStats().ResetAllStats();
  1012. GetStatBloodType().Set(bloodType);
  1013. GetStatWater().Set(waterValue);
  1014. GetStatEnergy().Set(energyValue);
  1015. GetStatHeatBuffer().Set(heatBuffer);
  1016. GetStatHeatComfort().Set(heatComfort);
  1017. }
  1018. // Agents
  1019. if (m_AgentPool)
  1020. m_AgentPool.RemoveAllAgents();
  1021. if (m_StaminaHandler)
  1022. m_StaminaHandler.SetStamina(GameConstants.STAMINA_MAX);
  1023. // uncon
  1024. if (IsUnconscious())
  1025. DayZPlayerSyncJunctures.SendPlayerUnconsciousness(this, false);
  1026. }
  1027. }
  1028. m_ShockHandler.CheckValue(true);
  1029. //analytics
  1030. GetGame().GetAnalyticsServer().OnEntityHit(source, this);
  1031. }
  1032. override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
  1033. {
  1034. super.EEHitByRemote(damageType, source, component, dmgZone, ammo, modelPos);
  1035. if (m_MeleeFightLogic.IsInBlock())
  1036. {
  1037. EffectSound sound = SEffectManager.PlaySoundOnObject("BlockingAttack_SoundSet", this);
  1038. sound.SetAutodestroy(true);
  1039. }
  1040. }
  1041. override void EEDelete(EntityAI parent)
  1042. {
  1043. SEffectManager.DestroyEffect(m_FliesEff);
  1044. StopSoundSet(m_SoundFliesEffect);
  1045. if (GetArrowManager())
  1046. GetArrowManager().ClearArrows();
  1047. }
  1048. override protected float ConvertNonlethalDamage(float damage, DamageType damageType)
  1049. {
  1050. if (damageType == DamageType.FIRE_ARM)
  1051. return damage * GameConstants.NL_DAMAGE_FIREARM_CONVERSION_PLAYERS;
  1052. return super.ConvertNonlethalDamage(damage, damageType);
  1053. }
  1054. /** Call only on client or single player PlayerBase
  1055. * (as GetGame().GetPlayer())
  1056. */
  1057. override void OnReceivedHit(ImpactEffectsData hitData)
  1058. {
  1059. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  1060. {
  1061. float shakeStrength = Math.InverseLerp(0, 500, hitData.m_InSpeed.Length());
  1062. GetCurrentCamera().SpawnCameraShake(shakeStrength);
  1063. OnPlayerRecievedHit();
  1064. }
  1065. if (hitData.m_AmmoType == "Bullet_CupidsBolt")
  1066. Ammo_CupidsBolt.PlayOnHitParticle(hitData.m_Position);
  1067. }
  1068. // DEPRECATED by method OnReceivedHit
  1069. override void OnPlayerRecievedHit()
  1070. {
  1071. #ifndef NO_GUI
  1072. if (m_MeleeFightLogic.IsInBlock())
  1073. {
  1074. EffectSound sound = SEffectManager.PlaySoundOnObject("BlockingAttack_SoundSet", this);
  1075. sound.SetAutodestroy(true);
  1076. return;
  1077. }
  1078. SpawnDamageDealtEffect();
  1079. CachedObjectsParams.PARAM2_FLOAT_FLOAT.param1 = 32;
  1080. CachedObjectsParams.PARAM2_FLOAT_FLOAT.param2 = 0.3;
  1081. SpawnDamageDealtEffect2(CachedObjectsParams.PARAM2_FLOAT_FLOAT);
  1082. CloseMapEx(true);
  1083. #endif
  1084. }
  1085. void OnPlayerReceiveFlashbangHitStart(bool visual)
  1086. {
  1087. SpawnFlashbangEffect(this, visual);
  1088. }
  1089. void OnPlayerReceiveFlashbangHitEnd() {}
  1090. //--------------------------------------------------------------------------
  1091. //! Melee helpers
  1092. //--------------------------------------------------------------------------
  1093. //! select & return hit component for attacking AI
  1094. override string GetHitComponentForAI()
  1095. {
  1096. return GetDayZPlayerType().GetHitComponentForAI();
  1097. }
  1098. //! returns default hit component (fallback)
  1099. override string GetDefaultHitComponent()
  1100. {
  1101. return GetDayZPlayerType().GetDefaultHitComponent();
  1102. }
  1103. override vector GetDefaultHitPosition()
  1104. {
  1105. return m_DefaultHitPosition;
  1106. }
  1107. //! returns list of suitable finisher hit components (defined on base entity/entity type)
  1108. override array<string> GetSuitableFinisherHitComponents()
  1109. {
  1110. return GetDayZPlayerType().GetSuitableFinisherHitComponents();
  1111. }
  1112. protected vector SetDefaultHitPosition(string pSelection)
  1113. {
  1114. return GetSelectionPositionMS(pSelection);
  1115. }
  1116. //--------------------------------------------------------------------------
  1117. //!DEPRECATED!
  1118. void AddPossibleCoverFaceForShave()
  1119. {
  1120. m_FaceCoveredForShaveLayers++;
  1121. }
  1122. //!DEPRECATED!
  1123. void RemovePossibleCoverFaceForShave()
  1124. {
  1125. m_FaceCoveredForShaveLayers--;
  1126. }
  1127. //--------------------------------------------------------------------------
  1128. override void EEItemAttached(EntityAI item, string slot_name)
  1129. {
  1130. super.EEItemAttached(item, slot_name);
  1131. ItemBase itemIB = ItemBase.Cast(item);
  1132. SwitchItemSelectionTexture(item, slot_name);
  1133. Param1<PlayerBase> p = new Param1<PlayerBase>(this);
  1134. item.SwitchItemSelectionTextureEx(EItemManipulationContext.ATTACHING, p);
  1135. m_QuickBarBase.updateSlotsCount();
  1136. CalculateVisibilityForAI();
  1137. UpdateShoulderProxyVisibility(item, slot_name);
  1138. HideHairSelections(itemIB,true);
  1139. GetGame().GetAnalyticsClient().OnItemAttachedAtPlayer(item, slot_name);
  1140. Clothing clothing = Clothing.Cast(item);
  1141. if (clothing)
  1142. {
  1143. if (!GetGame().IsDedicatedServer())
  1144. {
  1145. if (clothing.GetEffectWidgetTypes())
  1146. {
  1147. QueueAddEffectWidget(clothing.GetEffectWidgetTypes());
  1148. }
  1149. if (clothing.GetGlassesEffectID() > -1)
  1150. {
  1151. QueueAddGlassesEffect(clothing.GetGlassesEffectID());
  1152. }
  1153. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(UpdateCorpseStateVisual, 200, false);//sometimes it takes a while to load in
  1154. UpdateCorpseStateVisual();//....but if possible, we don't want a delay
  1155. }
  1156. else if (GetGame().IsServer())
  1157. {
  1158. if (clothing.IsGasMask())
  1159. {
  1160. GetModifiersManager().ActivateModifier(eModifiers.MDF_MASK);
  1161. }
  1162. }
  1163. clothing.UpdateNVGStatus(this,true);
  1164. }
  1165. AdjustBandana(item,slot_name);
  1166. AdjustShemag(item,slot_name);
  1167. }
  1168. override void EEItemDetached(EntityAI item, string slot_name)
  1169. {
  1170. super.EEItemDetached(item, slot_name);
  1171. ItemBase item_base = ItemBase.Cast(item);
  1172. SwitchItemSelectionTexture(item, slot_name);
  1173. item.SwitchItemSelectionTextureEx(EItemManipulationContext.DETACHING);
  1174. m_QuickBarBase.updateSlotsCount();
  1175. CalculateVisibilityForAI();
  1176. HideHairSelections(item_base,false);
  1177. Clothing clothing = Clothing.Cast(item);
  1178. if (clothing)
  1179. {
  1180. if (!GetGame().IsDedicatedServer())
  1181. {
  1182. if (clothing.GetEffectWidgetTypes())
  1183. {
  1184. QueueRemoveEffectWidget(clothing.GetEffectWidgetTypes());
  1185. }
  1186. if (clothing.GetGlassesEffectID() > -1)
  1187. {
  1188. QueueRemoveGlassesEffect(clothing.GetGlassesEffectID());
  1189. }
  1190. }
  1191. if (GetGame().IsServer())
  1192. {
  1193. if (clothing.IsGasMask())
  1194. {
  1195. GetModifiersManager().DeactivateModifier(eModifiers.MDF_MASK);
  1196. }
  1197. }
  1198. clothing.UpdateNVGStatus(this, false, true);
  1199. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(UpdateCorpseStateVisual, 200, false);//sometimes it takes a while to load in
  1200. UpdateCorpseStateVisual();//....but if possible, we don't want a delay
  1201. }
  1202. }
  1203. void UpdateShoulderProxyVisibility(EntityAI item, string slot_name)
  1204. {
  1205. string slot = slot_name;
  1206. bool boo;
  1207. boo = item.IsWeapon();
  1208. if (slot == "Melee")
  1209. {
  1210. SetSimpleHiddenSelectionState(SIMPLE_SELECTION_MELEE_RIFLE,boo);
  1211. SetSimpleHiddenSelectionState(SIMPLE_SELECTION_MELEE_MELEE,!boo);
  1212. }
  1213. else if (slot == "Shoulder")
  1214. {
  1215. SetSimpleHiddenSelectionState(SIMPLE_SELECTION_SHOULDER_RIFLE,boo);
  1216. SetSimpleHiddenSelectionState(SIMPLE_SELECTION_SHOULDER_MELEE,!boo);
  1217. }
  1218. }
  1219. override void SwitchItemSelectionTexture(EntityAI item, string slot_name)
  1220. {
  1221. super.SwitchItemSelectionTexture(item,slot_name);
  1222. //shirt + armband
  1223. EntityAI armband = FindAttachmentBySlotName("Armband");
  1224. if (slot_name == "Body" && armband)
  1225. {
  1226. Param1<PlayerBase> p = new Param1<PlayerBase>(this);
  1227. armband.SwitchItemSelectionTextureEx(EItemManipulationContext.UPDATE,p);
  1228. }
  1229. }
  1230. void RemoveAllItems()
  1231. {
  1232. array<EntityAI> itemsArray = new array<EntityAI>;
  1233. ItemBase item;
  1234. GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER, itemsArray);
  1235. for (int i = 0; i < itemsArray.Count(); i++)
  1236. {
  1237. Class.CastTo(item, itemsArray.Get(i));
  1238. if (item && !item.IsInherited(SurvivorBase)) GetInventory().LocalDestroyEntity(item);
  1239. }
  1240. }
  1241. bool GetHitPPEEnabled()
  1242. {
  1243. return m_CanDisplayHitEffectPPE;
  1244. }
  1245. void SetHitPPEEnabled(bool enabled)
  1246. {
  1247. m_CanDisplayHitEffectPPE = enabled;
  1248. }
  1249. bool IsMale()
  1250. {
  1251. if (ConfigGetBool("woman") != 1)
  1252. {
  1253. return true;
  1254. }
  1255. return false;
  1256. }
  1257. int GetVoiceType()
  1258. {
  1259. int voice_type = ConfigGetInt("voiceType");
  1260. if (voice_type == 0)
  1261. {
  1262. voice_type = 1;
  1263. }
  1264. return voice_type;
  1265. }
  1266. PlayerSoundManagerServer GetPlayerSoundManagerServer()
  1267. {
  1268. return m_PlayerSoundManagerServer;
  1269. }
  1270. UndergroundHandlerClient GetUndergroundHandler()
  1271. {
  1272. if (!m_UndergroundHandler && IsAlive())
  1273. {
  1274. m_UndergroundHandler = new UndergroundHandlerClient(this);
  1275. }
  1276. return m_UndergroundHandler;
  1277. }
  1278. UndergroundBunkerHandlerClient GetUndergroundBunkerHandler()
  1279. {
  1280. if (!m_UndergroundBunkerHandler && IsAlive())
  1281. {
  1282. m_UndergroundBunkerHandler = new UndergroundBunkerHandlerClient(this);
  1283. }
  1284. return m_UndergroundBunkerHandler;
  1285. }
  1286. void KillUndergroundHandler()
  1287. {
  1288. m_UndergroundHandler = null;
  1289. m_UndergroundBunkerHandler = null;
  1290. }
  1291. // --------------------------------------------------
  1292. // User Actions
  1293. //---------------------------------------------------
  1294. void SetActions(out TInputActionMap InputActionMap)
  1295. {
  1296. AddAction(ActionOpenDoors, InputActionMap);
  1297. AddAction(ActionCloseDoors, InputActionMap);
  1298. AddAction(ActionLockedDoors, InputActionMap);
  1299. AddAction(ActionEnterLadder, InputActionMap);
  1300. AddAction(ActionExitLadder, InputActionMap);
  1301. //-----------CheckIfCanMOveToTarget----------
  1302. AddAction(ActionStartEngine, InputActionMap);
  1303. AddAction(ActionStartEngineBoat, InputActionMap);
  1304. AddAction(ActionStopEngine, InputActionMap);
  1305. AddAction(ActionStopEngineBoat, InputActionMap);
  1306. AddAction(ActionSwitchSeats, InputActionMap);
  1307. AddAction(ActionOpenCarDoors,InputActionMap);
  1308. AddAction(ActionCloseCarDoors,InputActionMap);
  1309. AddAction(ActionUncoverHeadSelf, InputActionMap);
  1310. AddAction(ActionDrinkPondContinuous, InputActionMap);
  1311. AddAction(ActionEatSnowContinuous, InputActionMap);
  1312. AddAction(ActionIgniteFireplaceByAir, InputActionMap);
  1313. AddAction(ActionMineBushByHand, InputActionMap);
  1314. AddAction(ActionUngagSelf, InputActionMap);
  1315. AddAction(ActionWashHandsWater, InputActionMap);
  1316. AddAction(ActionWashHandsSnow, InputActionMap);
  1317. AddAction(ActionGetOutTransport, InputActionMap);
  1318. AddAction(ActionUnrestrainTargetHands, InputActionMap);
  1319. AddAction(ActionTakeArrow, InputActionMap);
  1320. AddAction(ActionTakeArrowToHands, InputActionMap);
  1321. AddAction(ActionOperatePanelPowerStation, InputActionMap);
  1322. }
  1323. void SetActions() // Backwards compatibility, not recommended to use
  1324. {
  1325. }
  1326. void SetActionsRemoteTarget(out TInputActionMap InputActionMap)
  1327. {
  1328. AddAction(ActionCPR, InputActionMap);
  1329. AddAction(ActionUncoverHeadTarget, InputActionMap);
  1330. AddAction(ActionUngagTarget, InputActionMap);
  1331. AddAction(ActionPullBodyFromTransport, InputActionMap);
  1332. AddAction(ActionCheckPulseTarget, InputActionMap);
  1333. }
  1334. void SetActionsRemoteTarget() // Backwards compatibility, not recommended to use
  1335. {
  1336. }
  1337. void InitializeActions()
  1338. {
  1339. // Backwards compatibility
  1340. if (IsControlledPlayer())
  1341. {
  1342. m_InputActionMap = new TInputActionMap;
  1343. SetActions();
  1344. }
  1345. else
  1346. {
  1347. m_InputActionMap = new TInputActionMap;
  1348. SetActionsRemoteTarget();
  1349. }
  1350. //////////////////////////
  1351. m_InputActionMapControled = new TInputActionMap;
  1352. SetActions(m_InputActionMapControled);
  1353. m_InputActionMapAsTarget = new TInputActionMap;
  1354. SetActionsRemoteTarget(m_InputActionMapAsTarget);
  1355. }
  1356. override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
  1357. {
  1358. if (!m_ActionsInitialize)
  1359. {
  1360. m_ActionsInitialize = true;
  1361. InitializeActions();
  1362. }
  1363. // Backwards compatibility
  1364. array<ActionBase_Basic> bcActions = m_InputActionMap.Get(action_input_type);
  1365. if (!bcActions)
  1366. {
  1367. if (IsControlledPlayer())
  1368. actions = m_InputActionMapControled.Get(action_input_type);
  1369. else
  1370. actions = m_InputActionMapAsTarget.Get(action_input_type);
  1371. }
  1372. else
  1373. {
  1374. if (!actions)
  1375. actions = new array<ActionBase_Basic>();
  1376. if (IsControlledPlayer())
  1377. actions.InsertAll(m_InputActionMapControled.Get(action_input_type));
  1378. else
  1379. actions.InsertAll(m_InputActionMapAsTarget.Get(action_input_type));
  1380. actions.InsertAll(bcActions);
  1381. }
  1382. }
  1383. void AddAction(typename actionName, out TInputActionMap InputActionMap)
  1384. {
  1385. ActionBase action = GetActionManager().GetAction(actionName);
  1386. typename ai = action.GetInputType();
  1387. if (!ai)
  1388. {
  1389. m_ActionsInitialize = false;
  1390. return;
  1391. }
  1392. ref array<ActionBase_Basic> action_array = InputActionMap.Get(ai);
  1393. if (!action_array)
  1394. {
  1395. action_array = new array<ActionBase_Basic>;
  1396. InputActionMap.Insert(ai, action_array);
  1397. }
  1398. action_array.Insert(action);
  1399. }
  1400. void AddAction(typename actionName) // Backwards compatibility, not recommended to use
  1401. {
  1402. AddAction(actionName, m_InputActionMap);
  1403. }
  1404. void RemoveAction(typename actionName, out TInputActionMap InputActionMap)
  1405. {
  1406. ActionBase action = GetActionManager().GetAction(actionName);
  1407. typename ai = action.GetInputType();
  1408. ref array<ActionBase_Basic> action_array = InputActionMap.Get(ai);
  1409. if (action_array)
  1410. {
  1411. for (int i = 0; i < action_array.Count(); i++)
  1412. {
  1413. if (action == action_array.Get(i))
  1414. {
  1415. action_array.Remove(i);
  1416. }
  1417. }
  1418. action_array = new array<ActionBase_Basic>;
  1419. InputActionMap.Insert(ai, action_array);
  1420. }
  1421. action_array.Insert(action);
  1422. }
  1423. void RemoveAction(typename actionName) // Backwards compatibility, not recommended to use
  1424. {
  1425. RemoveAction(actionName, m_InputActionMap);
  1426. }
  1427. int GetCurrentRecipe()
  1428. {
  1429. return m_RecipePick;
  1430. }
  1431. void SetNextRecipe()
  1432. {
  1433. m_RecipePick++;
  1434. }
  1435. void SetFirstRecipe()
  1436. {
  1437. m_RecipePick = 0;
  1438. }
  1439. //---------------------------------------------------
  1440. ActionManagerBase GetActionManager()
  1441. {
  1442. return m_ActionManager;
  1443. }
  1444. EmoteManager GetEmoteManager()
  1445. {
  1446. return m_EmoteManager;
  1447. }
  1448. RandomGeneratorSyncManager GetRandomGeneratorSyncManager()
  1449. {
  1450. return m_RGSManager;
  1451. }
  1452. //!called every command handler tick when player is on ladder
  1453. override void OnLadder(float delta_time, HumanMovementState pState)
  1454. {
  1455. ProcessHandDamage(delta_time, pState);
  1456. }
  1457. void ProcessHandDamage(float delta_time, HumanMovementState pState)
  1458. {
  1459. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || !GetGame().IsMultiplayer())
  1460. {
  1461. if (pState.m_iMovement == DayZPlayerConstants.MOVEMENTIDX_SLIDE)
  1462. {
  1463. //Print("sliding down");
  1464. EntityAI gloves = GetInventory().FindAttachment(InventorySlots.GLOVES);
  1465. if (gloves && gloves.GetHealthLevel() < 4)
  1466. {
  1467. gloves.AddHealth("","", PlayerConstants.GLOVES_DAMAGE_SLIDING_LADDER_PER_SEC * delta_time);
  1468. return;
  1469. }
  1470. if (Math.RandomFloat01() < PlayerConstants.CHANCE_TO_BLEED_SLIDING_LADDER_PER_SEC * delta_time)
  1471. {
  1472. if (Math.RandomFloat01() < 0.5)
  1473. {
  1474. if (GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll"))
  1475. {
  1476. SendSoundEvent(EPlayerSoundEventID.INJURED_LIGHT);
  1477. }
  1478. }
  1479. else
  1480. {
  1481. if (GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightForeArmRoll"))
  1482. {
  1483. SendSoundEvent(EPlayerSoundEventID.INJURED_LIGHT);
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. override void ProcessFeetDamageServer(int pUserInt)
  1491. {
  1492. //InventorySlots.HEADGEAR
  1493. EntityAI shoes = GetInventory().FindAttachment(InventorySlots.FEET);
  1494. string surface; int liquid;
  1495. GetGame().SurfaceUnderObject(this, surface, liquid);
  1496. float modifier_surface = Surface.GetParamFloat(surface, "footDamage");
  1497. if (shoes && shoes.GetHealthLevel() < 4)
  1498. {
  1499. shoes.AddHealth("", "", -1 * modifier_surface * PlayerConstants.SHOES_MOVEMENT_DAMAGE_PER_STEP * (float)PlayerConstants.CHECK_EVERY_N_STEP);
  1500. return;
  1501. }
  1502. float rnd = Math.RandomFloat01();
  1503. float modifier_movement = GetFeetDamageMoveModifier();
  1504. float chance = modifier_movement * modifier_surface * PlayerConstants.BAREFOOT_MOVEMENT_BLEED_MODIFIER * (float)PlayerConstants.CHECK_EVERY_N_STEP;
  1505. if (rnd < chance)
  1506. {
  1507. if (pUserInt % 2 == 0)
  1508. {
  1509. if (GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightFoot"))
  1510. SendSoundEvent(EPlayerSoundEventID.INJURED_LIGHT);
  1511. }
  1512. else
  1513. {
  1514. if (GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftFoot"))
  1515. SendSoundEvent(EPlayerSoundEventID.INJURED_LIGHT);
  1516. }
  1517. }
  1518. }
  1519. float GetFeetDamageMoveModifier()
  1520. {
  1521. float modifier;
  1522. switch(m_MovementState.m_iMovement)
  1523. {
  1524. case DayZPlayerConstants.MOVEMENTIDX_SPRINT:
  1525. modifier = 1;
  1526. break
  1527. case DayZPlayerConstants.MOVEMENTIDX_RUN:
  1528. modifier = 0.5;
  1529. break
  1530. case DayZPlayerConstants.MOVEMENTIDX_WALK:
  1531. modifier = 0;
  1532. break
  1533. }
  1534. return modifier;
  1535. }
  1536. void SetStamina(int value, int range)
  1537. {
  1538. if (m_ModulePlayerStatus)
  1539. m_ModulePlayerStatus.SetStamina(value, range);
  1540. }
  1541. #ifdef DIAG_DEVELOPER
  1542. void SetStaminaDisabled(bool value)
  1543. {
  1544. if (m_StaminaHandler)
  1545. m_StaminaHandler.SetStaminaDisabled(value);
  1546. }
  1547. #endif
  1548. void SetQuickRestrain(bool enable)
  1549. {
  1550. m_AllowQuickRestrain = enable;
  1551. }
  1552. void SetQuickFishing(bool enable)
  1553. {
  1554. m_AllowQuickFishing = enable;
  1555. }
  1556. bool IsQuickRestrain()
  1557. {
  1558. return m_AllowQuickRestrain;
  1559. }
  1560. bool IsQuickFishing()
  1561. {
  1562. return m_AllowQuickFishing;
  1563. }
  1564. PlayerStats GetPlayerStats()
  1565. {
  1566. return m_PlayerStats;
  1567. }
  1568. CraftingManager GetCraftingManager()
  1569. {
  1570. return m_CraftingManager;
  1571. }
  1572. StaminaHandler GetStaminaHandler()
  1573. {
  1574. return m_StaminaHandler;
  1575. }
  1576. override WeaponManager GetWeaponManager()
  1577. {
  1578. return m_WeaponManager;
  1579. }
  1580. override ArrowManagerBase GetArrowManager()
  1581. {
  1582. return m_ArrowManager;
  1583. }
  1584. bool CanBeRestrained()
  1585. {
  1586. if (IsInVehicle() || IsRaised() || IsSwimming() || IsClimbing() || IsClimbingLadder() || IsRestrained() || !GetWeaponManager() || GetWeaponManager().IsRunning() || !GetActionManager() || GetActionManager().GetRunningAction() != null || IsMapOpen())
  1587. {
  1588. return false;
  1589. }
  1590. if (GetThrowing() && GetThrowing().IsThrowingModeEnabled())
  1591. {
  1592. return false;
  1593. }
  1594. return true;
  1595. }
  1596. void SetRestrainStarted(bool restrain_started)
  1597. {
  1598. m_IsRestrainStarted = restrain_started;
  1599. SetSynchDirty();
  1600. }
  1601. bool IsRestrainStarted()
  1602. {
  1603. return m_IsRestrainStarted;
  1604. }
  1605. void SetRestrainPrelocked(bool restrain_prelock)
  1606. {
  1607. m_IsRestrainPrelocked = restrain_prelock;
  1608. SetSynchDirty();
  1609. }
  1610. bool IsRestrainPrelocked()
  1611. {
  1612. return m_IsRestrainPrelocked;
  1613. }
  1614. void SetRestrained(bool is_restrained)
  1615. {
  1616. m_IsRestrained = is_restrained;
  1617. SetSynchDirty();
  1618. }
  1619. override bool IsRestrained()
  1620. {
  1621. return m_IsRestrained;
  1622. }
  1623. void OnRestrainStartedChangeClient()
  1624. {
  1625. if (m_IsRestrainStarted && IsControlledPlayer())
  1626. {
  1627. if (GetGame().GetUIManager().IsMenuOpen(MENU_RADIAL_QUICKBAR))
  1628. GetGame().GetUIManager().FindMenu(MENU_RADIAL_QUICKBAR).Close();
  1629. if (GetGame().GetUIManager().IsMenuOpen(MENU_INVENTORY))
  1630. GetGame().GetMission().HideInventory();
  1631. }
  1632. }
  1633. void OnRestrainChangeClient()
  1634. {
  1635. if (m_IsRestrained && IsControlledPlayer())
  1636. {
  1637. if (GetGame().GetUIManager().IsMenuOpen(MENU_RADIAL_QUICKBAR))
  1638. GetGame().GetUIManager().FindMenu(MENU_RADIAL_QUICKBAR).Close();
  1639. if (GetGame().GetUIManager().IsMenuOpen(MENU_INVENTORY))
  1640. GetGame().GetMission().HideInventory();
  1641. }
  1642. }
  1643. override bool IsInventoryVisible()
  1644. {
  1645. return true;
  1646. }
  1647. bool CanManipulateInventory()
  1648. {
  1649. if (IsControlledPlayer())
  1650. {
  1651. return !IsRestrained() && !IsRestrainPrelocked() && !IsRestrainStarted();
  1652. }
  1653. return true;
  1654. }
  1655. override bool CanReleaseAttachment (EntityAI attachment)
  1656. {
  1657. return super.CanReleaseAttachment(attachment);
  1658. }
  1659. override bool CanReleaseCargo (EntityAI cargo)
  1660. {
  1661. return super.CanReleaseCargo(cargo);
  1662. }
  1663. override bool CanReceiveItemIntoCargo(EntityAI item)
  1664. {
  1665. return super.CanReceiveItemIntoCargo(item);
  1666. }
  1667. override bool CanSwapItemInCargo (EntityAI child_entity, EntityAI new_entity)
  1668. {
  1669. return super.CanSwapItemInCargo(child_entity, new_entity);
  1670. }
  1671. override bool CanReceiveItemIntoHands(EntityAI item_to_hands)
  1672. {
  1673. if (IsInVehicle())
  1674. return false;
  1675. if (!CanPickupHeavyItem(item_to_hands))
  1676. return false;
  1677. return super.CanReceiveItemIntoHands(item_to_hands);
  1678. }
  1679. int GetCraftingRecipeID()
  1680. {
  1681. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  1682. {
  1683. return GetCraftingManager().GetRecipeID();
  1684. }
  1685. else
  1686. {
  1687. return m_RecipeID;
  1688. }
  1689. }
  1690. void SetCraftingRecipeID(int recipeID)
  1691. {
  1692. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  1693. {
  1694. GetCraftingManager().SetRecipeID(recipeID);
  1695. }
  1696. else
  1697. {
  1698. m_RecipeID = recipeID;
  1699. }
  1700. }
  1701. // --------------------------------------------------
  1702. // Action data for base building actions
  1703. //---------------------------------------------------
  1704. ConstructionActionData GetConstructionActionData()
  1705. {
  1706. return m_ConstructionActionData;
  1707. }
  1708. void ResetConstructionActionData()
  1709. {
  1710. if (m_ConstructionActionData)
  1711. {
  1712. m_ConstructionActionData.ResetActionIndexes();
  1713. }
  1714. }
  1715. // --------------------------------------------------
  1716. // Action data for fireplace (indoor)
  1717. //---------------------------------------------------
  1718. vector GetLastFirePoint()
  1719. {
  1720. return m_LastFirePoint;
  1721. }
  1722. float GetLastFirePointRot()
  1723. {
  1724. return m_LastFirePointRot;
  1725. }
  1726. int GetLastFirePointIndex()
  1727. {
  1728. return m_LastFirePointIndex;
  1729. }
  1730. void SetLastFirePoint(vector last_fire_point)
  1731. {
  1732. m_LastFirePoint = last_fire_point;
  1733. }
  1734. void SetLastFirePointRot(float last_fire_point_rot)
  1735. {
  1736. m_LastFirePointRot = last_fire_point_rot;
  1737. }
  1738. void SetLastFirePointIndex(int last_fire_point_index)
  1739. {
  1740. m_LastFirePointIndex = last_fire_point_index;
  1741. }
  1742. // --------------------------------------------------
  1743. // QuickBar
  1744. //---------------------------------------------------
  1745. void RemoveQuickBarEntityShortcut(EntityAI entity)
  1746. {
  1747. int index = m_QuickBarBase.FindEntityIndex(entity);
  1748. if (index != -1)
  1749. m_QuickBarBase.SetEntityShortcut(entity,-1);
  1750. }
  1751. //---------------------------------------------------
  1752. void SetEnableQuickBarEntityShortcut(EntityAI entity, bool value)
  1753. {
  1754. int index = m_QuickBarBase.FindEntityIndex(entity);
  1755. if (index != -1)
  1756. m_QuickBarBase.SetShotcutEnable(index,value);
  1757. }
  1758. //---------------------------------------------------
  1759. int FindQuickBarEntityIndex(EntityAI entity)
  1760. {
  1761. int index;
  1762. index = m_QuickBarBase.FindEntityIndex(entity);
  1763. if (m_QuickBarBase.GetEntity(index) == NULL)
  1764. return -1;
  1765. return index;
  1766. }
  1767. //---------------------------------------------------
  1768. int GetQuickBarSize()
  1769. {
  1770. return m_QuickBarBase.GetSize();
  1771. }
  1772. //---------------------------------------------------
  1773. EntityAI GetQuickBarEntity(int index)
  1774. {
  1775. return m_QuickBarBase.GetEntity(index);
  1776. }
  1777. //---------------------------------------------------
  1778. void UpdateQuickBarEntityVisibility(EntityAI entity)
  1779. {
  1780. int i = FindQuickBarEntityIndex(entity);
  1781. if (i >= 0)
  1782. m_QuickBarBase.UpdateShotcutVisibility(i);
  1783. }
  1784. //---------------------------------------------------
  1785. void SetQuickBarEntityShortcut(EntityAI entity, int index, bool force = false)
  1786. {
  1787. m_QuickBarBase.SetEntityShortcut(entity, index, force);
  1788. }
  1789. //---------------------------------------------------
  1790. void OnQuickbarSetEntityRequest(ParamsReadContext ctx)
  1791. {
  1792. m_QuickBarBase.OnSetEntityRequest(ctx);
  1793. }
  1794. //---------------------------------------------------
  1795. // Applies splint on all limbs.
  1796. void ApplySplint()
  1797. {
  1798. float add_health_coef = 0.33;
  1799. // The idea is to slightly increase health of broken limb so the player is still limping. Using more splints will help but each time less. 100% recovery can be achieved only through long term healing.
  1800. if (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  1801. {
  1802. AddHealth("LeftLeg", "Health", (GetMaxHealth("LeftLeg", "Health") - GetHealth("LeftLeg", "Health") ) * add_health_coef );
  1803. AddHealth("RightLeg", "Health", (GetMaxHealth("RightLeg", "Health") - GetHealth("RightLeg", "Health")) * add_health_coef );
  1804. AddHealth("RightFoot", "Health", (GetMaxHealth("RightFoot", "Health") - GetHealth("RightFoot", "Health")) * add_health_coef );
  1805. AddHealth("LeftFoot", "Health", (GetMaxHealth("LeftFoot", "Health") - GetHealth("LeftFoot", "Health")) * add_health_coef );
  1806. }
  1807. }
  1808. void ProcessDrowning(float dT)
  1809. {
  1810. GetStaminaHandler().DepleteStamina(EStaminaModifiers.DROWN,dT);
  1811. #ifndef SERVER
  1812. //PP EFFECTS
  1813. PPERequester_Drowning req = PPERequester_Drowning.Cast(PPERequesterBank.GetRequester(PPERequesterBank.REQ_DROWNING));
  1814. req.SetStamina01(GetStaminaHandler().GetStaminaNormalized());
  1815. #endif
  1816. }
  1817. void SpawnDrowningBubbles()
  1818. {
  1819. if (!GetDrowningWaterLevelCheck())
  1820. return;
  1821. float bubbleFrequency = Math.Lerp(PlayerConstants.DROWNING_BUBBLE_FREQUENCY_MIN, PlayerConstants.DROWNING_BUBBLE_FREQUENCY_MAX, GetStaminaHandler().GetSyncedStaminaNormalized());
  1822. int boneIdx = GetBoneIndexByName("Head");
  1823. if (boneIdx != -1)
  1824. {
  1825. Particle p = ParticleManager.GetInstance().PlayInWorld(ParticleList.DROWNING_BUBBLES, "-0.03 0.15 0");
  1826. if (p)
  1827. AddChild(p, boneIdx);
  1828. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SpawnDrowningBubbles, bubbleFrequency);
  1829. }
  1830. }
  1831. void ProcessHoldBreath(float dT)
  1832. {
  1833. if (IsTryingHoldBreath() && CanStartConsumingStamina(EStaminaConsumers.HOLD_BREATH))
  1834. {
  1835. if (!m_IsHoldingBreath)
  1836. {
  1837. OnHoldBreathStart();
  1838. m_IsHoldingBreath = true;
  1839. }
  1840. }
  1841. else if (!IsTryingHoldBreath() || !CanConsumeStamina(EStaminaConsumers.HOLD_BREATH))
  1842. {
  1843. if (m_IsHoldingBreath) OnHoldBreathEnd();
  1844. m_IsHoldingBreath = false;
  1845. }
  1846. }
  1847. void OnHoldBreathStart()
  1848. {
  1849. //SendSoundEvent(SoundSetMap.GetSoundSetID("holdBreath_male_Char_SoundSet"));
  1850. RequestSoundEventEx(EPlayerSoundEventID.HOLD_BREATH, true, EPlayerSoundEventParam.SKIP_CONTROLLED_PLAYER);
  1851. }
  1852. void OnHoldBreathExhausted()
  1853. {
  1854. RequestSoundEventEx(EPlayerSoundEventID.EXHAUSTED_BREATH, true, EPlayerSoundEventParam.SKIP_CONTROLLED_PLAYER);
  1855. }
  1856. void OnHoldBreathEnd()
  1857. {
  1858. //SendSoundEvent(SoundSetMap.GetSoundSetID("releaseBreath_male_Char_SoundSet"));
  1859. RequestSoundEventEx(EPlayerSoundEventID.RELEASE_BREATH, true, EPlayerSoundEventParam.SKIP_CONTROLLED_PLAYER);
  1860. }
  1861. override bool IsHoldingBreath()
  1862. {
  1863. return m_IsHoldingBreath;
  1864. }
  1865. override bool IsRefresherSignalingViable()
  1866. {
  1867. return false;
  1868. }
  1869. override bool IsSelfAdjustingTemperature()
  1870. {
  1871. return IsAlive();
  1872. }
  1873. eMixedSoundStates GetMixedSoundStates()
  1874. {
  1875. return m_MixedSoundStates;
  1876. }
  1877. AbstractWave SaySoundSet(string name)
  1878. {
  1879. if (m_SaySoundLastSetName != name)
  1880. {
  1881. m_SaySoundParams = new SoundParams(name);
  1882. m_SaySoundBuilder = new SoundObjectBuilder(m_SaySoundParams);
  1883. m_SaySoundLastSetName = name;
  1884. }
  1885. m_SaySoundObject = m_SaySoundBuilder.BuildSoundObject();
  1886. m_SaySoundObject.SetPosition(GetPosition());
  1887. return GetGame().GetSoundScene().Play3D(m_SaySoundObject, m_SaySoundBuilder);
  1888. }
  1889. EntityAI FindCargoByBaseType(string searched_item)
  1890. {
  1891. EntityAI attachment;
  1892. string item_name;
  1893. int attcount = this.GetInventory().AttachmentCount();
  1894. for (int att = 0; att < attcount; att++)
  1895. {
  1896. attachment = GetInventory().GetAttachmentFromIndex(att);
  1897. if (attachment.IsItemBase())
  1898. {
  1899. item_name = attachment.GetType();
  1900. if (GetGame().IsKindOf(item_name, searched_item))
  1901. {
  1902. return attachment;
  1903. }
  1904. }
  1905. }
  1906. return NULL;
  1907. }
  1908. void InitEditor()
  1909. {
  1910. if (GetGame().IsDebug())
  1911. {
  1912. if (!GetGame().IsMultiplayer() && GetGame().GetPlayer() && GetGame().GetPlayer().GetID() == this.GetID())
  1913. {
  1914. PluginSceneManager scene_editor = PluginSceneManager.Cast(GetPlugin(PluginSceneManager));
  1915. scene_editor.InitLoad();
  1916. }
  1917. }
  1918. }
  1919. //---------------------------------------------------------------------------------------------------------------------------
  1920. void OnPlayerLoaded()
  1921. {
  1922. InitEditor();
  1923. //! initialize EnvironmentExposure data; waits for PlayerStats load
  1924. if (m_Environment)
  1925. m_Environment.Init();
  1926. if (GetGame().IsMultiplayer() || GetGame().IsServer())
  1927. {
  1928. if (m_ModuleLifespan)
  1929. {
  1930. m_ModuleLifespan.SynchLifespanVisual(this, m_LifeSpanState, m_HasBloodyHandsVisible, m_HasBloodTypeVisible, m_BloodType);
  1931. }
  1932. }
  1933. if (IsControlledPlayer())//true only on client for the controlled character
  1934. {
  1935. if (!m_VirtualHud)
  1936. m_VirtualHud = new VirtualHud(this);
  1937. if (m_Hud)
  1938. {
  1939. m_Hud.UpdateBloodName();
  1940. PPEManagerStatic.GetPPEManager().StopAllEffects(PPERequesterCategory.GAMEPLAY_EFFECTS);
  1941. GetGame().GetUIManager().CloseAll();
  1942. GetGame().GetMission().SetPlayerRespawning(false);
  1943. GetGame().GetMission().OnPlayerRespawned(this);
  1944. m_Hud.ShowQuickbarUI(true);
  1945. m_Hud.UpdateQuickbarGlobalVisibility();
  1946. m_Hud.InitHeatBufferUI(this);
  1947. m_Hud.OnPlayerLoaded();
  1948. }
  1949. m_EffectWidgets = GetGame().GetMission().GetEffectWidgets();
  1950. }
  1951. if (!GetGame().IsDedicatedServer())
  1952. {
  1953. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(UpdateCorpseStateVisual, 2000, false);//sometimes it takes a while to load in
  1954. m_PlayerSoundEventHandler = new PlayerSoundEventHandler(this);
  1955. m_ReplaceSoundEventHandler = new ReplaceSoundEventHandler(this);
  1956. }
  1957. int slotId = InventorySlots.GetSlotIdFromString("Head");
  1958. m_CharactersHead = Head_Default.Cast(GetInventory().FindPlaceholderForSlot(slotId));
  1959. CheckHairClippingOnCharacterLoad();
  1960. UpdateHairSelectionVisibility();
  1961. PreloadDecayTexture();
  1962. Weapon_Base wpn = Weapon_Base.Cast(GetItemInHands());
  1963. if (wpn)
  1964. {
  1965. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_REMOTE)
  1966. {
  1967. wpn.DelayedValidateAndRepair();
  1968. }
  1969. else
  1970. {
  1971. wpn.ValidateAndRepair();
  1972. }
  1973. }
  1974. m_PlayerLoaded = true;
  1975. }
  1976. void SetPlayerDisconnected(bool state)
  1977. {
  1978. m_PlayerDisconnectProcessed = state;
  1979. }
  1980. bool IsPlayerDisconnected()
  1981. {
  1982. return m_PlayerDisconnectProcessed;
  1983. }
  1984. // --------------------------------------------------
  1985. // Advanced placement
  1986. //---------------------------------------------------
  1987. //get hologram
  1988. Hologram GetHologramServer()
  1989. {
  1990. return m_HologramServer;
  1991. }
  1992. Hologram GetHologramLocal()
  1993. {
  1994. return m_HologramLocal;
  1995. }
  1996. void PlacingStartServer(ItemBase item)
  1997. {
  1998. if (item)
  1999. {
  2000. m_HologramServer = new Hologram(this, GetLocalProjectionPosition(), item);
  2001. GetHologramServer().SetProjectionPosition(GetLocalProjectionPosition());
  2002. GetHologramServer().SetProjectionOrientation(GetLocalProjectionOrientation());
  2003. GetHologramServer().GetProjectionEntity().OnPlacementStarted(this);
  2004. GetHologramServer().CheckPowerSource();
  2005. GetHologramServer().RefreshVisual();
  2006. }
  2007. }
  2008. void PlacingStartLocal(ItemBase item)
  2009. {
  2010. if (GetGame().IsMultiplayer() && GetGame().IsServer())
  2011. return;
  2012. if (item)
  2013. {
  2014. m_HologramLocal = new Hologram(this, GetLocalProjectionPosition(), item);
  2015. GetHologramLocal().GetProjectionEntity().OnPlacementStarted(this);
  2016. }
  2017. }
  2018. void PlacingCancelServer()
  2019. {
  2020. EntityAI entityInHands = GetHumanInventory().GetEntityInHands();
  2021. if (IsPlacingServer())
  2022. {
  2023. GetHologramServer().CheckPowerSource();
  2024. GetHologramServer().GetParentEntity().OnPlacementCancelled(this);
  2025. delete m_HologramServer;
  2026. return;
  2027. }
  2028. else if (entityInHands && entityInHands.HasEnergyManager())
  2029. {
  2030. if (entityInHands.GetCompEM().IsPlugged())
  2031. entityInHands.OnPlacementCancelled(this);
  2032. }
  2033. }
  2034. //Called when item placement is canceled, will prevent quickbar usage until the item the player was placing is back in hands
  2035. void LockHandsUntilItemHeld()
  2036. {
  2037. m_AreHandsLocked = true;
  2038. }
  2039. void PlacingCancelLocal()
  2040. {
  2041. EntityAI entityInHands = GetHumanInventory().GetEntityInHands();
  2042. if (entityInHands && entityInHands.HasEnergyManager())
  2043. {
  2044. if (entityInHands.GetCompEM().IsPlugged())
  2045. entityInHands.OnPlacementCancelled(this);
  2046. }
  2047. delete m_HologramLocal;
  2048. }
  2049. void PlacingCompleteServer()
  2050. {
  2051. SetLocalProjectionPosition(vector.Zero);
  2052. delete m_HologramServer;
  2053. }
  2054. void PlacingCompleteLocal()
  2055. {
  2056. SetLocalProjectionPosition(vector.Zero);
  2057. delete m_HologramLocal;
  2058. }
  2059. bool IsPlacingServer()
  2060. {
  2061. if (m_HologramServer)
  2062. return true;
  2063. return false;
  2064. }
  2065. bool IsPlacingLocal()
  2066. {
  2067. if (m_HologramLocal)
  2068. return true;
  2069. return false;
  2070. }
  2071. void SetDrowning(bool enable)
  2072. {
  2073. if (enable != m_IsDrowning)
  2074. {
  2075. if (enable)
  2076. OnDrowningStart();
  2077. else
  2078. OnDrowningEnd();
  2079. }
  2080. m_IsDrowning = enable;
  2081. }
  2082. void OnDrowningStart()
  2083. {
  2084. #ifndef SERVER
  2085. if (IsControlledPlayer())
  2086. {
  2087. PPERequester_Drowning req = PPERequester_Drowning.Cast(PPERequesterBank.GetRequester(PPERequesterBank.REQ_DROWNING));
  2088. req.Start();
  2089. }
  2090. //Particles
  2091. SpawnDrowningBubbles();
  2092. #endif
  2093. }
  2094. void OnDrowningEnd()
  2095. {
  2096. #ifndef SERVER
  2097. if (IsControlledPlayer())
  2098. {
  2099. PPERequester_Drowning req = PPERequester_Drowning.Cast(PPERequesterBank.GetRequester(PPERequesterBank.REQ_DROWNING));
  2100. req.Stop();
  2101. }
  2102. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(SpawnDrowningBubbles);
  2103. #endif
  2104. }
  2105. bool TogglePlacingServer(int userDataType, ParamsReadContext ctx)
  2106. {
  2107. if (userDataType == INPUT_UDT_ADVANCED_PLACEMENT)
  2108. {
  2109. PlacingCancelServer();
  2110. return true;
  2111. }
  2112. return false;
  2113. }
  2114. void RequestResetADSSync()
  2115. {
  2116. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT && GetGame().IsMultiplayer())
  2117. {
  2118. m_ProcessResetADS = true;
  2119. ProcessADSSyncResetRequest();
  2120. }
  2121. else if (!GetGame().IsMultiplayer())
  2122. {
  2123. m_ResetADS = true;
  2124. }
  2125. }
  2126. void ProcessADSSyncResetRequest()
  2127. {
  2128. if (ScriptInputUserData.CanStoreInputUserData())
  2129. {
  2130. ScriptInputUserData ctx = new ScriptInputUserData;
  2131. ctx.Write(INPUT_UDT_RESET_ADS);
  2132. ctx.Send();
  2133. m_ProcessResetADS = false;
  2134. }
  2135. }
  2136. //! server only
  2137. bool ResetADSPlayerSync(int userDataType, ParamsReadContext ctx)
  2138. {
  2139. if (userDataType == INPUT_UDT_RESET_ADS)
  2140. {
  2141. ScriptJunctureData pCtx = new ScriptJunctureData;
  2142. SendSyncJuncture(DayZPlayerSyncJunctures.SJ_ADS_RESET,pCtx);
  2143. return true;
  2144. }
  2145. return false;
  2146. }
  2147. override bool CanPlaceItem(EntityAI item)
  2148. {
  2149. if (m_UndergroundPresence > EUndergroundPresence.NONE)
  2150. {
  2151. TStringSet disallowedUndergroundTypes = CfgGameplayHandler.GetDisallowedTypesInUnderground();
  2152. foreach (string t: disallowedUndergroundTypes)
  2153. {
  2154. if (item.IsKindOf(t))
  2155. return false;
  2156. }
  2157. }
  2158. return true;
  2159. }
  2160. void SetUnderground(EUndergroundPresence presence)
  2161. {
  2162. m_UndergroundPresence = presence;
  2163. }
  2164. void TogglePlacingLocal(ItemBase item = null)
  2165. {
  2166. if (IsPlacingLocal())
  2167. {
  2168. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT && GetGame().IsMultiplayer())
  2169. {
  2170. if (ScriptInputUserData.CanStoreInputUserData())
  2171. {
  2172. ScriptInputUserData ctx = new ScriptInputUserData;
  2173. ctx.Write(INPUT_UDT_ADVANCED_PLACEMENT);
  2174. ctx.Send();
  2175. PlacingCancelLocal();
  2176. }
  2177. }
  2178. }
  2179. else if (!item)
  2180. {
  2181. PlacingStartLocal(GetItemInHands());
  2182. }
  2183. else
  2184. {
  2185. PlacingStartLocal(item);
  2186. }
  2187. }
  2188. void SetLocalProjectionPosition(vector local_position)
  2189. {
  2190. m_LocalProjectionPosition = local_position;
  2191. #ifdef DEVELOPER
  2192. if (IsCLIParam("hologramLogs"))
  2193. {
  2194. Debug.Log(string.Format("SetLocalProjectionPosition | pos: %1", m_LocalProjectionPosition), "hologramLogs");
  2195. }
  2196. #endif
  2197. }
  2198. void SetLocalProjectionOrientation(vector local_orientation)
  2199. {
  2200. m_LocalProjectionOrientation = local_orientation;
  2201. }
  2202. vector GetLocalProjectionPosition()
  2203. {
  2204. return m_LocalProjectionPosition;
  2205. }
  2206. vector GetLocalProjectionOrientation()
  2207. {
  2208. return m_LocalProjectionOrientation;
  2209. }
  2210. void SetInColdArea(bool state)
  2211. {
  2212. if (m_IsInColdArea != state)
  2213. {
  2214. m_IsInColdArea = state;
  2215. SetSynchDirty();
  2216. }
  2217. }
  2218. bool GetInColdArea()
  2219. {
  2220. return m_IsInColdArea;
  2221. }
  2222. // ------------------------------------------------------------------------
  2223. //! water contact (driven by Environment)
  2224. void SetInWater(bool pState)
  2225. {
  2226. m_IsInWater = pState;
  2227. SetSynchDirty();
  2228. }
  2229. bool IsInWater()
  2230. {
  2231. return m_IsInWater;
  2232. }
  2233. // -------------------------------------------------------------------------
  2234. void ~PlayerBase()
  2235. {
  2236. if (GetGame() && (!GetGame().IsDedicatedServer()))
  2237. {
  2238. ClientData.RemovePlayerBase(this);
  2239. SetContaminatedEffectEx(false);
  2240. }
  2241. SEffectManager.DestroyEffect(m_FliesEff);
  2242. StopSoundSet(m_SoundFliesEffect);
  2243. }
  2244. void OnCameraChanged(DayZPlayerCameraBase new_camera)
  2245. {
  2246. m_CameraSwayModifier = new_camera.GetWeaponSwayModifier();
  2247. m_CurrentCamera = new_camera;
  2248. }
  2249. DayZPlayerCamera GetCurrentPlayerCamera()
  2250. {
  2251. return m_CurrentCamera;
  2252. }
  2253. bool IsCurrentCameraAimedAtGround()
  2254. {
  2255. if (!m_CurrentCamera)
  2256. return false;
  2257. return m_CurrentCamera.GetCurrentPitch() < PlayerConstants.CAMERA_THRESHOLD_PITCH;
  2258. }
  2259. BleedingSourcesManagerServer GetBleedingManagerServer()
  2260. {
  2261. return m_BleedingManagerServer;
  2262. }
  2263. BleedingSourcesManagerRemote GetBleedingManagerRemote()
  2264. {
  2265. return m_BleedingManagerRemote;
  2266. }
  2267. SymptomManager GetSymptomManager()
  2268. {
  2269. return m_SymptomManager;
  2270. }
  2271. VirtualHud GetVirtualHud()
  2272. {
  2273. if (!m_VirtualHud)
  2274. {
  2275. m_VirtualHud = new VirtualHud(this);
  2276. }
  2277. return m_VirtualHud;
  2278. }
  2279. TransferValues GetTransferValues()
  2280. {
  2281. return m_TrasferValues;
  2282. }
  2283. DebugMonitorValues GetDebugMonitorValues()
  2284. {
  2285. return m_DebugMonitorValues;
  2286. }
  2287. //--------------------------------------------------------------------------
  2288. void OnScheduledTick(float deltaTime)
  2289. {
  2290. if (!IsPlayerSelected() || !IsAlive())
  2291. return;
  2292. if (m_ModifiersManager)
  2293. m_ModifiersManager.OnScheduledTick(deltaTime);
  2294. if (m_NotifiersManager)
  2295. m_NotifiersManager.OnScheduledTick();
  2296. if (m_TrasferValues)
  2297. m_TrasferValues.OnScheduledTick(deltaTime);
  2298. if (m_VirtualHud)
  2299. m_VirtualHud.OnScheduledTick();
  2300. if (GetBleedingManagerServer())
  2301. GetBleedingManagerServer().OnTick(deltaTime);
  2302. if (m_Environment)
  2303. m_Environment.Update(deltaTime);
  2304. // Check if electric device needs to be unplugged
  2305. ItemBase heldItem = GetItemInHands();
  2306. if (heldItem && heldItem.HasEnergyManager() && heldItem.GetCompEM().IsPlugged())
  2307. {
  2308. // Now we know we are working with an electric device which is plugged into a power source.
  2309. EntityAI placed_entity = heldItem;
  2310. // Unplug the device when the player is too far from the power source.
  2311. placed_entity.GetCompEM().UpdatePlugState();
  2312. }
  2313. }
  2314. void OnCommandHandlerTick(float delta_time, int pCurrentCommandID)
  2315. {
  2316. if (!IsAlive())
  2317. {
  2318. if (!m_DeathSyncSent && m_KillerData)
  2319. {
  2320. SyncEvents.SendEntityKilled(this, m_KillerData.m_Killer, m_KillerData.m_MurderWeapon, m_KillerData.m_KillerHiTheBrain);
  2321. m_DeathSyncSent = true;
  2322. }
  2323. return;
  2324. }
  2325. if (m_DebugMonitorValues)
  2326. m_DebugMonitorValues.OnScheduledTick(delta_time);
  2327. if (GetSymptomManager())
  2328. GetSymptomManager().OnTick(delta_time, pCurrentCommandID, m_MovementState);//needs to stay in command handler tick as it's playing animations
  2329. //if (GetBleedingManagerServer()) GetBleedingManagerServer().OnTick(delta_time);
  2330. DayZPlayerInstanceType instType = GetInstanceType();
  2331. if (instType == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  2332. {
  2333. if (m_PlayerSoundEventHandler)
  2334. m_PlayerSoundEventHandler.OnTick(delta_time);
  2335. if (m_ProcessRemoveEffectWidgets && m_ProcessRemoveEffectWidgets.Count() > 0)
  2336. {
  2337. m_EffectWidgets.RemoveActiveEffects(m_ProcessRemoveEffectWidgets);
  2338. }
  2339. if (m_ProcessAddEffectWidgets && m_ProcessAddEffectWidgets.Count() > 0)
  2340. {
  2341. m_EffectWidgets.AddActiveEffects(m_ProcessAddEffectWidgets);
  2342. }
  2343. HandleGlassesEffect();
  2344. if (m_ContaminatedAreaEffectEnabled)
  2345. ContaminatedParticleAdjustment();
  2346. #ifdef DIAG_DEVELOPER
  2347. if (m_WeaponDebug)
  2348. {
  2349. m_WeaponDebug.OnCommandHandlerUpdate();
  2350. }
  2351. #endif
  2352. m_ProcessAddEffectWidgets.Clear(); //clears array for remotes as well
  2353. m_ProcessRemoveEffectWidgets.Clear(); //clears array for remotes as well
  2354. }
  2355. m_AnimCommandStarting = HumanMoveCommandID.None;
  2356. if (CfgGameplayHandler.GetAllowStaminaAffectInertia())
  2357. UpdateMovementInertia();
  2358. if (m_ProcessResetADS)
  2359. ProcessADSSyncResetRequest();
  2360. }
  2361. //! Update movement inertia based on stamina available
  2362. void UpdateMovementInertia()
  2363. {
  2364. HumanCommandMove hcm = GetCommand_Move();
  2365. if (hcm)
  2366. {
  2367. float staminaPercentage = GetStaminaHandler().GetSyncedStaminaNormalized();
  2368. hcm.SetTurnSpanSprintModifier(2 - staminaPercentage);
  2369. hcm.SetRunSprintFilterModifier((2 - staminaPercentage) * 0.5);
  2370. hcm.SetDirectionSprintFilterModifier(2 - staminaPercentage);
  2371. }
  2372. }
  2373. bool m_ShowDbgUI = true;
  2374. int m_DbgListSelection = 0;
  2375. float m_DbgSliderValue = 0.0;
  2376. ref array<string> m_DbgOptions = {"jedna", "dva", "tri"};
  2377. NotifiersManager GetNotifiersManager()
  2378. {
  2379. return m_NotifiersManager;
  2380. }
  2381. //--------------------------------------------------------------------------
  2382. void OnTick()
  2383. {
  2384. float deltaT = (GetGame().GetTime() - m_LastTick) * 0.001;
  2385. if (m_LastTick < 0)
  2386. deltaT = 0; //first tick protection
  2387. m_LastTick = GetGame().GetTime();
  2388. OnScheduledTick(deltaT);
  2389. }
  2390. // -------------------------------------------------------------------------
  2391. override void EEItemIntoHands(EntityAI item)
  2392. {
  2393. super.EEItemIntoHands(item);
  2394. if (item)
  2395. {
  2396. MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(item, {Bolt_Base});
  2397. Weapon_Base w;
  2398. if (Class.CastTo(w, item))
  2399. {
  2400. w.ResetWeaponAnimState();
  2401. HumanCommandMove cm = GetCommand_Move();
  2402. if (cm)
  2403. {
  2404. cm.SetMeleeBlock(false);
  2405. GetMeleeFightLogic().SetBlock(false);
  2406. }
  2407. }
  2408. //! fixes situation where raise is canceling some manipulation with heavy item(ex. TakeItemToHands), forces normal stance
  2409. if (item.IsHeavyBehaviour() && IsRaised())
  2410. {
  2411. HumanCommandMove cm2 = GetCommand_Move();
  2412. if (cm2)
  2413. {
  2414. cm2.ForceStance(DayZPlayerConstants.STANCEIDX_ERECT);
  2415. }
  2416. }
  2417. SurrenderDummyItem dummyItem;
  2418. if (Class.CastTo(dummyItem, item) && GetEmoteManager())
  2419. GetEmoteManager().ForceSurrenderState(true);
  2420. OnItemInHandsChanged();
  2421. }
  2422. }
  2423. override void EEItemOutOfHands(EntityAI item)
  2424. {
  2425. super.EEItemOutOfHands(item);
  2426. if (IsPlacingLocal())
  2427. {
  2428. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(TogglePlacingLocal);
  2429. }
  2430. OnItemInHandsChanged();
  2431. }
  2432. PlayerStomach GetStomach()
  2433. {
  2434. return m_PlayerStomach;
  2435. }
  2436. override void CommandHandler(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
  2437. {
  2438. EvaluateDamageHit(pCurrentCommandID);
  2439. // lower implement
  2440. super.CommandHandler(pDt,pCurrentCommandID,pCurrentCommandFinished);
  2441. vector playerPosition = PhysicsGetPositionWS();
  2442. HumanInputController hic = GetInputController();
  2443. CheckZeroSoundEvent();
  2444. CheckSendSoundEvent();
  2445. ProcessADDModifier();
  2446. if (m_BrokenLegsJunctureReceived)//was there a change in broken legs state ?
  2447. {
  2448. m_BrokenLegsJunctureReceived = false;
  2449. bool initial = m_BrokenLegState < 0;//negative values indicate initial activation
  2450. if (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  2451. {
  2452. DropHeavyItem();
  2453. if (initial)
  2454. {
  2455. BrokenLegForceProne();
  2456. hic.ResetADS();
  2457. GetUApi().GetInputByID(UATempRaiseWeapon).Supress();
  2458. ExitSights();
  2459. }
  2460. }
  2461. }
  2462. if (IsFireWeaponRaised() || m_IsHoldingBreath)
  2463. {
  2464. ProcessHoldBreath(pDt);
  2465. }
  2466. ActionManagerBase mngr = GetActionManager();
  2467. if (m_AreHandsLocked && GetHumanInventory().GetEntityInHands())
  2468. {
  2469. m_AreHandsLocked = false;
  2470. }
  2471. // freelook camera memory for weapon raycast
  2472. if (hic.CameraIsFreeLook() && m_DirectionToCursor == vector.Zero)
  2473. {
  2474. m_DirectionToCursor = GetGame().GetCurrentCameraDirection();
  2475. }
  2476. else if (!hic.CameraIsFreeLook() && m_DirectionToCursor != vector.Zero)
  2477. {
  2478. m_DirectionToCursor = vector.Zero;
  2479. }
  2480. if (m_WeaponManager)
  2481. {
  2482. m_WeaponManager.Update(pDt);
  2483. }
  2484. if (m_EmoteManager && IsPlayerSelected())
  2485. {
  2486. m_EmoteManager.Update(pDt);
  2487. }
  2488. if (m_RGSManager)
  2489. {
  2490. m_RGSManager.Update();
  2491. }
  2492. if (m_StanceIndicator)
  2493. {
  2494. m_StanceIndicator.Update();
  2495. }
  2496. if (m_StaminaHandler)
  2497. {
  2498. m_StaminaHandler.Update(pDt, pCurrentCommandID);
  2499. }
  2500. if (m_InjuryHandler)
  2501. {
  2502. m_InjuryHandler.Update(pDt);
  2503. }
  2504. if (m_HCAnimHandler)
  2505. {
  2506. m_HCAnimHandler.Update(pDt, m_MovementState);
  2507. }
  2508. if (m_ShockHandler)
  2509. {
  2510. m_ShockHandler.Update(pDt);
  2511. }
  2512. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || !GetGame().IsMultiplayer())
  2513. {
  2514. GetPlayerSoundManagerServer().Update();
  2515. ShockRefill(pDt);
  2516. FreezeCheck();
  2517. }
  2518. if (m_IsDrowning)
  2519. {
  2520. ProcessDrowning(pDt);
  2521. }
  2522. UpdateDelete();
  2523. HandleDamageHit(pCurrentCommandID);
  2524. if (mngr && hic)
  2525. {
  2526. mngr.Update(pCurrentCommandID);
  2527. HumanCommandUnconscious hcu = GetCommand_Unconscious();
  2528. HumanCommandVehicle hcv = GetCommand_Vehicle();
  2529. if (!m_UnconsciousDebug)
  2530. {
  2531. //! When the player should be and is unconscious
  2532. if (m_ShouldBeUnconscious && m_IsUnconscious)
  2533. {
  2534. if (hcu)
  2535. {
  2536. //! Player can start floating while unconscious
  2537. m_Swimming.m_bWasSwimming |= hcu.IsInWater();
  2538. }
  2539. if (m_Swimming.m_bWasSwimming)
  2540. {
  2541. m_LastCommandBeforeUnconscious = DayZPlayerConstants.COMMANDID_SWIM;
  2542. }
  2543. OnUnconsciousUpdate(pDt, m_LastCommandBeforeUnconscious);
  2544. }
  2545. //! When the player will be unconscious, or is being blocked from being unconscious
  2546. else if (m_ShouldBeUnconscious)
  2547. {
  2548. //! If the player is getting in/out or switching seats, delay unconsciousness until after animation has finished
  2549. bool isTransitioning = hcv && (hcv.IsGettingIn() || hcv.IsGettingOut() || hcv.IsSwitchSeat());
  2550. if (pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS)
  2551. {
  2552. OnUnconsciousUpdate(pDt, m_LastCommandBeforeUnconscious);
  2553. m_IsUnconscious = true;
  2554. OnUnconsciousStart();
  2555. }
  2556. //! Death gate - prevent unlikely occurence of death -> unconsciousness transition
  2557. //! Fall gate - prevent unconciousness animation from playing while falling, doesn't look good
  2558. //! Transition gate - prevent unconciousness while previous command is transitioning
  2559. else if (pCurrentCommandID != DayZPlayerConstants.COMMANDID_DEATH && pCurrentCommandID != DayZPlayerConstants.COMMANDID_FALL && !isTransitioning)
  2560. {
  2561. m_LastCommandBeforeUnconscious = pCurrentCommandID;
  2562. if (hcv)
  2563. {
  2564. m_TransportCache = hcv.GetTransport();
  2565. }
  2566. else
  2567. {
  2568. m_TransportCache = null;
  2569. }
  2570. //! TODO: rework vehicle command Knockout back to force player prone after they have exited the vehicle
  2571. m_JumpClimb.CheckAndFinishJump();
  2572. StartCommand_Unconscious(0);
  2573. SetFallYDiff(playerPosition[1]);
  2574. }
  2575. }
  2576. //! When the player is waking up
  2577. else if (m_IsUnconscious)
  2578. {
  2579. //! Make sure the player is actually unconscious
  2580. if (hcu && pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS)
  2581. {
  2582. OnUnconsciousUpdate(pDt, m_LastCommandBeforeUnconscious);
  2583. //! protection for a player being broken when attempting to wake them up too early into unconsciousness
  2584. if (m_UnconsciousTime > 2)
  2585. {
  2586. int wakeUpStance = DayZPlayerConstants.STANCEIDX_PRONE;
  2587. //! Don't set the stance if we are swimming or in a vehicle, stance change animation could play
  2588. if (m_Swimming.m_bWasSwimming || m_LastCommandBeforeUnconscious == DayZPlayerConstants.COMMANDID_VEHICLE)
  2589. wakeUpStance = -1;
  2590. hcu.WakeUp(wakeUpStance);
  2591. m_IsUnconscious = false;
  2592. OnUnconsciousStop(pCurrentCommandID);
  2593. }
  2594. }
  2595. else
  2596. {
  2597. //! Maybe instead error out or notify of possible desync?
  2598. if (IsAlive())
  2599. {
  2600. m_IsUnconscious = false;
  2601. OnUnconsciousStop(pCurrentCommandID);
  2602. }
  2603. }
  2604. }
  2605. }
  2606. // quickbar use
  2607. int quickBarSlot = hic.IsQuickBarSlot();
  2608. if (quickBarSlot && IsAlive())
  2609. {
  2610. if (hic.IsQuickBarSingleUse())
  2611. {
  2612. OnQuickBarSingleUse(quickBarSlot);
  2613. //Print("PlayerBase.c IsQuickBarSingleUse - slot: " + quickBarSlot.ToString());
  2614. }
  2615. if (hic.IsQuickBarContinuousUseStart() && ((!GetGame().IsDedicatedServer()) && !GetGame().GetUIManager().GetMenu()))
  2616. {
  2617. OnQuickBarContinuousUseStart(quickBarSlot);
  2618. //Print("PlayerBase.c IsQuickBarContinuousUseStart - slot: " + quickBarSlot.ToString());
  2619. }
  2620. if (hic.IsQuickBarContinuousUseEnd() && ((!GetGame().IsDedicatedServer())))
  2621. {
  2622. OnQuickBarContinuousUseEnd(quickBarSlot);
  2623. //Print("PlayerBase.c IsQuickBarContinuousUseEnd - slot: " + quickBarSlot.ToString());
  2624. }
  2625. }
  2626. /*if ((pCurrentCommandID == DayZPlayerConstants.COMMANDID_ACTION || pCurrentCommandID == DayZPlayerConstants.COMMANDID_MOVE || pCurrentCommandID == DayZPlayerConstants.COMMANDID_LADDER || pCurrentCommandID == DayZPlayerConstants.COMMANDID_SWIM))
  2627. {
  2628. mngr.Update(); // checks for suitable action and sets it
  2629. }*/
  2630. }
  2631. if (m_StaminaHandler && hic)
  2632. {
  2633. HumanCommandMove hcm = GetCommand_Move();
  2634. bool isSwimmingOrClimbing = GetCommand_Swim() || GetCommand_Climb() || GetCommand_Ladder();
  2635. bool isStaminaLimitAppliable = hcm || isSwimmingOrClimbing;
  2636. if (isStaminaLimitAppliable)
  2637. {
  2638. hic.LimitsDisableSprint(!(CanConsumeStamina(EStaminaConsumers.SPRINT) && CanSprint()));
  2639. }
  2640. }
  2641. //map closing - feel free to move to different "update" if it does not belong here
  2642. if (IsMapOpen())
  2643. {
  2644. if (!GetGame().IsDedicatedServer())
  2645. {
  2646. if (!CfgGameplayHandler.GetUse3DMap() && !GetGame().GetUIManager().IsMenuOpen(MENU_MAP))
  2647. {
  2648. CloseMapEx(false);
  2649. }
  2650. else if (CfgGameplayHandler.GetUse3DMap())
  2651. {
  2652. if (IsMapCallbackCancelInput())
  2653. {
  2654. CloseMapEx(true);
  2655. }
  2656. else if (IsMapCallbackEndInput())
  2657. {
  2658. CloseMapEx(false);
  2659. }
  2660. }
  2661. }
  2662. }
  2663. #ifdef DIAG_DEVELOPER
  2664. if (m_Bot)
  2665. m_Bot.OnUpdate(pDt);
  2666. #endif
  2667. if (m_CheckMeleeItem && (!GetGame().IsDedicatedServer()))
  2668. {
  2669. CheckMeleeItemDamage(m_CheckMeleeItem);
  2670. SetCheckMeleeItem();
  2671. }
  2672. #ifdef DEVELOPER
  2673. TryGetInVehicleDebug();
  2674. #endif
  2675. OnCommandHandlerTick(pDt, pCurrentCommandID);
  2676. }
  2677. #ifdef DEVELOPER
  2678. void SetGetInVehicleDebug(EntityAI ent)
  2679. {
  2680. m_GetInVehicleTransportDebug = Transport.Cast(ent);
  2681. }
  2682. void TryGetInVehicleDebug()
  2683. {
  2684. if (m_GetInVehicleTransportDebug)
  2685. {
  2686. HumanCommandVehicle vehCommand = StartCommand_Vehicle(m_GetInVehicleTransportDebug, 0, 0);
  2687. if (vehCommand)
  2688. {
  2689. vehCommand.SetVehicleType(m_GetInVehicleTransportDebug.GetAnimInstance());
  2690. }
  2691. m_GetInVehicleTransportDebug = null;
  2692. }
  2693. }
  2694. #endif
  2695. //MAP handling
  2696. //! DEPRECATED; terminates map animation callback and re-enables controls
  2697. void CloseMap()
  2698. {
  2699. CloseMapEx(false);
  2700. }
  2701. void CloseMapEx(bool cancelled)
  2702. {
  2703. if (m_hac && !GetMapClosingSyncSent())
  2704. {
  2705. if (ScriptInputUserData.CanStoreInputUserData())
  2706. {
  2707. if (GetGame().IsMultiplayer() && GetGame().IsClient())
  2708. {
  2709. ActionManagerClient mngr_client;
  2710. CastTo(mngr_client, GetActionManager());
  2711. if (cancelled)
  2712. {
  2713. mngr_client.RequestInterruptAction();
  2714. }
  2715. else
  2716. {
  2717. mngr_client.RequestEndAction();
  2718. }
  2719. GetGame().GetMission().RemoveActiveInputExcludes({"map"});
  2720. GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
  2721. }
  2722. else if (!GetGame().IsMultiplayer())
  2723. {
  2724. int command_ID = DayZPlayerConstants.CMD_ACTIONINT_END;
  2725. if (cancelled)
  2726. {
  2727. command_ID = DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT;
  2728. }
  2729. m_hac.InternalCommand(command_ID);
  2730. }
  2731. SetMapClosingSyncSet(true);
  2732. }
  2733. }
  2734. if (!GetGame().IsDedicatedServer())
  2735. {
  2736. if (GetGame().GetUIManager().IsMenuOpen(MENU_MAP))
  2737. {
  2738. GetGame().GetUIManager().FindMenu(MENU_MAP).Close();
  2739. if (m_Hud)
  2740. {
  2741. m_Hud.ShowQuickbarPlayer(true);
  2742. }
  2743. GetGame().GetMission().RemoveActiveInputExcludes({"map"});
  2744. GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.MAP);
  2745. }
  2746. }
  2747. }
  2748. void SetMapOpen(bool state)
  2749. {
  2750. m_MapOpen = state;
  2751. }
  2752. bool IsMapOpen()
  2753. {
  2754. return m_MapOpen;
  2755. }
  2756. void SetMapClosingSyncSet(bool state)
  2757. {
  2758. m_MapClosingSyncSent = state;
  2759. }
  2760. bool GetMapClosingSyncSent()
  2761. {
  2762. return m_MapClosingSyncSent;
  2763. }
  2764. bool IsMapCallbackCancelInput()
  2765. {
  2766. if (IsRaised())
  2767. {
  2768. return true;
  2769. }
  2770. return false;
  2771. }
  2772. bool IsMapCallbackEndInput()
  2773. {
  2774. if (GetUApi().GetInputByID(UADefaultAction).LocalPress() || GetUApi().GetInputByID(UAUIMenu).LocalPress() || GetUApi().GetInputByID(UAGear).LocalPress())
  2775. {
  2776. return true;
  2777. }
  2778. return false;
  2779. }
  2780. MapNavigationBehaviour GetMapNavigationBehaviour()
  2781. {
  2782. return m_MapNavigationBehaviour;
  2783. }
  2784. void MapNavigationItemInPossession(EntityAI item)
  2785. {
  2786. if (GetMapNavigationBehaviour())
  2787. {
  2788. GetMapNavigationBehaviour().OnItemInPlayerPossession(item);
  2789. }
  2790. }
  2791. void MapNavigationItemNotInPossession(EntityAI item)
  2792. {
  2793. if (GetMapNavigationBehaviour())
  2794. {
  2795. GetMapNavigationBehaviour().OnItemNotInPlayerPossession(item);
  2796. }
  2797. }
  2798. void SetCheckMeleeItem(ItemBase item = null)
  2799. {
  2800. m_CheckMeleeItem = item;
  2801. }
  2802. void SetShakesForced(int value)
  2803. {
  2804. m_ShakesForced = value;
  2805. }
  2806. void FreezeCheck()
  2807. {
  2808. int level;
  2809. if (m_ShakesForced > 0)
  2810. {
  2811. level = m_ShakesForced;
  2812. }
  2813. else
  2814. {
  2815. float heat_comfort = GetStatHeatComfort().Get();
  2816. if (heat_comfort <= PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_WARNING)
  2817. {
  2818. float value = Math.InverseLerp(PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_WARNING, PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_CRITICAL,heat_comfort);
  2819. level = Math.Lerp(1,7,value);
  2820. level = Math.Clamp(value,1,7);
  2821. /*
  2822. value = Math.Clamp(value,0,1);
  2823. level = Math.Round(value * SHAKE_LEVEL_MAX);//translate from normalized value to levels
  2824. */
  2825. }
  2826. }
  2827. if (level != m_Shakes)
  2828. {
  2829. m_Shakes = level;
  2830. SetSynchDirty();
  2831. }
  2832. }
  2833. override bool IsLanded(int pCurrentCommandID)
  2834. {
  2835. if (super.IsLanded(pCurrentCommandID))
  2836. {
  2837. return true;
  2838. }
  2839. //! Handle fall damage for unconscious
  2840. if (pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS)
  2841. {
  2842. bool wasFalling = m_IsUnconsciousFalling;
  2843. m_IsUnconsciousFalling = PhysicsIsFalling(false);
  2844. return wasFalling && !m_IsUnconsciousFalling;
  2845. }
  2846. //! No fall damage for players currently being damaged, animation is temporary
  2847. return false;
  2848. }
  2849. override bool OnLand(int pCurrentCommandID, FallDamageData fallDamageData)
  2850. {
  2851. if (super.OnLand(pCurrentCommandID, fallDamageData))
  2852. {
  2853. return true;
  2854. }
  2855. //! Nothing happens for unconscious
  2856. //! Nothing happens for being damaged
  2857. return false;
  2858. }
  2859. override bool IsAlreadyInFallingCommand(int pCurrentCommandID)
  2860. {
  2861. if (super.IsAlreadyInFallingCommand(pCurrentCommandID))
  2862. {
  2863. return true;
  2864. }
  2865. //! Don't switch to falling command if unconscious
  2866. //! Don't switch to falling command if being damaged
  2867. return pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS || pCurrentCommandID == DayZPlayerConstants.COMMANDID_DAMAGE;
  2868. }
  2869. void OnUnconsciousStart()
  2870. {
  2871. CloseInventoryMenu();
  2872. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  2873. {
  2874. GetGame().GetMission().GetHud().ShowHudUI(false);
  2875. SetInventorySoftLock(true);
  2876. if (m_LastCommandBeforeUnconscious != DayZPlayerConstants.COMMANDID_VEHICLE)
  2877. {
  2878. EntityAI entity_in_hands = GetHumanInventory().GetEntityInHands();
  2879. if (entity_in_hands && CanDropEntity(entity_in_hands) && !IsRestrained() && !IsSurrendered())
  2880. {
  2881. DropItem(ItemBase.Cast(entity_in_hands));
  2882. }
  2883. }
  2884. GetGame().GetSoundScene().SetSoundVolume(0,2);
  2885. m_EffectWidgets.AddSuspendRequest(EffectWidgetSuspends.UNCON);
  2886. }
  2887. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || (!GetGame().IsMultiplayer() && GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT))
  2888. {
  2889. SetSynchDirty();
  2890. if (m_LastCommandBeforeUnconscious == DayZPlayerConstants.COMMANDID_VEHICLE)
  2891. {
  2892. if (m_TransportCache)
  2893. m_TransportCache.MarkCrewMemberUnconscious(m_TransportCache.CrewMemberIndex(this));
  2894. }
  2895. // disable voice communication
  2896. GetGame().EnableVoN(this, false);
  2897. if (m_AdminLog)
  2898. {
  2899. m_AdminLog.UnconStart(this);
  2900. }
  2901. // When we fall uncon we force out of block
  2902. if (GetMeleeFightLogic())
  2903. {
  2904. GetMeleeFightLogic().SetBlock(false);
  2905. }
  2906. }
  2907. SetMasterAttenuation("UnconsciousAttenuation");
  2908. if (m_OnUnconsciousStart)
  2909. m_OnUnconsciousStart.Invoke(this);
  2910. }
  2911. void OnUnconsciousStop(int pCurrentCommandID)
  2912. {
  2913. m_UnconRefillModifier =1;
  2914. SetSynchDirty();
  2915. m_UnconsciousTime = 0;
  2916. m_UnconsciousVignetteTarget = 2;
  2917. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  2918. {
  2919. GetGame().GetMission().GetHud().ShowHudUI(true);
  2920. if (pCurrentCommandID != DayZPlayerConstants.COMMANDID_DEATH)
  2921. {
  2922. GetGame().GetSoundScene().SetSoundVolume(g_Game.m_volume_sound,1);
  2923. PPERequester_UnconEffects requester = PPERequester_UnconEffects.Cast(PPERequesterBank.GetRequester(PPERequester_UnconEffects));
  2924. requester.FadeOutEffect(); //fading
  2925. GetGame().GetMission().GetHud().ShowQuickbarUI(true);
  2926. if (GetGame().GetUIManager().IsDialogVisible())
  2927. {
  2928. GetGame().GetUIManager().CloseDialog();
  2929. }
  2930. if (GetGame().GetUIManager().IsMenuOpen(MENU_RESPAWN_DIALOGUE))
  2931. {
  2932. GetGame().GetUIManager().FindMenu(MENU_RESPAWN_DIALOGUE).Close();
  2933. }
  2934. }
  2935. SetInventorySoftLock(false);
  2936. m_EffectWidgets.RemoveSuspendRequest(EffectWidgetSuspends.UNCON);
  2937. }
  2938. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  2939. {
  2940. // enable voice communication
  2941. if (IsAlive())
  2942. GetGame().EnableVoN(this, true);
  2943. if (m_AdminLog)
  2944. {
  2945. m_AdminLog.UnconStop(this);
  2946. }
  2947. }
  2948. SetMasterAttenuation("");
  2949. if (m_OnUnconsciousStop)
  2950. m_OnUnconsciousStop.Invoke(this);
  2951. }
  2952. void OnUnconsciousUpdate(float pDt, int last_command)
  2953. {
  2954. m_UnconsciousTime += pDt;
  2955. if (GetGame().IsServer())
  2956. {
  2957. int shock_simplified = SimplifyShock();
  2958. if (m_ShockSimplified != shock_simplified)
  2959. {
  2960. m_ShockSimplified = shock_simplified;
  2961. SetSynchDirty();
  2962. }
  2963. if (m_UnconsciousTime > PlayerConstants.UNCONSCIOUS_IN_WATER_TIME_LIMIT_TO_DEATH && last_command == DayZPlayerConstants.COMMANDID_SWIM)
  2964. {
  2965. PluginAdminLog adm = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
  2966. adm.PlayerKilledByDrowningUncon(this);
  2967. SetHealth("","",-100);
  2968. }
  2969. }
  2970. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  2971. {
  2972. GetGame().GetMission().GetHud().ShowQuickbarUI(false);
  2973. if (GetPulseType() == EPulseType.REGULAR)
  2974. {
  2975. float shock_simple_normalized = GetSimplifiedShockNormalized();
  2976. float sin = Math.Sin(m_UnconsciousTime * 0.35);
  2977. float sin_normalized = (sin + 1) / 2;
  2978. if (sin_normalized < 0.05)
  2979. {
  2980. m_UnconsciousVignetteTarget = (1 - shock_simple_normalized / 3) * 2/*vignette max*/;
  2981. }
  2982. float vignette = Math.Lerp(2,m_UnconsciousVignetteTarget, sin_normalized);
  2983. m_UnconParam.param1 = vignette;
  2984. PPERequesterBank.GetRequester(PPERequester_UnconEffects).Start(m_UnconParam);
  2985. }
  2986. }
  2987. }
  2988. int SimplifyShock()
  2989. {
  2990. int shock = Math.Lerp(0, SIMPLIFIED_SHOCK_CAP, GetHealth("","Shock") / GetMaxHealth("","Shock"));
  2991. shock = Math.Clamp(shock, 0, SIMPLIFIED_SHOCK_CAP);
  2992. return shock;
  2993. }
  2994. float GetSimplifiedShockNormalized()
  2995. {
  2996. return (m_ShockSimplified / SIMPLIFIED_SHOCK_CAP);
  2997. }
  2998. override bool IsUnconscious()
  2999. {
  3000. return m_MovementState.m_CommandTypeId == DayZPlayerConstants.COMMANDID_UNCONSCIOUS || m_IsUnconscious;
  3001. }
  3002. override bool IsUnconsciousStateOnly()
  3003. {
  3004. return m_IsUnconscious;
  3005. }
  3006. override bool CanBeTargetedByAI(EntityAI ai)
  3007. {
  3008. #ifdef DIAG_DEVELOPER
  3009. if (!m_CanBeTargetedDebug)
  3010. {
  3011. return false;
  3012. }
  3013. #endif
  3014. return super.CanBeTargetedByAI(ai) && !IsUnconscious() && !IsInVehicle();
  3015. }
  3016. void GiveShock(float shock)
  3017. {
  3018. AddHealth("","Shock",shock);
  3019. }
  3020. void OnRestrainStart()
  3021. {
  3022. CloseInventoryMenu();
  3023. GetGame().GetMission().RemoveActiveInputExcludes({"inventory"},true);
  3024. GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.INVENTORY);
  3025. }
  3026. //! functionality moved to ShockMdfr::OnTick
  3027. void ShockRefill(float pDt);
  3028. //BrokenLegs
  3029. // -----------------------
  3030. eBrokenLegs GetBrokenLegs()
  3031. {
  3032. return Math.AbsInt(m_BrokenLegState);//negative value denotes first time activation
  3033. }
  3034. //Server side
  3035. void SetBrokenLegs(int stateId)
  3036. {
  3037. m_BrokenLegState = stateId;
  3038. DayZPlayerSyncJunctures.SendBrokenLegsEx(this, stateId);
  3039. eBrokenLegs state = GetBrokenLegs();//m_BrokenLegState can go bellow 0, cannot be used directly
  3040. if (state == eBrokenLegs.NO_BROKEN_LEGS)
  3041. {
  3042. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS;
  3043. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS_SPLINT;
  3044. }
  3045. else if (state == eBrokenLegs.BROKEN_LEGS)
  3046. {
  3047. SetLegHealth();
  3048. }
  3049. else if (state == eBrokenLegs.BROKEN_LEGS_SPLINT)
  3050. {
  3051. // handle splint here
  3052. }
  3053. SetSynchDirty();
  3054. }
  3055. //Update of state
  3056. void UpdateBrokenLegs(int stateId)
  3057. {
  3058. eBrokenLegs state = GetBrokenLegs();
  3059. //Raise broken legs flag and force to prone
  3060. if (state != eBrokenLegs.NO_BROKEN_LEGS)
  3061. {
  3062. if (state == eBrokenLegs.BROKEN_LEGS_SPLINT)
  3063. {
  3064. if (m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE)
  3065. {
  3066. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.PRONE_ANIM_OVERRIDE;
  3067. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS;
  3068. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask | eInjuryOverrides.BROKEN_LEGS_SPLINT;
  3069. }
  3070. m_InjuryHandler.CheckValue(false);
  3071. }
  3072. else if (state == eBrokenLegs.BROKEN_LEGS)
  3073. {
  3074. if (m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE)
  3075. {
  3076. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.PRONE_ANIM_OVERRIDE;
  3077. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS_SPLINT;
  3078. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask | eInjuryOverrides.BROKEN_LEGS;
  3079. }
  3080. BrokenLegWalkShock();
  3081. m_InjuryHandler.CheckValue(false);
  3082. }
  3083. }
  3084. else if (state == eBrokenLegs.NO_BROKEN_LEGS)
  3085. {
  3086. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS;
  3087. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.BROKEN_LEGS_SPLINT;
  3088. }
  3089. }
  3090. void BreakLegSound()
  3091. {
  3092. PlaySoundSet(m_BrokenLegSound, SOUND_BREAK_LEG, 0.1, 0.1);
  3093. }
  3094. void BrokenLegForceProne(bool forceOverride = false)
  3095. {
  3096. if (!IsInWater() && !IsSwimming() && !IsClimbingLadder() && !IsInVehicle() && !IsClimbing() && DayZPlayerUtils.PlayerCanChangeStance(this, DayZPlayerConstants.STANCEIDX_PRONE))
  3097. {
  3098. if (m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE && m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_RAISEDPRONE)
  3099. {
  3100. EntityAI attachment;
  3101. Class.CastTo(attachment, GetItemOnSlot("Splint_Right"));
  3102. if (attachment && attachment.GetType() == "Splint_Applied")
  3103. {
  3104. attachment.Delete();
  3105. }
  3106. m_ShockHandler.SetShock(PlayerConstants.BROKEN_LEGS_INITIAL_SHOCK);
  3107. m_ShockHandler.CheckValue(true);
  3108. if (m_ShockHandler.GetCurrentShock() >= 25) //Prevent conflict with unconsciousness by not forcing prone when going uncon (25 shock or less left)
  3109. {
  3110. //calcels user action
  3111. HumanCommandActionCallback cmd = GetCommand_Action();
  3112. if (cmd)
  3113. {
  3114. cmd.Cancel();
  3115. }
  3116. StopHandEvent();
  3117. //Get command move and verify not null
  3118. HumanCommandMove hcm = StartCommand_Move();//not sure why this is here
  3119. hcm = GetCommand_Move();
  3120. if (hcm)
  3121. {
  3122. hcm.ForceStance(DayZPlayerConstants.STANCEIDX_PRONE);
  3123. }
  3124. }
  3125. }
  3126. }
  3127. m_JumpClimb.CheckAndFinishJump();
  3128. }
  3129. //Used to inflict shock when player is walking (only inflicted on Update timer)
  3130. void BrokenLegWalkShock()
  3131. {
  3132. //No need to pursue here if player is prone as the following logic is not applied
  3133. if (m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE && m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_RAISEDPRONE)
  3134. {
  3135. float avgLegHealth = GetHealth("RightLeg","") + GetHealth("LeftLeg","") + GetHealth("RightFoot","") + GetHealth("LeftFoot","");
  3136. avgLegHealth *= 0.25; //divide by 4 to make the average leg health;
  3137. if (IsSwimming())
  3138. {
  3139. //swimming other than forward is not detectable in script other than through velocity check
  3140. vector v;
  3141. PhysicsGetVelocity(v);
  3142. if (v.LengthSq() > 0)
  3143. {
  3144. m_ShockHandler.SetShock(PlayerConstants.BROKEN_LEGS_SHOCK_SWIM);
  3145. }
  3146. }
  3147. else if (m_MovementState.m_iMovement != 0)
  3148. {
  3149. if (IsClimbingLadder())
  3150. {
  3151. MovingShock(avgLegHealth, PlayerConstants.BROKEN_LEGS_HIGH_SHOCK_WALK, PlayerConstants.BROKEN_LEGS_MID_SHOCK_WALK, PlayerConstants.BROKEN_LEGS_LOW_SHOCK_WALK);
  3152. }
  3153. else if (m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_ERECT || m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDERECT)
  3154. {
  3155. if (m_MovementState.m_iMovement > 1)//only jog and faster
  3156. {
  3157. MovingShock(avgLegHealth, PlayerConstants.BROKEN_LEGS_HIGH_SHOCK_WALK, PlayerConstants.BROKEN_LEGS_MID_SHOCK_WALK, PlayerConstants.BROKEN_LEGS_LOW_SHOCK_WALK);
  3158. }
  3159. }
  3160. else if (m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_CROUCH || m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDCROUCH)
  3161. {
  3162. //any speed other than idle
  3163. MovingShock(avgLegHealth, PlayerConstants.BROKEN_LEGS_HIGH_SHOCK_WALK * PlayerConstants.BROKEN_CROUCH_MODIFIER, PlayerConstants.BROKEN_LEGS_MID_SHOCK_WALK * PlayerConstants.BROKEN_CROUCH_MODIFIER, PlayerConstants.BROKEN_LEGS_LOW_SHOCK_WALK * PlayerConstants.BROKEN_CROUCH_MODIFIER);
  3164. }
  3165. }
  3166. else
  3167. {
  3168. //Here apply shock if player is standing or crouched and STANDING STILL
  3169. m_ShockHandler.SetShock(PlayerConstants.BROKEN_LEGS_STAND_SHOCK);
  3170. }
  3171. m_ShockHandler.CheckValue(true);
  3172. }
  3173. }
  3174. //Always use the same thresholds but allow passing of different shock values
  3175. void MovingShock(float legHealth, float highShock, float midShock, float lowShock)
  3176. {
  3177. if (legHealth <= PlayerConstants.BROKEN_LEGS_LOW_HEALTH_THRESHOLD)
  3178. {
  3179. //Inflict "high shock"
  3180. m_ShockHandler.SetShock(highShock);
  3181. }
  3182. else if (legHealth >= PlayerConstants.BROKEN_LEGS_HIGH_HEALTH_THRESHOLD)
  3183. {
  3184. //Inflict "low shock"
  3185. m_ShockHandler.SetShock(lowShock);
  3186. }
  3187. else
  3188. {
  3189. //If neither high nore low, inflict "mid shock"
  3190. m_ShockHandler.SetShock(midShock);
  3191. }
  3192. }
  3193. void DealShock(float dmg)
  3194. {
  3195. Param1<float> damage = new Param1<float>(0);
  3196. damage.param1 = dmg;
  3197. GetGame().RPCSingleParam(this, ERPCs.RPC_SHOCK, damage, true, GetIdentity());
  3198. }
  3199. //Prevent player from picking up heavy items when legs are broken
  3200. override bool CanPickupHeavyItem(notnull EntityAI item)
  3201. {
  3202. if (item.IsHeavyBehaviour() && (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS || GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS_SPLINT))
  3203. return false;
  3204. return super.CanPickupHeavyItem(item);
  3205. }
  3206. //Set all leg zones' health to 0 in order to limit emergent behaviour and prevent confusion as to how broken legs really work
  3207. void SetLegHealth()
  3208. {
  3209. SetHealth("RightLeg", "", 0);
  3210. SetHealth("RightFoot", "", 0);
  3211. SetHealth("LeftLeg", "", 0);
  3212. SetHealth("LeftFoot", "", 0);
  3213. }
  3214. void DropHeavyItem()
  3215. {
  3216. ItemBase itemInHands = GetItemInHands();
  3217. if (itemInHands && itemInHands.IsHeavyBehaviour())
  3218. DropItem(itemInHands);
  3219. }
  3220. bool IsWearingSplint()
  3221. {
  3222. EntityAI attachment;
  3223. Class.CastTo(attachment, GetItemOnSlot("Splint_Right"));
  3224. if (attachment && attachment.GetType() == "Splint_Applied")
  3225. {
  3226. return true;
  3227. }
  3228. return false;
  3229. }
  3230. // -----------------------
  3231. override void OnCommandSwimStart()
  3232. {
  3233. ItemBase itemInHands = GetItemInHands();
  3234. if (itemInHands)
  3235. {
  3236. if (itemInHands.IsHeavyBehaviour())
  3237. {
  3238. TryHideItemInHands(false);
  3239. #ifdef SERVER
  3240. ServerDropEntity(itemInHands); // Let server handle the hand item drop
  3241. #endif
  3242. }
  3243. else
  3244. {
  3245. TryHideItemInHands(true);
  3246. }
  3247. itemInHands.OnItemInHandsPlayerSwimStart(this);
  3248. }
  3249. m_AnimCommandStarting = HumanMoveCommandID.CommandSwim;
  3250. if (GetInventory())
  3251. GetInventory().LockInventory(LOCK_FROM_SCRIPT);
  3252. CloseInventoryMenu();
  3253. GetDayZGame().GetBacklit().OnSwimmingStart();
  3254. AbortWeaponEvent();
  3255. GetWeaponManager().DelayedRefreshAnimationState(10);
  3256. RequestHandAnimationStateRefresh();
  3257. GetGame().GetMission().AddActiveInputExcludes({"swimming"});
  3258. }
  3259. override void OnCommandSwimFinish()
  3260. {
  3261. TryHideItemInHands(false, true);
  3262. if (GetInventory())
  3263. GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
  3264. GetDayZGame().GetBacklit().OnSwimmingStop();
  3265. GetWeaponManager().RefreshAnimationState();
  3266. GetGame().GetMission().RemoveActiveInputExcludes({"swimming"});
  3267. }
  3268. override void OnCommandLadderStart()
  3269. {
  3270. m_AnimCommandStarting = HumanMoveCommandID.CommandLadder;
  3271. TryHideItemInHands(true);
  3272. if (GetInventory())
  3273. GetInventory().LockInventory(LOCK_FROM_SCRIPT);
  3274. CloseInventoryMenu();
  3275. GetGame().GetMission().AddActiveInputExcludes({"ladderclimbing"});
  3276. }
  3277. override void OnCommandLadderFinish()
  3278. {
  3279. TryHideItemInHands(false, true);
  3280. if (GetInventory())
  3281. GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
  3282. GetGame().GetMission().RemoveActiveInputExcludes({"ladderclimbing"});
  3283. }
  3284. override void OnCommandFallStart()
  3285. {
  3286. m_AnimCommandStarting = HumanMoveCommandID.CommandFall;
  3287. if (GetInventory())
  3288. GetInventory().LockInventory(LOCK_FROM_SCRIPT);
  3289. CloseInventoryMenu();
  3290. AbortWeaponEvent();
  3291. GetWeaponManager().DelayedRefreshAnimationState(10);
  3292. RequestHandAnimationStateRefresh();
  3293. }
  3294. override void OnCommandFallFinish()
  3295. {
  3296. if (GetInventory())
  3297. GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
  3298. // properly finish jump in case it was interrupted by smth (heavy hit for example in the FOV expoit)
  3299. m_JumpClimb.CheckAndFinishJump();
  3300. GetWeaponManager().RefreshAnimationState();
  3301. }
  3302. override void OnCommandClimbStart()
  3303. {
  3304. m_AnimCommandStarting = HumanMoveCommandID.CommandClimb;
  3305. if (GetInventory())
  3306. GetInventory().LockInventory(LOCK_FROM_SCRIPT);
  3307. CloseInventoryMenu();
  3308. AbortWeaponEvent();
  3309. GetWeaponManager().DelayedRefreshAnimationState(10);
  3310. RequestHandAnimationStateRefresh();
  3311. }
  3312. override void OnCommandClimbFinish()
  3313. {
  3314. if (GetInventory())
  3315. GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
  3316. GetWeaponManager().RefreshAnimationState();
  3317. }
  3318. override void OnCommandVehicleStart()
  3319. {
  3320. m_AnimCommandStarting = HumanMoveCommandID.CommandVehicle;
  3321. if (GetInventory())
  3322. GetInventory().LockInventory(LOCK_FROM_SCRIPT);
  3323. CloseInventoryMenu();
  3324. ItemBase itemInHand = GetItemInHands();
  3325. EntityAI itemOnHead = FindAttachmentBySlotName("Headgear");
  3326. if (itemInHand && itemInHand.GetCompEM())
  3327. itemInHand.GetCompEM().SwitchOff();
  3328. TryHideItemInHands(true);
  3329. if (itemOnHead && itemOnHead.GetCompEM())
  3330. itemOnHead.GetCompEM().SwitchOff();
  3331. GetGame().GetMission().AddActiveInputExcludes({"vehicledriving"});
  3332. }
  3333. override void OnCommandVehicleFinish()
  3334. {
  3335. if (GetInventory())
  3336. GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
  3337. if (!m_ShouldBeUnconscious)
  3338. TryHideItemInHands(false, true);
  3339. GetGame().GetMission().RemoveActiveInputExcludes({"vehicledriving"});
  3340. }
  3341. override void OnCommandMelee2Start()
  3342. {
  3343. m_AnimCommandStarting = HumanMoveCommandID.CommandMelee2;
  3344. m_IsFighting = true;
  3345. AbortWeaponEvent();
  3346. GetWeaponManager().DelayedRefreshAnimationState(10);
  3347. RequestHandAnimationStateRefresh();
  3348. }
  3349. override void OnCommandMelee2Finish()
  3350. {
  3351. RunFightBlendTimer();
  3352. GetWeaponManager().RefreshAnimationState();
  3353. }
  3354. override void OnCommandDeathStart()
  3355. {
  3356. m_AnimCommandStarting = HumanMoveCommandID.CommandDeath;
  3357. AbortWeaponEvent();
  3358. GetWeaponManager().DelayedRefreshAnimationState(10);
  3359. RequestHandAnimationStateRefresh();
  3360. super.OnCommandDeathStart();
  3361. }
  3362. override void OnJumpStart()
  3363. {
  3364. m_ActionManager.OnJumpStart();
  3365. AbortWeaponEvent();
  3366. GetWeaponManager().DelayedRefreshAnimationState(10);
  3367. RequestHandAnimationStateRefresh();
  3368. CloseMapEx(true);
  3369. }
  3370. override void OnJumpEnd(int pLandType = 0)
  3371. {
  3372. if (m_PresenceNotifier)
  3373. {
  3374. switch (pLandType)
  3375. {
  3376. case HumanCommandFall.LANDTYPE_NONE:
  3377. case HumanCommandFall.LANDTYPE_LIGHT:
  3378. m_PresenceNotifier.ProcessEvent(EPresenceNotifierNoiseEventType.LAND_LIGHT);
  3379. break;
  3380. case HumanCommandFall.LANDTYPE_MEDIUM:
  3381. case HumanCommandFall.LANDTYPE_HEAVY:
  3382. m_PresenceNotifier.ProcessEvent(EPresenceNotifierNoiseEventType.LAND_HEAVY);
  3383. break;
  3384. }
  3385. }
  3386. GetWeaponManager().RefreshAnimationState();
  3387. }
  3388. bool IsStance(int stance, int stanceMask)
  3389. {
  3390. return ((1 << stance) & stanceMask) != 0;
  3391. }
  3392. override void OnStanceChange(int previousStance, int newStance)
  3393. {
  3394. int prone = DayZPlayerConstants.STANCEMASK_PRONE | DayZPlayerConstants.STANCEMASK_RAISEDPRONE;
  3395. int notProne = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_RAISEDERECT | DayZPlayerConstants.STANCEMASK_RAISEDCROUCH;
  3396. if (IsStance(previousStance, DayZPlayerConstants.STANCEMASK_PRONE) && IsStance(newStance, DayZPlayerConstants.STANCEMASK_ERECT))
  3397. m_SprintedTimePerStanceMin = PlayerConstants.FULL_SPRINT_DELAY_FROM_PRONE;
  3398. if (IsStance(previousStance, DayZPlayerConstants.STANCEMASK_PRONE) && IsStance(previousStance, DayZPlayerConstants.STANCEMASK_CROUCH) || (IsStance(previousStance, DayZPlayerConstants.STANCEMASK_CROUCH) && IsStance(newStance, DayZPlayerConstants.STANCEMASK_ERECT)))
  3399. m_SprintedTimePerStanceMin = PlayerConstants.FULL_SPRINT_DELAY_FROM_CROUCH;
  3400. if ((IsStance(previousStance, prone) && IsStance(newStance, notProne)) || (IsStance(previousStance, notProne) && IsStance(newStance, prone)))
  3401. {
  3402. AbortWeaponEvent();
  3403. GetWeaponManager().RefreshAnimationState();
  3404. }
  3405. }
  3406. override bool CanChangeStance(int previousStance, int newStance)
  3407. {
  3408. // Check if the player is trying to perform restricted action while changing stance
  3409. if (GetActionManager() && GetActionManager().GetRunningAction() && !GetActionManager().GetRunningAction().CanBePerformedWhileChangingStance())
  3410. return false;
  3411. // Check if the player is playing a throwing animation
  3412. if (GetThrowing().IsThrowingAnimationPlaying())
  3413. return false;
  3414. // don't allow base stance change, only raised hands change
  3415. if (IsRolling())
  3416. {
  3417. if (Math.AbsInt(previousStance - newStance) == 3)
  3418. return true;
  3419. return false;
  3420. }
  3421. // Check if the player is going to crouch or raised crouch
  3422. if (newStance == DayZPlayerConstants.STANCEIDX_CROUCH || newStance == DayZPlayerConstants.STANCEIDX_RAISEDCROUCH)
  3423. {
  3424. return GetCurrentWaterLevel() <= GetDayZPlayerType().CommandSwimSettingsW().m_fToErectLevel;
  3425. }
  3426. // Check if the player is going to prone
  3427. if (newStance == DayZPlayerConstants.STANCEIDX_PRONE || newStance == DayZPlayerConstants.STANCEIDX_RAISEDPRONE)
  3428. {
  3429. return GetCurrentWaterLevel() <= GetDayZPlayerType().CommandSwimSettingsW().m_fToCrouchLevel;
  3430. }
  3431. // The player can change stance if none of the conditions above are met
  3432. return true;
  3433. }
  3434. override void OnCommandMoveStart()
  3435. {
  3436. if (GetGame().IsServer())
  3437. {
  3438. //In case player changes stance through a different command, we refresh the anim overrides
  3439. int prone = DayZPlayerConstants.STANCEMASK_PRONE | DayZPlayerConstants.STANCEMASK_RAISEDPRONE;
  3440. if (!IsPlayerInStance(prone))
  3441. {
  3442. m_InjuryHandler.m_ForceInjuryAnimMask = m_InjuryHandler.m_ForceInjuryAnimMask & ~eInjuryOverrides.PRONE_ANIM_OVERRIDE;
  3443. ForceUpdateInjuredState();
  3444. }
  3445. }
  3446. }
  3447. override bool CanRoll()
  3448. {
  3449. if (!CanConsumeStamina(EStaminaConsumers.ROLL))
  3450. return false;
  3451. if (IsInFBEmoteState() || m_EmoteManager.m_MenuEmote)
  3452. {
  3453. return false;
  3454. }
  3455. return IsPlayerInStance(DayZPlayerConstants.STANCEMASK_PRONE | DayZPlayerConstants.STANCEMASK_RAISEDPRONE) && GetCommand_Move() && !GetCommand_Move().IsOnBack();
  3456. }
  3457. override void OnRollStart(bool isToTheRight)
  3458. {
  3459. DepleteStamina(EStaminaModifiers.ROLL);
  3460. if (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  3461. m_ShockHandler.SetShock(PlayerConstants.BROKEN_LEGS_ROLL_SHOCK);
  3462. }
  3463. override void OnRollFinish()
  3464. {
  3465. }
  3466. void OnJumpOutVehicleFinish(float carSpeed)
  3467. {
  3468. string surfaceType;
  3469. int liquidType;
  3470. GetGame().SurfaceUnderObject(this, surfaceType, liquidType);
  3471. }
  3472. void OnVehicleSwitchSeat(int seatIndex)
  3473. {
  3474. }
  3475. override void OnVehicleSeatDriverEnter()
  3476. {
  3477. m_IsVehicleSeatDriver = true;
  3478. if (m_Hud)
  3479. m_Hud.ShowVehicleInfo();
  3480. #ifdef FEATURE_NETWORK_RECONCILIATION
  3481. PlayerIdentity identity = GetIdentity();
  3482. if (identity)
  3483. {
  3484. Pawn pawn = Pawn.Cast(GetParent());
  3485. //! Hand off control to the vehicle - null is valid
  3486. identity.Possess(pawn);
  3487. }
  3488. #endif
  3489. }
  3490. override void OnVehicleSeatDriverLeft()
  3491. {
  3492. #ifdef FEATURE_NETWORK_RECONCILIATION
  3493. PlayerIdentity identity = GetIdentity();
  3494. //! Don't possess the player if we are in the vehicle and unconscious, we are still the driver!
  3495. if (identity && !m_ShouldBeUnconscious)
  3496. {
  3497. //! And now we want to resume control of the player
  3498. identity.Possess(this);
  3499. }
  3500. #endif
  3501. m_IsVehicleSeatDriver = false;
  3502. if (m_Hud)
  3503. m_Hud.HideVehicleInfo();
  3504. }
  3505. override void OnThrowingModeChange(bool change_to_enabled)
  3506. {
  3507. if (change_to_enabled)
  3508. {
  3509. PlacingCancelLocal();
  3510. PlacingCancelServer();
  3511. }
  3512. }
  3513. override void EOnFrame(IEntity other, float timeSlice)
  3514. {
  3515. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3516. {
  3517. #ifndef NO_GUI
  3518. m_Hud.Update(timeSlice);
  3519. if (IsControlledPlayer() && m_EffectWidgets && m_EffectWidgets.IsAnyEffectRunning())
  3520. {
  3521. m_EffectWidgets.Update(timeSlice);
  3522. }
  3523. #endif
  3524. if (m_UndergroundHandler)
  3525. m_UndergroundHandler.Tick(timeSlice);
  3526. if (m_UndergroundBunkerHandler)
  3527. m_UndergroundBunkerHandler.Tick(timeSlice);
  3528. }
  3529. if (m_InEffectAreaType != 0 && GetGame().IsServer())
  3530. OnUpdateEffectAreaServer(timeSlice);
  3531. }
  3532. override void EOnPostFrame(IEntity other, int extra)
  3533. {
  3534. float delta_time = (GetGame().GetTime() - m_LastPostFrameTickTime) / 1000;
  3535. m_LastPostFrameTickTime = GetGame().GetTime();
  3536. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3537. {
  3538. if (GetDamageDealtEffect())
  3539. {
  3540. if (IsAlive())
  3541. GetDamageDealtEffect().Update(delta_time);
  3542. else
  3543. delete GetDamageDealtEffect();
  3544. }
  3545. if (m_EffectRadial)
  3546. {
  3547. if (IsAlive())
  3548. {
  3549. m_EffectRadial.Update(delta_time);
  3550. }
  3551. else
  3552. m_EffectRadial = null;
  3553. }
  3554. if (GetFlashbangEffect())
  3555. {
  3556. if (IsAlive())
  3557. {
  3558. GetFlashbangEffect().Update(delta_time);
  3559. }
  3560. else
  3561. {
  3562. GetFlashbangEffect().Stop();
  3563. delete GetFlashbangEffect();
  3564. }
  3565. }
  3566. if (GetShockEffect())
  3567. {
  3568. if (IsAlive())
  3569. GetShockEffect().Update(delta_time);
  3570. else
  3571. delete GetShockEffect();
  3572. }
  3573. m_InventoryActionHandler.OnUpdate();
  3574. }
  3575. #ifdef DIAG_DEVELOPER
  3576. DiagOnPostFrame(other, extra);
  3577. #endif
  3578. }
  3579. #ifdef DIAG_DEVELOPER
  3580. protected void DiagOnPostFrame(IEntity other, int extra)
  3581. {
  3582. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3583. {
  3584. if (m_WeaponDebug)
  3585. {
  3586. m_WeaponDebug.OnPostFrameUpdate();
  3587. }
  3588. if (GetBleedingManagerRemote())
  3589. {
  3590. GetBleedingManagerRemote().OnUpdate();
  3591. }
  3592. if (m_MeleeCombat)
  3593. {
  3594. if (DiagMenu.GetBool(DiagMenuIDs.MELEE_DEBUG))
  3595. {
  3596. m_MeleeDebug = true;
  3597. m_MeleeCombat.Debug(GetItemInHands(), m_MeleeCombat.GetHitType());
  3598. }
  3599. else if (!DiagMenu.GetBool(DiagMenuIDs.MELEE_DEBUG) && m_MeleeDebug)
  3600. {
  3601. m_MeleeDebug = false;
  3602. m_MeleeCombat.Debug(GetItemInHands(), m_MeleeCombat.GetHitType());
  3603. }
  3604. }
  3605. if (DiagMenu.GetBool(DiagMenuIDs.SOUNDS_ITEM_IMPACT_SOUNDS))
  3606. InventoryItem.DrawImpacts();
  3607. if (GetPluginManager())
  3608. {
  3609. PluginDrawCheckerboard drawCheckerboard = PluginDrawCheckerboard.Cast(GetPluginManager().GetPluginByType(PluginDrawCheckerboard));
  3610. if (drawCheckerboard && !drawCheckerboard.IsActive())
  3611. {
  3612. drawCheckerboard.ShowWidgets(DiagMenu.GetBool(DiagMenuIDs.MISC_DRAW_CHECKERBOARD));
  3613. }
  3614. }
  3615. if (m_PresenceNotifier)
  3616. {
  3617. m_PresenceNotifier.EnableDebug(DiagMenu.GetBool(DiagMenuIDs.MISC_PRESENCE_NOTIFIER_DBG));
  3618. }
  3619. if (m_TargetTemperatureDiag)
  3620. {
  3621. m_TargetTemperatureDiag.ShowDebug(DiagMenu.GetBool(DiagMenuIDs.MISC_TARGET_TEMPERATURE));
  3622. }
  3623. if (DiagMenu.GetBool(DiagMenuIDs.TRIGGER_PLAYER_DEBUG))
  3624. {
  3625. vector minmax[2];
  3626. GetCollisionBox(minmax);
  3627. int color = COLOR_RED_A;
  3628. if (m_IsInsideTrigger)
  3629. color = COLOR_GREEN_A;
  3630. Shape dbgShape = Debug.DrawBoxEx(minmax[0], minmax[1], color, ShapeFlags.TRANSP|ShapeFlags.NOZWRITE|ShapeFlags.ONCE);
  3631. vector mat[4];
  3632. GetTransform(mat);
  3633. dbgShape.CreateMatrix(mat);
  3634. dbgShape.SetMatrix(mat);
  3635. }
  3636. }
  3637. if (m_Environment && m_Environment.m_Debug)
  3638. {
  3639. #ifdef SERVER
  3640. EnvDebugData envDebugData = m_Environment.GetEnvDebugData();
  3641. GetGame().RPCSingleParam(this, ERPCs.DIAG_MISC_ENVIRONMENT_DEBUG_DATA, envDebugData, false, GetIdentity());
  3642. #else
  3643. m_Environment.ShowEnvDebugPlayerInfo(DiagMenu.GetBool(DiagMenuIDs.MISC_ENVIRONMENT_DEBUG));
  3644. #endif
  3645. }
  3646. if (m_FallDamage && m_FallDamage.m_Debug)
  3647. {
  3648. #ifdef SERVER
  3649. FallDamageDebugData fallDamageDebugData = m_FallDamage.GetFallDamageDebugData();
  3650. GetGame().RPCSingleParam(this, ERPCs.DIAG_MISC_FALLDAMAGE_DEBUG_DATA, fallDamageDebugData, false, GetIdentity());
  3651. #else
  3652. m_FallDamage.ShowFallDamageDebugInfo(DiagMenu.GetBool(DiagMenuIDs.MISC_FALLDAMAGE_DEBUG));
  3653. #endif
  3654. }
  3655. }
  3656. override void OnEnterTrigger(ScriptedEntity trigger)
  3657. {
  3658. super.OnEnterTrigger(trigger);
  3659. ++m_IsInsideTrigger;
  3660. }
  3661. override void OnLeaveTrigger(ScriptedEntity trigger)
  3662. {
  3663. super.OnLeaveTrigger(trigger);
  3664. --m_IsInsideTrigger;
  3665. }
  3666. #endif
  3667. void StaminaHUDNotifier(bool show)
  3668. {
  3669. if (m_Hud)
  3670. m_Hud.SetStaminaBarVisibility(show);
  3671. }
  3672. override void DepleteStaminaEx(EStaminaModifiers modifier, float dT = -1, float coef = 1.0)
  3673. {
  3674. if (GetStaminaHandler())
  3675. GetStaminaHandler().DepleteStaminaEx(modifier,dT,coef);
  3676. }
  3677. override bool CanConsumeStamina(EStaminaConsumers consumer)
  3678. {
  3679. if (!GetStaminaHandler())
  3680. return false;
  3681. bool val = (GetStaminaHandler().HasEnoughStaminaFor(consumer) && !IsRestrained() && !IsInFBEmoteState());
  3682. if (!val)
  3683. StaminaHUDNotifier(false);
  3684. return val;
  3685. }
  3686. override bool CanStartConsumingStamina(EStaminaConsumers consumer)
  3687. {
  3688. if (!GetStaminaHandler())
  3689. return false;
  3690. bool val = (GetStaminaHandler().HasEnoughStaminaToStart(consumer) && !IsRestrained() && !IsInFBEmoteState());
  3691. if (!val)
  3692. StaminaHUDNotifier(false);
  3693. return val;
  3694. }
  3695. override bool CanClimb(int climbType, SHumanCommandClimbResult climbRes)
  3696. {
  3697. if (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  3698. return false;
  3699. if (climbType == 1 && !CanConsumeStamina(EStaminaConsumers.VAULT))
  3700. return false;
  3701. //! vault from water allowed
  3702. if (IsSwimming())
  3703. return true;
  3704. if (climbType == 2 && (!CanConsumeStamina(EStaminaConsumers.CLIMB) || GetBrokenLegs() != eBrokenLegs.NO_BROKEN_LEGS))
  3705. return false;
  3706. if (climbType > 0 && m_InjuryHandler && m_InjuryHandler.GetInjuryAnimValue() >= InjuryAnimValues.LVL3)
  3707. return false;
  3708. return super.CanClimb(climbType,climbRes);
  3709. }
  3710. override bool CanJump()
  3711. {
  3712. if (GetBrokenLegs() != eBrokenLegs.NO_BROKEN_LEGS)
  3713. {
  3714. return false;
  3715. }
  3716. if (!CanConsumeStamina(EStaminaConsumers.JUMP))
  3717. return false;
  3718. //! disables jump when player is significantly injured
  3719. if (m_InjuryHandler && m_InjuryHandler.GetInjuryAnimValue() >= InjuryAnimValues.LVL3)
  3720. return false;
  3721. if (IsInFBEmoteState() || m_EmoteManager.m_MenuEmote)
  3722. {
  3723. return false;
  3724. }
  3725. return super.CanJump();
  3726. }
  3727. bool IsJumpInProgress()
  3728. {
  3729. return m_JumpClimb.m_bIsJumpInProgress;
  3730. }
  3731. bool IsTargetInActiveRefresherRange(EntityAI target)
  3732. {
  3733. array<vector> temp = new array<vector>;
  3734. temp = GetGame().GetMission().GetActiveRefresherLocations();
  3735. int count = temp.Count();
  3736. if (count > 0)
  3737. {
  3738. vector pos = target.GetPosition();
  3739. for (int i = 0; i < count; i++)
  3740. {
  3741. if (vector.Distance(pos,temp.Get(i)) < GameConstants.REFRESHER_RADIUS)
  3742. return true;
  3743. }
  3744. return false;
  3745. }
  3746. else
  3747. {
  3748. return false;
  3749. }
  3750. }
  3751. void RequestHandAnimationStateRefresh()
  3752. {
  3753. if ((GetGame().IsMultiplayer() && GetGame().IsServer()))
  3754. {
  3755. m_RefreshAnimStateIdx++;
  3756. if (m_RefreshAnimStateIdx > 3)
  3757. m_RefreshAnimStateIdx = 0;
  3758. SetSynchDirty();
  3759. }
  3760. }
  3761. void RefreshHandAnimationState(int delay = 0)
  3762. {
  3763. if (delay == 0)
  3764. {
  3765. GetItemAccessor().OnItemInHandsChanged(true);
  3766. GetItemAccessor().ResetWeaponInHands();
  3767. }
  3768. else
  3769. {
  3770. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(RefreshHandAnimationState,delay,false,0);
  3771. }
  3772. }
  3773. // -------------------------------------------------------------------------
  3774. // USER ACTIONS
  3775. // -------------------------------------------------------------------------
  3776. bool IsFacingTarget(Object target)
  3777. {
  3778. vector pdir = GetDirection();
  3779. vector ptv = target.GetPosition() - GetPosition();
  3780. pdir.Normalize();
  3781. ptv.Normalize();
  3782. if (Math.AbsFloat(pdir[0]-ptv[0]) < 0.5 && Math.AbsFloat(pdir[2]-ptv[2]) < 0.5)
  3783. {
  3784. return true;
  3785. }
  3786. return false;
  3787. }
  3788. //---------------------------------------------------------
  3789. void OnQuickBarSingleUse(int slotClicked)
  3790. {
  3791. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  3792. return;
  3793. if (m_AreHandsLocked)
  3794. return; //Player is in the short window of time after interrupting placement of an item and before getting it back in hands
  3795. if (GetInventory().IsInventoryLocked() || IsEmotePlaying())
  3796. return;
  3797. if (GetThrowing().IsThrowingModeEnabled() || GetThrowing().IsThrowingAnimationPlaying())
  3798. return;
  3799. if (IsRaised() || GetCommand_Melee() || IsSwimming() || IsClimbingLadder() || IsClimbing() || IsRestrained() || IsRestrainPrelocked())
  3800. return;
  3801. if (GetDayZPlayerInventory().IsProcessing() || IsItemsToDelete())
  3802. return;
  3803. if (GetActionManager().GetRunningAction() != null)
  3804. return;
  3805. if (GetWeaponManager() && GetWeaponManager().IsRunning())
  3806. return;
  3807. if (!ScriptInputUserData.CanStoreInputUserData())
  3808. return;
  3809. //TODO MW change locking method
  3810. //if (GetDayZPlayerInventory().HasLockedHands())
  3811. // return;
  3812. EntityAI quickBarEntity = GetQuickBarEntity(slotClicked - 1);//GetEntityInQuickBar(slotClicked - 1);
  3813. if (!quickBarEntity)
  3814. return;
  3815. Magazine mag;
  3816. Weapon_Base wpn;
  3817. if (Class.CastTo(mag, quickBarEntity) && Class.CastTo(wpn, mag.GetHierarchyParent()))
  3818. return;
  3819. EntityAI inHandEntity = GetHumanInventory().GetEntityInHands();
  3820. if (!GetDayZPlayerInventory().IsIdle())
  3821. return; // player is already performing some animation
  3822. InventoryLocation handInventoryLocation = new InventoryLocation;
  3823. handInventoryLocation.SetHands(this,quickBarEntity);
  3824. if (this.GetInventory().HasInventoryReservation(quickBarEntity, handInventoryLocation))
  3825. return;
  3826. if (inHandEntity == quickBarEntity)
  3827. {
  3828. if (GetHumanInventory().CanRemoveEntityInHands())
  3829. {
  3830. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[QB] Stash - PredictiveMoveItemFromHandsToInventory HND=" + Object.GetDebugName(inHandEntity));
  3831. PredictiveMoveItemFromHandsToInventory();
  3832. }
  3833. }
  3834. else
  3835. {
  3836. InventoryLocation invLocQBItem = new InventoryLocation;
  3837. quickBarEntity.GetInventory().GetCurrentInventoryLocation(invLocQBItem);
  3838. if (GetInventory().HasInventoryReservation(quickBarEntity,invLocQBItem))
  3839. return;
  3840. if (inHandEntity)
  3841. {
  3842. InventoryLocation Reserved_Item_il = new InventoryLocation;
  3843. InventoryLocation inHandEntityFSwapDst = new InventoryLocation;
  3844. inHandEntity.GetInventory().GetCurrentInventoryLocation(inHandEntityFSwapDst);
  3845. int index = GetHumanInventory().FindUserReservedLocationIndex(inHandEntity);
  3846. if (index >= 0)
  3847. GetHumanInventory().GetUserReservedLocation(index, Reserved_Item_il);
  3848. if (Reserved_Item_il)
  3849. inHandEntityFSwapDst.CopyLocationFrom(Reserved_Item_il, true);
  3850. if (index < 0 && GameInventory.CanSwapEntitiesEx(quickBarEntity, inHandEntity))
  3851. {
  3852. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[QB] PredictiveSwapEntities QB=" + Object.GetDebugName(quickBarEntity) + " HND=" + Object.GetDebugName(inHandEntity));
  3853. PredictiveSwapEntities(quickBarEntity, inHandEntity);
  3854. }
  3855. else if (GameInventory.CanForceSwapEntitiesEx(quickBarEntity, handInventoryLocation, inHandEntity, inHandEntityFSwapDst))
  3856. {
  3857. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[QB] Swap - PredictiveForceSwapEntities HND=" + Object.GetDebugName(inHandEntity) + " QB=" + Object.GetDebugName(quickBarEntity) + " fswap_dst=" + InventoryLocation.DumpToStringNullSafe(inHandEntityFSwapDst));
  3858. PredictiveForceSwapEntities(quickBarEntity, inHandEntity, inHandEntityFSwapDst);
  3859. }
  3860. }
  3861. else
  3862. {
  3863. if (GetInventory().HasInventoryReservation(quickBarEntity,handInventoryLocation))
  3864. return;
  3865. if (GetInventory().CanAddEntityIntoHands(quickBarEntity))
  3866. {
  3867. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[QB] Stash - PredictiveTakeEntityToHands QB=" + Object.GetDebugName(quickBarEntity));
  3868. PredictiveTakeEntityToHands(quickBarEntity);
  3869. }
  3870. }
  3871. }
  3872. }
  3873. //---------------------------------------------------------
  3874. void OnQuickBarContinuousUseStart(int slotClicked)
  3875. {
  3876. if (GetInventory().IsInventoryLocked())
  3877. return;
  3878. if (IsSwimming() || IsClimbingLadder() || GetCommand_Melee() || IsClimbing() || IsRestrained() || IsRestrainPrelocked())
  3879. return;
  3880. ItemBase quickBarItem = ItemBase.Cast(GetQuickBarEntity(slotClicked - 1));
  3881. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3882. {
  3883. ItemBase itemInHands = ItemBase.Cast(GetHumanInventory().GetEntityInHands());
  3884. if (itemInHands != quickBarItem)
  3885. {
  3886. ActionManagerClient amc = ActionManagerClient.Cast(GetActionManager());
  3887. if (amc.CanPerformActionFromQuickbar(itemInHands, quickBarItem))
  3888. {
  3889. amc.PerformActionFromQuickbar(itemInHands, quickBarItem);
  3890. }
  3891. else
  3892. {
  3893. if (IsRaised() || GetCommand_Melee())
  3894. return;
  3895. amc.ForceTarget(quickBarItem);
  3896. m_QuickBarFT = true;
  3897. }
  3898. }
  3899. }
  3900. m_QuickBarHold = true;
  3901. }
  3902. //---------------------------------------------------------
  3903. void OnQuickBarContinuousUseEnd(int slotClicked)
  3904. {
  3905. if (m_QuickBarHold)
  3906. {
  3907. if ( GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3908. {
  3909. ActionManagerClient am = ActionManagerClient.Cast(GetActionManager());
  3910. if (m_ActionQBControl)
  3911. {
  3912. ActionBase action = am.GetRunningAction();
  3913. if (action)
  3914. {
  3915. if (!action.GetInput().IsActive())
  3916. {
  3917. am.EndActionInput();
  3918. }
  3919. }
  3920. }
  3921. if (m_QuickBarFT)
  3922. {
  3923. am.ClearForceTarget();
  3924. m_QuickBarFT = false;
  3925. }
  3926. }
  3927. }
  3928. m_QuickBarHold = false;
  3929. }
  3930. void SetActionEndInput(ActionBase action)
  3931. {
  3932. m_ActionQBControl = !action.GetInput().IsActive();
  3933. }
  3934. bool IsQBControl()
  3935. {
  3936. return m_ActionQBControl;
  3937. }
  3938. void ResetActionEndInput()
  3939. {
  3940. m_ActionQBControl = false;
  3941. }
  3942. //---------------------------------------------------------
  3943. // RADIAL QUICKBAR AND RELOAD ACTIONS
  3944. //---------------------------------------------------------
  3945. //the same functionality as normal quick bar slot key press
  3946. void RadialQuickBarSingleUse(int slotClicked)
  3947. {
  3948. OnQuickBarSingleUse(slotClicked);
  3949. }
  3950. //removed the need for holding down quick bar slot key
  3951. void RadialQuickBarCombine(int slotClicked)
  3952. {
  3953. EntityAI quickBarEntity = GetQuickBarEntity(slotClicked - 1);
  3954. EntityAI entity_in_hands = GetHumanInventory().GetEntityInHands();
  3955. ReloadWeapon(entity_in_hands, quickBarEntity);
  3956. }
  3957. //removed the need for holding down quick bar slot key
  3958. void QuickReloadWeapon(EntityAI weapon)
  3959. {
  3960. EntityAI magazine = GetMagazineToReload(weapon);
  3961. ReloadWeapon(weapon, magazine);
  3962. }
  3963. //Reload weapon with given magazine
  3964. void ReloadWeapon(EntityAI weapon, EntityAI magazine)
  3965. {
  3966. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  3967. {
  3968. ActionManagerClient mngr_client;
  3969. CastTo(mngr_client, GetActionManager());
  3970. if (mngr_client && FirearmActionLoadMultiBulletRadial.Cast(mngr_client.GetRunningAction()))
  3971. {
  3972. mngr_client.Interrupt();
  3973. }
  3974. else if (GetHumanInventory().GetEntityInHands()!= magazine)
  3975. {
  3976. Weapon_Base wpn;
  3977. Magazine mag;
  3978. Class.CastTo(wpn, weapon);
  3979. Class.CastTo(mag, magazine);
  3980. if (GetWeaponManager().CanUnjam(wpn))
  3981. {
  3982. GetWeaponManager().Unjam();
  3983. }
  3984. else if (GetWeaponManager().CanAttachMagazine(wpn, mag))
  3985. {
  3986. GetWeaponManager().AttachMagazine(mag);
  3987. }
  3988. else if (GetWeaponManager().CanSwapMagazine(wpn, mag))
  3989. {
  3990. GetWeaponManager().SwapMagazine(mag);
  3991. }
  3992. else if (GetWeaponManager().CanLoadBullet(wpn, mag))
  3993. {
  3994. //GetWeaponManager().LoadMultiBullet(mag);
  3995. ActionTarget atrg = new ActionTarget(mag, this, -1, vector.Zero, -1.0);
  3996. if (mngr_client && !mngr_client.GetRunningAction() && mngr_client.GetAction(FirearmActionLoadMultiBulletRadial).Can(this, atrg, wpn))
  3997. mngr_client.PerformActionStart(mngr_client.GetAction(FirearmActionLoadMultiBulletRadial), atrg, wpn);
  3998. }
  3999. }
  4000. }
  4001. }
  4002. //returns compatible magazine from player inventory with highest ammo count
  4003. EntityAI GetMagazineToReload(EntityAI weapon)
  4004. {
  4005. Weapon_Base weapon_base = Weapon_Base.Cast(weapon);
  4006. WeaponManager weapon_manager = GetWeaponManager();
  4007. EntityAI magazine_to_reload;
  4008. EntityAI ammo_magazine; //magazine
  4009. int last_ammo_magazine_count;
  4010. int ammo_magazine_count;
  4011. EntityAI ammo_pile; //ammo pile
  4012. int last_ammo_pile_count;
  4013. int ammo_pile_count;
  4014. //Get all magazines in (player) inventory
  4015. for (int att_i = 0; att_i < GetInventory().AttachmentCount(); ++att_i)
  4016. {
  4017. EntityAI attachment = GetInventory().GetAttachmentFromIndex(att_i);
  4018. ref CargoBase attachment_cargo = attachment.GetInventory().GetCargo();
  4019. if (attachment_cargo)
  4020. {
  4021. for (int cgo_i = 0; cgo_i < attachment_cargo.GetItemCount(); ++cgo_i)
  4022. {
  4023. EntityAI cargo_item = attachment_cargo.GetItem(cgo_i);
  4024. //check for proper magazine
  4025. if (cargo_item.IsMagazine())
  4026. {
  4027. Magazine magazine = Magazine.Cast(cargo_item);
  4028. ammo_pile_count = magazine.GetAmmoCount();
  4029. //magazines (get magazine with max ammo count)
  4030. if (weapon_manager.CanAttachMagazine(weapon_base, magazine) || weapon_manager.CanSwapMagazine(weapon_base, magazine))
  4031. {
  4032. if (ammo_pile_count > 0)
  4033. {
  4034. if (last_ammo_magazine_count == 0)
  4035. {
  4036. ammo_magazine = magazine;
  4037. last_ammo_magazine_count = ammo_pile_count;
  4038. }
  4039. else
  4040. {
  4041. if (last_ammo_magazine_count < ammo_pile_count)
  4042. {
  4043. ammo_magazine = magazine;
  4044. last_ammo_magazine_count = ammo_pile_count;
  4045. }
  4046. }
  4047. }
  4048. }
  4049. //bullets (get ammo pile with min ammo count)
  4050. else if (weapon_manager.CanLoadBullet(weapon_base, magazine))
  4051. {
  4052. if (ammo_pile_count > 0)
  4053. {
  4054. if (last_ammo_pile_count == 0)
  4055. {
  4056. ammo_pile = magazine;
  4057. last_ammo_pile_count = ammo_pile_count;
  4058. }
  4059. else
  4060. {
  4061. if (last_ammo_pile_count > ammo_pile_count)
  4062. {
  4063. ammo_pile = magazine;
  4064. last_ammo_pile_count = ammo_pile_count;
  4065. }
  4066. }
  4067. }
  4068. }
  4069. }
  4070. }
  4071. }
  4072. }
  4073. //prioritize magazine
  4074. if (ammo_magazine)
  4075. {
  4076. return ammo_magazine;
  4077. }
  4078. return ammo_pile;
  4079. }
  4080. //---------------------------------------------------------
  4081. //---------------------------------------------------------
  4082. void OnSpawnedFromConsole()
  4083. {
  4084. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || !GetGame().IsMultiplayer())
  4085. {
  4086. GetGame().GetMission().AddDummyPlayerToScheduler(this);
  4087. OnSelectPlayer();
  4088. }
  4089. #ifdef DIAG_DEVELOPER
  4090. if (!m_Bot)
  4091. {
  4092. m_Bot = new Bot(this);
  4093. m_Bot.Start();
  4094. }
  4095. #endif
  4096. }
  4097. //---------------------------------------------------------
  4098. //Obsolete
  4099. bool GetLiquidTendencyDrain()
  4100. {
  4101. return m_LiquidTendencyDrain;
  4102. }
  4103. //---------------------------------------------------------
  4104. //Obsolete
  4105. void SetLiquidTendencyDrain(bool state)
  4106. {
  4107. m_LiquidTendencyDrain = state;
  4108. }
  4109. //---------------------------------------------------------
  4110. //! DEPRECATED
  4111. bool GetFlagTendencyRaise()
  4112. {
  4113. return m_FlagRaisingTendency;
  4114. }
  4115. //---------------------------------------------------------
  4116. //! DEPRECATED
  4117. void SetFlagTendencyRaise(bool state)
  4118. {
  4119. m_FlagRaisingTendency = state;
  4120. }
  4121. override SoundOnVehicle PlaySound(string sound_name, float range, bool create_local = false)
  4122. {
  4123. return BetaSound.SaySound(this, sound_name, range, false);
  4124. }
  4125. float GetPlayerLoad()
  4126. {
  4127. return GetWeightEx();
  4128. }
  4129. bool IsOverloaded()
  4130. {
  4131. return GetWeightEx() >= OVERLOAD_LIMIT;
  4132. }
  4133. void SetPlayerLoad(float load)//Deprecated
  4134. {
  4135. m_CargoLoad = load;
  4136. //Print("m_CargoLoad: " + m_CargoLoad);
  4137. //Log(ToString(this) + "'s load weight is " + ftoa(m_CargoLoad) + " g.", LogTemplates.TEMPLATE_PLAYER_WEIGHT);
  4138. }
  4139. //Deprecated, will be overrid by other method calls (in order to ensure stamina calculation is properly set)
  4140. void AddPlayerLoad(float addedload)//Deprecated
  4141. {
  4142. float newload = GetPlayerLoad() + addedload;
  4143. SetPlayerLoad(newload);
  4144. // Do not need -> Log is in SetPlayerLoad
  4145. //PrintString(ToString(this) + "'s load weight is " + ToString(m_CargoLoad) + " g.");
  4146. }
  4147. bool IsItemInInventory(EntityAI entity)
  4148. {
  4149. return GetInventory().HasEntityInInventory(entity);
  4150. }
  4151. override bool NeedInventoryJunctureFromServer(notnull EntityAI item, EntityAI currParent, EntityAI newParent)
  4152. {
  4153. if (GetGame().IsMultiplayer())
  4154. {
  4155. DayZPlayerInstanceType t = GetInstanceType();
  4156. switch (t)
  4157. {
  4158. case DayZPlayerInstanceType.INSTANCETYPE_AI_SINGLEPLAYER:
  4159. return false;
  4160. case DayZPlayerInstanceType.INSTANCETYPE_CLIENT:
  4161. case DayZPlayerInstanceType.INSTANCETYPE_SERVER:
  4162. case DayZPlayerInstanceType.INSTANCETYPE_AI_SERVER:
  4163. case DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE:
  4164. case DayZPlayerInstanceType.INSTANCETYPE_REMOTE:
  4165. return true; // Might help mitigate "megabugged" (desync)
  4166. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " NeedInventoryJunctureFromServer item=" + Object.GetDebugName(item) + " currPar=" + currParent + " newPar=" + newParent);
  4167. bool i_owned = GetHumanInventory().HasEntityInInventory(item);
  4168. bool cp_owned = false;
  4169. if (currParent)
  4170. cp_owned = GetHumanInventory().HasEntityInInventory(currParent);
  4171. bool np_owned = false;
  4172. if (newParent)
  4173. np_owned = GetHumanInventory().HasEntityInInventory(newParent);
  4174. bool all_owned = i_owned && cp_owned && (np_owned || (newParent == null));
  4175. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " NeedInventoryJunctureFromServer=" + !all_owned + " i_pwn=" + i_owned + " cp_pwn=" + cp_owned + " np_pwn=" + np_owned);
  4176. return !all_owned;
  4177. default:
  4178. Error("[syncinv] unsupported instance type t=" + t);
  4179. break;
  4180. }
  4181. }
  4182. return false;
  4183. }
  4184. override protected float GetWeightSpecialized(bool forceRecalc = false)
  4185. {
  4186. float totalWeight = super.GetWeightSpecialized(forceRecalc);
  4187. ItemBase itemHands = GetItemInHands();
  4188. if (itemHands) // adds weight of item carried in hands
  4189. {
  4190. totalWeight += itemHands.GetWeightEx(forceRecalc);
  4191. }
  4192. #ifdef DEVELOPER
  4193. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  4194. {
  4195. float itemInHandsWeight = totalWeight - super.GetWeightSpecialized(forceRecalc);
  4196. WeightDebugData dta = WeightDebug.GetWeightDebug(this);
  4197. dta.SetCalcDetails("TMan: " + (super.GetWeightSpecialized(forceRecalc)+ itemInHandsWeight) +"(contents weight[includes item in hands])");
  4198. }
  4199. #endif
  4200. return totalWeight;
  4201. }
  4202. void CalculateVisibilityForAI()
  4203. {
  4204. const int VISIBILITY_SLOTS_COUNT = 10;
  4205. int attcount = GetInventory().AttachmentCount();
  4206. float sumVisibility = 0;
  4207. float countVisibility = 0;
  4208. float visibilityMean = 0;
  4209. if (attcount > 0)
  4210. {
  4211. for (int att = 0; att < attcount; att++)
  4212. {
  4213. EntityAI attachment = GetInventory().GetAttachmentFromIndex(att);
  4214. if (attachment.IsClothing())
  4215. {
  4216. ClothingBase clothing;
  4217. Class.CastTo(clothing, attachment);
  4218. sumVisibility += clothing.GetItemVisibility();
  4219. countVisibility++;
  4220. }
  4221. }
  4222. visibilityMean = (sumVisibility + (VISIBILITY_SLOTS_COUNT - countVisibility)) / VISIBILITY_SLOTS_COUNT;
  4223. SetVisibilityCoef(visibilityMean);
  4224. }
  4225. else
  4226. {
  4227. visibilityMean = 1;
  4228. SetVisibilityCoef(visibilityMean);
  4229. }
  4230. }
  4231. void SetVisibilityCoef(float pVisibility)
  4232. {
  4233. m_VisibilityCoef = pVisibility;
  4234. }
  4235. float GetVisibilityCoef()
  4236. {
  4237. return m_VisibilityCoef;
  4238. }
  4239. int GetShakeLevel()
  4240. {
  4241. return m_Shakes;
  4242. }
  4243. EStatLevels GetStatLevelHealth()
  4244. {
  4245. float health = GetHealth("","");
  4246. return GetStatLevel(health, PlayerConstants.SL_HEALTH_CRITICAL, PlayerConstants.SL_HEALTH_LOW, PlayerConstants.SL_HEALTH_NORMAL, PlayerConstants.SL_HEALTH_HIGH);
  4247. }
  4248. EStatLevels GetStatLevelToxicity()
  4249. {
  4250. float toxicity = GetStatToxicity().Get();
  4251. return GetStatLevel(toxicity, PlayerConstants.SL_HEALTH_CRITICAL, PlayerConstants.SL_HEALTH_LOW, PlayerConstants.SL_HEALTH_NORMAL, PlayerConstants.SL_HEALTH_HIGH);
  4252. }
  4253. EStatLevels GetStatLevelBlood()
  4254. {
  4255. float blood = GetHealth("","Blood");
  4256. return GetStatLevel(blood, PlayerConstants.SL_BLOOD_CRITICAL, PlayerConstants.SL_BLOOD_LOW, PlayerConstants.SL_BLOOD_NORMAL, PlayerConstants.SL_BLOOD_HIGH);
  4257. }
  4258. EStatLevels GetStatLevelEnergy()
  4259. {
  4260. float energy = GetStatEnergy().Get();
  4261. return GetStatLevel(energy, PlayerConstants.SL_ENERGY_CRITICAL, PlayerConstants.SL_ENERGY_LOW, PlayerConstants.SL_ENERGY_NORMAL, PlayerConstants.SL_ENERGY_HIGH);
  4262. }
  4263. EStatLevels GetStatLevelWater()
  4264. {
  4265. float water = GetStatWater().Get();
  4266. return GetStatLevel(water, PlayerConstants.SL_WATER_CRITICAL, PlayerConstants.SL_WATER_LOW, PlayerConstants.SL_WATER_NORMAL, PlayerConstants.SL_WATER_HIGH);
  4267. }
  4268. EStatLevels GetImmunityLevel()
  4269. {
  4270. float immunity = GetImmunity();
  4271. if (m_ImmunityBoosted)
  4272. return EStatLevels.GREAT;
  4273. return GetStatLevel(immunity, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_CRITICAL, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_LOW, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_NORMAL, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_HIGH);
  4274. }
  4275. //-------------------------------------
  4276. float GetBordersImmunity()
  4277. {
  4278. float immunity = GetImmunity();
  4279. float immmunity_max = 1;
  4280. return GetStatLevelBorders(immunity, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_CRITICAL, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_LOW, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_NORMAL, PlayerConstants.IMMUNITY_THRESHOLD_LEVEL_HIGH, immmunity_max);
  4281. }
  4282. float GetStatBordersHealth()
  4283. {
  4284. float health = GetHealth("","");
  4285. float health_max = GetMaxHealth("","");
  4286. return GetStatLevelBorders(health, PlayerConstants.SL_HEALTH_CRITICAL, PlayerConstants.SL_HEALTH_LOW, PlayerConstants.SL_HEALTH_NORMAL, PlayerConstants.SL_HEALTH_HIGH, health_max);
  4287. }
  4288. float GetStatBordersToxicity()
  4289. {
  4290. float toxicity = GetStatToxicity().Get();
  4291. float toxicity_max = GetStatToxicity().GetMax();
  4292. return GetStatLevelBorders(toxicity, PlayerConstants.SL_HEALTH_CRITICAL, PlayerConstants.SL_HEALTH_LOW, PlayerConstants.SL_HEALTH_NORMAL, PlayerConstants.SL_HEALTH_HIGH, toxicity_max);
  4293. }
  4294. float GetStatBordersBlood()
  4295. {
  4296. float blood = GetHealth("","Blood");
  4297. float blood_max = GetMaxHealth("","Blood");
  4298. return GetStatLevelBorders(blood, PlayerConstants.SL_BLOOD_CRITICAL, PlayerConstants.SL_BLOOD_LOW, PlayerConstants.SL_BLOOD_NORMAL, PlayerConstants.SL_BLOOD_HIGH, blood_max);
  4299. }
  4300. float GetStatBordersEnergy()
  4301. {
  4302. float energy = GetStatEnergy().Get();
  4303. float energy_max = GetStatEnergy().GetMax();
  4304. return GetStatLevelBorders(energy, PlayerConstants.SL_ENERGY_CRITICAL, PlayerConstants.SL_ENERGY_LOW, PlayerConstants.SL_ENERGY_NORMAL, PlayerConstants.SL_ENERGY_HIGH, energy_max);
  4305. }
  4306. float GetStatBordersWater()
  4307. {
  4308. float water = GetStatWater().Get();
  4309. float water_max = GetStatWater().GetMax();
  4310. return GetStatLevelBorders(water, PlayerConstants.SL_WATER_CRITICAL, PlayerConstants.SL_WATER_LOW, PlayerConstants.SL_WATER_NORMAL, PlayerConstants.SL_WATER_HIGH, water_max);
  4311. }
  4312. //------------------------------------
  4313. float GetStatLevelBorders(float stat_value, float critical, float low, float normal, float high, float max)
  4314. {
  4315. if (stat_value <= critical)
  4316. {
  4317. return Math.InverseLerp(0, critical, stat_value);
  4318. }
  4319. if (stat_value <= low)
  4320. {
  4321. return Math.InverseLerp(critical, low, stat_value);
  4322. }
  4323. if (stat_value <= normal)
  4324. {
  4325. return Math.InverseLerp(low, normal, stat_value);
  4326. }
  4327. if (stat_value <= high)
  4328. {
  4329. return Math.InverseLerp(normal, high, stat_value);
  4330. }
  4331. return Math.InverseLerp(high, max, stat_value);
  4332. }
  4333. EStatLevels GetStatLevel(float stat_value, float critical, float low, float normal, float high)
  4334. {
  4335. if (stat_value <= critical)
  4336. {
  4337. return EStatLevels.CRITICAL;
  4338. }
  4339. if (stat_value <= low)
  4340. {
  4341. return EStatLevels.LOW;
  4342. }
  4343. if (stat_value <= normal)
  4344. {
  4345. return EStatLevels.MEDIUM;
  4346. }
  4347. if (stat_value <= high)
  4348. {
  4349. return EStatLevels.HIGH;
  4350. }
  4351. return EStatLevels.GREAT;
  4352. }
  4353. void SetImmunityBoosted(bool boosted)
  4354. {
  4355. m_ImmunityBoosted = boosted;
  4356. }
  4357. //!returns player's immunity strength between 0..1
  4358. float GetImmunity()
  4359. {
  4360. float immunity;
  4361. if (GetPlayerStats())
  4362. {
  4363. float max_health = GetMaxHealth("GlobalHealth", "Health") + 0.01;//addition to prevent divisioin by zero in case of some messup
  4364. float max_blood = GetMaxHealth("GlobalHealth", "Blood") + 0.01;//addition to prevent divisioin by zero in case of some messup
  4365. float energy_normalized = GetStatEnergy().Get() / PlayerConstants.SL_ENERGY_MAX;
  4366. float water_normalized = GetStatWater().Get() / PlayerConstants.SL_WATER_MAX;
  4367. float health_normalized = GetHealth("GlobalHealth", "Health") / max_health;
  4368. float blood_normalized = GetHealth("GlobalHealth", "Blood") / max_blood;
  4369. immunity = energy_normalized + water_normalized + health_normalized + blood_normalized;
  4370. immunity = immunity / 4;//avg
  4371. immunity = Math.Clamp(immunity,0,1);
  4372. }
  4373. return immunity;
  4374. }
  4375. bool IsSprinting()
  4376. {
  4377. return m_MovementState.m_iMovement == DayZPlayerConstants.MOVEMENT_SPRINT;
  4378. }
  4379. bool CanSprint()
  4380. {
  4381. ItemBase item = GetItemInHands();
  4382. if (IsRaised() || (item && item.IsHeavyBehaviour()))
  4383. return false;
  4384. if (item && GetThrowing() && GetThrowing().IsThrowingModeEnabled())
  4385. return false;
  4386. if (GetBrokenLegs() != eBrokenLegs.NO_BROKEN_LEGS)
  4387. return false;
  4388. return true;
  4389. }
  4390. bool IsInProne()
  4391. {
  4392. return m_MovementState.IsInProne();
  4393. }
  4394. bool IsInRasedProne()
  4395. {
  4396. return m_MovementState.IsInRaisedProne();
  4397. }
  4398. bool IsLeaning()
  4399. {
  4400. return m_MovementState.IsLeaning();
  4401. }
  4402. bool IsRolling()
  4403. {
  4404. return GetCommand_Move() && GetCommand_Move().IsInRoll();
  4405. }
  4406. bool IsClimbing()
  4407. {
  4408. return m_MovementState.m_CommandTypeId == DayZPlayerConstants.COMMANDID_CLIMB;
  4409. }
  4410. bool IsFalling()
  4411. {
  4412. return m_MovementState.m_CommandTypeId == DayZPlayerConstants.COMMANDID_FALL;
  4413. }
  4414. override bool IsFighting()
  4415. {
  4416. return m_IsFighting;
  4417. }
  4418. bool IsEmotePlaying()
  4419. {
  4420. return m_EmoteManager && m_EmoteManager.IsEmotePlaying();
  4421. }
  4422. override bool IsIgnoredByConstruction()
  4423. {
  4424. return IsRuined();
  4425. }
  4426. /*!
  4427. Returns whether the specified movement command(s) are starting the next frame.
  4428. Use caution when using this for anything player animation-related, some commands may require the movement state to be truly active (wait until next update)
  4429. */
  4430. bool AnimCommandCheck(HumanMoveCommandID mask)
  4431. {
  4432. return m_AnimCommandStarting & mask;
  4433. }
  4434. void RunFightBlendTimer()
  4435. {
  4436. if (!m_FightEndBlendTimer)
  4437. m_FightEndBlendTimer = new Timer();
  4438. if (!m_FightEndBlendTimer.IsRunning())
  4439. {
  4440. m_FightEndBlendTimer.Run(PlayerConstants.MELEE2_MOVEMENT_BLEND_DELAY,this,"EndFighting");
  4441. }
  4442. }
  4443. void EndFighting()
  4444. {
  4445. m_IsFighting = false;
  4446. }
  4447. bool CheckMeleeItemDamage(ItemBase item)
  4448. {
  4449. //on-hit drop of melee weapons
  4450. //bayonets & buttstocks
  4451. if (item && item.GetHierarchyParent() && item.GetHierarchyParent().IsWeapon() && item.IsRuined()/*&& item.FindAttachmentBySlotName()*/)
  4452. {
  4453. PlayAttachmentDropSound();
  4454. return DropItem(item);
  4455. }
  4456. //handheld items themselves
  4457. if (item && item == GetItemInHands() && item.IsRuined())
  4458. {
  4459. return PredictiveDropEntity(item);
  4460. }
  4461. return false;
  4462. }
  4463. void PlayAttachmentDropSound()
  4464. {
  4465. //TODO
  4466. }
  4467. // -------------------------------------------------------------------------
  4468. override void RPC(int rpc_type, array<ref Param> params, bool guaranteed, PlayerIdentity recipient = NULL)
  4469. {
  4470. super.RPC(rpc_type, params, guaranteed, recipient);
  4471. }
  4472. // -------------------------------------------------------------------------
  4473. override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
  4474. {
  4475. super.OnRPC(sender, rpc_type, ctx);
  4476. switch (rpc_type)
  4477. {
  4478. #ifndef SERVER
  4479. case ERPCs.RPC_PLAYER_STAT:
  4480. if (GetPlayerStats())
  4481. GetPlayerStats().OnRPC(ctx);
  4482. break;
  4483. case ERPCs.RPC_SYNC_DISPLAY_STATUS:
  4484. if (GetVirtualHud())
  4485. {
  4486. GetVirtualHud().OnRPC(ctx);
  4487. }
  4488. break;
  4489. case ERPCs.RPC_PLAYER_SYMPTOM_ON:
  4490. if (GetSymptomManager())
  4491. {
  4492. GetSymptomManager().OnRPC(ERPCs.RPC_PLAYER_SYMPTOM_ON, ctx);
  4493. }
  4494. break;
  4495. case ERPCs.RPC_PLAYER_SYMPTOM_OFF:
  4496. if (GetSymptomManager())
  4497. {
  4498. GetSymptomManager().OnRPC(ERPCs.RPC_PLAYER_SYMPTOM_OFF, ctx);
  4499. }
  4500. break;
  4501. case ERPCs.RPC_DAMAGE_VALUE_SYNC:
  4502. if (m_TrasferValues)
  4503. m_TrasferValues.OnRPC(ctx);
  4504. break;
  4505. case ERPCs.RPC_USER_ACTION_MESSAGE:
  4506. if (!GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  4507. {
  4508. break;
  4509. }
  4510. if (ctx.Read(m_UAParamMessage))
  4511. {
  4512. string actiontext = m_UAParamMessage.param1;
  4513. MessageAction(actiontext);
  4514. }
  4515. break;
  4516. case ERPCs.RPC_SOFT_SKILLS_SPECIALTY_SYNC:
  4517. ref Param1<float> p_synch = new Param1<float>(0);
  4518. ctx.Read(p_synch);
  4519. float specialty_level = p_synch.param1;
  4520. GetSoftSkillsManager().SetSpecialtyLevel(specialty_level);
  4521. break;
  4522. case ERPCs.RPC_SOFT_SKILLS_STATS_SYNC:
  4523. ref Param5<float, float, float, float, bool> p_debug_synch = new Param5<float, float ,float, float, bool>(0, 0, 0, 0, false);
  4524. ctx.Read(p_debug_synch);
  4525. float general_bonus_before = p_debug_synch.param1;
  4526. float general_bonus_after = p_debug_synch.param2;
  4527. float last_UA_value = p_debug_synch.param3;
  4528. float cooldown_value = p_debug_synch.param4;
  4529. float cooldown_active = p_debug_synch.param5;
  4530. GetSoftSkillsManager().SetGeneralBonusBefore(general_bonus_before);
  4531. GetSoftSkillsManager().SetGeneralBonusAfter(general_bonus_after);
  4532. GetSoftSkillsManager().SetLastUAValue(last_UA_value);
  4533. GetSoftSkillsManager().SetCoolDownValue(cooldown_value);
  4534. GetSoftSkillsManager().SetCoolDown(cooldown_active);
  4535. break;
  4536. case ERPCs.RPC_WARNING_ITEMDROP:
  4537. {
  4538. if (GetGame().IsClient() && GetGame().GetUIManager() && !GetGame().GetUIManager().FindMenu(MENU_WARNING_ITEMDROP))
  4539. {
  4540. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_WARNING_ITEMDROP,null);
  4541. GetGame().GetMission().AddActiveInputExcludes({"menu"});
  4542. }
  4543. break;
  4544. }
  4545. case ERPCs.RPC_WARNING_TELEPORT:
  4546. {
  4547. if (GetGame().IsClient() && GetGame().GetUIManager() && !GetGame().GetUIManager().FindMenu(MENU_WARNING_TELEPORT))
  4548. {
  4549. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_WARNING_TELEPORT,null);
  4550. GetGame().GetMission().AddActiveInputExcludes({"menu"});
  4551. }
  4552. break;
  4553. }
  4554. case ERPCs.RPC_INIT_SET_QUICKBAR:
  4555. ref Param1<int> count = new Param1<int>(0);
  4556. if (ctx.Read(count))
  4557. {
  4558. for (int i = 0; i < count.param1 ; i++)
  4559. {
  4560. m_QuickBarBase.OnSetEntityRPC(ctx);
  4561. }
  4562. }
  4563. break;
  4564. case ERPCs.RPC_SYNC_THERMOMETER:
  4565. {
  4566. float value;
  4567. if (ctx.Read(value))
  4568. m_Hud.SetTemperature(value.ToString() + "#degrees_celsius");
  4569. break;
  4570. }
  4571. case ERPCs.RPC_CHECK_PULSE:
  4572. ctx.Read(CachedObjectsParams.PARAM1_INT);
  4573. EPulseType pulse;
  4574. if ((CachedObjectsParams.PARAM1_INT.param1 & ActionCheckPulse.TARGET_IRREGULAR_PULSE_BIT) == 0)
  4575. {
  4576. pulse = EPulseType.REGULAR;
  4577. }
  4578. else
  4579. {
  4580. pulse = EPulseType.IRREGULAR;
  4581. }
  4582. int blood_level = ~ActionCheckPulse.TARGET_IRREGULAR_PULSE_BIT & CachedObjectsParams.PARAM1_INT.param1;
  4583. if (m_CheckPulseLastTarget)
  4584. {
  4585. m_CheckPulseLastTarget.SetLastUAMessage(ActionCheckPulse.GetPulseMessage(pulse, blood_level));
  4586. }
  4587. break;
  4588. //! uses contants outside of ERPCs !!!!
  4589. //woodcutting
  4590. case PlantType.TREE_HARD:
  4591. SoundHardTreeFallingPlay();
  4592. break;
  4593. case PlantType.TREE_SOFT:
  4594. SoundSoftTreeFallingPlay();
  4595. break;
  4596. case PlantType.BUSH_HARD:
  4597. SoundHardBushFallingPlay();
  4598. break;
  4599. case PlantType.BUSH_SOFT:
  4600. SoundSoftBushFallingPlay();
  4601. break;
  4602. case ERPCs.RPC_DEBUG_MONITOR_FLT:
  4603. if (m_DebugMonitorValues)
  4604. {
  4605. m_DebugMonitorValues.OnRPCFloat(ctx);
  4606. }
  4607. break;
  4608. case ERPCs.RPC_DEBUG_MONITOR_STR:
  4609. if (m_DebugMonitorValues)
  4610. {
  4611. m_DebugMonitorValues.OnRPCString(ctx);
  4612. }
  4613. break;
  4614. #endif
  4615. /*
  4616. case ERPCs.RPC_CRAFTING_INVENTORY_INSTANT:
  4617. ref Param3<int, ItemBase, ItemBase> craftParam = new Param3<int, ItemBase, ItemBase>(-1, NULL, NULL);
  4618. if (ctx.Read(craftParam))
  4619. {
  4620. m_ModuleRecipesManager.PerformRecipeServer(craftParam.param1, craftParam.param2, craftParam.param3, this);
  4621. }
  4622. break;
  4623. */
  4624. #ifdef DIAG_DEVELOPER
  4625. case ERPCs.DEV_RPC_AGENT_RESET:
  4626. {
  4627. bool val;
  4628. if (ctx.Read(val))
  4629. m_AgentPool.RemoveAllAgents();
  4630. break;
  4631. }
  4632. case ERPCs.DEV_PLAYER_DEBUG_REQUEST:
  4633. {
  4634. PluginRemotePlayerDebugServer plugin_remote_server = PluginRemotePlayerDebugServer.Cast(GetPlugin(PluginRemotePlayerDebugServer));
  4635. plugin_remote_server.OnRPC(ctx, this);
  4636. break;
  4637. }
  4638. case ERPCs.DEV_PLAYER_DEBUG_DATA:
  4639. {
  4640. PluginRemotePlayerDebugClient plugin_remote_client = PluginRemotePlayerDebugClient.Cast(GetPlugin(PluginRemotePlayerDebugClient));
  4641. PluginDeveloper plugin_dev = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  4642. if (plugin_dev.m_ScriptConsole)
  4643. plugin_dev.m_ScriptConsole.OnRPCEx(rpc_type, ctx);
  4644. else
  4645. plugin_remote_client.OnRPC(ctx);
  4646. break;
  4647. }
  4648. case ERPCs.DEV_AGENT_GROW:
  4649. {
  4650. m_AgentPool.RemoteGrowRequestDebug(ctx);
  4651. break;
  4652. }
  4653. case ERPCs.RPC_ITEM_DIAG_CLOSE:
  4654. {
  4655. PluginItemDiagnostic mid = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  4656. mid.StopWatchRequest(this);
  4657. break;
  4658. }
  4659. //! Universal Temperature Sources debug
  4660. case ERPCs.DEV_REQUEST_UTS_DEBUG:
  4661. {
  4662. PluginUniversalTemperatureSourceServer plugin_uts_server = PluginUniversalTemperatureSourceServer.Cast(GetPlugin(PluginUniversalTemperatureSourceServer));
  4663. plugin_uts_server.OnRPC(ctx, this);
  4664. break;
  4665. }
  4666. case ERPCs.DEV_UTS_DEBUG_DATA:
  4667. {
  4668. PluginUniversalTemperatureSourceClient plugin_uts_client = PluginUniversalTemperatureSourceClient.Cast(GetPlugin(PluginUniversalTemperatureSourceClient));
  4669. plugin_uts_client.OnRPC(ctx);
  4670. break;
  4671. }
  4672. //! ---
  4673. #endif
  4674. #ifdef DEVELOPER
  4675. case ERPCs.DEV_RPC_SERVER_SCRIPT:
  4676. {
  4677. //PluginItemDiagnostic plugin = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  4678. //SetDebugDeveloper_item(plugin.GetWatchedItem(this));//!! needs to be inside DEVELOPER ifdef
  4679. if (ctx.Read(CachedObjectsParams.PARAM1_STRING))
  4680. {
  4681. _player = this;
  4682. string code = CachedObjectsParams.PARAM1_STRING.param1;
  4683. bool success = GetGame().ExecuteEnforceScript("void scConsMain() \n{\n" + code + "\n}\n", "scConsMain");
  4684. CachedObjectsParams.PARAM1_BOOL.param1 = success;
  4685. RPCSingleParam(ERPCs.DEV_RPC_SERVER_SCRIPT_RESULT, CachedObjectsParams.PARAM1_BOOL,true, GetIdentity());
  4686. }
  4687. break;
  4688. }
  4689. case ERPCs.DEV_RPC_SERVER_SCRIPT_RESULT:
  4690. {
  4691. PluginDeveloper dev = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  4692. if (dev.m_ScriptConsole)
  4693. dev.m_ScriptConsole.OnRPCEx(rpc_type, ctx);
  4694. break;
  4695. }
  4696. case ERPCs.DEV_SET_DEV_ITEM:
  4697. {
  4698. Param1<EntityAI> ent = new Param1<EntityAI>(null);
  4699. if (ctx.Read(ent) && ent.param1)
  4700. {
  4701. PluginItemDiagnostic mid2 = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  4702. mid2.RegisterDebugItem(ent.param1, this);
  4703. }
  4704. //SetDebugDeveloper_item(this);
  4705. break;
  4706. }
  4707. case ERPCs.RPC_ITEM_DIAG:
  4708. {
  4709. Param1<EntityAI> p1 = new Param1<EntityAI>(null);
  4710. if (ctx.Read(p1))
  4711. {
  4712. PluginItemDiagnostic plgn = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  4713. plgn.OnRPC(p1.param1, ctx);
  4714. }
  4715. break;
  4716. }
  4717. #endif
  4718. }
  4719. #ifdef DIAG_DEVELOPER
  4720. PluginDeveloper module_rc = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  4721. if (module_rc)
  4722. module_rc.OnRPC(this, rpc_type, ctx);
  4723. PluginDeveloperSync module_rcs = PluginDeveloperSync.Cast(GetPlugin(PluginDeveloperSync));
  4724. if (module_rcs)
  4725. module_rcs.OnRPC(this, rpc_type, ctx);
  4726. #ifdef SERVER
  4727. PluginDiagMenu plugin_diag_menu = PluginDiagMenu.Cast(GetPlugin(PluginDiagMenuServer));
  4728. #else
  4729. PluginDiagMenu plugin_diag_menu = PluginDiagMenu.Cast(GetPlugin(PluginDiagMenuClient));
  4730. #endif
  4731. if (plugin_diag_menu)
  4732. plugin_diag_menu.OnRPC(this, rpc_type, ctx);
  4733. #endif
  4734. }
  4735. override void OnGameplayDataHandlerSync()
  4736. {
  4737. super.OnGameplayDataHandlerSync();
  4738. UpdateLighting();
  4739. GetGame().GetMission().SetRespawnModeClient(CfgGameplayHandler.GetDisableRespawnDialog());
  4740. SetHitPPEEnabled(CfgGameplayHandler.GetHitIndicationPPEEnabled());
  4741. }
  4742. void UpdateLighting()
  4743. {
  4744. Mission mission = GetGame().GetMission();
  4745. if (mission)
  4746. {
  4747. WorldLighting wLighting = mission.GetWorldLighting();
  4748. if (wLighting)
  4749. wLighting.SetGlobalLighting(CfgGameplayHandler.GetLightingConfig());
  4750. }
  4751. }
  4752. void SetContaminatedEffectEx(bool enable, int ppeIdx = -1, int aroundId = ParticleList.CONTAMINATED_AREA_GAS_AROUND, int tinyId = ParticleList.CONTAMINATED_AREA_GAS_TINY, string soundset = "", bool partDynaUpdate = false, int newBirthRate = 0)
  4753. {
  4754. if (enable) // enable
  4755. {
  4756. // We assume that if this is set to true the PPE is already active
  4757. if (m_ContaminatedAreaEffectEnabled == enable)
  4758. return;
  4759. if (aroundId !=0)
  4760. {
  4761. if (!m_ContaminatedAroundPlayer)
  4762. {
  4763. m_ContaminatedAroundPlayer = ParticleManager.GetInstance().PlayInWorld(aroundId, GetPosition());
  4764. }
  4765. // First entry in an area with dynamic tweaks to particles
  4766. if (partDynaUpdate)
  4767. {
  4768. m_ContaminatedAroundPlayer.SetParameter(0, EmitorParam.BIRTH_RATE, newBirthRate);
  4769. }
  4770. }
  4771. if (!m_ContaminatedAroundPlayerTiny && tinyId !=0)
  4772. {
  4773. m_ContaminatedAroundPlayerTiny = ParticleManager.GetInstance().PlayInWorld(tinyId, GetPosition());
  4774. }
  4775. if (ppeIdx != -1)
  4776. {
  4777. PPERequesterBase ppeRequester;
  4778. if (Class.CastTo(ppeRequester, PPERequesterBank.GetRequester(ppeIdx)))
  4779. ppeRequester.Start();
  4780. }
  4781. // We start playing the ambient sound
  4782. if (!m_AmbientContamination && soundset != "")
  4783. PlaySoundSetLoop(m_AmbientContamination, soundset, 0.1, 0.1);
  4784. SetSoundControllerOverride("contamination",1,SoundControllerAction.Overwrite);
  4785. }
  4786. else // disable
  4787. {
  4788. if (m_ContaminatedAroundPlayer)
  4789. {
  4790. m_ContaminatedAroundPlayer.Stop();
  4791. m_ContaminatedAroundPlayer = null;
  4792. }
  4793. if (m_ContaminatedAroundPlayerTiny)
  4794. {
  4795. m_ContaminatedAroundPlayerTiny.Stop();
  4796. m_ContaminatedAroundPlayerTiny = null;
  4797. }
  4798. if (ppeIdx != -1)
  4799. PPERequesterBank.GetRequester(ppeIdx).Stop(new Param1<bool>(true)); //fade out
  4800. // We stop the ambient sound
  4801. if (m_AmbientContamination)
  4802. StopSoundSet(m_AmbientContamination);
  4803. SetSoundControllerOverride("contamination",0,SoundControllerAction.None);
  4804. // We make sure to reset the state
  4805. }
  4806. m_ContaminatedAreaEffectEnabled = enable;
  4807. }
  4808. void SetContaminatedEffect(bool enable, int ppeIdx = -1, int aroundId = ParticleList.CONTAMINATED_AREA_GAS_AROUND, int tinyId = ParticleList.CONTAMINATED_AREA_GAS_TINY, bool partDynaUpdate = false, int newBirthRate = 0)
  4809. {
  4810. SetContaminatedEffectEx(enable, ppeIdx, aroundId, tinyId, "", partDynaUpdate, newBirthRate);
  4811. }
  4812. // -------------------------------------------------------------------------
  4813. void UpdateCorpseState()
  4814. {
  4815. UpdateCorpseStateVisual();
  4816. if (m_CorpseState > 0 && !GetIsFrozen())
  4817. SetDecayEffects(Math.AbsInt(m_CorpseState));
  4818. else
  4819. SetDecayEffects();//no params means remove the effects
  4820. m_CorpseStateLocal = m_CorpseState;
  4821. }
  4822. // -------------------------------------------------------------------------
  4823. override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
  4824. {
  4825. super.EEHealthLevelChanged(oldLevel, newLevel, zone);
  4826. if (!GetGame().IsDedicatedServer())
  4827. {
  4828. if (newLevel == GameConstants.STATE_RUINED)
  4829. {
  4830. ClearLastUAMessage();
  4831. }
  4832. if (m_CorpseState != 0)
  4833. {
  4834. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(UpdateCorpseState, 0, false);
  4835. }
  4836. }
  4837. }
  4838. // -------------------------------------------------------------------------
  4839. override void OnVariablesSynchronized()
  4840. {
  4841. super.OnVariablesSynchronized();
  4842. if (m_ModuleLifespan)
  4843. {
  4844. m_ModuleLifespan.SynchLifespanVisual(this, m_LifeSpanState, m_HasBloodyHandsVisible, m_HasBloodTypeVisible, m_BloodType);
  4845. if (m_LifespanLevelLocal != m_LifeSpanState) //client solution, lifespan level changed
  4846. {
  4847. m_LifespanLevelLocal = m_LifeSpanState;
  4848. UpdateHairSelectionVisibility();
  4849. }
  4850. }
  4851. CheckSoundEvent();
  4852. if (GetBleedingManagerRemote() && IsPlayerLoaded())
  4853. {
  4854. GetBleedingManagerRemote().OnVariablesSynchronized(GetBleedingBits());
  4855. }
  4856. if (m_CorpseStateLocal != m_CorpseState && (IsPlayerLoaded() || IsControlledPlayer()))
  4857. {
  4858. UpdateCorpseState();
  4859. }
  4860. if (m_RefreshAnimStateIdx != m_LocalRefreshAnimStateIdx)
  4861. {
  4862. RefreshHandAnimationState(396); //mean animation blend time
  4863. m_LocalRefreshAnimStateIdx = m_RefreshAnimStateIdx;
  4864. }
  4865. if (m_InsideEffectArea != m_InsideEffectAreaPrev)
  4866. {
  4867. if (m_InsideEffectArea)
  4868. {
  4869. OnPlayerIsNowInsideEffectAreaBeginClient();
  4870. }
  4871. else
  4872. {
  4873. OnPlayerIsNowInsideEffectAreaEndClient();
  4874. }
  4875. m_InsideEffectAreaPrev = m_InsideEffectArea;
  4876. }
  4877. //-------MODIFIERS START--------
  4878. if (m_SyncedModifiers != m_SyncedModifiersPrev)
  4879. {
  4880. int diff = (m_SyncedModifiers & ~m_SyncedModifiersPrev) | (~m_SyncedModifiers & m_SyncedModifiersPrev);//XOR gets us a mask for modifiers that changed by either deactivating, or activating
  4881. if (eModifierSyncIDs.MODIFIER_SYNC_DROWNING & diff)//has this modifier's status as active/inactive changed ?
  4882. {
  4883. if (eModifierSyncIDs.MODIFIER_SYNC_DROWNING & m_SyncedModifiers)//is this modifier currently active ? if so, it means it's been just activated
  4884. {
  4885. SetDrowning(true);
  4886. }
  4887. else
  4888. {
  4889. SetDrowning(false);
  4890. }
  4891. }
  4892. m_SyncedModifiersPrev = m_SyncedModifiers;
  4893. }
  4894. //-------MODIFIERS END--------
  4895. HandleBrokenLegsSync();
  4896. //! Remotely Activated Item Behaviour refresh on item is in hands
  4897. ItemBase itemHands = GetItemInHands();
  4898. if (itemHands)
  4899. {
  4900. RemotelyActivatedItemBehaviour raib = itemHands.GetRemotelyActivatedItemBehaviour();
  4901. if (raib)
  4902. raib.OnVariableSynchronized();
  4903. }
  4904. //restrain events
  4905. if (m_IsRestrainedLocal != m_IsRestrained)
  4906. {
  4907. m_IsRestrainedLocal = m_IsRestrained;
  4908. OnRestrainChangeClient();
  4909. }
  4910. if (m_IsRestrainStartedLocal != m_IsRestrainStarted)
  4911. {
  4912. m_IsRestrainStartedLocal = m_IsRestrainStarted;
  4913. OnRestrainStartedChangeClient();
  4914. }
  4915. }
  4916. //! Checks whether modifier (which has syncing enabled) is currently active, works on both Client and Server
  4917. bool IsSyncedModifierActive(eModifierSyncIDs modifier)
  4918. {
  4919. return (m_SyncedModifiers & m_SyncedModifiersPrev);
  4920. }
  4921. void HandleBrokenLegsSync()
  4922. {
  4923. if (m_BrokenLegState != m_LocalBrokenState)
  4924. {
  4925. m_LocalBrokenState = m_BrokenLegState;
  4926. if (GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  4927. {
  4928. if (m_BrokenLegState < 0)
  4929. BreakLegSound();
  4930. }
  4931. }
  4932. }
  4933. void FixAllInventoryItems()
  4934. {
  4935. array<EntityAI> items = new array<EntityAI>();
  4936. GetInventory().EnumerateInventory(InventoryTraversalType.INORDER, items);
  4937. foreach (EntityAI item : items)
  4938. {
  4939. item.SetHealthMax("", "");
  4940. item.SetWet(item.GetWetInit());
  4941. item.SetTemperatureDirect(GameConstants.ITEM_TEMPERATURE_NEUTRAL_ZONE_MIDDLE);
  4942. item.SetFrozen(false);
  4943. }
  4944. }
  4945. void OnInventoryMenuOpen();
  4946. void OnInventoryMenuClose();
  4947. //--------------------------------------------------------------------------
  4948. void OnSelectPlayer()
  4949. {
  4950. //Print("PlayerBase | OnSelectPlayer()");
  4951. m_PlayerSelected = true;
  4952. m_QuickBarBase.updateSlotsCount();
  4953. m_WeaponManager.SortMagazineAfterLoad();
  4954. PlayerIdentity identity = GetIdentity();
  4955. #ifdef FEATURE_NETWORK_RECONCILIATION
  4956. if (identity)
  4957. {
  4958. //! TODO(kumarjac): vhc: Check if it causes further issues with SelectPlayer while a player is leaving freecam
  4959. identity.Possess(this);
  4960. }
  4961. #endif
  4962. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || !GetGame().IsMultiplayer())
  4963. {
  4964. if (identity)
  4965. {
  4966. m_CachedPlayerID = identity.GetId();
  4967. m_CachedPlayerName = identity.GetName();
  4968. }
  4969. //! add callbacks for ai target system
  4970. SetAITargetCallbacks(new AITargetCallbacksPlayer(this));
  4971. array<ref Param> params = new array<ref Param>;
  4972. if (m_aQuickBarLoad)
  4973. {
  4974. int count = m_aQuickBarLoad.Count();
  4975. Param1<int> paramCount = new Param1<int>(count);
  4976. params.Insert(paramCount);
  4977. for (int i = 0; i < count; i++)
  4978. {
  4979. m_QuickBarBase.OnSetEntityNoSync(m_aQuickBarLoad.Get(i).param1,m_aQuickBarLoad.Get(i).param2);
  4980. params.Insert(m_aQuickBarLoad.Get(i));
  4981. }
  4982. if (count > 0 && GetGame().IsMultiplayer())
  4983. {
  4984. GetGame().RPC(this, ERPCs.RPC_INIT_SET_QUICKBAR, params, true, identity);
  4985. }
  4986. m_aQuickBarLoad = NULL;
  4987. }
  4988. GetSoftSkillsManager().InitSpecialty(GetStatSpecialty().Get());
  4989. GetModifiersManager().SetModifiers(true);
  4990. SetSynchDirty();
  4991. if (GetGame().IsMultiplayer())
  4992. {
  4993. //Drop item warning
  4994. if (m_ProcessUIWarning)
  4995. {
  4996. GetGame().RPCSingleParam(this, ERPCs.RPC_WARNING_ITEMDROP, null, true, identity);
  4997. m_ProcessUIWarning = false;
  4998. }
  4999. GetGame().GetMission().SyncRespawnModeInfo(identity);
  5000. }
  5001. }
  5002. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  5003. {
  5004. m_ActionManager = new ActionManagerServer(this);
  5005. m_ConstructionActionData = new ConstructionActionData();
  5006. CheckForGag();
  5007. }
  5008. else if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  5009. {
  5010. m_ActionManager = new ActionManagerClient(this);
  5011. m_CraftingManager = new CraftingManager(this,m_ModuleRecipesManager);
  5012. m_ConstructionActionData = new ConstructionActionData();
  5013. }
  5014. else if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SINGLEPLAYER)
  5015. {
  5016. m_ActionManager = new ActionManagerServer(this);
  5017. }
  5018. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  5019. {
  5020. if (GetGame().GetMission())
  5021. {
  5022. GetGame().GetMission().ResetGUI();
  5023. // force update player
  5024. GetDayZGame().GetBacklit().UpdatePlayer(true);
  5025. }
  5026. m_DeathCheckTimer = new Timer();
  5027. m_DeathCheckTimer.Run(0.1, this, "CheckDeath", null, true);
  5028. PPEManagerStatic.GetPPEManager().StopAllEffects(PPERequesterCategory.ALL);
  5029. CheckForBurlap();
  5030. int characterCount = GetGame().GetMenuData().GetCharactersCount() - 1;
  5031. int idx = GetGame().GetMenuData().GetLastPlayedCharacter();
  5032. if (idx == GameConstants.DEFAULT_CHARACTER_MENU_ID || idx > characterCount)
  5033. {
  5034. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(SetNewCharName);
  5035. }
  5036. GetGame().GetMission().EnableAllInputs(true);
  5037. m_PresenceNotifier = PluginPresenceNotifier.Cast(GetPlugin(PluginPresenceNotifier));
  5038. m_PresenceNotifier.Init(this);
  5039. #ifdef DIAG_DEVELOPER
  5040. m_TargetTemperatureDiag = PluginTargetTemperature.Cast(GetPlugin(PluginTargetTemperature));
  5041. m_TargetTemperatureDiag.Init(this);
  5042. #endif
  5043. OnGameplayDataHandlerSync();//only here for legacy reasons
  5044. }
  5045. #ifdef BOT
  5046. m_Bot = new Bot(this);
  5047. m_Bot.Start(true, new MyBotTrigger(this));
  5048. #endif
  5049. }
  5050. override void SimulateDeath(bool state)
  5051. {
  5052. super.SimulateDeath(state);
  5053. m_UndergroundHandler = null;
  5054. m_UndergroundBunkerHandler = null;
  5055. if (m_EffectWidgets)
  5056. {
  5057. m_EffectWidgets.StopAllEffects();
  5058. m_EffectWidgets.ClearSuspendRequests();
  5059. }
  5060. }
  5061. void SetNewCharName()
  5062. {
  5063. g_Game.GetMenuData().SaveCharacter(false, true);
  5064. g_Game.GetMenuData().SetCharacterName(g_Game.GetMenuData().GetLastPlayedCharacter(), g_Game.GetMenuDefaultCharacterData(false).GetCharacterName());
  5065. g_Game.GetMenuData().SaveCharactersLocal();
  5066. }
  5067. void CheckForBurlap()
  5068. {
  5069. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  5070. {
  5071. BurlapSackCover attachment;
  5072. Class.CastTo(attachment, GetInventory().FindAttachment(InventorySlots.HEADGEAR));
  5073. PPERequester_BurlapSackEffects req;
  5074. if (Class.CastTo(req,PPERequesterBank.GetRequester(PPERequesterBank.REQ_BURLAPSACK)))
  5075. {
  5076. if (attachment)
  5077. {
  5078. req.Start();
  5079. }
  5080. else if (req.IsRequesterRunning())
  5081. {
  5082. PPERequesterBank.GetRequester(PPERequester_BurlapSackEffects).Stop();
  5083. }
  5084. }
  5085. }
  5086. }
  5087. void CheckForGag()
  5088. {
  5089. #ifdef SERVER
  5090. Clothing item;
  5091. Class.CastTo(item, GetInventory().FindAttachment(InventorySlots.MASK));
  5092. if (!item)
  5093. {
  5094. Class.CastTo(item, GetInventory().FindAttachment(InventorySlots.HEADGEAR));
  5095. }
  5096. if (item && item.IsObstructingVoice())
  5097. {
  5098. item.MutePlayer(this,true);
  5099. }
  5100. else //should probably check for relevant types before removing mumbling and obstruction specifically..
  5101. {
  5102. GetGame().SetVoiceEffect(this, VoiceEffectMumbling, false);
  5103. GetGame().SetVoiceEffect(this, VoiceEffectObstruction, false);
  5104. }
  5105. #endif
  5106. }
  5107. void UpdateMaskBreathWidget(notnull MaskBase mask, bool is_start = false)
  5108. {
  5109. if (is_start)
  5110. m_EffectWidgets.ResetMaskUpdateCount();
  5111. float resistance = 0;
  5112. if (mask.HasIntegratedFilter() || mask.IsExternalFilterAttached())
  5113. resistance = 1 - mask.GetFilterQuantity01();
  5114. m_EffectWidgets.OnVoiceEvent(resistance);
  5115. m_EffectWidgets.IncreaseMaskUpdateCount();
  5116. }
  5117. // -------------------------------------------------------------------------
  5118. void OnVoiceEvent(PlayerSoundEventBase voice_event)
  5119. {
  5120. if (m_EffectWidgets)
  5121. {
  5122. MaskBase mask = MaskBase.Cast(GetInventory().FindAttachment(InventorySlots.MASK));
  5123. if (mask)
  5124. {
  5125. UpdateMaskBreathWidget(mask, true);
  5126. //m_EffectWidgets.SetBreathIntensityStamina(GetStaminaHandler().GetStaminaCap(),GetStaminaHandler().GetStamina());
  5127. }
  5128. }
  5129. }
  5130. // -------------------------------------------------------------------------
  5131. //! called every cmd handler tick during a playback of PlayerSoundEvent, m_ProcessPlaybackEvent needs to be enabled on the PlayerSoundEvent
  5132. void OnVoiceEventPlayback(PlayerSoundEventBase voice_event, AbstractWave callback, float playback_time)
  5133. {
  5134. if (m_EffectWidgets)
  5135. {
  5136. MaskBase mask = MaskBase.Cast(GetInventory().FindAttachment(InventorySlots.MASK));
  5137. if (mask)
  5138. {
  5139. if (m_EffectWidgets.m_MaskWidgetUpdateCount < 2 && callback.GetLength() > 2 && playback_time > 0.5 )
  5140. UpdateMaskBreathWidget(mask);
  5141. }
  5142. }
  5143. }
  5144. // -------------------------------------------------------------------------
  5145. override bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
  5146. {
  5147. if (super.OnInputUserDataProcess(userDataType, ctx))
  5148. return true;
  5149. if (m_QuickBarBase.OnInputUserDataProcess(userDataType, ctx))
  5150. return true;
  5151. if (m_WeaponManager.OnInputUserDataProcess(userDataType, ctx))
  5152. return true;
  5153. if (HandleRemoteItemManipulation(userDataType, ctx))
  5154. return true;
  5155. if (userDataType == INPUT_UDT_INVENTORY && GetHumanInventory().OnInputUserDataProcess(ctx))
  5156. return true;
  5157. if (TogglePlacingServer(userDataType, ctx))
  5158. return true;
  5159. if (ResetADSPlayerSync(userDataType, ctx))
  5160. return true;
  5161. string uid;
  5162. bool mute;
  5163. if (userDataType == INPUT_UDT_USER_MUTE_XBOX)
  5164. {
  5165. if (ctx.Read(uid) && ctx.Read(mute))
  5166. {
  5167. GetGame().MutePlayer(uid, GetIdentity().GetPlainId(), mute);
  5168. // commented because plainID should not be present in logs
  5169. //Print("Player: " + GetIdentity().GetId() + " set mute for " + uid + " to " + mute);
  5170. }
  5171. }
  5172. if (m_EmoteManager && userDataType == INPUT_UDT_GESTURE)
  5173. return m_EmoteManager.OnInputUserDataProcess(userDataType, ctx);
  5174. if (userDataType == INPUT_UDT_WEAPON_LIFT_EVENT)
  5175. return ReadLiftWeaponRequest(userDataType, ctx);
  5176. if (m_ActionManager)
  5177. return m_ActionManager.OnInputUserDataProcess(userDataType, ctx);
  5178. return false;
  5179. }
  5180. float GetHealthRegenSpeed()
  5181. {
  5182. float blood = GetHealth("GlobalHealth", "Blood");
  5183. float blood_scale_normalized = Math.InverseLerp(PlayerConstants.BLOOD_THRESHOLD_FATAL, GetMaxHealth("", "Blood"), blood);
  5184. blood_scale_normalized = Math.Clamp(blood_scale_normalized,0,1);
  5185. return Math.Lerp(PlayerConstants.HEALTH_REGEN_MIN, PlayerConstants.HEALTH_REGEN_MAX, blood_scale_normalized);
  5186. }
  5187. bool HandleRemoteItemManipulation(int userDataType, ParamsReadContext ctx)
  5188. {
  5189. if (userDataType == INPUT_UDT_ITEM_MANIPULATION)
  5190. {
  5191. int type = -1;
  5192. ItemBase item1 = null;
  5193. ItemBase item2 = null;
  5194. bool use_stack_max = false;
  5195. int slot_id = -1;
  5196. if (!ctx.Read(type))
  5197. return false;
  5198. if (type == 4)
  5199. {
  5200. if (!ctx.Read(item1))
  5201. return false;
  5202. InventoryLocation dst = new InventoryLocation;
  5203. if (item1 && dst.ReadFromContext(ctx))
  5204. {
  5205. //Print(InventoryLocation.DumpToStringNullSafe(dst));
  5206. bool dummy;
  5207. if (ctx.Read(dummy))
  5208. item1.SplitItemToInventoryLocation(dst);
  5209. else
  5210. item1.SplitIntoStackMaxToInventoryLocation(dst);
  5211. return true;
  5212. }
  5213. return false;
  5214. }
  5215. if (!ctx.Read(item1))
  5216. return false;
  5217. if (!ctx.Read(item2))
  5218. return false;
  5219. if (!ctx.Read(use_stack_max))
  5220. return false;
  5221. if (!ctx.Read(slot_id))
  5222. return false;
  5223. if (type == -1 && item1 && item2)//combine
  5224. {
  5225. item1.CombineItems(item2, use_stack_max);
  5226. }
  5227. else if (type == 1 && item1)
  5228. {
  5229. if (use_stack_max)
  5230. item1.SplitIntoStackMax(item2, slot_id, this);
  5231. else
  5232. item1.SplitItem(this);
  5233. }
  5234. else if (type == 2 && item1)
  5235. {
  5236. int row, col;
  5237. if (!ctx.Read(row))
  5238. return false;
  5239. if (!ctx.Read(col))
  5240. return false;
  5241. item1.SplitIntoStackMaxCargo(item2, slot_id, row, col);
  5242. }
  5243. else if (type == 3 && item1)
  5244. {
  5245. item1.SplitIntoStackMaxHands(this);
  5246. }
  5247. return true;
  5248. }
  5249. return false;
  5250. }
  5251. // -------------------------------------------------------------------------
  5252. ItemBase GetItemInHands()
  5253. {
  5254. HumanInventory humanInventory = GetHumanInventory();
  5255. if (humanInventory)
  5256. return ItemBase.Cast(humanInventory.GetEntityInHands());
  5257. return null;
  5258. }
  5259. //--------------------------------------------------------------------------
  5260. override EntityAI SpawnEntityOnGroundPos(string object_name, vector pos)
  5261. {
  5262. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || !GetGame().IsMultiplayer())
  5263. {
  5264. bool is_AI = GetGame().IsKindOf(object_name, "DZ_LightAI");
  5265. if (is_AI)
  5266. {
  5267. return SpawnAI(object_name, pos);
  5268. }
  5269. else
  5270. {
  5271. InventoryLocation inv_loc = new InventoryLocation;
  5272. vector mtx[4];
  5273. Math3D.MatrixIdentity4(mtx);
  5274. mtx[3] = pos;
  5275. inv_loc.SetGround(null, mtx);
  5276. int flags = ECE_PLACE_ON_SURFACE;
  5277. #ifdef DEVELOPER
  5278. if (g_Game.IsKindOf(object_name, "Boat"))
  5279. flags = ECE_KEEPHEIGHT;
  5280. #endif
  5281. return EntityAI.Cast(GetGame().CreateObjectEx(object_name, inv_loc.GetPos(), flags));
  5282. }
  5283. }
  5284. return null;
  5285. }
  5286. EntityAI SpawnEntityOnGroundRaycastDispersed(string object_name, float raycastDistance = DEFAULT_SPAWN_DISTANCE, float radius = UAItemsSpreadRadius.DEFAULT)
  5287. {
  5288. vector posRandom = MiscGameplayFunctions.GetRandomizedPositionVerifiedPlayer(this,raycastDistance,radius,this);
  5289. return SpawnEntityOnGroundPos(object_name,posRandom);
  5290. }
  5291. EntityAI SpawnEntityOnGroundOnCursorDir(string object_name, float distance)
  5292. {
  5293. vector position = GetPosition() + (GetDirection() * distance);
  5294. return SpawnEntityOnGroundPos(object_name, position);
  5295. }
  5296. EntityAI SpawnAI(string object_name, vector pos)
  5297. {
  5298. bool is_ai = GetGame().IsKindOf(object_name, "DZ_LightAI");
  5299. if (is_ai)
  5300. {
  5301. return EntityAI.Cast(GetGame().CreateObjectEx(object_name, pos, ECE_PLACE_ON_SURFACE|ECE_INITAI|ECE_EQUIP_ATTACHMENTS));
  5302. }
  5303. return NULL;
  5304. }
  5305. //--------------------------------------------------------------------------
  5306. bool DropItem(ItemBase item)
  5307. {
  5308. bool can_be_dropped = CanDropEntity(item);
  5309. if (can_be_dropped)
  5310. {
  5311. can_be_dropped = PredictiveDropEntity(item);
  5312. }
  5313. vector pos_spawn = GetPosition() + GetDirection();
  5314. pos_spawn[0] = pos_spawn[0] + Math.RandomFloat(-0.2, 0.2);
  5315. pos_spawn[2] = pos_spawn[2] + Math.RandomFloat(-0.2, 0.2);
  5316. item.SetPosition(pos_spawn);
  5317. item.PlaceOnSurface();
  5318. return can_be_dropped;
  5319. }
  5320. // -------------------------------------------------------------------------
  5321. /**
  5322. /brief Creates \p ItemBase in players inventory. If player dont have enough slots for new item, item will be created on the ground under player.
  5323. \param item_name \p string Class name of ItemBase in configs
  5324. \returns \p ItemBase Created item
  5325. @code
  5326. ItemBase item = g_Game.GetPlayer().CreateInInventory("Consumable_GardenLime", "cargo_weapon");
  5327. @endcode
  5328. */
  5329. EntityAI CreateInInventory(string item_name, string cargo_type = "", bool full_quantity = false)
  5330. {
  5331. InventoryLocation inv_loc = new InventoryLocation;
  5332. if (GetInventory().FindFirstFreeLocationForNewEntity(item_name, FindInventoryLocationType.ANY, inv_loc))
  5333. {
  5334. return SpawnItemOnLocation(item_name, inv_loc, full_quantity);
  5335. }
  5336. return NULL;
  5337. }
  5338. ItemBase CreateCopyOfItemInInventory (ItemBase src)
  5339. {
  5340. InventoryLocation loc = new InventoryLocation;
  5341. string t = src.GetType();
  5342. if (GetInventory().FindFirstFreeLocationForNewEntity(t, FindInventoryLocationType.CARGO, loc))
  5343. {
  5344. bool locked = GetGame().HasInventoryJunctureDestination(this, loc);
  5345. if (locked)
  5346. {
  5347. Print("Warning: Split: CreateCopyOfItemInInventory - Cannot create entity at locked inventory at loc=" + InventoryLocation.DumpToStringNullSafe(loc));
  5348. return null;
  5349. }
  5350. ItemBase dst = ItemBase.Cast(GetInventory().LocationCreateLocalEntity(loc, t, ECE_IN_INVENTORY, RF_DEFAULT));
  5351. if (dst)
  5352. {
  5353. MiscGameplayFunctions.TransferItemProperties(src, dst);
  5354. GetGame().RemoteObjectTreeCreate(dst);
  5355. Print("CreateCopyOfItemInInventory - created " + dst.GetName() + " at loc=" + InventoryLocation.DumpToStringNullSafe(loc));
  5356. }
  5357. return dst;
  5358. }
  5359. return NULL;
  5360. }
  5361. ItemBase CreateCopyOfItemInInventoryOrGround(ItemBase src)
  5362. {
  5363. return CreateCopyOfItemInInventoryOrGroundEx(src, false);
  5364. }
  5365. ItemBase CreateCopyOfItemInInventoryOrGroundEx(ItemBase src, bool markItemAsSplitResult = false)
  5366. {
  5367. ItemBase dst = CreateCopyOfItemInInventory(src);
  5368. if (!dst)
  5369. {
  5370. dst = ItemBase.Cast(SpawnEntityOnGroundPos(src.GetType(), this.GetPosition()));
  5371. dst.PlaceOnSurface();
  5372. dst.SetResultOfSplit(markItemAsSplitResult);
  5373. MiscGameplayFunctions.TransferItemProperties(src, dst);
  5374. }
  5375. return dst;
  5376. }
  5377. // -------------------------------------------------------------------------
  5378. /**
  5379. colorStatusChannel
  5380. colorAction
  5381. colorFriendly
  5382. colorImportant
  5383. */
  5384. void Message(string text, string style)
  5385. {
  5386. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  5387. {
  5388. GetGame().ChatMP(this, text, style);
  5389. }
  5390. else
  5391. {
  5392. GetGame().Chat(text, style);
  5393. }
  5394. }
  5395. // -------------------------------------------------------------------------
  5396. void MessageStatus(string text)
  5397. {
  5398. Message(text, "colorStatusChannel");
  5399. }
  5400. // -------------------------------------------------------------------------
  5401. void MessageAction(string text)
  5402. {
  5403. Message(text, "colorAction");
  5404. }
  5405. // -------------------------------------------------------------------------
  5406. void MessageFriendly(string text)
  5407. {
  5408. Message(text, "colorFriendly");
  5409. }
  5410. // -------------------------------------------------------------------------
  5411. void MessageImportant(string text)
  5412. {
  5413. Message(text, "colorImportant");
  5414. }
  5415. void CloseInventoryMenu()
  5416. {
  5417. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  5418. {
  5419. #ifndef NO_GUI
  5420. UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
  5421. if (menu && (menu.GetID() == MENU_INVENTORY || menu.GetID() == MENU_INSPECT))
  5422. {
  5423. GetGame().GetUIManager().CloseAll();
  5424. GetGame().GetMission().RemoveActiveInputExcludes({"inventory"},false);
  5425. GetGame().GetMission().RemoveActiveInputRestriction(EInputRestrictors.INVENTORY);
  5426. }
  5427. #endif
  5428. }
  5429. }
  5430. // -------------------------------------------------------------------------
  5431. /**
  5432. /brief Delete all items in inventory
  5433. \returns \p void
  5434. @code
  5435. PlayerBase player = GetGame().GetPlayer();
  5436. player.ClearInventory();
  5437. @endcode
  5438. */
  5439. override void ClearInventory()
  5440. {
  5441. if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && GetInventory())
  5442. {
  5443. GameInventory inv = PlayerBase.Cast(this).GetInventory();
  5444. array<EntityAI> items = new array<EntityAI>;
  5445. inv.EnumerateInventory(InventoryTraversalType.INORDER, items);
  5446. for (int i = 0; i < items.Count(); i++)
  5447. {
  5448. ItemBase item = ItemBase.Cast(items.Get(i));
  5449. if (item)
  5450. {
  5451. GetGame().ObjectDelete(item);
  5452. }
  5453. }
  5454. ItemBase item_in_hands = ItemBase.Cast(GetHumanInventory().GetEntityInHands());
  5455. if (item_in_hands)
  5456. {
  5457. LocalDestroyEntityInHands();
  5458. }
  5459. }
  5460. }
  5461. //! Drops all clothes/wearables this character is carrying on themselves.
  5462. void DropAllItems()
  5463. {
  5464. array<EntityAI> itemsArray = new array<EntityAI>;
  5465. ItemBase item;
  5466. GetInventory().EnumerateInventory(InventoryTraversalType.LEVELORDER, itemsArray);
  5467. int count = itemsArray.Count();
  5468. for (int i = 0; i < itemsArray.Count(); i++)
  5469. {
  5470. Class.CastTo(item, itemsArray.Get(i));
  5471. if (item && !item.IsInherited(SurvivorBase))
  5472. {
  5473. ServerDropEntity(item);
  5474. }
  5475. }
  5476. }
  5477. string GetPlayerClass()
  5478. {
  5479. string type;
  5480. GetGame().ObjectGetType(this, type);
  5481. return type;
  5482. }
  5483. // --------------------------------------------------
  5484. // Lifespan
  5485. //---------------------------------------------------
  5486. void ShavePlayer()
  5487. {
  5488. SetLastShavedSeconds(StatGet(AnalyticsManagerServer.STAT_PLAYTIME));
  5489. m_ModuleLifespan.UpdateLifespan(this, true);
  5490. }
  5491. bool CanShave()
  5492. {
  5493. if (!HasCoveredFaceForShave() && GetLifeSpanState())
  5494. {
  5495. return true;
  5496. }
  5497. else
  5498. {
  5499. return false;
  5500. }
  5501. }
  5502. override void OnParticleEvent(string pEventType, string pUserString, int pUserInt)
  5503. {
  5504. super.OnParticleEvent(pEventType ,pUserString, pUserInt);
  5505. if (!GetGame().IsDedicatedServer())
  5506. {
  5507. if (pUserInt == 123456) // 123456 is ID for vomiting effect. The current implementation is WIP.
  5508. {
  5509. PlayerBase player = PlayerBase.Cast(this);
  5510. int boneIdx = player.GetBoneIndexByName("Head");
  5511. if (boneIdx != -1)
  5512. {
  5513. EffectParticle eff;
  5514. if (m_SyncedModifiers & eModifierSyncIDs.MODIFIER_SYNC_CONTAMINATION2)
  5515. {
  5516. eff = new EffVomitBlood();
  5517. }
  5518. else
  5519. {
  5520. eff = new EffVomit();
  5521. }
  5522. eff.SetDecalOwner(player);
  5523. eff.SetAutodestroy(true);
  5524. SEffectManager.PlayInWorld(eff, vector.Zero);
  5525. Particle p = eff.GetParticle();
  5526. player.AddChild(p, boneIdx);
  5527. }
  5528. }
  5529. }
  5530. }
  5531. bool CanSpawnBreathVaporEffect()
  5532. {
  5533. if (!ToDelete() && IsAlive() && !IsSwimming() && !m_IsDrowning)
  5534. {
  5535. return true;
  5536. }
  5537. return false;
  5538. }
  5539. void ProcessADDModifier()
  5540. {
  5541. if (m_AddModifier != -1)
  5542. {
  5543. HumanCommandAdditives ad = GetCommandModifier_Additives();
  5544. if (ad)
  5545. ad.StartModifier(m_AddModifier);
  5546. m_AddModifier = -1;
  5547. }
  5548. }
  5549. void SpawnBreathVaporEffect()
  5550. {
  5551. //Print("SpawnBreathVaporEffect:"+GetGame().GetTime());
  5552. int boneIdx = GetBoneIndexByName("Head");
  5553. if (boneIdx != -1)
  5554. {
  5555. Particle p;
  5556. switch (m_BreathVapour)
  5557. {
  5558. case 1:
  5559. p = ParticleManager.GetInstance().PlayInWorld(ParticleList.BREATH_VAPOUR_LIGHT, "-0.03 0.15 0");
  5560. break;
  5561. case 2:
  5562. p = ParticleManager.GetInstance().PlayInWorld(ParticleList.BREATH_VAPOUR_MEDIUM, "-0.03 0.15 0");
  5563. break;
  5564. case 3:
  5565. p = ParticleManager.GetInstance().PlayInWorld(ParticleList.BREATH_VAPOUR_HEAVY, "-0.03 0.15 0");
  5566. break;
  5567. default:
  5568. break;
  5569. }
  5570. if (p)
  5571. AddChild(p, boneIdx);
  5572. }
  5573. }
  5574. // returns 'true' if the player is submerged under water deep enough so that we consider him/her to be eligible for drowning, do note some other conditions may apply for actual drowning to be turned on
  5575. bool GetDrowningWaterLevelCheck()
  5576. {
  5577. int index = GetBoneIndexByName("head");
  5578. vector pos = GetBonePositionWS(index);
  5579. float depth = g_Game.GetWaterDepth(pos);
  5580. if (IsSwimming())
  5581. {
  5582. return depth > PlayerConstants.DROWNING_SWIMMING_THRESHOLD;
  5583. }
  5584. else if (IsUnconscious())
  5585. {
  5586. return depth > PlayerConstants.DROWNING_UNCONSCIOUS_THRESHOLD;
  5587. }
  5588. return depth > PlayerConstants.DROWNING_DEFAULT_THRESHOLD;
  5589. }
  5590. void SetLifeSpanStateVisible(int show_state)
  5591. {
  5592. bool state_changed;
  5593. if (show_state != m_LifeSpanState)
  5594. state_changed = true;
  5595. m_LifeSpanState = show_state;
  5596. SetSynchDirty();
  5597. if (state_changed) //server only, client solution in OnVariablesSynchronized()
  5598. {
  5599. //SendLifespanSyncEvent(m_LifeSpanState);
  5600. UpdateHairSelectionVisibility();
  5601. }
  5602. }
  5603. int GetLifeSpanState()
  5604. {
  5605. return m_LifeSpanState;
  5606. }
  5607. int GetLastShavedSeconds()
  5608. {
  5609. return m_LastShavedSeconds;
  5610. }
  5611. void SetLastShavedSeconds(int last_shaved_seconds)
  5612. {
  5613. m_LastShavedSeconds = last_shaved_seconds;
  5614. }
  5615. bool HasCoveredFaceForShave()
  5616. {
  5617. return IsExclusionFlagPresent(GetFaceCoverageShaveValues());
  5618. }
  5619. //! returns a set of face covering values
  5620. static set<int> GetFaceCoverageShaveValues()
  5621. {
  5622. set<int> ret = new set<int>;
  5623. ret.Insert(EAttExclusions.SHAVING_MASK_ATT_0);
  5624. ret.Insert(EAttExclusions.SHAVING_HEADGEAR_ATT_0);
  5625. //ret.Insert(EAttExclusions.SHAVING_EYEWEAR_ATT_0);
  5626. return ret;
  5627. }
  5628. eBloodyHandsTypes HasBloodyHandsEx()
  5629. {
  5630. return m_HasBloodyHandsVisible;
  5631. }
  5632. bool HasBloodyHands()
  5633. {
  5634. return m_HasBloodyHandsVisible;
  5635. }
  5636. void SetBloodyHands(bool show)
  5637. {
  5638. SetBloodyHandsBase(show);
  5639. }
  5640. void SetBloodyHandsEx(eBloodyHandsTypes type)
  5641. {
  5642. SetBloodyHandsBase(type);
  5643. }
  5644. private void SetBloodyHandsBase(int type)
  5645. {
  5646. m_HasBloodyHandsVisible = type;
  5647. SetSynchDirty();
  5648. #ifdef DIAG_DEVELOPER
  5649. #ifndef SERVER
  5650. if (IsControlledPlayer())
  5651. {
  5652. bool enable = type;
  5653. DiagMenu.SetValue(DiagMenuIDs.LIFESPAN_BLOODY_HANDS, enable);
  5654. }
  5655. #endif
  5656. #endif
  5657. }
  5658. int GetBloodyHandsPenaltyAgents()
  5659. {
  5660. if (HasBloodyHands())
  5661. {
  5662. if (GetInventory().FindAttachment(InventorySlots.GLOVES))
  5663. return 0;
  5664. float randomValue = Math.RandomFloat01();
  5665. if (GetBloodyHandsPenaltyChancePerAgent(eAgents.SALMONELLA) >= randomValue)
  5666. return eAgents.SALMONELLA;
  5667. return eAgents.FOOD_POISON;
  5668. }
  5669. return 0;
  5670. }
  5671. float GetBloodyHandsPenaltyChancePerAgent(eAgents type)
  5672. {
  5673. float value = 0.0;
  5674. if (m_BloodyHandsPenaltyChancePerAgent.Find(type, value))
  5675. return value;
  5676. return value;
  5677. }
  5678. //! increments the chances per agents
  5679. void SetBloodyHandsPenaltyChancePerAgent(eAgents type, float amount)
  5680. {
  5681. float storedValue = GetBloodyHandsPenaltyChancePerAgent(type);
  5682. if (amount > storedValue)
  5683. m_BloodyHandsPenaltyChancePerAgent.Set(type, Math.Clamp(amount, 0.0, 1.0));
  5684. }
  5685. void ClearBloodyHandsPenaltyChancePerAgent(eAgents type)
  5686. {
  5687. m_BloodyHandsPenaltyChancePerAgent.Set(type, 0.0);
  5688. }
  5689. bool HasBloodTypeVisible()
  5690. {
  5691. return m_HasBloodTypeVisible;
  5692. }
  5693. void SetBloodTypeVisible(bool show)
  5694. {
  5695. m_HasBloodTypeVisible = show;
  5696. SetSynchDirty();
  5697. }
  5698. int GetBloodType()
  5699. {
  5700. return m_BloodType;
  5701. }
  5702. void SetBloodType(int blood_type)
  5703. {
  5704. m_BloodType = blood_type;
  5705. SetSynchDirty();
  5706. }
  5707. // --------------------------------------------------
  5708. // Soft Skills
  5709. //---------------------------------------------------
  5710. SoftSkillsManager GetSoftSkillsManager()
  5711. {
  5712. return m_SoftSkillsManager;
  5713. }
  5714. void CheckDeath()
  5715. {
  5716. if (IsPlayerSelected() && !IsAlive())
  5717. {
  5718. SimulateDeath(true);
  5719. m_DeathCheckTimer.Stop();
  5720. }
  5721. }
  5722. // -------------------------------------------------------------------------
  5723. // --------------------------------------------------
  5724. // AI Presence
  5725. //---------------------------------------------------
  5726. //! Return actual noise presence of player
  5727. int GetNoisePresenceInAI()
  5728. {
  5729. if (m_PresenceNotifier)
  5730. {
  5731. return m_PresenceNotifier.GetNoisePresence();
  5732. }
  5733. return 0;
  5734. }
  5735. // is a bit on in the persistent flags
  5736. bool IsPersistentFlag(PersistentFlag bit)
  5737. {
  5738. return (m_PersistentFlags & bit);
  5739. }
  5740. // turn on/off a bit in the persistent flag
  5741. void SetPersistentFlag(PersistentFlag bit, bool enable)
  5742. {
  5743. if (enable)//turn on bit
  5744. m_PersistentFlags = (m_PersistentFlags | bit);
  5745. else//turn off bit
  5746. m_PersistentFlags = ((~bit) & m_PersistentFlags);
  5747. }
  5748. // -------------------------------------------------------------------------
  5749. int GetStoreLoadVersion()
  5750. {
  5751. return m_StoreLoadVersion;
  5752. }
  5753. override void OnStoreSave(ParamsWriteContext ctx)
  5754. {
  5755. //Print("OnStoreSave");
  5756. if (GetGame().SaveVersion() < 102)
  5757. {
  5758. ctx.Write(ACT_STORE_SAVE_VERSION);//to be removed after we push 102+
  5759. }
  5760. super.OnStoreSave(ctx);
  5761. GetHumanInventory().OnStoreSave(ctx); // FSM of hands
  5762. OnStoreSaveLifespan(ctx);
  5763. if (GetDayZGame().IsServer() && GetDayZGame().IsMultiplayer())
  5764. {
  5765. GetPlayerStats().SaveStats(ctx);// save stats
  5766. m_ModifiersManager.OnStoreSave(ctx);// save modifiers
  5767. m_AgentPool.OnStoreSave(ctx);//save agents
  5768. GetSymptomManager().OnStoreSave(ctx);//save states
  5769. if (GetBleedingManagerServer())
  5770. {
  5771. GetBleedingManagerServer().OnStoreSave(ctx);//save bleeding sources
  5772. }
  5773. m_PlayerStomach.OnStoreSave(ctx);
  5774. ctx.Write(GetBrokenLegs());
  5775. //ctx.Write(m_LocalBrokenState);
  5776. SaveAreaPersistenceFlag(ctx);
  5777. HumanCommandLadder ladder = GetCommand_Ladder();
  5778. if (ladder)
  5779. {
  5780. ctx.Write(true);
  5781. ctx.Write(ladder.GetLogoutPosition());
  5782. }
  5783. else
  5784. {
  5785. ctx.Write(false);
  5786. }
  5787. ArrowManagerPlayer arrowManager = ArrowManagerPlayer.Cast(GetArrowManager());
  5788. arrowManager.Save(ctx);
  5789. }
  5790. }
  5791. void SaveAreaPersistenceFlag(ParamsWriteContext ctx)
  5792. {
  5793. if (GetModifiersManager())
  5794. SetPersistentFlag(PersistentFlag.AREA_PRESENCE, GetModifiersManager().IsModifierActive(eModifiers.MDF_AREAEXPOSURE));//set the flag for player's presence in contaminated area
  5795. ctx.Write(m_PersistentFlags);
  5796. }
  5797. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  5798. {
  5799. //Print("---- PlayerBase OnStoreLoad START ----, version: "+version);
  5800. m_aQuickBarLoad = new array<ref Param2<EntityAI,int>>;
  5801. // todo :: this should be after base call !!!!
  5802. if (version < 102)//write removed in v. 102
  5803. {
  5804. if (!ctx.Read(m_StoreLoadVersion))
  5805. return false;
  5806. }
  5807. if (!super.OnStoreLoad(ctx, version))
  5808. return false;
  5809. // FSM of hands
  5810. if (!GetHumanInventory().OnStoreLoad(ctx, version))
  5811. return false;
  5812. if (!OnStoreLoadLifespan(ctx, version))
  5813. return false;
  5814. if (GetDayZGame().IsServer() && GetDayZGame().IsMultiplayer())
  5815. {
  5816. if (!GetPlayerStats().LoadStats(ctx, version)) // load stats
  5817. {
  5818. Print("---- failed to load PlayerStats ----");
  5819. return false;
  5820. }
  5821. if (!m_ModifiersManager.OnStoreLoad(ctx, version))
  5822. {
  5823. Print("---- failed to load ModifiersManager, read fail ----");
  5824. return false;
  5825. }
  5826. if (!m_AgentPool.OnStoreLoad(ctx, version))
  5827. {
  5828. Print("---- failed to load AgentPool, read fail ----");
  5829. return false;
  5830. }
  5831. if (!GetSymptomManager().OnStoreLoad(ctx, version))
  5832. {
  5833. Print("---- failed to load SymptomManager, read fail ----");
  5834. return false;
  5835. }
  5836. if (!GetBleedingManagerServer().OnStoreLoad(ctx, version))
  5837. {
  5838. Print("---- failed to load BleedingManagerServer, read fail ----");
  5839. return false;
  5840. }
  5841. if (!m_PlayerStomach.OnStoreLoad(ctx, version))
  5842. {
  5843. Print("---- failed to load PlayerStomach, read fail ----");
  5844. return false;
  5845. }
  5846. //Check for broken leg value
  5847. if (version >= 116)
  5848. {
  5849. if (!ctx.Read(m_BrokenLegState))
  5850. {
  5851. return false;
  5852. }
  5853. if (version <= 126)// WHILE >= 116
  5854. {
  5855. if (!ctx.Read(m_LocalBrokenState))
  5856. {
  5857. return false;
  5858. }
  5859. }
  5860. }
  5861. //Load persistent flags value
  5862. if (version >= 125 && (!ctx.Read(m_PersistentFlags)))
  5863. {
  5864. Print("---- failed to load Persistent Flags, read fail ----");
  5865. return false;
  5866. }
  5867. if (version >= 131)
  5868. {
  5869. bool onLadder;
  5870. if (!ctx.Read(onLadder))
  5871. {
  5872. return false;
  5873. }
  5874. if (onLadder)
  5875. {
  5876. vector position;
  5877. if (!ctx.Read(position))
  5878. {
  5879. return false;
  5880. }
  5881. Hive hive = GetHive();
  5882. if (!hive || !hive.CharacterIsLoginPositionChanged(this))
  5883. {
  5884. SetPosition(position);
  5885. }
  5886. }
  5887. }
  5888. if (version >= 134)
  5889. {
  5890. ArrowManagerPlayer arrowManager = ArrowManagerPlayer.Cast(GetArrowManager());
  5891. arrowManager.Load(ctx);
  5892. }
  5893. }
  5894. Print("---- PlayerBase OnStoreLoad SUCCESS ----");
  5895. return true;
  5896. }
  5897. override void AfterStoreLoad()
  5898. {
  5899. GetHumanInventory().OnAfterStoreLoad();
  5900. if (m_EmoteManager)
  5901. m_EmoteManager.AfterStoreLoad();
  5902. if (GetPlayerStats())
  5903. GetPlayerStats().OnAfterStoreLoad();
  5904. PlayerRestrictedAreaInstance pra;
  5905. vector currentPos = GetPosition();
  5906. if (g_Game.GetGameState() != DayZGameState.MAIN_MENU && CfgPlayerRestrictedAreaHandler.IsInitialized() && CfgPlayerRestrictedAreaHandler.IsPointInPlayerRestrictedArea(currentPos,pra))
  5907. {
  5908. //vector safePos = pra.GetClosestSafePos3D(currentPos);
  5909. vector safePos = pra.GetRandomSafePos3D(currentPos);
  5910. if (MiscGameplayFunctions.TeleportPlayerToSafeLocation3D(this,safePos) && m_AdminLog)
  5911. m_AdminLog.PlayerTeleportedLog(this,currentPos,safePos,"Spawning in Player Restricted Area: " + pra.areaName);
  5912. }
  5913. }
  5914. void OnStoreSaveLifespan(ParamsWriteContext ctx)
  5915. {
  5916. ctx.Write(m_LifeSpanState);
  5917. ctx.Write(m_LastShavedSeconds);
  5918. ctx.Write(m_HasBloodyHandsVisible);
  5919. ctx.Write(m_HasBloodTypeVisible);
  5920. ctx.Write(m_BloodType);
  5921. }
  5922. bool OnStoreLoadLifespan(ParamsReadContext ctx, int version)
  5923. {
  5924. int lifespan_state = 0;
  5925. if (!ctx.Read(lifespan_state))
  5926. return false;
  5927. m_LifeSpanState = lifespan_state;
  5928. int last_shaved = 0;
  5929. if (!ctx.Read(last_shaved))
  5930. return false;
  5931. m_LastShavedSeconds = last_shaved;
  5932. if (version < 122)
  5933. {
  5934. bool bloody_hands_old;
  5935. if (!ctx.Read(bloody_hands_old))
  5936. return false;
  5937. m_HasBloodyHandsVisible = bloody_hands_old;
  5938. }
  5939. else
  5940. {
  5941. int bloody_hands = 0;
  5942. if (!ctx.Read(bloody_hands))
  5943. return false;
  5944. m_HasBloodyHandsVisible = bloody_hands;
  5945. }
  5946. bool blood_visible = false;
  5947. if (!ctx.Read(blood_visible))
  5948. return false;
  5949. m_HasBloodTypeVisible = blood_visible;
  5950. int blood_type = 0;
  5951. if (!ctx.Read(blood_type))
  5952. return false;
  5953. m_BloodType = blood_type;
  5954. return true;
  5955. }
  5956. vector m_PlayerOldPos;
  5957. void UpdatePlayerMeasures()
  5958. {
  5959. int hour, minute, second;
  5960. GetHourMinuteSecond(hour, minute, second);
  5961. float distance;
  5962. distance = StatGet(AnalyticsManagerServer.STAT_DISTANCE);
  5963. if (m_AnalyticsTimer)
  5964. {
  5965. StatsEventMeasuresData data = new StatsEventMeasuresData();
  5966. data.m_CharacterId = g_Game.GetDatabaseID();
  5967. data.m_TimeInterval = m_AnalyticsTimer.GetRemaining();
  5968. data.m_DaytimeHour = hour;
  5969. data.m_PositionStart = m_PlayerOldPos;
  5970. data.m_PositionEnd = GetPosition();
  5971. data.m_DistanceOnFoot = distance;
  5972. Analytics.PlayerMeasures(data);
  5973. }
  5974. m_PlayerOldPos = GetPosition();
  5975. }
  5976. void OnConnect()
  5977. {
  5978. Debug.Log("Player connected:"+this.ToString(),"Connect");
  5979. // analytics
  5980. GetGame().GetAnalyticsServer().OnPlayerConnect(this);
  5981. m_PlayerOldPos = GetPosition();
  5982. if (m_AnalyticsTimer)
  5983. m_AnalyticsTimer.Run(60, this, "UpdatePlayerMeasures", null, true);
  5984. //construction action data
  5985. ResetConstructionActionData();
  5986. }
  5987. void OnReconnect()
  5988. {
  5989. Debug.Log("Player reconnected:"+this.ToString(),"Reconnect");
  5990. //construction action data
  5991. ResetConstructionActionData();
  5992. }
  5993. void OnDisconnect()
  5994. {
  5995. Debug.Log("Player disconnected:"+this.ToString(),"Connect");
  5996. // analytics
  5997. // force update of the stats
  5998. // if player disconnect too soon, UpdatePlayersStats() is not called
  5999. GetGame().GetAnalyticsServer().OnPlayerDisconnect(this);
  6000. StatsEventDisconnectedData data = new StatsEventDisconnectedData();
  6001. data.m_CharacterId = g_Game.GetDatabaseID();
  6002. data.m_Reason = "Disconnected";
  6003. Analytics.PlayerDisconnected(data);
  6004. if (m_AnalyticsTimer)
  6005. m_AnalyticsTimer.Stop();
  6006. UpdatePlayerMeasures();
  6007. SetPlayerDisconnected(true);
  6008. }
  6009. void SetModifiers(bool enable)
  6010. {
  6011. GetModifiersManager().SetModifiers(enable);
  6012. }
  6013. bool Consume(PlayerConsumeData data)
  6014. {
  6015. PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
  6016. int pollution = GetGame().GetMission().GetWorldData().GetPollution();
  6017. float temperature = 0;
  6018. if (data.m_Type == EConsumeType.ENVIRO_POND || data.m_Type == EConsumeType.ENVIRO_WELL || data.m_Type == EConsumeType.ENVIRO_SNOW)
  6019. {
  6020. if (data.m_Type != EConsumeType.ENVIRO_WELL)
  6021. {
  6022. if (pollution & EPollution.HEAVYMETAL)
  6023. data.m_Agents = data.m_Agents | eAgents.HEAVYMETAL;
  6024. if (data.m_Type == EConsumeType.ENVIRO_POND)
  6025. data.m_Agents = data.m_Agents | eAgents.CHOLERA;
  6026. }
  6027. temperature = GetGame().GetMission().GetWorldData().GetLiquidTypeEnviroTemperature(data.m_LiquidType);
  6028. m_PlayerStomach.AddToStomach(Liquid.GetLiquidClassname(LIQUID_WATER), data.m_Amount, 0 , data.m_Agents, temperature);
  6029. return true;
  6030. }
  6031. Edible_Base edibleItem = Edible_Base.Cast(data.m_Source);
  6032. if (!edibleItem || !edibleItem.CanBeConsumed())
  6033. return false;
  6034. if (data.m_Type == EConsumeType.ITEM_SINGLE_TIME || data.m_Type == EConsumeType.ITEM_CONTINUOUS)
  6035. {
  6036. data.m_Agents = edibleItem.FilterAgents(data.m_Agents | edibleItem.GetAgents());
  6037. temperature = edibleItem.GetTemperature();
  6038. if (data.m_Type == EConsumeType.ITEM_SINGLE_TIME)
  6039. plugin.TransmitAgents(edibleItem, this, AGT_UACTION_CONSUME, data.m_Amount);
  6040. if (edibleItem.IsLiquidContainer())
  6041. {
  6042. int liquidType = edibleItem.GetLiquidType();
  6043. string liquidClassName = Liquid.GetLiquidClassname(liquidType);
  6044. if (liquidClassName.Length() == 0)
  6045. Error("Error! Trying to add unknown liquid to stomach with item=" + Object.GetDebugName(edibleItem) + " data.m_Type=" + data.m_Type + " liquid_type=" + liquidType);
  6046. m_PlayerStomach.AddToStomach(liquidClassName, data.m_Amount, 0, data.m_Agents, temperature);
  6047. }
  6048. else
  6049. {
  6050. int foodStageType;
  6051. if (edibleItem.GetFoodStage())
  6052. foodStageType = edibleItem.GetFoodStage().GetFoodStageType();
  6053. m_PlayerStomach.AddToStomach(data.m_Source.GetType(), data.m_Amount, foodStageType, data.m_Agents, temperature);
  6054. }
  6055. edibleItem.Consume(data.m_Amount, this);
  6056. return true;
  6057. }
  6058. return false;
  6059. }
  6060. void ShowUnconsciousScreen(bool show)
  6061. {
  6062. #ifndef NO_GUI
  6063. if (show)
  6064. {
  6065. GetGame().GetUIManager().ScreenFadeIn(0, "You are Unconscious", FadeColors.BLACK, FadeColors.WHITE);
  6066. PrintString("Fade in");
  6067. }
  6068. else
  6069. {
  6070. GetGame().GetUIManager().ScreenFadeOut(0);
  6071. PrintString("Fade out");
  6072. }
  6073. #endif
  6074. }
  6075. override void RequestSoundEventEx(EPlayerSoundEventID id, bool from_server_and_client = false, int param = 0)
  6076. {
  6077. if (from_server_and_client && GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  6078. {
  6079. PlaySoundEventEx(id, false, false, param);
  6080. return;
  6081. }
  6082. SendSoundEventEx(id, param);
  6083. }
  6084. override void RequestSoundEvent(EPlayerSoundEventID id, bool from_server_and_client = false)
  6085. {
  6086. RequestSoundEventEx(id, from_server_and_client);
  6087. }
  6088. override protected void SendSoundEvent(EPlayerSoundEventID id)
  6089. {
  6090. SendSoundEventEx(id);
  6091. }
  6092. override protected void SendSoundEventEx(EPlayerSoundEventID id, int param = 0)
  6093. {
  6094. if (!GetGame().IsServer())
  6095. {
  6096. return;
  6097. }
  6098. m_SoundEvent = id;
  6099. m_SoundEventParam = param;
  6100. SetSynchDirty();
  6101. if (!GetGame().IsMultiplayer())
  6102. {
  6103. CheckSoundEvent();
  6104. }
  6105. //PrintString(GetGame().GetTime().ToString() + " Set SoundEvent, id:" + id.ToString());
  6106. }
  6107. void CheckZeroSoundEvent()
  6108. {
  6109. if (m_SoundEvent != 0 && m_SoundEventSent)
  6110. {
  6111. m_SoundEvent = 0;
  6112. m_SoundEventParam = 0;
  6113. m_SoundEventSent = false;
  6114. SetSynchDirty();
  6115. }
  6116. }
  6117. void CheckSendSoundEvent()
  6118. {
  6119. if (m_SoundEvent!= 0 && !m_SoundEventSent)
  6120. {
  6121. m_SoundEventSent = true;
  6122. }
  6123. }
  6124. override bool PlaySoundEventType(ESoundEventType soundType, int soundEventID, int param = 0)
  6125. {
  6126. if (m_ReplaceSoundEventHandler)
  6127. return m_ReplaceSoundEventHandler.PlayReplaceSound(soundEventID, soundType, param);
  6128. return false;
  6129. }
  6130. override bool PlaySoundEvent(EPlayerSoundEventID id, bool from_anim_system = false, bool is_from_server = false)
  6131. {
  6132. return PlaySoundEventEx(id, from_anim_system, is_from_server);
  6133. }
  6134. override bool PlaySoundEventEx(EPlayerSoundEventID id, bool from_anim_system = false, bool is_from_server = false, int param = 0)
  6135. {
  6136. if (!m_PlayerSoundEventHandler)
  6137. return false;
  6138. return m_PlayerSoundEventHandler.PlayRequestEx(id, is_from_server, param);
  6139. }
  6140. PlayerSoundEventHandler GetPlayerSoundEventHandler()
  6141. {
  6142. return m_PlayerSoundEventHandler;
  6143. }
  6144. void OnBleedingBegin();
  6145. void OnBleedingEnd();
  6146. void OnBleedingSourceAdded()
  6147. {
  6148. m_BleedingSourceCount++;
  6149. if (IsControlledPlayer())
  6150. {
  6151. if (!GetGame().IsDedicatedServer())
  6152. {
  6153. DisplayElementBadge dis_elm = DisplayElementBadge.Cast(GetVirtualHud().GetElement(eDisplayElements.DELM_BADGE_BLEEDING));
  6154. if (dis_elm)
  6155. {
  6156. dis_elm.SetValue(GetBleedingSourceCount());
  6157. }
  6158. //Print("----------bleeding_SoundSet----------");
  6159. SEffectManager.PlaySoundOnObject("bleeding_SoundSet", this);
  6160. }
  6161. }
  6162. }
  6163. void OnBleedingSourceRemoved()
  6164. {
  6165. m_BleedingSourceCount--;
  6166. if (GetGame().IsServer())
  6167. {
  6168. ArrowManagerBase arrowManager = GetArrowManager();
  6169. if (GetBleedingSourceCount() > 0)
  6170. {
  6171. arrowManager.DropFirstArrow();
  6172. }
  6173. else
  6174. {
  6175. arrowManager.DropAllArrows();
  6176. }
  6177. }
  6178. if (IsControlledPlayer())
  6179. {
  6180. if (!GetGame().IsDedicatedServer())
  6181. {
  6182. //Print("GetBleedingSourceCount() "+GetBleedingSourceCount());
  6183. DisplayElementBadge dis_elm = DisplayElementBadge.Cast(GetVirtualHud().GetElement(eDisplayElements.DELM_BADGE_BLEEDING));
  6184. if (dis_elm)
  6185. {
  6186. dis_elm.SetValue(GetBleedingSourceCount());
  6187. }
  6188. }
  6189. }
  6190. }
  6191. void OnBleedingSourceRemovedEx(ItemBase item)
  6192. {
  6193. OnBleedingSourceRemoved();
  6194. }
  6195. int GetBleedingSourceCount()
  6196. {
  6197. return m_BleedingSourceCount;
  6198. }
  6199. // for debug purposes, should reset some systems like Modifiers, Stats, Damage etc.....
  6200. void ResetPlayer(bool set_max)
  6201. {
  6202. #ifdef DIAG_DEVELOPER
  6203. if (GetGame().IsServer() || !GetGame().IsMultiplayer())
  6204. {
  6205. GetStomach().ClearContents();
  6206. DamageSystem.ResetAllZones(this);
  6207. GetModifiersManager().ResetAll();
  6208. // bleeding sources
  6209. if (m_BleedingManagerServer)
  6210. m_BleedingManagerServer.RemoveAllSources();
  6211. // Stats
  6212. if (GetPlayerStats())
  6213. {
  6214. int bloodType = GetStatBloodType().Get();
  6215. GetPlayerStats().ResetAllStats();
  6216. GetStatBloodType().Set(bloodType);
  6217. }
  6218. // Agents
  6219. if (m_AgentPool)
  6220. m_AgentPool.RemoveAllAgents();
  6221. if (m_StaminaHandler)
  6222. m_StaminaHandler.SetStamina(GameConstants.STAMINA_MAX);
  6223. // uncon
  6224. if (IsUnconscious())
  6225. DayZPlayerSyncJunctures.SendPlayerUnconsciousness(this, false);
  6226. // set max
  6227. if (set_max)
  6228. {
  6229. GetStatWater().Set(GetStatWater().GetMax());
  6230. GetStatEnergy().Set(GetStatEnergy().GetMax());
  6231. }
  6232. // fix up inventory
  6233. FixAllInventoryItems();
  6234. //remove bloody hands
  6235. PluginLifespan moduleLifespan = PluginLifespan.Cast(GetPlugin(PluginLifespan));
  6236. moduleLifespan.UpdateBloodyHandsVisibilityEx(this, eBloodyHandsTypes.CLEAN);
  6237. ClearBloodyHandsPenaltyChancePerAgent(eAgents.SALMONELLA);
  6238. if (GetArrowManager())
  6239. GetArrowManager().ClearArrows();
  6240. }
  6241. // client + single + server
  6242. HumanCommandVehicle vehCmd = GetCommand_Vehicle();
  6243. if (vehCmd)
  6244. {
  6245. Transport transport = vehCmd.GetTransport();
  6246. if (transport)
  6247. transport.FixEntity();
  6248. }
  6249. #endif
  6250. }
  6251. void CheckSoundEvent()
  6252. {
  6253. if (m_SoundEvent != 0)
  6254. {
  6255. PlaySoundEventEx(m_SoundEvent, false, true,m_SoundEventParam);
  6256. m_SoundEvent = 0;
  6257. m_SoundEventParam = 0;
  6258. }
  6259. // cancelling marked interrupted sounds
  6260. if (m_PerformedAnimActionID == -1)
  6261. {
  6262. if (m_PerformedActionSounds.Count() == 0)
  6263. return;
  6264. foreach (AbstractWave sound : m_PerformedActionSounds)
  6265. {
  6266. if (sound)
  6267. sound.Stop();
  6268. }
  6269. m_PerformedActionSounds.Clear();
  6270. }
  6271. }
  6272. void TestSend()
  6273. {
  6274. if (GetGame().IsClient()) return;
  6275. RequestSoundEvent(1234);
  6276. //Math.RandomInt(1,4096)
  6277. }
  6278. void SetStaminaState(eStaminaState state)
  6279. {
  6280. if (state != m_StaminaState)
  6281. {
  6282. m_StaminaState = state;
  6283. //PrintString("m_StaminaState:"+m_StaminaState.ToString());
  6284. SetSynchDirty();
  6285. }
  6286. }
  6287. int GetStaminaState()
  6288. {
  6289. return m_StaminaState;
  6290. }
  6291. void UpdateQuickBarExtraSlots()
  6292. {
  6293. m_QuickBarBase.updateSlotsCount();
  6294. }
  6295. bool Save()
  6296. {
  6297. // saved player must be alive and not captive
  6298. if (GetPlayerState() == EPlayerStates.ALIVE && !IsRestrained())
  6299. {
  6300. GetHive().CharacterSave(this);
  6301. Debug.Log("Player "+this.ToString()+ " saved as alive");
  6302. return true;
  6303. }
  6304. return false;
  6305. }
  6306. // agent transfer
  6307. //! chance between [0..1] , distance in meters
  6308. void SpreadAgentsEx(float distance = 3,float chance = 0.25)
  6309. {
  6310. if (Math.RandomFloat01() > chance)
  6311. return;
  6312. GetGame().GetPlayers(m_ServerPlayers);
  6313. float dist_check = distance * distance;//make it sq
  6314. PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
  6315. foreach (Man target: m_ServerPlayers)
  6316. {
  6317. if (vector.DistanceSq(GetWorldPosition(), target.GetWorldPosition()) < dist_check && target != this)
  6318. {
  6319. plugin.TransmitAgents(this, target, AGT_AIRBOURNE_BIOLOGICAL, 1);
  6320. }
  6321. }
  6322. }
  6323. void SpreadAgents()//legacy method
  6324. {
  6325. SpreadAgentsEx(3,1);
  6326. }
  6327. //--------------------------------------------------------------------------------------------
  6328. override int GetAgents()
  6329. {
  6330. return m_AgentPool.GetAgents();
  6331. }
  6332. //--------------------------------------------------------------------------------------------
  6333. override void RemoveAgent(int agent_id) //removes a single agent type from the player agent pool
  6334. {
  6335. m_AgentPool.RemoveAgent(agent_id);
  6336. }
  6337. //--------------------------------------------------------------------------------------------
  6338. override void RemoveAllAgents()
  6339. {
  6340. m_AgentPool.RemoveAllAgents();
  6341. }
  6342. //--------------------------------------------------------------------------------------------
  6343. override void InsertAgent(int agent, float count = 1) //adds a single agent type to the player agent pool
  6344. {
  6345. m_AgentPool.AddAgent(agent,count);
  6346. }
  6347. //--------------------------------------------------------------------------------------------
  6348. int GetSingleAgentCount(int agent_id)
  6349. {
  6350. return m_AgentPool.GetSingleAgentCount(agent_id);
  6351. }
  6352. //--------------------------------------------------------------------------------------------
  6353. float GetSingleAgentCountNormalized(int agent_id)
  6354. {
  6355. int max_count = PluginTransmissionAgents.GetAgentMaxCount(agent_id);
  6356. return m_AgentPool.GetSingleAgentCount(agent_id) / max_count;
  6357. }
  6358. float GetTotalAgentCount()
  6359. {
  6360. return m_AgentPool.GetTotalAgentCount();
  6361. }
  6362. void PrintAgents()
  6363. {
  6364. m_AgentPool.PrintAgents();
  6365. }
  6366. void ImmuneSystemTick(float value, float deltaT)
  6367. {
  6368. m_AgentPool.ImmuneSystemTick(value, deltaT);
  6369. }
  6370. void AntibioticsAttack(float value)
  6371. {
  6372. m_AgentPool.DrugsAttack(EMedicalDrugsType.ANTIBIOTICS, value);
  6373. }
  6374. void SetTemporaryResistanceToAgent(int agent, float time)
  6375. {
  6376. m_AgentPool.SetTemporaryResistance(agent, time);
  6377. }
  6378. float GetTemporaryResistanceToAgent(int agent)
  6379. {
  6380. return m_AgentPool.GetTemporaryResistance(agent);
  6381. }
  6382. //Get aim (player crosshair) position
  6383. vector GetAimPosition()
  6384. {
  6385. float min_distance = 0.5; //min distance, default = 5m
  6386. vector from = GetGame().GetCurrentCameraPosition();
  6387. vector to = from + (GetGame().GetCurrentCameraDirection() * min_distance);
  6388. vector contactPos;
  6389. vector contactDir;
  6390. int contactComponent;
  6391. DayZPhysics.RaycastRV(from, to, contactPos, contactDir, contactComponent, NULL, NULL, NULL, false, true);
  6392. return contactPos;
  6393. }
  6394. bool CanEatAndDrink()
  6395. {
  6396. ItemBase mask = ItemBase.Cast(GetInventory().FindAttachment(InventorySlots.MASK));
  6397. return (!mask || (mask && mask.AllowFoodConsumption()));
  6398. }
  6399. bool CanConsumeFood(ConsumeConditionData data = null)
  6400. {
  6401. return true;
  6402. }
  6403. //get modifier manager
  6404. ModifiersManager GetModifiersManager()
  6405. {
  6406. return m_ModifiersManager;
  6407. }
  6408. PlayerStat<float> GetStatWater()
  6409. {
  6410. if (!m_StatWater && GetPlayerStats())
  6411. {
  6412. m_StatWater = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.WATER));
  6413. }
  6414. return m_StatWater;
  6415. }
  6416. PlayerStat<float> GetStatToxicity()
  6417. {
  6418. if (!m_StatToxicity && GetPlayerStats())
  6419. {
  6420. m_StatToxicity = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.TOXICITY));
  6421. }
  6422. return m_StatToxicity;
  6423. }
  6424. PlayerStat<float> GetStatEnergy()
  6425. {
  6426. if (!m_StatEnergy && GetPlayerStats())
  6427. {
  6428. m_StatEnergy = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.ENERGY));
  6429. }
  6430. return m_StatEnergy;
  6431. }
  6432. PlayerStat<float> GetStatHeatComfort()
  6433. {
  6434. if (!m_StatHeatComfort && GetPlayerStats())
  6435. {
  6436. m_StatHeatComfort = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.HEATCOMFORT));
  6437. }
  6438. return m_StatHeatComfort;
  6439. }
  6440. PlayerStat<float> GetStatTremor()
  6441. {
  6442. if (!m_StatTremor && GetPlayerStats())
  6443. {
  6444. m_StatTremor = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.TREMOR));
  6445. }
  6446. return m_StatTremor;
  6447. }
  6448. PlayerStat<int> GetStatWet()
  6449. {
  6450. if (!m_StatWet && GetPlayerStats())
  6451. {
  6452. m_StatWet = PlayerStat<int>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.WET));
  6453. }
  6454. return m_StatWet;
  6455. }
  6456. PlayerStat<float> GetStatDiet()
  6457. {
  6458. if (!m_StatDiet && GetPlayerStats())
  6459. {
  6460. m_StatDiet = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.DIET));
  6461. }
  6462. return m_StatDiet;
  6463. }
  6464. PlayerStat<float> GetStatStamina()
  6465. {
  6466. if (!m_StatStamina && GetPlayerStats())
  6467. {
  6468. m_StatStamina = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.STAMINA));
  6469. }
  6470. return m_StatStamina;
  6471. }
  6472. PlayerStat<float> GetStatSpecialty()
  6473. {
  6474. if (!m_StatSpecialty && GetPlayerStats())
  6475. {
  6476. m_StatSpecialty = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.SPECIALTY));
  6477. }
  6478. return m_StatSpecialty;
  6479. }
  6480. PlayerStat<int> GetStatBloodType()
  6481. {
  6482. if (!m_StatBloodType && GetPlayerStats())
  6483. {
  6484. m_StatBloodType = PlayerStat<int>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.BLOODTYPE));
  6485. }
  6486. return m_StatBloodType;
  6487. }
  6488. PlayerStat<float> GetStatHeatBuffer()
  6489. {
  6490. if (!m_StatHeatBuffer && GetPlayerStats())
  6491. {
  6492. m_StatHeatBuffer = PlayerStat<float>.Cast(GetPlayerStats().GetStatObject(EPlayerStats_current.HEATBUFFER));
  6493. }
  6494. return m_StatHeatBuffer;
  6495. }
  6496. void SetHeatBufferDynamicMax(float value)
  6497. {
  6498. m_HeatBufferDynamicMax = value;
  6499. SetSynchDirty();
  6500. }
  6501. float GetHeatBufferDynamicMax()
  6502. {
  6503. return m_HeatBufferDynamicMax;
  6504. }
  6505. void ToggleHeatBufferVisibility(bool show)
  6506. {
  6507. m_HasHeatBuffer = show;
  6508. SetSynchDirty();
  6509. }
  6510. void ToggleHeatBufferVisibility(int heatbufferStage)
  6511. {
  6512. m_HeatBufferStage = heatbufferStage;
  6513. SetSynchDirty();
  6514. }
  6515. //! UA Last Message
  6516. string GetLastUAMessage()
  6517. {
  6518. return m_UALastMessage;
  6519. }
  6520. void SetLastUAMessage(string pMsg)
  6521. {
  6522. m_UALastMessage = pMsg;
  6523. if (m_UALastMessageTimer.IsRunning())
  6524. {
  6525. m_UALastMessageTimer.Stop();
  6526. }
  6527. m_UALastMessageTimer.Run(PlayerConstants.LAST_UA_MSG_LIFETIME, this, "ClearLastUAMessage", null);
  6528. }
  6529. protected void ClearLastUAMessage()
  6530. {
  6531. if (m_UALastMessageTimer.IsRunning())
  6532. {
  6533. m_UALastMessageTimer.Stop();
  6534. }
  6535. m_UALastMessage = "";
  6536. }
  6537. //! -------------------------------------------------------------------------
  6538. //! Injured stat
  6539. //! update injured state immediately
  6540. void ForceUpdateInjuredState()
  6541. {
  6542. m_InjuryHandler.CheckValue(true);
  6543. }
  6544. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  6545. {
  6546. #ifdef DIAG_DEVELOPER
  6547. if (m_Bot && action_id > EActions.PLAYER_BOT_INTERNAL_START && action_id < EActions.PLAYER_BOT_END)
  6548. {
  6549. m_Bot.StartAction(action_id);
  6550. return true;
  6551. }
  6552. #endif
  6553. if (super.OnAction(action_id, player, ctx))
  6554. return true;
  6555. if (GetGame().IsClient() || !GetGame().IsMultiplayer())
  6556. {
  6557. switch (action_id)
  6558. {
  6559. case EActions.GIZMO_OBJECT:
  6560. GetGame().GizmoSelectObject(this);
  6561. return true;
  6562. case EActions.GIZMO_PHYSICS:
  6563. GetGame().GizmoSelectPhysics(GetPhysics());
  6564. return true;
  6565. }
  6566. }
  6567. if (GetGame().IsServer())
  6568. {
  6569. switch (action_id)
  6570. {
  6571. case EActions.DELETE:
  6572. Delete();
  6573. return true;
  6574. }
  6575. }
  6576. return false;
  6577. }
  6578. // -------------------------------------------------------------------------
  6579. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  6580. {
  6581. int i;
  6582. PluginTransmissionAgents pluginTransmissionAgents = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
  6583. #ifdef DIAG_DEVELOPER
  6584. if (pluginTransmissionAgents && !(m_Bot || GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE))
  6585. #else
  6586. if (pluginTransmissionAgents && !(GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE))
  6587. #endif
  6588. {
  6589. map<int, string> agentList = pluginTransmissionAgents.GetSimpleAgentList();
  6590. if (agentList)
  6591. {
  6592. foreach (int tid, string tname : agentList)
  6593. {
  6594. string injectName = "Inject " + tname;
  6595. string removeName = "Remove " + tname;
  6596. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEBUG_AGENTS_RANGE_INJECT_START + tid, injectName, Colors.WHITE));
  6597. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEBUG_AGENTS_RANGE_REMOVE_START + tid, removeName, Colors.WHITE));
  6598. }
  6599. }
  6600. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
  6601. }
  6602. #ifdef DIAG_DEVELOPER
  6603. if (m_Bot || GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE)
  6604. {
  6605. typename e = EActions;
  6606. int cnt = e.GetVariableCount();
  6607. int val;
  6608. for (i = 0; i < cnt; i++)
  6609. {
  6610. if (!e.GetVariableValue(null, i, val))
  6611. continue;
  6612. if (val <= EActions.PLAYER_BOT_INTERNAL_START)
  6613. continue;
  6614. if (val == EActions.PLAYER_BOT_START)
  6615. {
  6616. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
  6617. continue;
  6618. }
  6619. if (val >= EActions.PLAYER_BOT_END)
  6620. break;
  6621. string name = e.GetVariableName(i);
  6622. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, val, name, FadeColors.LIGHT_GREY));
  6623. }
  6624. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
  6625. }
  6626. #endif
  6627. super.GetDebugActions(outputList);
  6628. if (Gizmo_IsSupported())
  6629. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GIZMO_OBJECT, "Gizmo Object", FadeColors.LIGHT_GREY));
  6630. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GIZMO_PHYSICS, "Gizmo Physics (SP Only)", FadeColors.LIGHT_GREY)); // intentionally allowed for testing physics desync
  6631. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SINGLEPLAYER) // Prevent deleting ourselves
  6632. {
  6633. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
  6634. }
  6635. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
  6636. }
  6637. //-------------------------------------------------------------
  6638. //!
  6639. //! SyncJunctures
  6640. //!
  6641. override void OnSyncJuncture(int pJunctureID, ParamsReadContext pCtx)
  6642. {
  6643. super.OnSyncJuncture(pJunctureID, pCtx);
  6644. switch(pJunctureID)
  6645. {
  6646. case DayZPlayerSyncJunctures.SJ_INJURY:
  6647. eInjuryHandlerLevels level;
  6648. bool enable;
  6649. DayZPlayerSyncJunctures.ReadInjuryParams(pCtx, enable, level);
  6650. m_InjuryHandler.SetInjuryCommandParams(enable, level);
  6651. break;
  6652. case DayZPlayerSyncJunctures.SJ_PLAYER_STATES:
  6653. GetSymptomManager().SetAnimation(pCtx);
  6654. break;
  6655. case DayZPlayerSyncJunctures.SJ_QUICKBAR_SET_SHORTCUT:
  6656. OnQuickbarSetEntityRequest(pCtx);
  6657. break;
  6658. case DayZPlayerSyncJunctures.SJ_INVENTORY:
  6659. GetInventory().OnInventoryJunctureFromServer(pCtx);
  6660. break;
  6661. case DayZPlayerSyncJunctures.SJ_INVENTORY_REPAIR:
  6662. GetInventory().OnInventoryJunctureRepairFromServer(pCtx);
  6663. break;
  6664. case DayZPlayerSyncJunctures.SJ_INVENTORY_FAILURE:
  6665. GetInventory().OnInventoryJunctureFailureFromServer(pCtx);
  6666. break;
  6667. case DayZPlayerSyncJunctures.SJ_ACTION_INTERRUPT:
  6668. case DayZPlayerSyncJunctures.SJ_ACTION_ACK_ACCEPT:
  6669. case DayZPlayerSyncJunctures.SJ_ACTION_ACK_REJECT:
  6670. m_ActionManager.OnSyncJuncture(pJunctureID,pCtx);
  6671. break;
  6672. case DayZPlayerSyncJunctures.SJ_WEAPON_ACTION_ACK_ACCEPT:
  6673. case DayZPlayerSyncJunctures.SJ_WEAPON_ACTION_ACK_REJECT:
  6674. case DayZPlayerSyncJunctures.SJ_WEAPON_SET_JAMMING_CHANCE:
  6675. m_WeaponManager.OnSyncJuncture(pJunctureID,pCtx);
  6676. break;
  6677. case DayZPlayerSyncJunctures.SJ_UNCONSCIOUSNESS:
  6678. DayZPlayerSyncJunctures.ReadPlayerUnconsciousnessParams(pCtx, m_ShouldBeUnconscious);
  6679. break;
  6680. case DayZPlayerSyncJunctures.SJ_PLAYER_ADD_MODIFIER:
  6681. GetSymptomManager().SetAnimation(pCtx);
  6682. break;
  6683. case DayZPlayerSyncJunctures.SJ_KURU_REQUEST:
  6684. float amount;
  6685. if (DayZPlayerSyncJunctures.ReadKuruRequest(pCtx, amount))
  6686. {
  6687. if (GetAimingModel() && IsFireWeaponRaised())
  6688. {
  6689. GetAimingModel().RequestKuruShake(amount);
  6690. }
  6691. }
  6692. break;
  6693. case DayZPlayerSyncJunctures.SJ_GESTURE_REQUEST :
  6694. m_EmoteManager.OnSyncJuncture(pJunctureID, pCtx);
  6695. break;
  6696. case DayZPlayerSyncJunctures.SJ_WEAPON_LIFT: // Obsolete
  6697. SetLiftWeapon(pJunctureID, pCtx);
  6698. break;
  6699. case DayZPlayerSyncJunctures.SJ_ADS_RESET:
  6700. m_ResetADS = true;
  6701. break;
  6702. case DayZPlayerSyncJunctures.SJ_DELETE_ITEM:
  6703. SetToDelete(pCtx);
  6704. break;
  6705. case DayZPlayerSyncJunctures.SJ_BROKEN_LEGS:
  6706. m_BrokenLegsJunctureReceived = true;
  6707. DayZPlayerSyncJunctures.ReadBrokenLegsParamsEx(pCtx, m_BrokenLegState);
  6708. break;
  6709. case DayZPlayerSyncJunctures.SJ_SHOCK :
  6710. DayZPlayerSyncJunctures.ReadShockParams(pCtx, m_CurrentShock);
  6711. break;
  6712. case DayZPlayerSyncJunctures.SJ_STAMINA:
  6713. m_StaminaHandler.OnSyncJuncture(pJunctureID, pCtx);
  6714. break;
  6715. case DayZPlayerSyncJunctures.SJ_STAMINA_MISC:
  6716. m_StaminaHandler.OnSyncJuncture(pJunctureID, pCtx);
  6717. break;
  6718. #ifdef DEVELOPER
  6719. case DayZPlayerSyncJunctures.SJ_DEBUG_GET_IN_VEHICLE:
  6720. EntityAI vehicle;
  6721. DayZPlayerSyncJunctures.ReadGetInVehicleParams(pCtx, vehicle);
  6722. SetGetInVehicleDebug(vehicle);
  6723. break;
  6724. #endif
  6725. }
  6726. }
  6727. bool IsItemsToDelete()
  6728. {
  6729. return m_ItemsToDelete.Count() > 0;
  6730. }
  6731. void SetToDelete(ParamsReadContext pCtx)
  6732. {
  6733. EntityAI item;
  6734. pCtx.Read(item);
  6735. AddItemToDelete(item);
  6736. }
  6737. override void AddItemToDelete(EntityAI item)
  6738. {
  6739. if (item)
  6740. {
  6741. item.SetPrepareToDelete();
  6742. m_ItemsToDelete.Insert(item);
  6743. }
  6744. }
  6745. bool CanDeleteItems()
  6746. {
  6747. return !(GetThrowing().IsThrowingAnimationPlaying() || GetDayZPlayerInventory().IsProcessing() || (GetActionManager() && GetActionManager().GetRunningAction()));
  6748. }
  6749. override void JunctureDeleteItem(EntityAI item)
  6750. {
  6751. DayZPlayerSyncJunctures.SendDeleteItem(this, item);
  6752. }
  6753. void UpdateDelete()
  6754. {
  6755. int count = m_ItemsToDelete.Count();
  6756. if (count > 0)
  6757. {
  6758. if (CanDeleteItems())
  6759. {
  6760. EntityAI itemToDelete;
  6761. if (GetGame().IsClient() && GetGame().IsMultiplayer())
  6762. {
  6763. InventoryLocation il = new InventoryLocation();
  6764. for (int i = count - 1; i >= 0 ; i--)
  6765. {
  6766. itemToDelete = m_ItemsToDelete.Get(i);
  6767. if (itemToDelete != null)
  6768. {
  6769. itemToDelete.GetInventory().GetCurrentInventoryLocation(il);
  6770. }
  6771. if (itemToDelete == null || (GetItemInHands() == null && il.GetType() == InventoryLocationType.UNKNOWN))
  6772. {
  6773. m_ItemsToDelete.Remove(i);
  6774. }
  6775. }
  6776. }
  6777. else
  6778. {
  6779. for (int j = count - 1; j >= 0 ; j--)
  6780. {
  6781. itemToDelete = m_ItemsToDelete.Get(j);
  6782. if (itemToDelete == null)
  6783. {
  6784. m_ItemsToDelete.Remove(j);
  6785. }
  6786. else
  6787. {
  6788. itemToDelete.Delete();
  6789. m_ItemsToDelete.Remove(j);
  6790. }
  6791. }
  6792. }
  6793. }
  6794. }
  6795. }
  6796. override bool HeadingModel(float pDt, SDayZPlayerHeadingModel pModel)
  6797. {
  6798. if (GetActionManager()) // disable character turning while performing actions
  6799. {
  6800. ActionContinuousBase action = ActionContinuousBase.Cast(GetActionManager().GetRunningAction());
  6801. if (action && action.IsFullBody(this) && action.IsCameraLockOnPerform())
  6802. {
  6803. if (!m_IsHeadingRestricted)
  6804. {
  6805. m_IsHeadingRestricted = true;
  6806. m_HeadingRestrictData.InitData(pModel.m_fHeadingAngle, action.GetCameraLRAngle());
  6807. }
  6808. return DayZPlayerImplementHeading.RestrictHeading(pDt, pModel, m_fLastHeadingDiff, m_HeadingRestrictData);
  6809. }
  6810. else
  6811. m_IsHeadingRestricted = false;
  6812. }
  6813. //! during fullbody gestures - disables character turning
  6814. if (GetEmoteManager().IsControllsLocked())
  6815. {
  6816. HumanItemAccessor hia = GetItemAccessor();
  6817. HumanItemBehaviorCfg hibcfg = hia.GetItemInHandsBehaviourCfg();
  6818. if (hibcfg && hibcfg.m_StanceRotation[m_MovementState.m_iStanceIdx] == DayZPlayerConstants.ROTATION_DISABLE)
  6819. {
  6820. return DayZPlayerImplementHeading.NoHeading(pDt, pModel, m_fLastHeadingDiff);
  6821. }
  6822. else
  6823. {
  6824. m_fLastHeadingDiff = 0;
  6825. return DayZPlayerImplementHeading.ClampHeading(pDt, pModel, m_fLastHeadingDiff);
  6826. }
  6827. }
  6828. return super.HeadingModel(pDt, pModel);
  6829. }
  6830. override bool IsInventorySoftLocked()
  6831. {
  6832. return m_InventorySoftLockCount > 0;
  6833. }
  6834. //! 'soft lock' meaning inventory screen cannot be displayed, but mechanically, inventory operations are still possible
  6835. override void SetInventorySoftLock(bool status)
  6836. {
  6837. if (status)
  6838. m_InventorySoftLockCount++;
  6839. else
  6840. m_InventorySoftLockCount--;
  6841. if (m_InventorySoftLockCount < 0)
  6842. m_InventorySoftLockCount = 0;
  6843. m_InventorySoftLocked = IsInventorySoftLocked();
  6844. }
  6845. void SetLoadedQuickBarItemBind(EntityAI entity, int index)
  6846. {
  6847. if (m_aQuickBarLoad)
  6848. m_aQuickBarLoad.Insert(new Param2<EntityAI, int>(entity,index));
  6849. }
  6850. override bool IsLiftWeapon()
  6851. {
  6852. return m_LiftWeapon_player;
  6853. }
  6854. override float GetWeaponObstruction()
  6855. {
  6856. return m_ObstructWeapon_player;
  6857. }
  6858. override bool IsWeaponObstructionBlockingADS()
  6859. {
  6860. Weapon_Base weapon = Weapon_Base.Cast(GetItemInHands());
  6861. if (!weapon)
  6862. return false;
  6863. // Recompute the relative obstruction [0 ... 1] value into actual distance ...
  6864. float obstruction = GetWeaponObstruction();
  6865. // ... unless there is no obstruction to begin with at which point the
  6866. // additional checks are rendered competely irrelevant.
  6867. if (obstruction <= 0.0)
  6868. {
  6869. return false;
  6870. }
  6871. float penetration = weapon.GetObstructionPenetrationDistance(obstruction);
  6872. bool inSights = m_CameraIronsight || m_CameraOptics;
  6873. // Create a threshold that allows the user to remain in ADS for lesser obstruction
  6874. // values, significantly reducing the continuous state changes near the edge.
  6875. if (inSights)
  6876. {
  6877. return penetration > 0.040; // 4.0 cm
  6878. }
  6879. // Prevent the user from entering ADS if there is even a tiny fraction of obstruction,
  6880. // further reinforcing the statement above.
  6881. else
  6882. {
  6883. return penetration > 0.005; // 0.5 cm
  6884. }
  6885. }
  6886. //Server
  6887. bool ReadLiftWeaponRequest(int userDataType, ParamsReadContext ctx)
  6888. {
  6889. bool state;
  6890. float obstruct;
  6891. ctx.Read(state);
  6892. ctx.Read(obstruct);
  6893. SetLiftWeapon(state, obstruct);
  6894. return true;
  6895. }
  6896. void SetLiftWeapon(int pJunctureID, ParamsReadContext ctx) // Obsolete
  6897. {
  6898. bool state;
  6899. float obstruct;
  6900. ctx.Read(state);
  6901. ctx.Read(obstruct);
  6902. SetLiftWeapon(state, obstruct);
  6903. //Print("SetLiftWeapon | STS: " + GetSimulationTimeStamp());
  6904. }
  6905. void SetLiftWeapon(bool state, float obstruct = 0)
  6906. {
  6907. m_ProcessLiftWeaponState = state;
  6908. m_ProcessLiftWeapon = true;
  6909. m_ProcessObstructWeapon = obstruct;
  6910. }
  6911. //! Client-side only
  6912. void SendLiftWeaponSync(bool state, float obstruct = 0)
  6913. {
  6914. HumanCommandWeapons hcw;
  6915. bool liftChange = m_LiftWeapon_player != state;
  6916. bool obstructChange = Math.AbsFloat(m_ObstructWeapon_player-obstruct) > 0.03;
  6917. // Apply state immediately
  6918. m_LiftWeapon_player = state;
  6919. m_ObstructWeapon_player = obstruct;
  6920. if (liftChange)
  6921. {
  6922. GetWeaponManager().OnLiftWeapon();
  6923. }
  6924. if (!liftChange && !obstructChange)
  6925. {
  6926. // insignificant difference
  6927. return;
  6928. }
  6929. // Notify server to apply same state
  6930. if (GetGame().IsMultiplayer() && GetGame().IsClient())
  6931. {
  6932. ScriptInputUserData ctx = new ScriptInputUserData;
  6933. if (!ctx.CanStoreInputUserData())
  6934. {
  6935. // ctx not available??
  6936. return;
  6937. }
  6938. ctx.Write(INPUT_UDT_WEAPON_LIFT_EVENT);
  6939. ctx.Write(state);
  6940. ctx.Write(obstruct);
  6941. ctx.Send();
  6942. }
  6943. }
  6944. override void CheckLiftWeapon()
  6945. {
  6946. // lift weapon check
  6947. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  6948. {
  6949. Weapon_Base weap;
  6950. if (Weapon_Base.CastTo(weap, GetItemInHands()))
  6951. {
  6952. Object hitObject;
  6953. float obstruct;
  6954. bool limited = weap.LiftWeaponCheckEx(this, obstruct, hitObject);
  6955. if (weap.UseWeaponObstruction(this, obstruct, hitObject))
  6956. {
  6957. limited = false;
  6958. }
  6959. else
  6960. {
  6961. obstruct = 0.0;
  6962. }
  6963. obstruct = Math.Clamp( obstruct, 0, 1 );
  6964. if (m_LiftWeapon_player != limited || m_ObstructWeapon_player != obstruct)
  6965. {
  6966. SendLiftWeaponSync(limited, obstruct);
  6967. }
  6968. }
  6969. else if (m_LiftWeapon_player || m_ObstructWeapon_player > 0)
  6970. {
  6971. SendLiftWeaponSync(false);
  6972. }
  6973. }
  6974. }
  6975. override void ProcessLiftWeapon()
  6976. {
  6977. if (m_ProcessLiftWeapon)
  6978. {
  6979. bool liftChange = m_LiftWeapon_player != m_ProcessLiftWeaponState;
  6980. if (liftChange)
  6981. {
  6982. GetWeaponManager().OnLiftWeapon();
  6983. }
  6984. m_LiftWeapon_player = m_ProcessLiftWeaponState;
  6985. m_ObstructWeapon_player = m_ProcessObstructWeapon;
  6986. m_ProcessLiftWeapon = false;
  6987. //Debug.Log("SimulationStamp_server: " + this.GetSimulationTimeStamp());
  6988. }
  6989. }
  6990. //! state 'true' == hide
  6991. override void HideClothing(ItemOptics optic, bool state)
  6992. {
  6993. super.HideClothing(optic, state);
  6994. array<int> clothingArray = new array<int>;
  6995. Clothing clothes;
  6996. if (state && DayZPlayerCameraOptics.Cast(m_CurrentCamera))
  6997. {
  6998. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  6999. {
  7000. clothingArray.Insert(InventorySlots.BACK);
  7001. clothingArray.Insert(InventorySlots.SHOULDER);
  7002. clothingArray.Insert(InventorySlots.MELEE);
  7003. if (optic && optic.GetCurrentStepFOV() < GameConstants.DZPLAYER_CAMERA_FOV_IRONSIGHTS)
  7004. {
  7005. clothingArray.Insert(InventorySlots.BODY);
  7006. clothingArray.Insert(InventorySlots.VEST);
  7007. }
  7008. SetInvisibleRecursive(true,this,clothingArray);
  7009. }
  7010. }
  7011. //showing should be instant (called directly, not via CallLater)
  7012. else
  7013. {
  7014. if (GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  7015. {
  7016. clothingArray = {InventorySlots.BACK,InventorySlots.BODY,InventorySlots.VEST,InventorySlots.SHOULDER,InventorySlots.MELEE};
  7017. SetInvisibleRecursive(false,this,clothingArray);
  7018. }
  7019. }
  7020. }
  7021. void RequestUnconsciousness(bool enable)
  7022. {
  7023. DayZPlayerSyncJunctures.SendPlayerUnconsciousness(this, enable);
  7024. }
  7025. override void SetDeathDarknessLevel(float duration, float tick_time)
  7026. {
  7027. super.SetDeathDarknessLevel(duration, tick_time);
  7028. if (IsControlledPlayer())
  7029. {
  7030. float actual_tick = tick_time;
  7031. if (GetDamageDealtEffect())
  7032. m_DamageDealtEffect = null;
  7033. if (GetFlashbangEffect())
  7034. m_FlashbangEffect = null;
  7035. float progress;
  7036. if (duration > 0)
  7037. progress = 1 - ((duration - m_DeathDarkeningCurrentTime) / duration);
  7038. m_DeathDarkeningCurrentTime += actual_tick;
  7039. if (!IsAlive() && IsPlayerSelected())
  7040. {
  7041. m_DeathDarkeningParam.param1 = progress;
  7042. PPERequesterBank.GetRequester(PPERequester_DeathDarkening).Start(m_DeathDarkeningParam);
  7043. }
  7044. if (m_DeathDarkeningCurrentTime >= duration)
  7045. {
  7046. StopDeathDarkeningEffect();
  7047. }
  7048. }
  7049. else
  7050. {
  7051. StopDeathDarkeningEffect();
  7052. }
  7053. }
  7054. override bool IsInFBEmoteState()
  7055. {
  7056. if (!IsEmotePlaying())
  7057. return false;
  7058. if ((m_EmoteManager.m_Callback && m_EmoteManager.m_Callback.m_IsFullbody) || m_EmoteManager.m_IsSurrendered)
  7059. {
  7060. return true;
  7061. }
  7062. return false;
  7063. }
  7064. //! ends surrender, originally intended for surrender->restrained transitioning
  7065. void EndSurrenderRequest(SurrenderData data = null)
  7066. {
  7067. if (m_EmoteManager)
  7068. m_EmoteManager.EndSurrenderRequest(data);
  7069. }
  7070. bool IsSurrendered()
  7071. {
  7072. if (m_EmoteManager)
  7073. return m_EmoteManager.m_IsSurrendered;
  7074. return false;
  7075. }
  7076. bool IsPlayerLoaded()
  7077. {
  7078. return m_PlayerLoaded;
  7079. }
  7080. //disconnected, caused problems. Awaiting refactor
  7081. override void CheckAnimationOverrides()
  7082. {
  7083. //FB gesture slideposeangle override
  7084. if (IsInFBEmoteState() && IsControlledPlayer() && IsPlayerSelected())
  7085. {
  7086. OverrideSlidePoseAngle(Math.PI2);
  7087. }
  7088. else if (!IsInFBEmoteState() && IsControlledPlayer() && IsPlayerSelected())
  7089. {
  7090. OverrideSlidePoseAngle(m_OriginalSlidePoseAngle);
  7091. }
  7092. //+add more, if needed
  7093. }
  7094. /*void OnSurrenderEnd()
  7095. {
  7096. }*/
  7097. bool CanRedirectToWeaponManager (notnull EntityAI item, out bool isActionPossible)
  7098. {
  7099. isActionPossible = false;
  7100. Magazine mag = Magazine.Cast(item);
  7101. Weapon_Base wpn = Weapon_Base.Cast(item.GetHierarchyParent());
  7102. if (mag && wpn)
  7103. {
  7104. if (GetWeaponManager().CanDetachMagazine(wpn, mag))
  7105. {
  7106. //Print("[inv] PlayerBase.CanRedirectToWeaponManager OK, can detach mag=" + mag + " from wpn=" + wpn);
  7107. isActionPossible = true;
  7108. }
  7109. else
  7110. {
  7111. //Print("[inv] PlayerBase.CanRedirectToWeaponManager cannot detach mag=" + mag + " from wpn=" + wpn);
  7112. }
  7113. return true;
  7114. }
  7115. return false;
  7116. }
  7117. // Inventory actions with redirection to weapon manager
  7118. override bool PredictiveTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  7119. {
  7120. bool can_detach;
  7121. if (CanRedirectToWeaponManager(item,can_detach))
  7122. {
  7123. InventoryLocation il = new InventoryLocation();
  7124. if (can_detach && target.GetInventory().FindFreeLocationFor(item, flags, il))
  7125. {
  7126. return GetWeaponManager().DetachMagazine(il);
  7127. }
  7128. return false;
  7129. }
  7130. return super.PredictiveTakeEntityToTargetInventory(target, flags, item);
  7131. }
  7132. override bool PredictiveTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  7133. {
  7134. bool can_detach;
  7135. if (CanRedirectToWeaponManager(item,can_detach))
  7136. {
  7137. InventoryLocation il = new InventoryLocation();
  7138. if (can_detach && GetInventory().FindFreeLocationFor(item, flags, il))
  7139. {
  7140. return GetWeaponManager().DetachMagazine(il);
  7141. }
  7142. return false;
  7143. }
  7144. return super.PredictiveTakeEntityToInventory(flags, item);
  7145. }
  7146. override bool PredictiveTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  7147. {
  7148. Weapon_Base parentWpn = Weapon_Base.Cast(target);
  7149. Magazine mag = Magazine.Cast(item);
  7150. if (parentWpn && mag)
  7151. {
  7152. if (GetWeaponManager().CanAttachMagazine(parentWpn, mag))
  7153. return GetWeaponManager().AttachMagazine(mag);
  7154. return false;
  7155. }
  7156. return super.PredictiveTakeEntityToTargetAttachment(target, item);
  7157. }
  7158. override bool PredictiveTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  7159. {
  7160. Weapon_Base parentWpn = Weapon_Base.Cast(target);
  7161. Magazine mag = Magazine.Cast(item);
  7162. if (parentWpn && mag)
  7163. {
  7164. if (target.CanReceiveAttachment(item,slot) && GetWeaponManager().CanAttachMagazine(parentWpn, mag))
  7165. return GetWeaponManager().AttachMagazine(mag);
  7166. return false;
  7167. }
  7168. return super.PredictiveTakeEntityToTargetAttachmentEx(target, item,slot);
  7169. }
  7170. override bool PredictiveTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  7171. {
  7172. bool can_detach;
  7173. if (CanRedirectToWeaponManager(item,can_detach))
  7174. {
  7175. InventoryLocation il = new InventoryLocation();
  7176. if (can_detach && target.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO, il))
  7177. {
  7178. return GetWeaponManager().DetachMagazine(il);
  7179. }
  7180. return false;
  7181. }
  7182. return super.PredictiveTakeEntityToTargetCargo(target,item);
  7183. }
  7184. override bool PredictiveTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  7185. {
  7186. bool can_detach;
  7187. if (CanRedirectToWeaponManager(item, can_detach))
  7188. {
  7189. if (can_detach)
  7190. {
  7191. InventoryLocation dst = new InventoryLocation;
  7192. dst.SetCargoAuto(cargo, item, row, col, item.GetInventory().GetFlipCargo());
  7193. return GetWeaponManager().DetachMagazine(dst);
  7194. }
  7195. return false;
  7196. }
  7197. return super.PredictiveTakeEntityToTargetCargoEx (cargo, item, row, col);
  7198. }
  7199. override bool PredictiveDropEntity (notnull EntityAI item)
  7200. {
  7201. bool can_detach;
  7202. if (CanRedirectToWeaponManager(item,can_detach))
  7203. {
  7204. if (can_detach)
  7205. {
  7206. vector m4[4];
  7207. Math3D.MatrixIdentity4(m4);
  7208. //! We don't care if a valid transform couldn't be found, we just want to preferably use it instead of placing on the player
  7209. GameInventory.PrepareDropEntityPos(this, item, m4, false, GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
  7210. InventoryLocation il = new InventoryLocation;
  7211. il.SetGround(item, m4);
  7212. return GetWeaponManager().DetachMagazine(il);
  7213. }
  7214. return false;
  7215. }
  7216. return super.PredictiveDropEntity(item);
  7217. }
  7218. override bool PredictiveSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  7219. {
  7220. //Print("PlayerBase | PredictiveSwapEntities");
  7221. Magazine swapmag1 = Magazine.Cast(item1);
  7222. Magazine swapmag2 = Magazine.Cast(item2);
  7223. if (swapmag1 && swapmag2)
  7224. {
  7225. Weapon_Base parentWpn;
  7226. if (Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()))
  7227. {
  7228. if (GetWeaponManager().CanSwapMagazine(parentWpn, swapmag2))
  7229. {
  7230. Print("[inv] PlayerBase.PredictiveSwapEntities: swapping mag1=" + swapmag1 + " to parent wpn=" + parentWpn + " of mag1=" + swapmag1);
  7231. return GetWeaponManager().SwapMagazine(swapmag2);
  7232. }
  7233. else
  7234. {
  7235. Print("[inv] PlayerBase.PredictiveSwapEntities: can not swap magazines");
  7236. return false;
  7237. }
  7238. }
  7239. if (Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()))
  7240. {
  7241. if (GetWeaponManager().CanSwapMagazine(parentWpn, swapmag1))
  7242. {
  7243. Print("[inv] PlayerBase.PredictiveSwapEntities: swapping mag1=" + swapmag1 + " to parent wpn=" + parentWpn + " of mag2=" + swapmag2);
  7244. return GetWeaponManager().SwapMagazine(swapmag1);
  7245. }
  7246. else
  7247. {
  7248. Print("[inv] PlayerBase.PredictiveSwapEntities: can not swap magazines");
  7249. return false;
  7250. }
  7251. }
  7252. }
  7253. EntityAI item_hands;
  7254. EntityAI item_ground;
  7255. if (IsSwapBetweenHandsAndGroundLargeItem(item1,item2,item_hands,item_ground) && !m_ActionManager.GetRunningAction())
  7256. {
  7257. ActionManagerClient mngr_client;
  7258. CastTo(mngr_client,m_ActionManager);
  7259. ActionTarget atrg = new ActionTarget(item_ground,null,-1,vector.Zero,-1.0);
  7260. if (mngr_client.GetAction(ActionSwapItemToHands).Can(this,atrg,ItemBase.Cast(item_hands)))
  7261. {
  7262. mngr_client.PerformActionStart(mngr_client.GetAction(ActionSwapItemToHands),atrg,ItemBase.Cast(item_hands));
  7263. return true;
  7264. }
  7265. return super.PredictiveSwapEntities(item1, item2);
  7266. }
  7267. else
  7268. return super.PredictiveSwapEntities(item1, item2);
  7269. }
  7270. override bool PredictiveForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  7271. {
  7272. InventoryLocation il = new InventoryLocation;
  7273. if (item1.IsHeavyBehaviour() && item1.GetInventory().GetCurrentInventoryLocation(il) && il.GetType() == InventoryLocationType.GROUND && !m_ActionManager.GetRunningAction())
  7274. {
  7275. //Print("override bool PredictiveForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)");
  7276. ActionManagerClient mngr_client;
  7277. CastTo(mngr_client,m_ActionManager);
  7278. ActionTarget atrg = new ActionTarget(item1,null,-1,vector.Zero,-1.0);
  7279. if (mngr_client.GetAction(ActionSwapItemToHands).Can(this,atrg,ItemBase.Cast(item2)))
  7280. {
  7281. mngr_client.PerformActionStart(mngr_client.GetAction(ActionSwapItemToHands),atrg,ItemBase.Cast(item2));
  7282. }
  7283. return true;
  7284. }
  7285. else
  7286. return super.PredictiveForceSwapEntities(item1, item2, item2_dst);
  7287. }
  7288. override void PredictiveTakeEntityToHands(EntityAI item)
  7289. {
  7290. if (item.IsHeavyBehaviour() && !m_ActionManager.GetRunningAction() && !item.GetHierarchyParent())
  7291. {
  7292. ActionManagerClient mngr_client;
  7293. if (CastTo(mngr_client,m_ActionManager))
  7294. {
  7295. ActionTarget atrg = new ActionTarget(item,null,-1,vector.Zero,-1.0);
  7296. if (mngr_client.GetAction(ActionTakeItemToHands).Can(this,atrg,null))
  7297. {
  7298. mngr_client.PerformActionStart(mngr_client.GetAction(ActionTakeItemToHands),atrg,null);
  7299. }
  7300. /*).Can(this,
  7301. mngr_client.ActionStart(mngr_client.GetAction(ActionTakeItemToHands),mngr_client.FindActionTarget(),null);
  7302. return;*/
  7303. }
  7304. }
  7305. else
  7306. super.PredictiveTakeEntityToHands(item);
  7307. }
  7308. override bool PredictiveTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  7309. {
  7310. EntityAI item = src.GetItem();
  7311. if (item)
  7312. {
  7313. bool can_detach;
  7314. if (CanRedirectToWeaponManager(item,can_detach))
  7315. {
  7316. if (can_detach)
  7317. {
  7318. return GetWeaponManager().DetachMagazine(dst);
  7319. }
  7320. return false;
  7321. }
  7322. return super.PredictiveTakeToDst(src,dst);
  7323. }
  7324. return false;
  7325. }
  7326. bool IsSwapBetweenHandsAndGroundLargeItem(notnull EntityAI item1, notnull EntityAI item2, out EntityAI item_hands, out EntityAI item_ground)
  7327. {
  7328. InventoryLocation il = new InventoryLocation;
  7329. if (item1.GetInventory().GetCurrentInventoryLocation(il) && il.GetType() == InventoryLocationType.HANDS)
  7330. item_hands = item1;
  7331. if (item2.GetInventory().GetCurrentInventoryLocation(il) && il.GetType() == InventoryLocationType.HANDS)
  7332. item_hands = item2;
  7333. if (item1.GetInventory().GetCurrentInventoryLocation(il) && il.GetType() == InventoryLocationType.GROUND)
  7334. item_ground = item1;
  7335. if (item2.GetInventory().GetCurrentInventoryLocation(il) && il.GetType() == InventoryLocationType.GROUND)
  7336. item_ground = item2;
  7337. return item_hands && item_ground && item_ground.IsHeavyBehaviour();
  7338. }
  7339. //! Dynamic hair hiding
  7340. void SetHairLevelToHide(int level, bool state, bool was_debug = false)
  7341. {
  7342. if (was_debug && GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  7343. return;
  7344. if (!m_CharactersHead)
  7345. {
  7346. ErrorEx("No valid head detected on character!");
  7347. return;
  7348. }
  7349. if (level == -1) //hide/show ALL
  7350. {
  7351. m_HideHairAnimated = !m_HideHairAnimated;
  7352. for (int i = 0; i < m_CharactersHead.m_HeadHairSelectionArray.Count(); ++i)
  7353. {
  7354. //m_CharactersHead.SetSimpleHiddenSelectionState(i,m_HideHairAnimated);
  7355. SelectionTranslation stt = SelectionTranslation.Cast(m_CharactersHead.m_HeadHairHidingStateMap.Get(i));
  7356. stt.SetSelectionState(m_HideHairAnimated);
  7357. m_CharactersHead.m_HeadHairHidingStateMap.Set(i, stt);
  7358. #ifdef DIAG_DEVELOPER
  7359. #ifndef SERVER
  7360. PluginDiagMenuClient diagmenu = PluginDiagMenuClient.Cast(GetPlugin(PluginDiagMenuClient));
  7361. diagmenu.m_HairHidingStateMap.Set(i, m_HideHairAnimated);
  7362. #endif
  7363. #endif
  7364. }
  7365. }
  7366. else //hide/show selected level only
  7367. {
  7368. bool switchState;
  7369. if (was_debug)
  7370. {
  7371. #ifdef DIAG_DEVELOPER
  7372. #ifndef SERVER
  7373. PluginDiagMenuClient diagmenuu = PluginDiagMenuClient.Cast(GetPlugin(PluginDiagMenuClient));
  7374. switchState = !diagmenuu.m_HairHidingStateMap.Get(level);
  7375. diagmenuu.m_HairHidingStateMap.Set(level, switchState);
  7376. #endif
  7377. #endif
  7378. }
  7379. else
  7380. {
  7381. switchState = !state;
  7382. }
  7383. //m_CharactersHead.SetSimpleHiddenSelectionState(level,switchState);
  7384. stt = SelectionTranslation.Cast(m_CharactersHead.m_HeadHairHidingStateMap.Get(level));
  7385. stt.SetSelectionState(switchState);
  7386. m_CharactersHead.m_HeadHairHidingStateMap.Set(level, stt); //nescessary?
  7387. }
  7388. }
  7389. void HideHairSelections(ItemBase item, bool state)
  7390. {
  7391. if (!item || !item.GetHeadHidingSelection() || !m_CharactersHead)
  7392. return;
  7393. int slot_id; //item currently attached (or detaching from) here
  7394. string slot_name; //item currently attached (or detaching from) here
  7395. string str
  7396. int idx = 0;
  7397. int i;
  7398. int count;
  7399. item.GetInventory().GetCurrentAttachmentSlotInfo(slot_id,slot_name);
  7400. if (item.HidesSelectionBySlot())
  7401. {
  7402. count = item.GetInventory().GetSlotIdCount();
  7403. for (i = 0; i < count; i++)
  7404. {
  7405. if (item.GetInventory().GetSlotId(i) == slot_id)
  7406. {
  7407. str = item.GetHeadHidingSelection().Get(i);
  7408. idx = m_CharactersHead.m_HeadHairSelectionArray.Find(str);
  7409. if (idx != -1)
  7410. SetHairLevelToHide(idx,state);
  7411. #ifdef DEVELOPER
  7412. else
  7413. Debug.Log("No valid selection '" + str + "' found on head of " + GetType() + ". Verify the p3d, model config, and the 'HAIR_HIDING_SELECTIONS' macro in basicDefines.");
  7414. #endif
  7415. }
  7416. }
  7417. }
  7418. else
  7419. {
  7420. count = item.GetHeadHidingSelection().Count();
  7421. for (i = 0; i < count; i++)
  7422. {
  7423. str = item.GetHeadHidingSelection().Get(i);
  7424. idx = m_CharactersHead.m_HeadHairSelectionArray.Find(str);
  7425. if (idx != -1)
  7426. SetHairLevelToHide(idx,state);
  7427. #ifdef DEVELOPER
  7428. else
  7429. Debug.Log("No valid selection '" + str + "' found on head of " + GetType() + ". Verify the p3d, model config, and the 'HAIR_HIDING_SELECTIONS' macro in basicDefines.");
  7430. #endif
  7431. }
  7432. }
  7433. UpdateHairSelectionVisibility();
  7434. }
  7435. void UpdateHairSelectionVisibility(bool was_debug = false)
  7436. {
  7437. if (!m_CharactersHead)
  7438. return;
  7439. bool shown;
  7440. bool exception_hidden = false;
  7441. int i;
  7442. int count = m_CharactersHead.m_HeadHairHidingStateMap.Count();
  7443. SelectionTranslation stt;
  7444. //hide/show beard
  7445. if (IsMale() && m_CharactersHead.GetBeardIndex() > -1 && !was_debug)
  7446. {
  7447. SetHairLevelToHide(m_CharactersHead.GetBeardIndex(),GetLifeSpanState() != LifeSpanState.BEARD_EXTRA);
  7448. }
  7449. //show all first
  7450. for (i = 0; i < count; i++)
  7451. {
  7452. m_CharactersHead.SetSimpleHiddenSelectionState(i,true);
  7453. }
  7454. //then carve it up
  7455. for (i = 0; i < count; i++)
  7456. {
  7457. stt = m_CharactersHead.m_HeadHairHidingStateMap.Get(i);
  7458. shown = stt.GetSelectionState();
  7459. if (!shown)
  7460. {
  7461. if (/*IsMale() && */!m_CharactersHead.IsHandlingException())
  7462. {
  7463. m_CharactersHead.SetSimpleHiddenSelectionState(i,shown);
  7464. UpdateTranslatedSelections(stt);
  7465. //Print("hidden idx: " + i);
  7466. }
  7467. else
  7468. {
  7469. exception_hidden = true;
  7470. }
  7471. }
  7472. }
  7473. //exceptions handled differently; hides hair
  7474. if (exception_hidden)
  7475. {
  7476. m_CharactersHead.SetSimpleHiddenSelectionState(m_CharactersHead.GetHairIndex(),false);
  7477. if (IsMale())
  7478. m_CharactersHead.SetSimpleHiddenSelectionState(m_CharactersHead.GetBeardIndex(),false);
  7479. }
  7480. }
  7481. void UpdateTranslatedSelections(SelectionTranslation stt)
  7482. {
  7483. int index;
  7484. array<int> translatedSelectinosArray = stt.GetTranslatedSelections();
  7485. for (int i = 0; i < translatedSelectinosArray.Count(); i++)
  7486. {
  7487. index = translatedSelectinosArray.Get(i);
  7488. //if (index > -1)
  7489. m_CharactersHead.SetSimpleHiddenSelectionState(index,false); //safe this way, only hiding/carving from shown parts
  7490. }
  7491. }
  7492. //! helper method for re-checking hairhiding on character load
  7493. void CheckHairClippingOnCharacterLoad()
  7494. {
  7495. ItemBase headgear = ItemBase.Cast(GetInventory().FindAttachment(InventorySlots.HEADGEAR));
  7496. ItemBase mask = ItemBase.Cast(GetInventory().FindAttachment(InventorySlots.MASK));
  7497. HideHairSelections(headgear,true);
  7498. HideHairSelections(mask,true);
  7499. }
  7500. bool IsNVGWorking()
  7501. {
  7502. return m_ActiveNVTypes && m_ActiveNVTypes.Count() > 0;
  7503. }
  7504. bool IsNVGLowered()
  7505. {
  7506. return m_LoweredNVGHeadset;
  7507. }
  7508. int GetNVType()
  7509. {
  7510. if (!m_ActiveNVTypes || m_ActiveNVTypes.Count() == 0)
  7511. {
  7512. return NVTypes.NONE;
  7513. }
  7514. else
  7515. {
  7516. return m_ActiveNVTypes[m_ActiveNVTypes.Count() - 1];
  7517. }
  7518. }
  7519. array<int> GetNVTypesArray()
  7520. {
  7521. return m_ActiveNVTypes;
  7522. }
  7523. //!Deprecated
  7524. void SetNVGWorking(bool state)
  7525. {
  7526. //Deprecated, below is for legacy's sake
  7527. AddActiveNV(NVTypes.NV_GOGGLES);
  7528. }
  7529. void SetNVGLowered(bool state)
  7530. {
  7531. m_LoweredNVGHeadset = state;
  7532. }
  7533. void AddActiveNV(int type)
  7534. {
  7535. if (!m_ActiveNVTypes || (GetGame().IsMultiplayer() && GetGame().IsServer()))
  7536. {
  7537. #ifdef DEVELOPER
  7538. Error("AddActiveNV | illegal server-side call!");
  7539. #endif
  7540. return;
  7541. }
  7542. if (m_ActiveNVTypes.Find(type) == -1)
  7543. m_ActiveNVTypes.Insert(type);
  7544. }
  7545. void RemoveActiveNV(int type)
  7546. {
  7547. if (!m_ActiveNVTypes || (GetGame().IsMultiplayer() && GetGame().IsServer()))
  7548. {
  7549. #ifdef DEVELOPER
  7550. Error("RemoveActiveNV | illegal server-side call!");
  7551. #endif
  7552. return;
  7553. }
  7554. if (m_ActiveNVTypes.Find(type) != -1)
  7555. m_ActiveNVTypes.RemoveItem(type);
  7556. }
  7557. void ResetActiveNV()
  7558. {
  7559. m_ActiveNVTypes.Clear();
  7560. }
  7561. #ifdef DEVELOPER
  7562. override string GetDebugText()
  7563. {
  7564. string text = super.GetDebugText();
  7565. /*
  7566. text += "GetMovementTimeToStrafeJog:" + CfgGameplayHandler.GetMovementTimeToStrafeJog() + "\n";
  7567. text += "GetMovementTimeToStrafeSprint:" + CfgGameplayHandler.GetMovementTimeToStrafeSprint()+ "\n";
  7568. SHumanCommandMoveSettings moveSettings = GetDayZPlayerType().CommandMoveSettingsW();
  7569. if (moveSettings)
  7570. {
  7571. text += "hmcs.m_fDirFilterTimeout:" + moveSettings.m_fDirFilterTimeout + "\n";
  7572. text += "hmcs.m_fDirFilterSprintTimeout:" + moveSettings.m_fDirFilterSprintTimeout+ "\n";
  7573. }*/
  7574. return text;
  7575. }
  7576. void DEBUGRotateNVG()
  7577. {
  7578. NVGoggles nvg;
  7579. if (FindAttachmentBySlotName("Eyewear"))
  7580. {
  7581. nvg = NVGoggles.Cast(FindAttachmentBySlotName("Eyewear").FindAttachmentBySlotName("NVG"));
  7582. }
  7583. else if (FindAttachmentBySlotName("Headgear"))
  7584. {
  7585. nvg = NVGoggles.Cast(FindAttachmentBySlotName("Headgear").FindAttachmentBySlotName("NVG"));
  7586. }
  7587. if (nvg)
  7588. {
  7589. nvg.RotateGoggles(nvg.m_IsLowered);
  7590. }
  7591. }
  7592. #endif
  7593. void AdjustBandana(EntityAI item, string slot_name)
  7594. {
  7595. if (Bandana_ColorBase.Cast(item))
  7596. {
  7597. if (slot_name == "Headgear")
  7598. {
  7599. item.SetSimpleHiddenSelectionState(0,1);
  7600. item.SetSimpleHiddenSelectionState(1,0);
  7601. }
  7602. else if (slot_name == "Mask")
  7603. {
  7604. item.SetSimpleHiddenSelectionState(0,0);
  7605. item.SetSimpleHiddenSelectionState(1,1);
  7606. }
  7607. }
  7608. }
  7609. void AdjustShemag(EntityAI item, string slot_name)
  7610. {
  7611. if (Shemag_ColorBase.Cast(item))
  7612. {
  7613. if (slot_name == "Headgear")
  7614. {
  7615. item.SetSimpleHiddenSelectionState(0,1);
  7616. item.SetSimpleHiddenSelectionState(1,0);
  7617. }
  7618. else if (slot_name == "Mask")
  7619. {
  7620. item.SetSimpleHiddenSelectionState(0,0);
  7621. item.SetSimpleHiddenSelectionState(1,1);
  7622. }
  7623. }
  7624. }
  7625. //client-side
  7626. void UpdateCorpseStateVisual()
  7627. {
  7628. //Print("---Prettying up corpses... | " + GetGame().GetTime() + " | " + this + " | " + GetType() + "---");
  7629. //Print("m_DecayedTexture = " + m_DecayedTexture);
  7630. int state = Math.AbsInt(m_CorpseState);//negative sign denotes a special meaning(state was forced to a live player), but we are only intetested in the positive value here
  7631. if (state == PlayerConstants.CORPSE_STATE_DECAYED)
  7632. {
  7633. EntityAI bodypart;
  7634. ItemBase item;
  7635. string path;
  7636. int idx;
  7637. int slot_id;
  7638. array<string> bodyparts = {"Gloves","Body","Legs","Feet"};
  7639. for (int i = 0; i < bodyparts.Count(); i++)
  7640. {
  7641. slot_id = InventorySlots.GetSlotIdFromString(bodyparts.Get(i));
  7642. bodypart = GetInventory().FindPlaceholderForSlot(slot_id);
  7643. item = ItemBase.Cast(GetInventory().FindAttachment(slot_id));
  7644. if (bodypart)
  7645. {
  7646. path = "cfgVehicles " + bodypart.GetType();
  7647. idx = bodypart.GetHiddenSelectionIndex("personality");
  7648. if (idx > -1)
  7649. {
  7650. bodypart.SetObjectTexture(idx,m_DecayedTexture);
  7651. }
  7652. }
  7653. if (item)
  7654. {
  7655. path = "cfgVehicles " + item.GetType();
  7656. idx = item.GetHiddenSelectionIndex("personality");
  7657. if (idx > -1)
  7658. {
  7659. item.SetObjectTexture(idx,m_DecayedTexture);
  7660. }
  7661. }
  7662. }
  7663. SetFaceTexture(m_DecayedTexture);
  7664. }
  7665. }
  7666. void SetDecayEffects(int effect = -1)
  7667. {
  7668. int boneIdx = GetBoneIndexByName("Spine2");
  7669. Particle p;
  7670. switch (effect)
  7671. {
  7672. case PlayerConstants.CORPSE_STATE_MEDIUM :
  7673. //play medium sound/flies particle
  7674. if (!m_FliesEff)
  7675. m_FliesEff = new EffSwarmingFlies();
  7676. if (m_FliesEff && !SEffectManager.IsEffectExist(m_FliesIndex))
  7677. {
  7678. m_FliesEff.SetDecalOwner(this);
  7679. m_FliesIndex = SEffectManager.PlayOnObject(m_FliesEff, this, "0 0.25 0");
  7680. p = m_FliesEff.GetParticle();
  7681. AddChild(p, boneIdx);
  7682. if (!m_SoundFliesEffect)
  7683. {
  7684. PlaySoundSetLoop(m_SoundFliesEffect, "Flies_SoundSet", 1.0, 1.0);
  7685. }
  7686. }
  7687. break;
  7688. case PlayerConstants.CORPSE_STATE_DECAYED :
  7689. //play serious sound/flies particle
  7690. if (!m_FliesEff)
  7691. m_FliesEff = new EffSwarmingFlies();
  7692. if (m_FliesEff && !SEffectManager.IsEffectExist(m_FliesIndex))
  7693. {
  7694. m_FliesEff.SetDecalOwner(this);
  7695. m_FliesIndex = SEffectManager.PlayOnObject(m_FliesEff, this, "0 0.25 0");
  7696. p = m_FliesEff.GetParticle();
  7697. AddChild(p, boneIdx);
  7698. if (!m_SoundFliesEffect)
  7699. {
  7700. PlaySoundSetLoop(m_SoundFliesEffect, "Flies_SoundSet", 1.0, 1.0);
  7701. }
  7702. }
  7703. break;
  7704. //remove
  7705. default:
  7706. SEffectManager.DestroyEffect(m_FliesEff);
  7707. StopSoundSet(m_SoundFliesEffect);
  7708. break;
  7709. }
  7710. }
  7711. void PreloadDecayTexture()
  7712. {
  7713. int idx = GetHiddenSelectionIndex("decay_preload");
  7714. if (idx > -1)
  7715. SetObjectTexture(idx, m_DecayedTexture);
  7716. }
  7717. void SetLastMapInfo(float scale, vector pos)
  7718. {
  7719. m_LastMapScale = scale;
  7720. m_LastMapPos = pos;
  7721. }
  7722. bool GetLastMapInfo(out float scale, out vector pos)
  7723. {
  7724. scale = m_LastMapScale;
  7725. pos = m_LastMapPos;
  7726. return m_LastMapScale != -1.0;
  7727. }
  7728. override bool PhysicalPredictiveDropItem(EntityAI entity, bool heavy_item_only = true)
  7729. {
  7730. vector dir;
  7731. ItemBase item = ItemBase.Cast(entity);
  7732. //! from hands
  7733. if (GetItemInHands() == item)
  7734. {
  7735. return PredictiveDropEntity(item);
  7736. }
  7737. else
  7738. {
  7739. ActionManagerClient actionManager = ActionManagerClient.Cast(m_ActionManager);
  7740. if (actionManager)
  7741. {
  7742. ActionTarget actionTarget = new ActionTarget(null, null, -1, vector.Zero, -1);
  7743. if (actionManager.GetAction(ActionDropItemSimple).Can(this, actionTarget, item))
  7744. {
  7745. actionManager.PerformActionStart(actionManager.GetAction(ActionDropItemSimple), actionTarget, item);
  7746. return true;
  7747. }
  7748. }
  7749. else
  7750. return true;
  7751. }
  7752. return false;
  7753. }
  7754. override void SetProcessUIWarning(bool state)
  7755. {
  7756. m_ProcessUIWarning = state;
  7757. }
  7758. void dmgDebugPrint(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  7759. {
  7760. /*Print("ProjectileDebugging | Damage Health: " + damageResult.GetDamage(dmgZone,"Health") + " | Component: " + component + " | Zone: " + dmgZone + "| Timestamp: " + GetSimulationTimeStamp());
  7761. Print("ProjectileDebugging | speedCoef: " + speedCoef);
  7762. Print("ProjectileDebugging | GetWorldTime(): " + GetWorldTime());
  7763. Print("-----------------------------------------------");*/
  7764. }
  7765. //Use this method to process additionnal dmg to legs specifically (must use the dmg system to fire relevant events)
  7766. //Legzone is a dummy to inflict damage once and NOT transfer damage to other zones. All leg zones will drop to 0 anyway
  7767. void DamageAllLegs(float inputDmg)
  7768. {
  7769. array<string> legZones = new array<string>;
  7770. legZones.Insert("LeftLeg");
  7771. legZones.Insert("RightLeg");
  7772. legZones.Insert("RightFoot");
  7773. legZones.Insert("LeftFoot");
  7774. foreach (string legZone : legZones)
  7775. DecreaseHealth(legZone, "", inputDmg);
  7776. }
  7777. //! tries to hide item in player's hands, some exceptions for various movement states
  7778. void TryHideItemInHands(bool hide, bool force = false)
  7779. {
  7780. if (!hide && ((!IsSwimming() && !IsClimbingLadder() && !IsInVehicle() && !AnimCommandCheck(HumanMoveCommandID.CommandSwim | HumanMoveCommandID.CommandLadder | HumanMoveCommandID.CommandVehicle)) || force))
  7781. {
  7782. GetItemAccessor().HideItemInHands(false);
  7783. }
  7784. else
  7785. {
  7786. GetItemAccessor().HideItemInHands(true);
  7787. }
  7788. }
  7789. //!
  7790. bool CheckAndExecuteStackSplit(FindInventoryLocationType flags, notnull EntityAI item, notnull EntityAI target)
  7791. {
  7792. InventoryLocation il = new InventoryLocation;
  7793. if (target.GetInventory().FindFreeLocationFor(item, flags, il))
  7794. {
  7795. return CheckAndExecuteStackSplitToInventoryLocation(il,item);
  7796. }
  7797. return false;
  7798. }
  7799. bool CheckAndExecuteStackSplitToInventoryLocation(InventoryLocation il, notnull EntityAI item)
  7800. {
  7801. int slotID = il.GetSlot();
  7802. float stackableTarget = item.GetTargetQuantityMax(slotID);
  7803. if (stackableTarget > 0 && stackableTarget < item.GetQuantity())
  7804. {
  7805. ItemBase itemB;
  7806. if (CastTo(itemB, item))
  7807. {
  7808. itemB.SplitIntoStackMaxToInventoryLocationClient(il);
  7809. return true;
  7810. }
  7811. }
  7812. return false;
  7813. }
  7814. override protected bool TakeEntityToInventoryImpl(InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
  7815. {
  7816. if (CheckAndExecuteStackSplit(flags, item, this))
  7817. {
  7818. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2Inv(SPLIT) item=" + GetDebugName(item));
  7819. return true;
  7820. }
  7821. return super.TakeEntityToInventoryImpl(mode, flags, item);
  7822. }
  7823. override protected bool TakeEntityToCargoImpl(InventoryMode mode, notnull EntityAI item)
  7824. {
  7825. if (CheckAndExecuteStackSplit(FindInventoryLocationType.CARGO, item, this))
  7826. {
  7827. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2Cgo(SPLIT) item=" +GetDebugName(item));
  7828. return true;
  7829. }
  7830. return super.TakeEntityToCargoImpl(mode, item);
  7831. }
  7832. override protected bool TakeEntityAsAttachmentImpl(InventoryMode mode, notnull EntityAI item)
  7833. {
  7834. if (CheckAndExecuteStackSplit(FindInventoryLocationType.ATTACHMENT, item, this))
  7835. {
  7836. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2Att(SPLIT) item=" + GetDebugName(item));
  7837. return true;
  7838. }
  7839. return super.TakeEntityAsAttachmentImpl(mode, item);
  7840. }
  7841. override void TakeEntityToHandsImpl(InventoryMode mode, EntityAI item)
  7842. {
  7843. if (CheckAndExecuteStackSplit(FindInventoryLocationType.HANDS, item, this))
  7844. {
  7845. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2Hands(SPLIT) item=" + GetDebugName(item));
  7846. return;
  7847. }
  7848. super.TakeEntityToHandsImpl(mode, item);
  7849. }
  7850. override protected bool TakeEntityToTargetInventoryImpl(InventoryMode mode, notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  7851. {
  7852. if (CheckAndExecuteStackSplit(flags, item, target))
  7853. {
  7854. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2TargetInv(SPLIT) item=" + GetDebugName(item));
  7855. return true;
  7856. }
  7857. return super.TakeEntityToTargetInventoryImpl(mode, target, flags, item);
  7858. }
  7859. override protected bool TakeEntityToTargetCargoImpl(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  7860. {
  7861. if (CheckAndExecuteStackSplit(FindInventoryLocationType.CARGO, item, target))
  7862. {
  7863. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2TargetCgo(SPLIT) item=" + GetDebugName(item));
  7864. return true;
  7865. }
  7866. return super.TakeEntityToTargetCargoImpl(mode, target, item);
  7867. }
  7868. override protected bool TakeEntityToTargetAttachmentImpl(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  7869. {
  7870. if (CheckAndExecuteStackSplit(FindInventoryLocationType.ATTACHMENT, item, target))
  7871. {
  7872. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2TargetAtt(SPLIT) item=" + GetDebugName(item));
  7873. return true;
  7874. }
  7875. return super.TakeEntityToTargetAttachmentImpl(mode, target, item);
  7876. }
  7877. override protected bool TakeToDstImpl(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  7878. {
  7879. if (CheckAndExecuteStackSplitToInventoryLocation(dst, dst.GetItem()))
  7880. {
  7881. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS=" + GetSimulationTimeStamp() + " Take2Dst(SPLIT) item=" + GetDebugName(dst.GetItem()));
  7882. return true;
  7883. }
  7884. return super.TakeToDstImpl(mode, src, dst);
  7885. }
  7886. override vector GetCenter()
  7887. {
  7888. return GetBonePositionWS(GetBoneIndexByName("spine3"));
  7889. }
  7890. // contaminated areas - temp stuff
  7891. void ContaminatedParticleAdjustment()
  7892. {
  7893. if (GetCommand_Move() && m_ContaminatedAroundPlayer && m_ContaminatedAroundPlayerTiny)
  7894. {
  7895. float playerSpeed = GetCommand_Move().GetCurrentMovementSpeed();
  7896. //Print(playerSpeed);
  7897. // 1 - prone, crouch
  7898. // 2 - jog
  7899. // 3 - sprint
  7900. float particleLifetime = 5.25;
  7901. float particleSpeed = 0.25;
  7902. if (playerSpeed >= 1)
  7903. {
  7904. particleLifetime = 3.5;
  7905. particleSpeed = 3.25;
  7906. }
  7907. if (playerSpeed >= 2)
  7908. {
  7909. particleLifetime = 2.5;
  7910. particleSpeed = 5.25;
  7911. }
  7912. if (playerSpeed >= 3)
  7913. {
  7914. particleLifetime = 1.5;
  7915. particleSpeed = 8.25;
  7916. }
  7917. m_ContaminatedAroundPlayer.SetParameter(0, EmitorParam.LIFETIME, particleLifetime);
  7918. m_ContaminatedAroundPlayer.SetParameter(1, EmitorParam.LIFETIME, particleLifetime);
  7919. m_ContaminatedAroundPlayer.SetParameter(2, EmitorParam.LIFETIME, particleLifetime);
  7920. m_ContaminatedAroundPlayer.SetParameter(3, EmitorParam.LIFETIME, particleLifetime);
  7921. m_ContaminatedAroundPlayerTiny.SetParameter(0, EmitorParam.VELOCITY, particleSpeed);
  7922. vector transform[4];
  7923. GetTransform(transform);
  7924. m_ContaminatedAroundPlayer.SetTransform(transform);
  7925. m_ContaminatedAroundPlayerTiny.SetTransform(transform);
  7926. }
  7927. }
  7928. void HandleGlassesEffect()
  7929. {
  7930. if (!IsControlledPlayer())
  7931. return;
  7932. int i;
  7933. if (m_ProcessRemoveGlassesEffects)
  7934. {
  7935. for (i = 0; i < m_ProcessRemoveGlassesEffects.Count(); i++)
  7936. {
  7937. PPERequesterBank.GetRequester(m_ProcessRemoveGlassesEffects[i]).Stop();
  7938. }
  7939. m_ProcessRemoveGlassesEffects.Clear();
  7940. }
  7941. if (m_ProcessAddGlassesEffects)
  7942. {
  7943. for (i = 0; i < m_ProcessAddGlassesEffects.Count(); i++)
  7944. {
  7945. PPERequesterBank.GetRequester(m_ProcessAddGlassesEffects[i]).Start();
  7946. }
  7947. m_ProcessAddGlassesEffects.Clear();
  7948. }
  7949. }
  7950. override void AddArrow(Object arrow, int componentIndex, vector closeBonePosWS, vector closeBoneRotWS)
  7951. {
  7952. CachedObjectsArrays.ARRAY_STRING.Clear();
  7953. GetActionComponentNameList(componentIndex, CachedObjectsArrays.ARRAY_STRING, LOD.NAME_FIRE);
  7954. int pivot = componentIndex;
  7955. int newPivot = -1;
  7956. string compName;
  7957. for (int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count() && newPivot == -1; i++)
  7958. {
  7959. compName = CachedObjectsArrays.ARRAY_STRING.Get(i);
  7960. newPivot = GetBoneIndexByName(compName);
  7961. }
  7962. if (newPivot != -1)
  7963. {
  7964. pivot = newPivot;
  7965. }
  7966. vector parentTransMat[4];
  7967. vector arrowTransMat[4];
  7968. arrow.GetTransform(arrowTransMat);
  7969. if (pivot == -1)
  7970. {
  7971. GetTransformWS(parentTransMat);
  7972. }
  7973. else
  7974. {
  7975. vector rotMatrix[3];
  7976. Math3D.YawPitchRollMatrix(closeBoneRotWS * Math.RAD2DEG,rotMatrix);
  7977. parentTransMat[0] = rotMatrix[0];
  7978. parentTransMat[1] = rotMatrix[1];
  7979. parentTransMat[2] = rotMatrix[2];
  7980. parentTransMat[3] = closeBonePosWS;
  7981. }
  7982. Math3D.MatrixInvMultiply4(parentTransMat, arrowTransMat, arrowTransMat);
  7983. Math3D.MatrixOrthogonalize4(arrowTransMat);
  7984. arrow.SetTransform(arrowTransMat);
  7985. AddChild(arrow, pivot);
  7986. #ifdef SERVER
  7987. // creating bleeding source
  7988. BleedingSourcesManagerServer bleedingManager = GetBleedingManagerServer();
  7989. if (bleedingManager)
  7990. {
  7991. if (!bleedingManager.AttemptAddBleedingSourceBySelection(compName))
  7992. bleedingManager.AttemptAddBleedingSourceBySelection("Pelvis");//fallback, if we can't attach bleeding source to the fallback location because there already is another one, it's fine, we are just trying make sure there is at least one
  7993. }
  7994. #endif
  7995. }
  7996. override bool IsManagingArrows()
  7997. {
  7998. return true;
  7999. }
  8000. string GetCachedName()
  8001. {
  8002. return m_CachedPlayerName;
  8003. }
  8004. string GetCachedID()
  8005. {
  8006. return m_CachedPlayerID;
  8007. }
  8008. override void OnFreezeStateChangeClient()
  8009. {
  8010. super.OnFreezeStateChangeClient();
  8011. UpdateCorpseState();
  8012. }
  8013. bool HasHeatBuffer()
  8014. {
  8015. return m_HasHeatBuffer;
  8016. }
  8017. int GetHeatBufferStage()
  8018. {
  8019. return m_HeatBufferStage;
  8020. }
  8021. //! ----------
  8022. //! DEPRECATED
  8023. //! ----------
  8024. static ref array<Object> SPREAD_AGENTS_OBJECTS = new array<Object>;
  8025. static ref array<CargoBase> SPREAD_AGENTS_PROXY_CARGOS = new array<CargoBase>;
  8026. private int m_FaceCoveredForShaveLayers = 0;
  8027. int m_AntibioticsActive;
  8028. void SwitchItemTypeAttach(EntityAI item, string slot)
  8029. {
  8030. if (!GetGame().IsServer())
  8031. return;
  8032. }
  8033. void SwitchItemTypeDetach(EntityAI item, string slot);
  8034. void AddToEnvironmentTemperature(float pTemperature);
  8035. void IncreaseAntibioticsCount()
  8036. {
  8037. AddMedicalDrugsInUse(EMedicalDrugsType.ANTIBIOTICS);
  8038. }
  8039. void DecreaseAntibioticsCount()
  8040. {
  8041. RemoveMedicalDrugsInUse(EMedicalDrugsType.ANTIBIOTICS);
  8042. }
  8043. bool Consume(ItemBase source, float amount, EConsumeType consume_type)
  8044. {
  8045. PlayerConsumeData consumeData = new PlayerConsumeData();
  8046. consumeData.m_Type = consume_type;
  8047. consumeData.m_Amount = amount;
  8048. consumeData.m_Source = source;
  8049. consumeData.m_Agents = 0;
  8050. return Consume(consumeData);
  8051. }
  8052. bool HasStaminaRemaining()
  8053. {
  8054. if (!GetStaminaHandler())
  8055. return false;
  8056. return GetStaminaHandler().GetStamina() > 0;
  8057. }
  8058. void SetBloodyHandsPenalty()
  8059. {
  8060. InsertAgent(eAgents.SALMONELLA, 1);
  8061. }
  8062. //!Deprecated
  8063. override void DepleteStamina(EStaminaModifiers modifier, float dT = -1)
  8064. {
  8065. if (GetStaminaHandler())
  8066. GetStaminaHandler().DepleteStamina(modifier,dT);
  8067. }
  8068. }
  8069. #ifdef DEVELOPER
  8070. PlayerBase _player;
  8071. #endif