123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854 |
- typedef ItemBase Inventory_Base;
- typedef map<typename,ref ActionOverrideData> TActionAnimOverrideMap;
- class DummyItem extends ItemBase
- {
- override bool CanPutAsAttachment(EntityAI parent)
- {
- return true;
- }
- };
- //const bool QUANTITY_DEBUG_REMOVE_ME = false;
- class ItemBase extends InventoryItem
- {
- static ref map<typename, ref TInputActionMap> m_ItemTypeActionsMap = new map<typename, ref TInputActionMap>;
- TInputActionMap m_InputActionMap;
- static ref map<typename, ref TActionAnimOverrideMap> m_ItemActionOverrides = new map<typename, ref TActionAnimOverrideMap>;
-
- bool m_ActionsInitialize;
-
- static int m_DebugActionsMask;
- bool m_RecipesInitialized;
- // ============================================
- // Variable Manipulation System
- // ============================================
- // Quantity
-
- float m_VarQuantity;
- float m_VarQuantityPrev;//for client to know quantity changed during synchronization
- int m_VarQuantityInit;
- int m_VarQuantityMin;
- int m_VarQuantityMax;
- int m_Count;
- float m_VarStackMax;
- float m_StoreLoadedQuantity = float.LOWEST;
- // Wet
- float m_VarWet;
- float m_VarWetPrev;//for client to know wetness changed during synchronization
- float m_VarWetInit;
- float m_VarWetMin;
- float m_VarWetMax;
- // Cleanness
- int m_Cleanness;
- int m_CleannessInit;
- int m_CleannessMin;
- int m_CleannessMax;
- // impact sounds
- bool m_WantPlayImpactSound;
- bool m_CanPlayImpactSound = true;
- float m_ImpactSpeed;
- int m_ImpactSoundSurfaceHash;
- //
- float m_HeatIsolation;
- float m_ItemModelLength;
- float m_ItemAttachOffset; // Offset length for when the item is attached e.g. to weapon
- int m_LiquidContainerMask;
- int m_VarLiquidType;
- int m_ItemBehaviour; // -1 = not specified; 0 = heavy item; 1= onehanded item; 2 = twohanded item
- int m_QuickBarBonus;
- bool m_IsBeingPlaced;
- bool m_IsHologram;
- bool m_IsPlaceSound;
- bool m_IsDeploySound;
- bool m_IsTakeable;
- bool m_IsSoundSynchRemote;
- bool m_ThrowItemOnDrop;
- bool m_ItemBeingDroppedPhys;
- bool m_CanBeMovedOverride;
- bool m_FixDamageSystemInit = false; //can be changed on storage version check
- bool can_this_be_combined; //Check if item can be combined
- bool m_CanThisBeSplit; //Check if item can be split
- bool m_IsStoreLoad = false;
- bool m_CanShowQuantity;
- bool m_HasQuantityBar;
- protected bool m_CanBeDigged;
- protected bool m_IsResultOfSplit //! distinguish if item has been created as new or it came from splitting (server only flag)
-
- protected EffectSound m_DeployLoopSoundEx;
-
- string m_SoundAttType;
- // items color variables
- int m_ColorComponentR;
- int m_ColorComponentG;
- int m_ColorComponentB;
- int m_ColorComponentA;
- //-------------------------------------------------------
-
- // light source managing
- ItemBase m_LightSourceItem;
-
- ref TIntArray m_SingleUseActions;
- ref TIntArray m_ContinuousActions;
- ref TIntArray m_InteractActions;
-
- //==============================================
- // agent system
- private int m_AttachedAgents;
- //! appears to be deprecated, legacy code
- void TransferModifiers(PlayerBase reciever);
-
-
- // Weapons & suppressors particle effects
- ref static map<int, ref array<ref WeaponParticlesOnFire>> m_OnFireEffect;
- ref static map<int, ref array<ref WeaponParticlesOnBulletCasingEject>> m_OnBulletCasingEjectEffect;
- ref map<int, ref array<ref WeaponParticlesOnOverheating>> m_OnOverheatingEffect;
- ref static map<string, int> m_WeaponTypeToID;
- static int m_LastRegisteredWeaponID = 0;
-
- // Overheating effects
- bool m_IsOverheatingEffectActive;
- float m_OverheatingShots;
- ref Timer m_CheckOverheating;
- int m_ShotsToStartOverheating = 0; // After these many shots, the overheating effect begins
- int m_MaxOverheatingValue = 0; // Limits the number of shots that will be tracked
- float m_OverheatingDecayInterval = 1; // Timer's interval for decrementing overheat effect's lifespan
- ref array <ref OverheatingParticle> m_OverheatingParticles;
-
- protected ref TStringArray m_HeadHidingSelections;
- protected bool m_HideSelectionsBySlot;
-
- // Admin Log
- PluginAdminLog m_AdminLog;
-
- // misc
- ref Timer m_PhysDropTimer;
- // Attachment Locking variables
- ref array<int> m_CompatibleLocks;
- protected int m_LockType;
- protected ref EffectSound m_LockingSound;
- protected string m_LockSoundSet;
-
- protected EffectSound m_SoundPlace;
- protected EffectSound m_SoundDeploy;
- protected EffectSound m_SoundDeployFinish;
-
- //temperature
- private float m_TemperaturePerQuantityWeight;
-
- // -------------------------------------------------------------------------
- void ItemBase()
- {
- SetEventMask(EntityEvent.INIT); // Enable EOnInit event
- m_SingleUseActions = new TIntArray;
- m_ContinuousActions = new TIntArray;
- m_InteractActions = new TIntArray;
-
- if (!GetGame().IsDedicatedServer())
- {
- if (HasMuzzle())
- {
- LoadParticleConfigOnFire(GetMuzzleID());
-
- if (m_ShotsToStartOverheating == 0)
- {
- LoadParticleConfigOnOverheating(GetMuzzleID());
- }
- }
-
- PreLoadSoundAttachmentType();
- m_ActionsInitialize = false;
- }
-
- m_OldLocation = null;
-
- if (GetGame().IsServer())
- {
- m_AdminLog = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
- }
-
- if (ConfigIsExisting("headSelectionsToHide"))
- {
- m_HeadHidingSelections = new TStringArray;
- ConfigGetTextArray("headSelectionsToHide",m_HeadHidingSelections);
- }
-
- m_HideSelectionsBySlot = false;
- if (ConfigIsExisting("hideSelectionsByinventorySlot"))
- {
- m_HideSelectionsBySlot = ConfigGetBool("hideSelectionsByinventorySlot");
- }
-
- m_QuickBarBonus = Math.Max(0, ConfigGetInt("quickBarBonus"));
- m_IsResultOfSplit = false;
-
- SetActionAnimOverrides();
- }
-
- override void InitItemVariables()
- {
- super.InitItemVariables();
-
- m_VarQuantityInit = ConfigGetInt("varQuantityInit");
- m_VarQuantity = m_VarQuantityInit;//should be by the CE, this is just a precaution
- m_VarQuantityMin = ConfigGetInt("varQuantityMin");
- m_VarQuantityMax = ConfigGetInt("varQuantityMax");
- m_VarStackMax = ConfigGetFloat("varStackMax");
- m_Count = ConfigGetInt("count");
-
- m_CanShowQuantity = ConfigGetBool("quantityShow");
- m_HasQuantityBar = ConfigGetBool("quantityBar");
-
- m_CleannessInit = ConfigGetInt("varCleannessInit");
- m_Cleanness = m_CleannessInit;
- m_CleannessMin = ConfigGetInt("varCleannessMin");
- m_CleannessMax = ConfigGetInt("varCleannessMax");
-
- m_WantPlayImpactSound = false;
- m_ImpactSpeed = 0.0;
-
- m_VarWetInit = ConfigGetFloat("varWetInit");
- m_VarWet = m_VarWetInit;
- m_VarWetMin = ConfigGetFloat("varWetMin");
- m_VarWetMax = ConfigGetFloat("varWetMax");
-
- m_LiquidContainerMask = ConfigGetInt("liquidContainerType");
- if (IsLiquidContainer() && GetQuantity() != 0)
- m_VarLiquidType = GetLiquidTypeInit();
- m_IsBeingPlaced = false;
- m_IsHologram = false;
- m_IsPlaceSound = false;
- m_IsDeploySound = false;
- m_IsTakeable = true;
- m_IsSoundSynchRemote = false;
- m_CanBeMovedOverride = false;
- m_HeatIsolation = GetHeatIsolationInit();
- m_ItemModelLength = GetItemModelLength();
- m_ItemAttachOffset = GetItemAttachOffset();
- m_CanBeDigged = ConfigGetBool("canBeDigged");
-
- m_CompatibleLocks = new array<int>();
- ConfigGetIntArray("compatibleLocks", m_CompatibleLocks);
- m_LockType = ConfigGetInt("lockType");
-
- //Define if item can be split and set ability to be combined accordingly
- m_CanThisBeSplit = false;
- can_this_be_combined = false;
- if (ConfigIsExisting("canBeSplit"))
- {
- can_this_be_combined = ConfigGetBool("canBeSplit");
- m_CanThisBeSplit = can_this_be_combined;
- }
-
- m_ItemBehaviour = -1;
- if (ConfigIsExisting("itemBehaviour"))
- m_ItemBehaviour = ConfigGetInt("itemBehaviour");
-
- //RegisterNetSyncVariableInt("m_VariablesMask");
- if (HasQuantity()) RegisterNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
- RegisterNetSyncVariableFloat("m_VarWet", GetWetMin(), GetWetMax(), 2);
- RegisterNetSyncVariableInt("m_VarLiquidType");
- RegisterNetSyncVariableInt("m_Cleanness",0,1);
-
- RegisterNetSyncVariableBoolSignal("m_WantPlayImpactSound");
- RegisterNetSyncVariableFloat("m_ImpactSpeed");
- RegisterNetSyncVariableInt("m_ImpactSoundSurfaceHash");
-
- RegisterNetSyncVariableInt("m_ColorComponentR", 0, 255);
- RegisterNetSyncVariableInt("m_ColorComponentG", 0, 255);
- RegisterNetSyncVariableInt("m_ColorComponentB", 0, 255);
- RegisterNetSyncVariableInt("m_ColorComponentA", 0, 255);
-
- RegisterNetSyncVariableBool("m_IsBeingPlaced");
- RegisterNetSyncVariableBool("m_IsTakeable");
- RegisterNetSyncVariableBool("m_IsHologram");
-
- if (UsesGlobalDeploy())
- {
- RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
- RegisterNetSyncVariableBool("m_IsDeploySound");
- }
-
- m_LockSoundSet = ConfigGetString("lockSoundSet");
-
- m_TemperaturePerQuantityWeight = 1.0;;
- if (ConfigIsExisting("temperaturePerQuantityWeight"))
- m_TemperaturePerQuantityWeight = ConfigGetFloat("temperaturePerQuantityWeight");
-
- }
-
- // allows for checking whether or not we can safely register net sync variables without causing VMEs for duplicate registration
- protected bool UsesGlobalDeploy()
- {
- return false;
- }
-
- override int GetQuickBarBonus()
- {
- return m_QuickBarBonus;
- }
- void InitializeActions()
- {
- m_InputActionMap = m_ItemTypeActionsMap.Get(this.Type());
- if (!m_InputActionMap)
- {
- TInputActionMap iam = new TInputActionMap;
- m_InputActionMap = iam;
- SetActions();
- m_ItemTypeActionsMap.Insert(this.Type(), m_InputActionMap);
- }
- }
-
- override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
- {
- if (!m_ActionsInitialize)
- {
- m_ActionsInitialize = true;
- InitializeActions();
- }
-
- actions = m_InputActionMap.Get(action_input_type);
- }
-
- void SetActions()
- {
- AddAction(ActionTakeItem);
- AddAction(ActionTakeItemToHands);
- AddAction(ActionWorldCraft);
- AddAction(ActionDropItem);
- AddAction(ActionAttachWithSwitch);
- }
-
- void SetActionAnimOverrides(); // Override action animation for specific item
-
- void AddAction(typename actionName)
- {
- ActionBase action = ActionManagerBase.GetAction(actionName);
- if (!action)
- {
- Debug.LogError("Action " + actionName + " dosn't exist!");
- return;
- }
-
- typename ai = action.GetInputType();
- if (!ai)
- {
- m_ActionsInitialize = false;
- return;
- }
-
- array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
- if (!action_array)
- {
- action_array = new array<ActionBase_Basic>;
- m_InputActionMap.Insert(ai, action_array);
- }
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action");
- }
-
- if (action_array.Find(action) != -1)
- {
- Debug.Log("Action " + action.Type() + " already added to " + this + ", skipping!");
- }
- else
- {
- action_array.Insert(action);
- }
- }
-
- void RemoveAction(typename actionName)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- ActionBase action = player.GetActionManager().GetAction(actionName);
- typename ai = action.GetInputType();
- array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
-
- if (action_array)
- {
- action_array.RemoveItem(action);
- }
- }
-
- // Allows override of default action command per item, defined in the SetActionAnimOverrides() of the item's class
- // Set -1 for params which should stay in default state
- void OverrideActionAnimation(typename action, int commandUID, int stanceMask = -1, int commandUIDProne = -1)
- {
- ActionOverrideData overrideData = new ActionOverrideData();
- overrideData.m_CommandUID = commandUID;
- overrideData.m_CommandUIDProne = commandUIDProne;
- overrideData.m_StanceMask = stanceMask;
-
- TActionAnimOverrideMap actionMap = m_ItemActionOverrides.Get(action);
- if (!actionMap) // create new map of action > overidables map
- {
- actionMap = new TActionAnimOverrideMap();
- m_ItemActionOverrides.Insert(action, actionMap);
- }
-
- actionMap.Insert(this.Type(), overrideData); // insert item -> overrides
-
- }
-
- void OnItemInHandsPlayerSwimStart(PlayerBase player);
-
- ScriptedLightBase GetLight();
-
- // Loads muzzle flash particle configuration from config and saves it to a map for faster access
- void LoadParticleConfigOnFire(int id)
- {
- if (!m_OnFireEffect)
- m_OnFireEffect = new map<int, ref array<ref WeaponParticlesOnFire>>;
-
- if (!m_OnBulletCasingEjectEffect)
- m_OnBulletCasingEjectEffect = new map<int, ref array<ref WeaponParticlesOnBulletCasingEject>>;
-
- string config_to_search = "CfgVehicles";
- string muzzle_owner_config;
-
- if (!m_OnFireEffect.Contains(id))
- {
- if (IsInherited(Weapon))
- config_to_search = "CfgWeapons";
-
- muzzle_owner_config = config_to_search + " " + GetType() + " ";
-
- string config_OnFire_class = muzzle_owner_config + "Particles " + "OnFire ";
-
- int config_OnFire_subclass_count = GetGame().ConfigGetChildrenCount(config_OnFire_class);
-
- if (config_OnFire_subclass_count > 0)
- {
- array<ref WeaponParticlesOnFire> WPOF_array = new array<ref WeaponParticlesOnFire>;
-
- for (int i = 0; i < config_OnFire_subclass_count; i++)
- {
- string particle_class = "";
- GetGame().ConfigGetChildName(config_OnFire_class, i, particle_class);
- string config_OnFire_entry = config_OnFire_class + particle_class;
- WeaponParticlesOnFire WPOF = new WeaponParticlesOnFire(this, config_OnFire_entry);
- WPOF_array.Insert(WPOF);
- }
-
-
- m_OnFireEffect.Insert(id, WPOF_array);
- }
- }
-
- if (!m_OnBulletCasingEjectEffect.Contains(id))
- {
- config_to_search = "CfgWeapons"; // Bullet Eject efect is supported on weapons only.
- muzzle_owner_config = config_to_search + " " + GetType() + " ";
-
- string config_OnBulletCasingEject_class = muzzle_owner_config + "Particles " + "OnBulletCasingEject ";
-
- int config_OnBulletCasingEject_count = GetGame().ConfigGetChildrenCount(config_OnBulletCasingEject_class);
-
- if (config_OnBulletCasingEject_count > 0 && IsInherited(Weapon))
- {
- array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = new array<ref WeaponParticlesOnBulletCasingEject>;
-
- for (i = 0; i < config_OnBulletCasingEject_count; i++)
- {
- string particle_class2 = "";
- GetGame().ConfigGetChildName(config_OnBulletCasingEject_class, i, particle_class2);
- string config_OnBulletCasingEject_entry = config_OnBulletCasingEject_class + particle_class2;
- WeaponParticlesOnBulletCasingEject WPOBE = new WeaponParticlesOnBulletCasingEject(this, config_OnBulletCasingEject_entry);
- WPOBE_array.Insert(WPOBE);
- }
-
-
- m_OnBulletCasingEjectEffect.Insert(id, WPOBE_array);
- }
- }
- }
-
- // Loads muzzle flash particle configuration from config and saves it to a map for faster access
- void LoadParticleConfigOnOverheating(int id)
- {
- if (!m_OnOverheatingEffect)
- m_OnOverheatingEffect = new map<int, ref array<ref WeaponParticlesOnOverheating>>;
-
- if (!m_OnOverheatingEffect.Contains(id))
- {
- string config_to_search = "CfgVehicles";
-
- if (IsInherited(Weapon))
- config_to_search = "CfgWeapons";
-
- string muzzle_owner_config = config_to_search + " " + GetType() + " ";
- string config_OnOverheating_class = muzzle_owner_config + "Particles " + "OnOverheating ";
-
- if (GetGame().ConfigIsExisting(config_OnOverheating_class))
- {
-
- m_ShotsToStartOverheating = GetGame().ConfigGetFloat(config_OnOverheating_class + "shotsToStartOverheating");
-
- if (m_ShotsToStartOverheating == 0)
- {
- m_ShotsToStartOverheating = -1; // This prevents futher readings from config for future creations of this item
- string error = "Error reading config " + GetType() + ">Particles>OnOverheating - Parameter shotsToStartOverheating is configured wrong or is missing! Its value must be 1 or higher!";
- Error(error);
- return;
- }
-
- m_OverheatingDecayInterval = GetGame().ConfigGetFloat(config_OnOverheating_class + "overheatingDecayInterval");
- m_MaxOverheatingValue = GetGame().ConfigGetFloat(config_OnOverheating_class + "maxOverheatingValue");
-
-
-
- int config_OnOverheating_subclass_count = GetGame().ConfigGetChildrenCount(config_OnOverheating_class);
- array<ref WeaponParticlesOnOverheating> WPOOH_array = new array<ref WeaponParticlesOnOverheating>;
-
- for (int i = 0; i < config_OnOverheating_subclass_count; i++)
- {
- string particle_class = "";
- GetGame().ConfigGetChildName(config_OnOverheating_class, i, particle_class);
- string config_OnOverheating_entry = config_OnOverheating_class + particle_class;
- int entry_type = GetGame().ConfigGetType(config_OnOverheating_entry);
-
- if (entry_type == CT_CLASS)
- {
- WeaponParticlesOnOverheating WPOF = new WeaponParticlesOnOverheating(this, config_OnOverheating_entry);
- WPOOH_array.Insert(WPOF);
- }
- }
-
-
- m_OnOverheatingEffect.Insert(id, WPOOH_array);
- }
- }
- }
-
- float GetOverheatingValue()
- {
- return m_OverheatingShots;
- }
-
- void IncreaseOverheating(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- if (m_MaxOverheatingValue > 0)
- {
- m_OverheatingShots++;
-
- if (!m_CheckOverheating)
- m_CheckOverheating = new Timer(CALL_CATEGORY_SYSTEM);
-
- m_CheckOverheating.Stop();
- m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay");
-
- CheckOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
-
- void CheckOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
- {
- if (m_OverheatingShots >= m_ShotsToStartOverheating && IsOverheatingEffectActive())
- UpdateOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
-
- if (m_OverheatingShots >= m_ShotsToStartOverheating && !IsOverheatingEffectActive())
- StartOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
-
- if (m_OverheatingShots < m_ShotsToStartOverheating && IsOverheatingEffectActive())
- StopOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
-
- if (m_OverheatingShots > m_MaxOverheatingValue)
- {
- m_OverheatingShots = m_MaxOverheatingValue;
- }
- }
-
- bool IsOverheatingEffectActive()
- {
- return m_IsOverheatingEffectActive;
- }
-
- void OnOverheatingDecay()
- {
- if (m_MaxOverheatingValue > 0)
- m_OverheatingShots -= 1 + m_OverheatingShots / m_MaxOverheatingValue; // The hotter a barrel is, the faster it needs to cool down.
- else
- m_OverheatingShots--;
-
- if (m_OverheatingShots <= 0)
- {
- m_CheckOverheating.Stop();
- m_OverheatingShots = 0;
- }
- else
- {
- if (!m_CheckOverheating)
- m_CheckOverheating = new Timer(CALL_CATEGORY_GAMEPLAY);
-
- m_CheckOverheating.Stop();
- m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay");
- }
-
- CheckOverheating(this, "", this);
- }
- void StartOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
- {
- m_IsOverheatingEffectActive = true;
- ItemBase.PlayOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons");
- }
-
- void UpdateOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
- {
- KillAllOverheatingParticles();
- ItemBase.UpdateOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons");
- UpdateAllOverheatingParticles();
- }
-
- void StopOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
- {
- m_IsOverheatingEffectActive = false;
- ItemBase.StopOverheatingParticles(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
- }
-
- void RegisterOverheatingParticle(Particle p, float min_heat_coef, float max_heat_coef, int particle_id, Object parent, vector local_pos, vector local_ori)
- {
- if (!m_OverheatingParticles)
- m_OverheatingParticles = new array<ref OverheatingParticle>;
-
- OverheatingParticle OP = new OverheatingParticle();
- OP.RegisterParticle(p);
- OP.SetOverheatingLimitMin(min_heat_coef);
- OP.SetOverheatingLimitMax(max_heat_coef);
- OP.SetParticleParams(particle_id, parent, local_pos, local_ori);
-
- m_OverheatingParticles.Insert(OP);
- }
-
- float GetOverheatingCoef()
- {
- if (m_MaxOverheatingValue > 0)
- return (m_OverheatingShots - m_ShotsToStartOverheating) / m_MaxOverheatingValue;
-
- return -1;
- }
-
- void UpdateAllOverheatingParticles()
- {
- if (m_OverheatingParticles)
- {
- float overheat_coef = GetOverheatingCoef();
- int count = m_OverheatingParticles.Count();
-
- for (int i = count; i > 0; --i)
- {
- int id = i - 1;
- OverheatingParticle OP = m_OverheatingParticles.Get(id);
- Particle p = OP.GetParticle();
-
- float overheat_min = OP.GetOverheatingLimitMin();
- float overheat_max = OP.GetOverheatingLimitMax();
-
- if (overheat_coef < overheat_min && overheat_coef >= overheat_max)
- {
- if (p)
- {
- p.Stop();
- OP.RegisterParticle(null);
- }
- }
- }
- }
- }
-
- void KillAllOverheatingParticles()
- {
- if (m_OverheatingParticles)
- {
- for (int i = m_OverheatingParticles.Count(); i > 0; i--)
- {
- int id = i - 1;
- OverheatingParticle OP = m_OverheatingParticles.Get(id);
-
- if (OP)
- {
- Particle p = OP.GetParticle();
-
- if (p)
- {
- p.Stop();
- }
-
- delete OP;
- }
- }
-
- m_OverheatingParticles.Clear();
- delete m_OverheatingParticles;
- }
- }
-
- //! Infection chance while/after using this item, originally used for wound infection after bandaging, params 'system' and 'param' can allow usage by other systems as well
- float GetInfectionChance(int system = 0, Param param = null)
- {
- return 0.0;
- }
-
-
- float GetDisinfectQuantity(int system = 0, Param param1 = null)
- {
- return 250;//default value
- }
-
- float GetFilterDamageRatio()
- {
- return 0;
- }
-
- //! Returns true if this item has a muzzle (weapons, suppressors)
- bool HasMuzzle()
- {
- if (IsInherited(Weapon) || IsInherited(SuppressorBase))
- return true;
-
- return false;
- }
-
- //! Returns global muzzle ID. If not found, then it gets automatically registered.
- int GetMuzzleID()
- {
- if (!m_WeaponTypeToID)
- m_WeaponTypeToID = new map<string, int>;
-
- if (m_WeaponTypeToID.Contains(GetType()))
- {
- return m_WeaponTypeToID.Get(GetType());
- }
- else
- {
- // Register new weapon ID
- m_WeaponTypeToID.Insert(GetType(), ++m_LastRegisteredWeaponID);
- }
-
- return m_LastRegisteredWeaponID;
- }
-
- /**
- \brief Re-sets DamageSystem changes
- \return storage version on which the config changes occured (default -1, to be overriden!)
- \note Significant changes to DamageSystem in item configs have to be re-set by increasing the storage version and overriding this method. Default return is -1 (does nothing).
- */
- int GetDamageSystemVersionChange()
- {
- return -1;
- }
-
-
-
- // -------------------------------------------------------------------------
- void ~ItemBase()
- {
- #ifndef SERVER
- if (m_DeployLoopSoundEx)
- m_DeployLoopSoundEx.SoundStop();
- #endif
-
- if (GetGame() && GetGame().GetPlayer() && (!GetGame().IsDedicatedServer()))
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this);
- if (r_index >= 0)
- {
- InventoryLocation r_il = new InventoryLocation;
- player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
- player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
- int r_type = r_il.GetType();
- if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
- {
- r_il.GetParent().GetOnReleaseLock().Invoke(this);
- }
- else if (r_type == InventoryLocationType.ATTACHMENT)
- {
- r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
- }
-
- }
-
- player.GetHumanInventory().ClearUserReservedLocation(this);
- }
-
- if (m_LockingSound)
- SEffectManager.DestroyEffect(m_LockingSound);
- }
-
-
- // -------------------------------------------------------------------------
- static int GetDebugActionsMask()
- {
- return ItemBase.m_DebugActionsMask;
- }
-
- static bool HasDebugActionsMask(int mask)
- {
- return ItemBase.m_DebugActionsMask & mask;
- }
-
- static void SetDebugActionsMask(int mask)
- {
- ItemBase.m_DebugActionsMask = mask;
- }
-
- static void AddDebugActionsMask(int mask)
- {
- ItemBase.m_DebugActionsMask |= mask;
- }
-
- static void RemoveDebugActionsMask(int mask)
- {
- ItemBase.m_DebugActionsMask &= ~mask;
- }
-
- static void ToggleDebugActionsMask(int mask)
- {
- if (HasDebugActionsMask(mask))
- {
- RemoveDebugActionsMask(mask);
- }
- else
- {
- AddDebugActionsMask(mask);
- }
- }
-
- // -------------------------------------------------------------------------
- void SetCEBasedQuantity()
- {
- if (GetEconomyProfile())
- {
- float q_max = GetEconomyProfile().GetQuantityMax();
- if (q_max > 0)
- {
- float q_min = GetEconomyProfile().GetQuantityMin();
- float quantity_randomized = Math.RandomFloatInclusive(q_min, q_max);
-
- if (HasComponent(COMP_TYPE_ENERGY_MANAGER))//more direct access for speed
- {
- ComponentEnergyManager comp = GetCompEM();
- if (comp && (comp.GetEnergyMaxPristine() || comp.GetEnergyAtSpawn()))//checking for a potential for energy, we need to check both values, as both are optional, only when both are set to 0, we know the item can't have energy
- {
- comp.SetEnergy0To1(quantity_randomized);
- }
- }
- else if (HasQuantity())
- {
- SetQuantityNormalized(quantity_randomized, false);
- //PrintString("<==> Normalized quantity for item: "+ GetType()+", qmin:"+q_min.ToString()+"; qmax:"+q_max.ToString()+";quantity:" +quantity_randomized.ToString());
- }
-
- }
- }
- }
-
- //! Locks this item in it's current attachment slot of its parent. This makes the "locked" icon visible in inventory over this item.
- void LockToParent()
- {
- EntityAI parent = GetHierarchyParent();
-
- if (parent)
- {
- InventoryLocation inventory_location_to_lock = new InventoryLocation;
- GetInventory().GetCurrentInventoryLocation(inventory_location_to_lock);
- parent.GetInventory().SetSlotLock(inventory_location_to_lock.GetSlot(), true);
- }
- }
-
- //! Unlocks this item from its attachment slot of its parent.
- void UnlockFromParent()
- {
- EntityAI parent = GetHierarchyParent();
-
- if (parent)
- {
- InventoryLocation inventory_location_to_unlock = new InventoryLocation;
- GetInventory().GetCurrentInventoryLocation(inventory_location_to_unlock);
- parent.GetInventory().SetSlotLock(inventory_location_to_unlock.GetSlot(), false);
- }
- }
-
- override void CombineItemsClient(EntityAI entity2, bool use_stack_max = true)
- {
- /*
- ref Param1<EntityAI> item = new Param1<EntityAI>(entity2);
- RPCSingleParam(ERPCs.RPC_ITEM_COMBINE, item, GetGame().GetPlayer());
- */
- ItemBase item2 = ItemBase.Cast(entity2);
-
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(-1);
- ItemBase i1 = this; // @NOTE: workaround for correct serialization
- ctx.Write(i1);
- ctx.Write(item2);
- ctx.Write(use_stack_max);
- ctx.Write(-1);
- ctx.Send();
-
- if (IsCombineAll(item2, use_stack_max))
- {
- GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(item2,null,GameInventory.c_InventoryReservationTimeoutShortMS);
- }
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- CombineItems(item2, use_stack_max);
- }
- }
-
- bool IsLiquidPresent()
- {
- return (GetLiquidType() != 0 && HasQuantity());
- }
-
- bool IsLiquidContainer()
- {
- return m_LiquidContainerMask != 0;
- }
-
- int GetLiquidContainerMask()
- {
- return m_LiquidContainerMask;
- }
-
- bool IsBloodContainer()
- {
- //m_LiquidContainerMask & GROUP_LIQUID_BLOOD ???
- return false;
- }
-
- bool IsNVG()
- {
- return false;
- }
-
- //! explosive
- //! ------------
- bool IsExplosive()
- {
- return false;
- }
-
- string GetExplosiveTriggerSlotName()
- {
- return "";
- }
-
- //! ------------
-
- bool IsLightSource()
- {
- return false;
- }
-
- bool CanBeRepairedByCrafting()
- {
- return true;
- }
-
- //--- ACTION CONDITIONS
- //direction
- bool IsFacingPlayer(PlayerBase player, string selection)
- {
- return true;
- }
-
- bool IsPlayerInside(PlayerBase player, string selection)
- {
- return true;
- }
-
- override bool CanObstruct()
- {
- PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
- return !player || !IsPlayerInside(player, "");
- }
-
- override bool IsBeingPlaced()
- {
- return m_IsBeingPlaced;
- }
-
- void SetIsBeingPlaced(bool is_being_placed)
- {
- m_IsBeingPlaced = is_being_placed;
- if (!is_being_placed)
- OnEndPlacement();
- SetSynchDirty();
- }
-
- //server-side
- void OnEndPlacement() {}
-
- override bool IsHologram()
- {
- return m_IsHologram;
- }
-
- bool CanBeDigged()
- {
- return m_CanBeDigged;
- }
-
- int GetOnDigWormsAmount()
- {
- return 1;
- }
-
- bool CanMakeGardenplot()
- {
- return false;
- }
-
- void SetIsHologram(bool is_hologram)
- {
- m_IsHologram = is_hologram;
- SetSynchDirty();
- }
- /*
- protected float GetNutritionalEnergy()
- {
- Edible_Base edible = Edible_Base.Cast(this);
- return edible.GetFoodEnergy();
- }
-
- protected float GetNutritionalWaterContent()
- {
- Edible_Base edible = Edible_Base.Cast(this);
- return edible.GetFoodWater();
- }
-
- protected float GetNutritionalIndex()
- {
- Edible_Base edible = Edible_Base.Cast(this);
- return edible.GetFoodNutritionalIndex();
- }
-
- protected float GetNutritionalFullnessIndex()
- {
- Edible_Base edible = Edible_Base.Cast(this);
- return edible.GetFoodTotalVolume();
- }
-
- protected float GetNutritionalToxicity()
- {
- Edible_Base edible = Edible_Base.Cast(this);
- return edible.GetFoodToxicity();
- }
- */
-
-
- // -------------------------------------------------------------------------
- override void OnMovedInsideCargo(EntityAI container)
- {
- super.OnMovedInsideCargo(container);
-
- MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base});
- }
-
- override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
- super.EEItemLocationChanged(oldLoc,newLoc);
-
- PlayerBase new_player = null;
- PlayerBase old_player = null;
-
- if (newLoc.GetParent())
- new_player = PlayerBase.Cast(newLoc.GetParent().GetHierarchyRootPlayer());
-
- if (oldLoc.GetParent())
- old_player = PlayerBase.Cast(oldLoc.GetParent().GetHierarchyRootPlayer());
-
- if (old_player && oldLoc.GetType() == InventoryLocationType.HANDS)
- {
- int r_index = old_player.GetHumanInventory().FindUserReservedLocationIndex(this);
- if (r_index >= 0)
- {
- InventoryLocation r_il = new InventoryLocation;
- old_player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
- old_player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
- int r_type = r_il.GetType();
- if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
- {
- r_il.GetParent().GetOnReleaseLock().Invoke(this);
- }
- else if (r_type == InventoryLocationType.ATTACHMENT)
- {
- r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
- }
-
- }
- }
-
- if (newLoc.GetType() == InventoryLocationType.HANDS)
- {
- if (new_player)
- new_player.ForceStandUpForHeavyItems(newLoc.GetItem());
-
- if (new_player == old_player)
- {
-
- if (oldLoc.GetParent() && new_player.GetHumanInventory().LocationGetEntity(oldLoc) == NULL)
- {
- if (oldLoc.GetType() == InventoryLocationType.CARGO)
- {
- if (oldLoc.GetParent().GetInventory().TestAddEntityInCargoExLoc(oldLoc, false, false, false, true, false, false))
- {
- new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc);
- }
- }
- else
- {
- new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc);
- }
- }
-
- if (new_player.GetHumanInventory().FindUserReservedLocationIndex(this) >= 0)
- {
- int type = oldLoc.GetType();
- if (type == InventoryLocationType.CARGO || type == InventoryLocationType.PROXYCARGO)
- {
- oldLoc.GetParent().GetOnSetLock().Invoke(this);
- }
- else if (type == InventoryLocationType.ATTACHMENT)
- {
- oldLoc.GetParent().GetOnAttachmentSetLock().Invoke(this, oldLoc.GetSlot());
- }
- }
- if (!m_OldLocation)
- {
- m_OldLocation = new InventoryLocation;
- }
- m_OldLocation.Copy(oldLoc);
- }
- else
- {
- if (m_OldLocation)
- {
- m_OldLocation.Reset();
- }
- }
-
- GetGame().GetAnalyticsClient().OnItemAttachedAtPlayer(this,"Hands");
- }
- else
- {
- if (new_player)
- {
- int res_index = new_player.GetHumanInventory().FindCollidingUserReservedLocationIndex(this, newLoc);
- if (res_index >= 0)
- {
- InventoryLocation il = new InventoryLocation;
- new_player.GetHumanInventory().GetUserReservedLocation(res_index,il);
- ItemBase it = ItemBase.Cast(il.GetItem());
- new_player.GetHumanInventory().ClearUserReservedLocationAtIndex(res_index);
- int rel_type = il.GetType();
- if (rel_type == InventoryLocationType.CARGO || rel_type == InventoryLocationType.PROXYCARGO)
- {
- il.GetParent().GetOnReleaseLock().Invoke(it);
- }
- else if (rel_type == InventoryLocationType.ATTACHMENT)
- {
- il.GetParent().GetOnAttachmentReleaseLock().Invoke(it, il.GetSlot());
- }
- //it.GetOnReleaseLock().Invoke(it);
- }
- }
- else if (old_player && newLoc.GetType() == InventoryLocationType.GROUND && m_ThrowItemOnDrop)
- {
- //ThrowPhysically(old_player, vector.Zero);
- m_ThrowItemOnDrop = false;
- }
-
- if (m_OldLocation)
- {
- m_OldLocation.Reset();
- }
- }
- }
-
- override void EOnContact(IEntity other, Contact extra)
- {
- if (m_CanPlayImpactSound)
- {
- int liquidType = -1;
- float impactSpeed = ProcessImpactSoundEx(other, extra, m_ConfigWeight, m_ImpactSoundSurfaceHash, liquidType);
- if (impactSpeed > 0.0)
- {
- m_ImpactSpeed = impactSpeed;
- #ifndef SERVER
- PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash);
- #else
- m_WantPlayImpactSound = true;
- SetSynchDirty();
- #endif
- m_CanPlayImpactSound = (liquidType == -1);// prevents further playing of the sound when the surface is a liquid type
- }
- }
-
- #ifdef SERVER
- if (GetCompEM() && GetCompEM().IsPlugged())
- {
- if (GetCompEM().GetCordLength() < vector.Distance(GetPosition(), GetCompEM().GetEnergySource().GetPosition()))
- GetCompEM().UnplugThis();
- }
- #endif
- }
-
- void RefreshPhysics();
-
- override void OnCreatePhysics()
- {
- RefreshPhysics();
- }
-
- override void OnItemAttachmentSlotChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
-
- }
- // -------------------------------------------------------------------------
- override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
- {
- super.OnItemLocationChanged(old_owner, new_owner);
-
- PlayerBase relatedPlayer = PlayerBase.Cast(old_owner);
- PlayerBase playerNew = PlayerBase.Cast(new_owner);
-
- if (!relatedPlayer && playerNew)
- relatedPlayer = playerNew;
-
- if (relatedPlayer && relatedPlayer.GetPerformedActionID() != -1)
- {
- ActionManagerBase actionMgr = relatedPlayer.GetActionManager();
- if (actionMgr)
- {
- ActionBase currentAction = actionMgr.GetRunningAction();
- if (currentAction)
- currentAction.OnItemLocationChanged(this);
- }
- }
-
- Man ownerPlayerOld = null;
- Man ownerPlayerNew = null;
-
- if (old_owner)
- {
- if (old_owner.IsMan())
- {
- ownerPlayerOld = Man.Cast(old_owner);
- }
- else
- {
- ownerPlayerOld = Man.Cast(old_owner.GetHierarchyRootPlayer());
- }
- }
- else
- {
- if (new_owner && IsElectricAppliance() && GetCompEM() && GetCompEM().IsPlugged())
- {
- ActionBase action = ActionManagerBase.GetAction(ActionRepositionPluggedItem);
-
- if (!action || !playerNew || playerNew.GetPerformedActionID() != action.GetID())
- {
- GetCompEM().UnplugThis();
- }
- }
- }
-
- if (new_owner)
- {
- if (new_owner.IsMan())
- {
- ownerPlayerNew = Man.Cast(new_owner);
- }
- else
- {
- ownerPlayerNew = Man.Cast(new_owner.GetHierarchyRootPlayer());
- }
- }
-
- if (ownerPlayerOld != ownerPlayerNew)
- {
- if (ownerPlayerOld)
- {
- array<EntityAI> subItemsExit = new array<EntityAI>;
- GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsExit);
- for (int i = 0; i < subItemsExit.Count(); i++)
- {
- ItemBase itemExit = ItemBase.Cast(subItemsExit.Get(i));
- itemExit.OnInventoryExit(ownerPlayerOld);
- }
- }
- if (ownerPlayerNew)
- {
- array<EntityAI> subItemsEnter = new array<EntityAI>;
- GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsEnter);
- for (int j = 0; j < subItemsEnter.Count(); j++)
- {
- ItemBase itemEnter = ItemBase.Cast(subItemsEnter.Get(j));
- itemEnter.OnInventoryEnter(ownerPlayerNew);
- }
- }
- }
- else if (ownerPlayerNew != null)
- {
- PlayerBase nplayer;
- if (PlayerBase.CastTo(nplayer, ownerPlayerNew))
- {
- array<EntityAI> subItemsUpdate = new array<EntityAI>;
- GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsUpdate);
- for (int k = 0; k < subItemsUpdate.Count(); k++)
- {
- ItemBase itemUpdate = ItemBase.Cast(subItemsUpdate.Get(k));
- itemUpdate.UpdateQuickbarShortcutVisibility(nplayer);
- }
- }
- }
-
- if (old_owner)
- old_owner.OnChildItemRemoved(this);
- if (new_owner)
- new_owner.OnChildItemReceived(this);
- }
- // -------------------------------------------------------------------------------
- override void EEDelete(EntityAI parent)
- {
- super.EEDelete(parent);
- PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
- if (player)
- {
- OnInventoryExit(player);
-
- if (player.IsAlive())
- {
- int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this);
- if (r_index >= 0)
- {
- InventoryLocation r_il = new InventoryLocation;
- player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
-
- player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
- int r_type = r_il.GetType();
- if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
- {
- r_il.GetParent().GetOnReleaseLock().Invoke(this);
- }
- else if (r_type == InventoryLocationType.ATTACHMENT)
- {
- r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
- }
-
- }
-
- player.RemoveQuickBarEntityShortcut(this);
- }
- }
- }
- // -------------------------------------------------------------------------------
- override void EEKilled(Object killer)
- {
- super.EEKilled(killer);
- //! item is able to explode in fire
- if (killer && killer.IsFireplace() && CanExplodeInFire())
- {
- if (GetTemperature() >= GameConstants.ITEM_TEMPERATURE_TO_EXPLODE_MIN)
- {
- if (IsMagazine())
- {
- if (Magazine.Cast(this).GetAmmoCount() > 0)
- {
- ExplodeAmmo();
- }
- }
- else
- {
- Explode(DamageType.EXPLOSION);
- }
- }
- }
- }
-
- override void OnWasAttached(EntityAI parent, int slot_id)
- {
- MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base});
-
- super.OnWasAttached(parent, slot_id);
-
- if (HasQuantity())
- UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
-
- PlayAttachSound(InventorySlots.GetSlotName(slot_id));
- }
-
- override void OnWasDetached(EntityAI parent, int slot_id)
- {
- super.OnWasDetached(parent, slot_id);
-
- if (HasQuantity())
- UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
- }
-
- override string ChangeIntoOnAttach(string slot)
- {
- int idx;
- TStringArray inventory_slots = new TStringArray;
- TStringArray attach_types = new TStringArray;
-
- ConfigGetTextArray("ChangeInventorySlot",inventory_slots);
- if (inventory_slots.Count() < 1) //is string
- {
- inventory_slots.Insert(ConfigGetString("ChangeInventorySlot"));
- attach_types.Insert(ConfigGetString("ChangeIntoOnAttach"));
- }
- else //is array
- {
- ConfigGetTextArray("ChangeIntoOnAttach",attach_types);
- }
-
- idx = inventory_slots.Find(slot);
- if (idx < 0)
- return "";
-
- return attach_types.Get(idx);
- }
-
- override string ChangeIntoOnDetach()
- {
- int idx = -1;
- string slot;
-
- TStringArray inventory_slots = new TStringArray;
- TStringArray detach_types = new TStringArray;
-
- this.ConfigGetTextArray("ChangeInventorySlot",inventory_slots);
- if (inventory_slots.Count() < 1) //is string
- {
- inventory_slots.Insert(this.ConfigGetString("ChangeInventorySlot"));
- detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach"));
- }
- else //is array
- {
- this.ConfigGetTextArray("ChangeIntoOnDetach",detach_types);
- if (detach_types.Count() < 1)
- detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach"));
- }
-
- for (int i = 0; i < inventory_slots.Count(); i++)
- {
- slot = inventory_slots.Get(i);
- }
-
- if (slot != "")
- {
- if (detach_types.Count() == 1)
- idx = 0;
- else
- idx = inventory_slots.Find(slot);
- }
- if (idx < 0)
- return "";
-
- return detach_types.Get(idx);
- }
-
- void ExplodeAmmo()
- {
- //timer
- ref Timer explode_timer = new Timer(CALL_CATEGORY_SYSTEM);
-
- //min/max time
- float min_time = 1;
- float max_time = 3;
- float delay = Math.RandomFloat(min_time, max_time);
-
- explode_timer.Run(delay, this, "DoAmmoExplosion");
- }
-
- void DoAmmoExplosion()
- {
- Magazine magazine = Magazine.Cast(this);
- int pop_sounds_count = 6;
- string pop_sounds[ 6 ] = { "ammopops_1","ammopops_2","ammopops_3","ammopops_4","ammopops_5","ammopops_6" };
-
- //play sound
- int sound_idx = Math.RandomInt(0, pop_sounds_count - 1);
- string sound_name = pop_sounds[ sound_idx ];
- GetGame().CreateSoundOnObject(this, sound_name, 20, false);
-
- //remove ammo count
- magazine.ServerAddAmmoCount(-1);
-
- //if condition then repeat -> ExplodeAmmo
- float min_temp_to_explode = 100; //min temperature for item to explode
-
- if (magazine.GetAmmoCount() > 0 && GetTemperature() >= min_temp_to_explode) //TODO ? add check for parent -> fireplace
- {
- ExplodeAmmo();
- }
- }
-
- // -------------------------------------------------------------------------------
- override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
- {
- super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
-
- const int CHANCE_DAMAGE_CARGO = 4;
- const int CHANCE_DAMAGE_ATTACHMENT = 1;
- const int CHANCE_DAMAGE_NOTHING = 2;
-
- if (IsClothing() || IsContainer() || IsItemTent())
- {
- float dmg = damageResult.GetDamage("","Health") * -0.5;
- int chances;
- int rnd;
-
- if (GetInventory().GetCargo())
- {
- chances = CHANCE_DAMAGE_CARGO + CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING;
- rnd = Math.RandomInt(0,chances);
-
- if (rnd < CHANCE_DAMAGE_CARGO)
- {
- DamageItemInCargo(dmg);
- }
- else if (rnd < (chances - CHANCE_DAMAGE_NOTHING))
- {
- DamageItemAttachments(dmg);
- }
- }
- else
- {
- chances = CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING;
- rnd = Math.RandomInt(0,chances);
-
- if (rnd < CHANCE_DAMAGE_ATTACHMENT)
- {
- DamageItemAttachments(dmg);
- }
- }
- }
- }
-
- bool DamageItemInCargo(float damage)
- {
- if (GetInventory().GetCargo())
- {
- int item_count = GetInventory().GetCargo().GetItemCount();
- if (item_count > 0)
- {
- int random_pick = Math.RandomInt(0, item_count);
- ItemBase item = ItemBase.Cast(GetInventory().GetCargo().GetItem(random_pick));
- if (!item.IsExplosive())
- {
- item.AddHealth("","",damage);
- return true;
- }
- }
- }
- return false;
- }
-
- bool DamageItemAttachments(float damage)
- {
- int attachment_count = GetInventory().AttachmentCount();
- if (attachment_count > 0)
- {
- int random_pick = Math.RandomInt(0, attachment_count);
- ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(random_pick));
- if (!attachment.IsExplosive())
- {
- attachment.AddHealth("","",damage);
- return true;
- }
- }
- return false;
- }
-
- override bool IsSplitable()
- {
- return m_CanThisBeSplit;
- }
- //----------------
- override bool CanBeSplit()
- {
- if (IsSplitable() && (GetQuantity() > 1))
- return GetInventory().CanRemoveEntity();
-
- return false;
- }
-
- override void SplitIntoStackMaxClient(EntityAI destination_entity, int slot_id )
- {
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(1);
- ItemBase i1 = this; // @NOTE: workaround for correct serialization
- ctx.Write(i1);
- ctx.Write(destination_entity);
- ctx.Write(true);
- ctx.Write(slot_id);
- ctx.Send();
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- SplitIntoStackMax(destination_entity, slot_id, PlayerBase.Cast(GetGame().GetPlayer()));
- }
- }
- void SplitIntoStackMax(EntityAI destination_entity, int slot_id, PlayerBase player)
- {
- float split_quantity_new;
- ref ItemBase new_item;
- float quantity = GetQuantity();
- float stack_max = GetTargetQuantityMax(slot_id);
- InventoryLocation loc = new InventoryLocation;
-
- if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
- {
- if (stack_max <= GetQuantity())
- split_quantity_new = stack_max;
- else
- split_quantity_new = GetQuantity();
- new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- else if (destination_entity && slot_id == -1)
- {
- if (quantity > stack_max)
- split_quantity_new = stack_max;
- else
- split_quantity_new = quantity;
-
- if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
- {
- Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
- new_item = ItemBase.Cast(o);
- }
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- else
- {
- if (stack_max != 0)
- {
- if (stack_max < GetQuantity())
- {
- split_quantity_new = GetQuantity() - stack_max;
- }
-
- if (split_quantity_new == 0)
- {
- if (!GetGame().IsMultiplayer())
- player.PhysicalPredictiveDropItem(this);
- else
- player.ServerDropEntity(this);
- return;
- }
-
- new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(), player.GetWorldPosition(), ECE_PLACE_ON_SURFACE));
-
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- SetQuantity(split_quantity_new);
- new_item.SetQuantity(stack_max);
- new_item.PlaceOnSurface();
- }
- }
- }
- }
-
- override void SplitIntoStackMaxEx(EntityAI destination_entity, int slot_id)
- {
- float split_quantity_new;
- ref ItemBase new_item;
- float quantity = GetQuantity();
- float stack_max = GetTargetQuantityMax(slot_id);
- InventoryLocation loc = new InventoryLocation;
-
- if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
- {
- if (stack_max <= GetQuantity())
- split_quantity_new = stack_max;
- else
- split_quantity_new = GetQuantity();
- new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- else if (destination_entity && slot_id == -1)
- {
- if (quantity > stack_max)
- split_quantity_new = stack_max;
- else
- split_quantity_new = quantity;
-
- if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
- {
- Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
- new_item = ItemBase.Cast(o);
- }
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- else
- {
- if (stack_max != 0)
- {
- if (stack_max < GetQuantity())
- {
- split_quantity_new = GetQuantity() - stack_max;
- }
-
- new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(),GetWorldPosition(), ECE_PLACE_ON_SURFACE));
-
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
- SetQuantity(split_quantity_new);
- new_item.SetQuantity(stack_max);
- new_item.PlaceOnSurface();
- }
- }
- }
- }
-
- void SplitIntoStackMaxToInventoryLocationClient(notnull InventoryLocation dst)
- {
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(4);
- ItemBase thiz = this; // @NOTE: workaround for correct serialization
- ctx.Write(thiz);
- dst.WriteToContext(ctx);
- ctx.Send();
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- SplitIntoStackMaxToInventoryLocation(dst);
- }
- }
-
- void SplitIntoStackMaxCargoClient(EntityAI destination_entity, int idx, int row, int col)
- {
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(2);
- ItemBase dummy = this; // @NOTE: workaround for correct serialization
- ctx.Write(dummy);
- ctx.Write(destination_entity);
- ctx.Write(true);
- ctx.Write(idx);
- ctx.Write(row);
- ctx.Write(col);
- ctx.Send();
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- SplitIntoStackMaxCargo(destination_entity, idx, row, col);
- }
- }
- void SplitIntoStackMaxToInventoryLocation(notnull InventoryLocation dst)
- {
- SplitIntoStackMaxToInventoryLocationEx(dst);
- }
-
- ItemBase SplitIntoStackMaxToInventoryLocationEx(notnull InventoryLocation dst)
- {
- float quantity = GetQuantity();
- float split_quantity_new;
- ItemBase new_item;
- if (dst.IsValid())
- {
- int slot_id = dst.GetSlot();
- float stack_max = GetTargetQuantityMax(slot_id);
-
- if (quantity > stack_max)
- split_quantity_new = stack_max;
- else
- split_quantity_new = quantity;
-
- new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, this.GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
-
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this,new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
-
- return new_item;
- }
-
- return null;
- }
-
- void SplitIntoStackMaxCargo(EntityAI destination_entity, int idx, int row, int col)
- {
- float quantity = GetQuantity();
- float split_quantity_new;
- ref ItemBase new_item;
- if (destination_entity)
- {
- float stackable = GetTargetQuantityMax();
- if (quantity > stackable)
- split_quantity_new = stackable;
- else
- split_quantity_new = quantity;
-
- new_item = ItemBase.Cast(destination_entity.GetInventory().CreateEntityInCargoEx(this.GetType(), idx, row, col, false));
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this,new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- }
-
- void SplitIntoStackMaxHandsClient(PlayerBase player)
- {
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(3);
- ItemBase i1 = this; // @NOTE: workaround for correct serialization
- ctx.Write(i1);
- ItemBase destination_entity = this;
- ctx.Write(destination_entity);
- ctx.Write(true);
- ctx.Write(0);
- ctx.Send();
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- SplitIntoStackMaxHands(player);
- }
- }
- void SplitIntoStackMaxHands(PlayerBase player)
- {
- float quantity = GetQuantity();
- float split_quantity_new;
- ref ItemBase new_item;
- if (player)
- {
- float stackable = GetTargetQuantityMax();
- if (quantity > stackable)
- split_quantity_new = stackable;
- else
- split_quantity_new = quantity;
-
- EntityAI in_hands = player.GetHumanInventory().CreateInHands(this.GetType());
- new_item = ItemBase.Cast(in_hands);
- if (new_item)
- {
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this,new_item);
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- }
-
- void SplitItemToInventoryLocation(notnull InventoryLocation dst)
- {
- if (!CanBeSplit())
- return;
-
- float quantity = GetQuantity();
- float split_quantity_new = Math.Floor(quantity * 0.5);
-
- ItemBase new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
- if (new_item)
- {
- if (new_item.GetQuantityMax() < split_quantity_new)
- {
- split_quantity_new = new_item.GetQuantityMax();
- }
-
- new_item.SetResultOfSplit(true);
- MiscGameplayFunctions.TransferItemProperties(this, new_item);
-
- if (dst.IsValid() && dst.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
- {
- AddQuantity(-1);
- new_item.SetQuantity(1);
- }
- else
- {
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- }
-
- void SplitItem(PlayerBase player)
- {
- if (!CanBeSplit())
- {
- return;
- }
-
- float quantity = GetQuantity();
- float split_quantity_new = Math.Floor(quantity / 2);
-
- InventoryLocation invloc = new InventoryLocation;
- bool found = player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.ATTACHMENT, invloc);
-
- ItemBase new_item;
- new_item = player.CreateCopyOfItemInInventoryOrGroundEx(this, true);
-
- if (new_item)
- {
- if (new_item.GetQuantityMax() < split_quantity_new)
- {
- split_quantity_new = new_item.GetQuantityMax();
- }
- if (found && invloc.IsValid() && invloc.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
- {
- AddQuantity(-1);
- new_item.SetQuantity(1);
- }
- else
- {
- AddQuantity(-split_quantity_new);
- new_item.SetQuantity(split_quantity_new);
- }
- }
- }
-
- //! Called on server side when this item's quantity is changed. Call super.OnQuantityChanged(); first when overriding this event.
- void OnQuantityChanged(float delta)
- {
- SetWeightDirty();
- ItemBase parent = ItemBase.Cast(GetHierarchyParent());
-
- if (parent)
- parent.OnAttachmentQuantityChangedEx(this, delta);
-
- if (IsLiquidContainer())
- {
- if (GetQuantityNormalized() <= 0.0)
- {
- SetLiquidType(LIQUID_NONE);
- }
- else if (GetLiquidType() == LIQUID_NONE)
- {
- ErrorEx("Undefined liquid type quantity changed, please define liquid type first! Using init value.",ErrorExSeverity.INFO);
- SetLiquidType(GetLiquidTypeInit());
- }
- }
-
- }
-
- //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
- void OnAttachmentQuantityChanged(ItemBase item)
- {
- // insert code here
- }
-
- //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
- void OnAttachmentQuantityChangedEx(ItemBase item , float delta)
- {
- OnAttachmentQuantityChanged(item);
- }
- override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
- {
- super.EEHealthLevelChanged(oldLevel,newLevel,zone);
-
- if (GetGame().IsServer())
- {
- if (newLevel == GameConstants.STATE_RUINED)
- {
- //! drops content of container when ruined in fireplace
- EntityAI parent = GetHierarchyParent();
- if (parent && parent.IsFireplace())
- {
- CargoBase cargo = GetInventory().GetCargo();
- if (cargo)
- {
- for (int i = 0; i < cargo.GetItemCount(); ++i)
- {
- parent.GetInventory().TakeEntityToInventory(InventoryMode.SERVER, FindInventoryLocationType.CARGO, cargo.GetItem(i));
- }
- }
- }
- }
-
- if (IsResultOfSplit())
- {
- // reset the splitting result flag, return to normal item behavior
- SetResultOfSplit(false);
- return;
- }
- if (m_Cleanness != 0 && oldLevel < newLevel && newLevel != 0)
- {
- SetCleanness(0);//unclean the item upon damage dealt
- }
- }
- }
-
- // just the split? TODO: verify
- override void OnRightClick()
- {
- super.OnRightClick();
-
- if (CanBeSplit() && !GetDayZGame().IsLeftCtrlDown() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(this,null))
- {
- if (GetGame().IsClient())
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- vector m4[4];
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- EntityAI root = GetHierarchyRoot();
-
- InventoryLocation dst = new InventoryLocation;
- if (!player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.CARGO, dst))
- {
- if (root)
- {
- root.GetTransform(m4);
- dst.SetGround(this, m4);
- }
- else
- GetInventory().GetCurrentInventoryLocation(dst);
- }
- else
- {
- dst.SetCargo(dst.GetParent(), this, dst.GetIdx(), dst.GetRow(), dst.GetCol(), dst.GetFlip());
- if (GetGame().GetPlayer().GetInventory().HasInventoryReservation(null, dst))
- {
- if (root)
- {
- root.GetTransform(m4);
- dst.SetGround(this, m4);
- }
- else
- GetInventory().GetCurrentInventoryLocation(dst);
- }
- else
- {
- GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(null, dst, GameInventory.c_InventoryReservationTimeoutShortMS);
- }
- }
-
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
- ctx.Write(4);
- ItemBase thiz = this; // @NOTE: workaround for correct serialization
- ctx.Write(thiz);
- dst.WriteToContext(ctx);
- ctx.Write(true); // dummy
- ctx.Send();
- }
- }
- else if (!GetGame().IsMultiplayer())
- {
- SplitItem(PlayerBase.Cast(GetGame().GetPlayer()));
- }
- }
- }
-
- override bool CanBeCombined(EntityAI other_item, bool reservation_check = true, bool stack_max_limit = false)
- {
- //TODO: delete check zero quantity check after fix double posts hands fsm events
- if (!other_item || GetType() != other_item.GetType() || (IsFullQuantity() && other_item.GetQuantity() > 0) || other_item == this)
- return false;
- if (GetHealthLevel() == GameConstants.STATE_RUINED || other_item.GetHealthLevel() == GameConstants.STATE_RUINED)
- return false;
-
- //can_this_be_combined = ConfigGetBool("canBeSplit");
- if (!can_this_be_combined)
- return false;
-
- Magazine mag = Magazine.Cast(this);
- if (mag)
- {
- if (mag.GetAmmoCount() >= mag.GetAmmoMax())
- return false;
-
- if (stack_max_limit)
- {
- Magazine other_mag = Magazine.Cast(other_item);
- if (other_item)
- {
- if (mag.GetAmmoCount() + other_mag.GetAmmoCount() > mag.GetAmmoMax())
- return false;
- }
-
- }
- }
- else
- {
- //TODO: delete check zero quantity check after fix double posts hands fsm events
- if (GetQuantity() >= GetQuantityMax() && other_item.GetQuantity() > 0 )
- return false;
-
- if (stack_max_limit && (GetQuantity() + other_item.GetQuantity() > GetQuantityMax()))
- return false;
- }
- PlayerBase player = null;
- if (CastTo(player, GetHierarchyRootPlayer())) //false when attached to player's attachment slot
- {
- if (player.GetInventory().HasAttachment(this))
- return false;
-
- if (player.IsItemsToDelete())
- return false;
- }
- if (reservation_check && (GetInventory().HasInventoryReservation(this, null) || other_item.GetInventory().HasInventoryReservation(other_item, null)))
- return false;
-
- int slotID;
- string slotName;
- if (GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName) && GetHierarchyParent().GetInventory().GetSlotLock(slotID))
- return false;
- return true;
- }
-
- bool IsCombineAll(ItemBase other_item, bool use_stack_max = false)
- {
- return ComputeQuantityUsed(other_item, use_stack_max) == other_item.GetQuantity();
- }
-
- bool IsResultOfSplit()
- {
- return m_IsResultOfSplit;
- }
-
- void SetResultOfSplit(bool value)
- {
- m_IsResultOfSplit = value;
- }
-
- int ComputeQuantityUsed(ItemBase other_item, bool use_stack_max = true)
- {
- return ComputeQuantityUsedEx(other_item, use_stack_max);
- }
-
- float ComputeQuantityUsedEx(ItemBase other_item, bool use_stack_max = true)
- {
- float other_item_quantity = other_item.GetQuantity();
- float this_free_space;
-
- float stack_max = GetQuantityMax();
-
- this_free_space = stack_max - GetQuantity();
-
- if (other_item_quantity > this_free_space)
- {
- return this_free_space;
- }
- else
- {
- return other_item_quantity;
- }
- }
-
- override void CombineItemsEx(EntityAI entity2, bool use_stack_max = true)
- {
- CombineItems(ItemBase.Cast(entity2),use_stack_max);
- }
-
- void CombineItems(ItemBase other_item, bool use_stack_max = true)
- {
- if (!CanBeCombined(other_item, false))
- return;
-
- if (!IsMagazine() && other_item)
- {
- float quantity_used = ComputeQuantityUsedEx(other_item,use_stack_max);
- if (quantity_used != 0)
- {
- float hp1 = GetHealth01("","");
- float hp2 = other_item.GetHealth01("","");
- float hpResult = ((hp1*GetQuantity()) + (hp2*quantity_used));
- hpResult = hpResult / (GetQuantity() + quantity_used);
- hpResult *= GetMaxHealth();
- Math.Round(hpResult);
- SetHealth("", "Health", hpResult);
- AddQuantity(quantity_used);
- other_item.AddQuantity(-quantity_used);
- }
- }
- OnCombine(other_item);
- }
- void OnCombine(ItemBase other_item)
- {
- #ifdef SERVER
- if (!GetHierarchyRootPlayer() && GetHierarchyParent())
- GetHierarchyParent().IncreaseLifetimeUp();
- #endif
- };
- void GetRecipesActions(Man player, out TSelectableActionInfoArray outputList)
- {
- PlayerBase p = PlayerBase.Cast(player);
-
- array<int> recipesIds = p.m_Recipes;
- PluginRecipesManager moduleRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
- if (moduleRecipesManager)
- {
- EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands();
- moduleRecipesManager.GetValidRecipes(ItemBase.Cast(this), ItemBase.Cast(itemInHands), recipesIds, p);
- }
- for (int i = 0;i < recipesIds.Count(); i++)
- {
- int key = recipesIds.Get(i);
- string recipeName = moduleRecipesManager.GetRecipeName(key);
- outputList.Insert(new TSelectableActionInfo(SAT_CRAFTING, key, recipeName));
- }
- }
-
- // -------------------------------------------------------------------------
- override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
- {
- super.GetDebugActions(outputList);
-
- //quantity
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_QUANTITY, "Quantity +20%", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_QUANTITY, "Quantity -20%", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_QUANTITY_0, "Set Quantity 0", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_MAX_QUANTITY, "Set Quantity Max", FadeColors.LIGHT_GREY));
-
- //health
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_HEALTH, "Health +20%", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_HEALTH, "Health -20%", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DESTROY_HEALTH, "Health 0", FadeColors.LIGHT_GREY));
- //temperature
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_TEMPERATURE, "Temperature +20", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_TEMPERATURE, "Temperature -20", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FLIP_FROZEN, "Toggle Frozen", FadeColors.LIGHT_GREY));
-
- //wet
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_WETNESS, "Wetness +20", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_WETNESS, "Wetness -20", FadeColors.LIGHT_GREY));
- //liquidtype
- if (IsLiquidContainer())
- {
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_UP, "LiquidType Next", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_DOWN, "LiquidType Previous", FadeColors.LIGHT_GREY));
- }
-
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.MAKE_SPECIAL, "Make Special", FadeColors.LIGHT_GREY));
- // watch
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_ITEM, "Watch (CTRL-Z)", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_PLAYER, "Watch Player", FadeColors.LIGHT_GREY));
-
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
- }
-
- // -------------------------------------------------------------------------
- // -------------------------------------------------------------------------
- // -------------------------------------------------------------------------
- override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
- {
- super.OnAction(action_id, player, ctx);
- if (action_id >= EActions.RECIPES_RANGE_START && action_id < EActions.RECIPES_RANGE_END)
- {
- PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
- int idWithoutOffset = action_id - EActions.RECIPES_RANGE_START;
- PlayerBase p = PlayerBase.Cast(player);
- if (EActions.RECIPES_RANGE_START < 1000)
- {
- float anim_length = plugin_recipes_manager.GetRecipeLengthInSecs(idWithoutOffset);
- float specialty_weight = plugin_recipes_manager.GetRecipeSpecialty(idWithoutOffset);
- }
- }
- #ifndef SERVER
- else if (action_id == EActions.WATCH_PLAYER)
- {
- PluginDeveloper.SetDeveloperItemClientEx(player);
- }
- #endif
- if (GetGame().IsServer())
- {
- if (action_id >= EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START && action_id < EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_END)
- {
- int id = action_id - EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START;
- OnDebugButtonPressServer(id + 1);
- }
-
- else if (action_id >= EActions.DEBUG_AGENTS_RANGE_INJECT_START && action_id < EActions.DEBUG_AGENTS_RANGE_INJECT_END)
- {
- int agent_id = action_id - EActions.DEBUG_AGENTS_RANGE_INJECT_START;
- InsertAgent(agent_id,100);
- }
-
- else if (action_id >= EActions.DEBUG_AGENTS_RANGE_REMOVE_START && action_id < EActions.DEBUG_AGENTS_RANGE_REMOVE_END)
- {
- int agent_id2 = action_id - EActions.DEBUG_AGENTS_RANGE_REMOVE_START;
- RemoveAgent(agent_id2);
- }
-
- else if (action_id == EActions.ADD_QUANTITY)
- {
- if (IsMagazine())
- {
- Magazine mag = Magazine.Cast(this);
- mag.ServerSetAmmoCount(mag.GetAmmoCount() + mag.GetAmmoMax() * 0.2);
- }
- else
- {
- AddQuantity(GetQuantityMax() * 0.2);
- }
-
- if (m_EM)
- {
- m_EM.AddEnergy(m_EM.GetEnergyMax() * 0.2);
- }
- //PrintVariables();
- }
-
- else if (action_id == EActions.REMOVE_QUANTITY) //Quantity -20%
- {
- if (IsMagazine())
- {
- Magazine mag2 = Magazine.Cast(this);
- mag2.ServerSetAmmoCount(mag2.GetAmmoCount() - mag2.GetAmmoMax() * 0.2);
- }
- else
- {
- AddQuantity(- GetQuantityMax() * 0.2);
- }
- if (m_EM)
- {
- m_EM.AddEnergy(- m_EM.GetEnergyMax() * 0.2);
- }
- //PrintVariables();
- }
-
- else if (action_id == EActions.SET_QUANTITY_0) //SetMaxQuantity
- {
- SetQuantity(0);
-
- if (m_EM)
- {
- m_EM.SetEnergy(0);
- }
- }
-
- else if (action_id == EActions.SET_MAX_QUANTITY) //SetMaxQuantity
- {
- SetQuantityMax();
-
- if (m_EM)
- {
- m_EM.SetEnergy(m_EM.GetEnergyMax());
- }
- }
-
- else if (action_id == EActions.ADD_HEALTH)
- {
- AddHealth("","",GetMaxHealth("","Health")/5);
- }
- else if (action_id == EActions.REMOVE_HEALTH)
- {
- AddHealth("","",-GetMaxHealth("","Health")/5);
- }
- else if (action_id == EActions.DESTROY_HEALTH)
- {
- SetHealth01("","",0);
- }
- else if (action_id == EActions.WATCH_ITEM)
- {
- PluginItemDiagnostic mid = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
- mid.RegisterDebugItem(ItemBase.Cast(this), PlayerBase.Cast(player));
- #ifdef DEVELOPER
- SetDebugDeveloper_item(this);
- #endif
- }
-
- else if (action_id == EActions.ADD_TEMPERATURE)
- {
- AddTemperature(20);
- //PrintVariables();
- }
-
- else if (action_id == EActions.REMOVE_TEMPERATURE)
- {
- AddTemperature(-20);
- //PrintVariables();
- }
-
- else if (action_id == EActions.FLIP_FROZEN)
- {
- SetFrozen(!GetIsFrozen());
- //PrintVariables();
- }
-
- else if (action_id == EActions.ADD_WETNESS)
- {
- AddWet(GetWetMax()/5);
- //PrintVariables();
- }
-
- else if (action_id == EActions.REMOVE_WETNESS)
- {
- AddWet(-GetWetMax()/5);
- //PrintVariables();
- }
-
- else if (action_id == EActions.LIQUIDTYPE_UP)
- {
- int curr_type = GetLiquidType();
- SetLiquidType(curr_type * 2);
- //AddWet(1);
- //PrintVariables();
- }
-
- else if (action_id == EActions.LIQUIDTYPE_DOWN)
- {
- int curr_type2 = GetLiquidType();
- SetLiquidType(curr_type2 / 2);
- }
- else if (action_id == EActions.MAKE_SPECIAL)
- {
- auto debugParams = DebugSpawnParams.WithPlayer(player);
- OnDebugSpawnEx(debugParams);
- }
-
- else if (action_id == EActions.DELETE)
- {
- Delete();
- }
-
- }
-
- return false;
- }
- // -------------------------------------------------------------------------
-
-
- //! DEPRECATED use OnActivatedByItem below
- //! Called when this item is activated from a trip wire that was stepped on.
- void OnActivatedByTripWire();
-
- //! Called when this item is activated by other
- void OnActivatedByItem(notnull ItemBase item);
- //----------------------------------------------------------------
- //returns true if item is able to explode when put in fire
- bool CanExplodeInFire()
- {
- return false;
- }
-
- //----------------------------------------------------------------
- bool CanEat()
- {
- return true;
- }
-
- //----------------------------------------------------------------
- override bool IsIgnoredByConstruction()
- {
- return true;
- }
-
- //----------------------------------------------------------------
- //has FoodStages in config?
- bool HasFoodStage()
- {
- string config_path = string.Format("CfgVehicles %1 Food FoodStages", GetType());
- return GetGame().ConfigIsExisting(config_path);
- }
-
- //! overridden on Edible_Base; so we don't have to parse configs all the time
- FoodStage GetFoodStage()
- {
- return null;
- }
-
- bool CanBeCooked()
- {
- return false;
- }
-
- bool CanBeCookedOnStick()
- {
- return false;
- }
-
- //----------------------------------------------------------------
- bool CanRepair(ItemBase item_repair_kit)
- {
- PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
- return module_repairing.CanRepair(this, item_repair_kit);
- }
- //----------------------------------------------------------------
- bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight)
- {
- PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
- return module_repairing.Repair(player, this, item_repair_kit, specialty_weight);
- }
- //----------------------------------------------------------------
- int GetItemSize()
- {
- /*
- vector v_size = this.ConfigGetVector("itemSize");
- int v_size_x = v_size[0];
- int v_size_y = v_size[1];
- int size = v_size_x * v_size_y;
- return size;
- */
-
- return 1;
- }
-
- //----------------------------------------------------------------
- //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
- bool CanBeMovedOverride()
- {
- return m_CanBeMovedOverride;
- }
-
- //----------------------------------------------------------------
- //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
- void SetCanBeMovedOverride(bool setting)
- {
- m_CanBeMovedOverride = setting;
- }
-
- //----------------------------------------------------------------
- /**
- \brief Send message to owner player in grey color
- \return \p void
- @code
- item_stone.MessageToOwnerStatus("Some Status Message");
- @endcode
- */
- void MessageToOwnerStatus(string text)
- {
- PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
-
- if (player)
- {
- player.MessageStatus(text);
- }
- }
- //----------------------------------------------------------------
- /**
- \brief Send message to owner player in yellow color
- \return \p void
- @code
- item_stone.MessageToOwnerAction("Some Action Message");
- @endcode
- */
- void MessageToOwnerAction(string text)
- {
- PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
-
- if (player)
- {
- player.MessageAction(text);
- }
- }
- //----------------------------------------------------------------
- /**
- \brief Send message to owner player in green color
- \return \p void
- @code
- item_stone.MessageToOwnerFriendly("Some Friendly Message");
- @endcode
- */
- void MessageToOwnerFriendly(string text)
- {
- PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
-
- if (player)
- {
- player.MessageFriendly(text);
- }
- }
- //----------------------------------------------------------------
- /**
- \brief Send message to owner player in red color
- \return \p void
- @code
- item_stone.MessageToOwnerImportant("Some Important Message");
- @endcode
- */
- void MessageToOwnerImportant(string text)
- {
- PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
-
- if (player)
- {
- player.MessageImportant(text);
- }
- }
- override bool IsItemBase()
- {
- return true;
- }
- // Checks if item is of questioned kind
- override bool KindOf(string tag)
- {
- bool found = false;
- string item_name = this.GetType();
- ref TStringArray item_tag_array = new TStringArray;
- GetGame().ConfigGetTextArray("cfgVehicles " + item_name + " itemInfo", item_tag_array);
-
- int array_size = item_tag_array.Count();
- for (int i = 0; i < array_size; i++)
- {
- if (item_tag_array.Get(i) == tag)
- {
- found = true;
- break;
- }
- }
- return found;
- }
-
- override void OnRPC(PlayerIdentity sender, int rpc_type,ParamsReadContext ctx)
- {
- //Debug.Log("OnRPC called");
- super.OnRPC(sender, rpc_type,ctx);
-
- //Play soundset for attachment locking (ActionLockAttachment.c)
- switch (rpc_type)
- {
- #ifndef SERVER
- case ERPCs.RPC_SOUND_LOCK_ATTACH:
- Param2<bool, string> p = new Param2<bool, string>(false, "");
-
- if (!ctx.Read(p))
- return;
-
- bool play = p.param1;
- string soundSet = p.param2;
-
- if (play)
- {
- if (m_LockingSound)
- {
- if (!m_LockingSound.IsSoundPlaying())
- {
- m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
- }
- }
- else
- {
- m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
- }
- }
- else
- {
- SEffectManager.DestroyEffect(m_LockingSound);
- }
-
- break;
- #endif
-
- }
-
- if (GetWrittenNoteData())
- {
- GetWrittenNoteData().OnRPC(sender, rpc_type,ctx);
- }
- }
- //-----------------------------
- // VARIABLE MANIPULATION SYSTEM
- //-----------------------------
- int NameToID(string name)
- {
- PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
- return plugin.GetID(name);
- }
- string IDToName(int id)
- {
- PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
- return plugin.GetName(id);
- }
- //! DEPRECATED (most likely)
- void OnSyncVariables(ParamsReadContext ctx)//with ID optimization
- {
- //Debug.Log("OnSyncVariables called for item: "+ ToString(this.GetType()),"varSync");
- //read the flags
- int varFlags;
- if (!ctx.Read(varFlags))
- return;
-
- if (varFlags & ItemVariableFlags.FLOAT)
- {
- ReadVarsFromCTX(ctx);
- }
- }
-
- override void SerializeNumericalVars(array<float> floats_out)
- {
- //some variables handled on EntityAI level already!
- super.SerializeNumericalVars(floats_out);
-
- // the order of serialization must be the same as the order of de-serialization
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_QUANTITY))
- {
- floats_out.Insert(m_VarQuantity);
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_WET))
- {
- floats_out.Insert(m_VarWet);
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_LIQUIDTYPE))
- {
- floats_out.Insert(m_VarLiquidType);
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_COLOR))
- {
- floats_out.Insert(m_ColorComponentR);
- floats_out.Insert(m_ColorComponentG);
- floats_out.Insert(m_ColorComponentB);
- floats_out.Insert(m_ColorComponentA);
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_CLEANNESS))
- {
- floats_out.Insert(m_Cleanness);
- }
- }
-
- override void DeSerializeNumericalVars(array<float> floats)
- {
- //some variables handled on EntityAI level already!
- super.DeSerializeNumericalVars(floats);
-
- // the order of serialization must be the same as the order of de-serialization
- int index = 0;
- int mask = Math.Round(floats.Get(index));
-
- index++;
- //--------------------------------------------
- if (mask & VARIABLE_QUANTITY)
- {
- if (m_IsStoreLoad)
- {
- SetStoreLoadedQuantity(floats.Get(index));
- }
- else
- {
- float quantity = floats.Get(index);
- SetQuantity(quantity, true, false, false, false);
- }
- index++;
- }
- //--------------------------------------------
- if (mask & VARIABLE_WET)
- {
- float wet = floats.Get(index);
- SetWet(wet);
- index++;
- }
- //--------------------------------------------
- if (mask & VARIABLE_LIQUIDTYPE)
- {
- int liquidtype = Math.Round(floats.Get(index));
- SetLiquidType(liquidtype);
- index++;
- }
- //--------------------------------------------
- if (mask & VARIABLE_COLOR)
- {
- m_ColorComponentR = Math.Round(floats.Get(index));
- index++;
- m_ColorComponentG = Math.Round(floats.Get(index));
- index++;
- m_ColorComponentB = Math.Round(floats.Get(index));
- index++;
- m_ColorComponentA = Math.Round(floats.Get(index));
- index++;
- }
- //--------------------------------------------
- if (mask & VARIABLE_CLEANNESS)
- {
- int cleanness = Math.Round(floats.Get(index));
- SetCleanness(cleanness);
- index++;
- }
- }
-
- override void WriteVarsToCTX(ParamsWriteContext ctx)
- {
- super.WriteVarsToCTX(ctx);
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_QUANTITY))
- {
- ctx.Write(GetQuantity());
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_WET))
- {
- ctx.Write(GetWet());
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_LIQUIDTYPE))
- {
- ctx.Write(GetLiquidType());
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_COLOR))
- {
- int r,g,b,a;
- GetColor(r,g,b,a);
- ctx.Write(r);
- ctx.Write(g);
- ctx.Write(b);
- ctx.Write(a);
- }
- //--------------------------------------------
- if (IsVariableSet(VARIABLE_CLEANNESS))
- {
- ctx.Write(GetCleanness());
- }
- }
-
- override bool ReadVarsFromCTX(ParamsReadContext ctx, int version = -1)//with ID optimization
- {
- if (!super.ReadVarsFromCTX(ctx,version))
- return false;
-
- int intValue;
- float value;
-
- if (version < 140)
- {
- if (!ctx.Read(intValue))
- return false;
-
- m_VariablesMask = intValue;
- }
-
- if (m_VariablesMask & VARIABLE_QUANTITY)
- {
- if (!ctx.Read(value))
- return false;
-
- if (IsStoreLoad())
- {
- SetStoreLoadedQuantity(value);
- }
- else
- {
- SetQuantity(value, true, false, false, false);
- }
- }
- //--------------------------------------------
- if (version < 140)
- {
- if (m_VariablesMask & VARIABLE_TEMPERATURE)
- {
- if (!ctx.Read(value))
- return false;
- SetTemperatureDirect(value);
- }
- }
- //--------------------------------------------
- if (m_VariablesMask & VARIABLE_WET)
- {
- if (!ctx.Read(value))
- return false;
- SetWet(value);
- }
- //--------------------------------------------
- if (m_VariablesMask & VARIABLE_LIQUIDTYPE)
- {
- if (!ctx.Read(intValue))
- return false;
- SetLiquidType(intValue);
- }
- //--------------------------------------------
- if (m_VariablesMask & VARIABLE_COLOR)
- {
- int r,g,b,a;
- if (!ctx.Read(r))
- return false;
- if (!ctx.Read(g))
- return false;
- if (!ctx.Read(b))
- return false;
- if (!ctx.Read(a))
- return false;
-
- SetColor(r,g,b,a);
- }
- //--------------------------------------------
- if (m_VariablesMask & VARIABLE_CLEANNESS)
- {
- if (!ctx.Read(intValue))
- return false;
- SetCleanness(intValue);
- }
- //--------------------------------------------
- if (version >= 138 && version < 140)
- {
- if (m_VariablesMask & VARIABLE_TEMPERATURE)
- {
- if (!ctx.Read(intValue))
- return false;
- SetFrozen(intValue);
- }
- }
-
- return true;
- }
- //----------------------------------------------------------------
- override bool OnStoreLoad(ParamsReadContext ctx, int version)
- {
- m_IsStoreLoad = true;
- if (GetDamageSystemVersionChange() != -1 && version < GetDamageSystemVersionChange())
- {
- m_FixDamageSystemInit = true;
- }
-
- if (!super.OnStoreLoad(ctx, version))
- {
- m_IsStoreLoad = false;
- return false;
- }
-
- if (version >= 114)
- {
- bool hasQuickBarIndexSaved;
-
- if (!ctx.Read(hasQuickBarIndexSaved))
- {
- m_IsStoreLoad = false;
- return false;
- }
-
- if (hasQuickBarIndexSaved)
- {
- int itmQBIndex;
-
- //Load quickbar item bind
- if (!ctx.Read(itmQBIndex))
- {
- m_IsStoreLoad = false;
- return false;
- }
-
- PlayerBase parentPlayer = PlayerBase.Cast(GetHierarchyRootPlayer());
- if (itmQBIndex != -1 && parentPlayer)
- parentPlayer.SetLoadedQuickBarItemBind(this, itmQBIndex);
- }
- }
- else
- {
- // Backup of how it used to be
- PlayerBase player;
- int itemQBIndex;
- if (version == int.MAX)
- {
- if (!ctx.Read(itemQBIndex))
- {
- m_IsStoreLoad = false;
- return false;
- }
- }
- else if (Class.CastTo(player, GetHierarchyRootPlayer()))
- {
- //Load quickbar item bind
- if (!ctx.Read(itemQBIndex))
- {
- m_IsStoreLoad = false;
- return false;
- }
- if (itemQBIndex != -1 && player)
- player.SetLoadedQuickBarItemBind(this,itemQBIndex);
- }
- }
-
- if (version < 140)
- {
- // variable management system
- if (!LoadVariables(ctx, version))
- {
- m_IsStoreLoad = false;
- return false;
- }
- }
-
- //agent trasmission system
- if (!LoadAgents(ctx, version))
- {
- m_IsStoreLoad = false;
- return false;
- }
- if (version >= 132)
- {
- RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
- if (raib)
- {
- if (!raib.OnStoreLoad(ctx,version))
- {
- m_IsStoreLoad = false;
- return false;
- }
- }
- }
- m_IsStoreLoad = false;
- return true;
- }
- //----------------------------------------------------------------
- override void OnStoreSave(ParamsWriteContext ctx)
- {
- super.OnStoreSave(ctx);
-
- PlayerBase player;
- if (PlayerBase.CastTo(player,GetHierarchyRootPlayer()))
- {
- ctx.Write(true); // Keep track of if we should actually read this in or not
- //Save quickbar item bind
- int itemQBIndex = -1;
- itemQBIndex = player.FindQuickBarEntityIndex(this);
- ctx.Write(itemQBIndex);
- }
- else
- {
- ctx.Write(false); // Keep track of if we should actually read this in or not
- }
-
- SaveAgents(ctx);//agent trasmission system
-
- RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
- if (raib)
- {
- raib.OnStoreSave(ctx);
- }
- }
- //----------------------------------------------------------------
- override void AfterStoreLoad()
- {
- super.AfterStoreLoad();
-
- if (m_FixDamageSystemInit)
- {
- PerformDamageSystemReinit();
- }
- if (GetStoreLoadedQuantity() != float.LOWEST)
- {
- SetQuantity(GetStoreLoadedQuantity());
- SetStoreLoadedQuantity(float.LOWEST);//IMPORTANT to do this !! we use 'm_StoreLoadedQuantity' inside SetQuantity to distinguish between initial quantity setting and the consequent(normal gameplay) calls
- }
- }
-
- override void EEOnAfterLoad()
- {
- super.EEOnAfterLoad();
-
- if (m_FixDamageSystemInit)
- {
- m_FixDamageSystemInit = false;
- }
-
- if (GetRemotelyActivatedItemBehaviour())
- GetRemotelyActivatedItemBehaviour().OnAfterLoad();
- }
-
- bool CanBeDisinfected()
- {
- return false;
- }
-
-
- //----------------------------------------------------------------
- override void OnVariablesSynchronized()
- {
- if (m_Initialized)
- {
- #ifdef PLATFORM_CONSOLE
- //bruteforce it is
- if (IsSplitable())
- {
- UIScriptedMenu menu = GetGame().GetUIManager().FindMenu(MENU_INVENTORY);
- if (menu)
- {
- menu.Refresh();
- }
- }
- #endif
- }
-
- if (CanPlayDeployLoopSound())
- {
- PlayDeployLoopSoundEx();
- }
-
- if (m_DeployLoopSoundEx && !CanPlayDeployLoopSound())
- {
- StopDeployLoopSoundEx();
- }
-
- if (IsDeploySound())
- {
- PlayDeploySound();
- }
-
- if (!dBodyIsDynamic(this) && m_WantPlayImpactSound)
- {
- PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash);
- m_WantPlayImpactSound = false;
- }
-
- if (m_VarQuantity != m_VarQuantityPrev)
- {
- SetWeightDirty();
- m_VarQuantityPrev = m_VarQuantity;
- }
- if (m_VarWet != m_VarWetPrev)
- {
- OnWetChanged(m_VarWet,m_VarWetPrev);
- m_VarWetPrev = m_VarWet;
- }
-
- super.OnVariablesSynchronized();
- }
- //------------------------- Quantity
- //----------------------------------------------------------------
- //! Set item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity reaches varQuantityMin or lower and the item config contains the varQuantityDestroyOnMin = true entry, the item gets destroyed. destroy_forced = true means item gets destroyed when quantity reaches varQuantityMin or lower regardless of config setting, returns true if the item gets deleted
- override bool SetQuantity(float value, bool destroy_config = true, bool destroy_forced = false, bool allow_client = false, bool clamp_to_stack_max = true)
- {
- if (!IsServerCheck(allow_client))
- return false;
-
- if (!HasQuantity())
- return false;
-
- float min = GetQuantityMin();
- float max = GetQuantityMax();
-
- if (value <= (min + 0.001))
- value = min;
-
- if (value == min)
- {
- if (destroy_config)
- {
- bool dstr = ConfigGetBool("varQuantityDestroyOnMin");
- if (dstr)
- {
- m_VarQuantity = Math.Clamp(value, min, max);
- this.Delete();
- return true;
- }
- }
- else if (destroy_forced)
- {
- m_VarQuantity = Math.Clamp(value, min, max);
- this.Delete();
- return true;
- }
- // we get here if destroy_config IS true AND dstr(config destroy param) IS false;
- RemoveAllAgents();//we remove all agents when we got to the min value, but the item is not getting deleted
- }
-
- float delta = m_VarQuantity;
- m_VarQuantity = Math.Clamp(value, min, max);
-
- if (GetStoreLoadedQuantity() == float.LOWEST)//any other value means we are setting quantity from storage
- {
- delta = m_VarQuantity - delta;
-
- if (delta)
- OnQuantityChanged(delta);
- }
-
- SetVariableMask(VARIABLE_QUANTITY);
-
- return false;
- }
- //----------------------------------------------------------------
- //! add item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity reaches varQuantityMin or lower and the item config contains the varQuantityDestroyOnMin = true entry, the item gets destroyed. destroy_forced = true means item gets destroyed when quantity reaches varQuantityMin or lower regardless of config setting, returns true if the item gets deleted
- bool AddQuantity(float value, bool destroy_config = true, bool destroy_forced = false)
- {
- return SetQuantity(GetQuantity() + value, destroy_config, destroy_forced);
- }
- //----------------------------------------------------------------
- void SetQuantityMax()
- {
- float max = GetQuantityMax();
- SetQuantity(max);
- }
-
- override void SetQuantityToMinimum()
- {
- float min = GetQuantityMin();
- SetQuantity(min);
- }
- //----------------------------------------------------------------
- //! Sets quantity in normalized 0..1 form between the item's Min a Max values as defined by item's config(for Min 0 and Max 5000, setting 0.5 will result in value 2500)
- void SetQuantityNormalized(float value, bool destroy_config = true, bool destroy_forced = false)
- {
- float value_clamped = Math.Clamp(value, 0, 1);//just to make sure
- int result = Math.Round(Math.Lerp(GetQuantityMin(), GetQuantityMax(), value_clamped));
- SetQuantity(result, destroy_config, destroy_forced);
- }
-
- //----------------------------------------------------------------
- //! Gets quantity in normalized 0..1 form between the item's Min a Max values as defined by item's config(for Min 0 and Max 5000, value 2500 will result in 0.5)
- override float GetQuantityNormalized()
- {
- return Math.InverseLerp(GetQuantityMin(), GetQuantityMax(),m_VarQuantity);
- }
-
- float GetQuantityNormalizedScripted()
- {
- return GetQuantityNormalized();
- }
- /*void SetAmmoNormalized(float value)
- {
- float value_clamped = Math.Clamp(value, 0, 1);
- Magazine this_mag = Magazine.Cast(this);
- int max_rounds = this_mag.GetAmmoMax();
- int result = value * max_rounds;//can the rounded if higher precision is required
- this_mag.SetAmmoCount(result);
- }*/
- //----------------------------------------------------------------
- override int GetQuantityMax()
- {
- int slot = -1;
- if (GetInventory())
- {
- InventoryLocation il = new InventoryLocation;
- GetInventory().GetCurrentInventoryLocation(il);
- slot = il.GetSlot();
- }
-
- return GetTargetQuantityMax(slot);
- }
-
- override int GetTargetQuantityMax(int attSlotID = -1)
- {
- float quantity_max = 0;
-
- if (IsSplitable()) //only stackable/splitable items can check for stack size
- {
- if (attSlotID != -1)
- quantity_max = InventorySlots.GetStackMaxForSlotId(attSlotID);
-
- if (quantity_max <= 0)
- quantity_max = m_VarStackMax;
- }
-
- if (quantity_max <= 0)
- quantity_max = m_VarQuantityMax;
- return quantity_max;
- }
- //----------------------------------------------------------------
- override int GetQuantityMin()
- {
- return m_VarQuantityMin;
- }
- //----------------------------------------------------------------
- int GetQuantityInit()
- {
- return m_VarQuantityInit;
- }
-
- //----------------------------------------------------------------
- override bool HasQuantity()
- {
- return !(GetQuantityMax() - GetQuantityMin() == 0);
- }
- override float GetQuantity()
- {
- return m_VarQuantity;
- }
-
- bool IsFullQuantity()
- {
- return GetQuantity() >= GetQuantityMax();
- }
-
- //Calculates weight of single item without attachments and cargo
- override float GetSingleInventoryItemWeightEx()
- {
- //this needs to be first stored inside local variables, when returned directly during inside return call, the result is completely different due to enforce script bug
- float weightEx = GetWeightEx();//overall weight of the item
- float special = GetInventoryAndCargoWeight();//cargo and attachment weight
- return weightEx - special;
- }
- // Obsolete, use GetSingleInventoryItemWeightEx() instead
- float GetSingleInventoryItemWeight()
- {
- return GetSingleInventoryItemWeightEx();
- }
-
- override protected float GetWeightSpecialized(bool forceRecalc = false)
- {
- if (IsSplitable()) //quantity determines size of the stack
- {
- #ifdef DEVELOPER
- if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
- {
- WeightDebugData data1 = WeightDebug.GetWeightDebug(this);
- data1.SetCalcDetails("TIB1: " + GetConfigWeightModifiedDebugText() +" * " + GetQuantity()+"(quantity)");
- }
- #endif
-
- return GetQuantity() * GetConfigWeightModified();
- }
- else if (HasEnergyManager())// items with energy manager
- {
- #ifdef DEVELOPER
- if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
- {
- WeightDebugData data2 = WeightDebug.GetWeightDebug(this);
- data2.SetCalcDetails("TIB2: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetCompEM().GetEnergy()+"(energy) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit)");
- }
- #endif
- return super.GetWeightSpecialized(forceRecalc) + (GetCompEM().GetEnergy() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
- }
- else//everything else
- {
- #ifdef DEVELOPER
- if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
- {
- WeightDebugData data3 = WeightDebug.GetWeightDebug(this);
- data3.SetCalcDetails("TIB3: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetQuantity()+"(quantity) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit))");
- }
- #endif
- return super.GetWeightSpecialized(forceRecalc) + (GetQuantity() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
- }
- }
- //! Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
- int GetNumberOfItems()
- {
- int item_count = 0;
- ItemBase item;
-
- if (GetInventory().GetCargo() != NULL)
- {
- item_count = GetInventory().GetCargo().GetItemCount();
- }
-
- for (int i = 0; i < GetInventory().AttachmentCount(); i++)
- {
- Class.CastTo(item,GetInventory().GetAttachmentFromIndex(i));
- if (item)
- item_count += item.GetNumberOfItems();
- }
- return item_count;
- }
-
- //! Obsolete, use GetWeightEx instead
- float GetUnitWeight(bool include_wetness = true)
- {
- float weight = 0;
- float wetness = 1;
- if (include_wetness)
- wetness += GetWet();
- if (IsSplitable()) //quantity determines size of the stack
- {
- weight = wetness * m_ConfigWeight;
- }
- else if (IsLiquidContainer()) //is a liquid container, default liquid weight is set to 1. May revisit later?
- {
- weight = 1;
- }
- return weight;
- }
-
- //-----------------------------------------------------------------
-
- override void ClearInventory()
- {
- if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && GetInventory())
- {
- GameInventory inv = GetInventory();
- array<EntityAI> items = new array<EntityAI>;
- inv.EnumerateInventory(InventoryTraversalType.INORDER, items);
- for (int i = 0; i < items.Count(); i++)
- {
- ItemBase item = ItemBase.Cast(items.Get(i));
- if (item)
- {
- GetGame().ObjectDelete(item);
- }
- }
- }
- }
-
- //------------------------- Energy
- //----------------------------------------------------------------
- float GetEnergy()
- {
- float energy = 0;
- if (HasEnergyManager())
- {
- energy = GetCompEM().GetEnergy();
- }
- return energy;
- }
-
-
- override void OnEnergyConsumed()
- {
- super.OnEnergyConsumed();
-
- ConvertEnergyToQuantity();
- }
- override void OnEnergyAdded()
- {
- super.OnEnergyAdded();
-
- ConvertEnergyToQuantity();
- }
-
- // Converts energy (from Energy Manager) to quantity, if enabled.
- void ConvertEnergyToQuantity()
- {
- if (GetGame().IsServer() && HasEnergyManager() && GetCompEM().HasConversionOfEnergyToQuantity())
- {
- if (HasQuantity())
- {
- float energy_0to1 = GetCompEM().GetEnergy0To1();
- SetQuantityNormalized(energy_0to1);
- }
- }
- }
- //----------------------------------------------------------------
- float GetHeatIsolationInit()
- {
- return ConfigGetFloat("heatIsolation");
- }
- float GetHeatIsolation()
- {
- return m_HeatIsolation;
- }
- float GetDryingIncrement(string pIncrementName)
- {
- string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Drying %2", GetType(), pIncrementName);
- if (GetGame().ConfigIsExisting(paramPath))
- return GetGame().ConfigGetFloat(paramPath);
-
- return 0.0;
- }
-
- float GetSoakingIncrement(string pIncrementName)
- {
- string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Soaking %2", GetType(), pIncrementName);
- if (GetGame().ConfigIsExisting(paramPath))
- return GetGame().ConfigGetFloat(paramPath);
-
- return 0.0;
- }
- //----------------------------------------------------------------
- override void SetWet(float value, bool allow_client = false)
- {
- if (!IsServerCheck(allow_client))
- return;
-
- float min = GetWetMin();
- float max = GetWetMax();
-
- float previousValue = m_VarWet;
-
- m_VarWet = Math.Clamp(value, min, max);
-
- if (previousValue != m_VarWet)
- {
- SetVariableMask(VARIABLE_WET);
- OnWetChanged(m_VarWet, previousValue);
- }
- }
- //----------------------------------------------------------------
- override void AddWet(float value)
- {
- SetWet(GetWet() + value);
- }
- //----------------------------------------------------------------
- override void SetWetMax()
- {
- SetWet(m_VarWetMax);
- }
- //----------------------------------------------------------------
- override float GetWet()
- {
- return m_VarWet;
- }
- //----------------------------------------------------------------
- override float GetWetMax()
- {
- return m_VarWetMax;
- }
- //----------------------------------------------------------------
- override float GetWetMin()
- {
- return m_VarWetMin;
- }
- //----------------------------------------------------------------
- override float GetWetInit()
- {
- return m_VarWetInit;
- }
- //----------------------------------------------------------------
- override void OnWetChanged(float newVal, float oldVal)
- {
- EWetnessLevel newLevel = GetWetLevelInternal(newVal);
- EWetnessLevel oldLevel = GetWetLevelInternal(oldVal);
- if (newLevel != oldLevel)
- {
- OnWetLevelChanged(newLevel,oldLevel);
- }
- }
-
- override void OnWetLevelChanged(EWetnessLevel newLevel, EWetnessLevel oldLevel)
- {
- SetWeightDirty();
- }
-
- override EWetnessLevel GetWetLevel()
- {
- return GetWetLevelInternal(m_VarWet);
- }
- //----------------------------------------------------------------
-
- override void SetStoreLoad(bool value)
- {
- m_IsStoreLoad = value;
- }
-
- override bool IsStoreLoad()
- {
- return m_IsStoreLoad;
- }
-
- override void SetStoreLoadedQuantity(float value)
- {
- m_StoreLoadedQuantity = value;
- }
-
- override float GetStoreLoadedQuantity()
- {
- return m_StoreLoadedQuantity;
- }
-
- //----------------------------------------------------------------
-
- float GetItemModelLength()
- {
- if (ConfigIsExisting("itemModelLength"))
- {
- return ConfigGetFloat("itemModelLength");
- }
- return 0;
- }
-
- float GetItemAttachOffset()
- {
- if (ConfigIsExisting("itemAttachOffset"))
- {
- return ConfigGetFloat("itemAttachOffset");
- }
- return 0;
- }
-
- override void SetCleanness(int value, bool allow_client = false)
- {
- if (!IsServerCheck(allow_client))
- return;
-
- int previousValue = m_Cleanness;
-
- m_Cleanness = Math.Clamp(value, m_CleannessMin, m_CleannessMax);
-
- if (previousValue != m_Cleanness)
- SetVariableMask(VARIABLE_CLEANNESS);
- }
-
- override int GetCleanness()
- {
- return m_Cleanness;
- }
-
- bool AllowFoodConsumption()
- {
- return true;
- }
-
- //----------------------------------------------------------------
- // ATTACHMENT LOCKING
- // Getters relevant to generic ActionLockAttachment
- int GetLockType()
- {
- return m_LockType;
- }
-
- string GetLockSoundSet()
- {
- return m_LockSoundSet;
- }
- //----------------------------------------------------------------
- //------------------------- Color
- // sets items color variable given color components
- override void SetColor(int r, int g, int b, int a)
- {
- m_ColorComponentR = r;
- m_ColorComponentG = g;
- m_ColorComponentB = b;
- m_ColorComponentA = a;
- SetVariableMask(VARIABLE_COLOR);
- }
- //! gets item's color variable as components
- override void GetColor(out int r,out int g,out int b,out int a)
- {
- r = m_ColorComponentR;
- g = m_ColorComponentG;
- b = m_ColorComponentB;
- a = m_ColorComponentA;
- }
-
- bool IsColorSet()
- {
- return IsVariableSet(VARIABLE_COLOR);
- }
-
- //! Returns item's PROCEDURAL color as formated string, i.e. "#(argb,8,8,3)color(0.15,0.15,0.15,1.0,CO)"
- string GetColorString()
- {
- int r,g,b,a;
- GetColor(r,g,b,a);
- r = r/255;
- g = g/255;
- b = b/255;
- a = a/255;
- return MiscGameplayFunctions.GetColorString(r, g, b, a);
- }
- //----------------------------------------------------------------
- //------------------------- LiquidType
- override void SetLiquidType(int value, bool allow_client = false)
- {
- if (!IsServerCheck(allow_client))
- return;
-
- int old = m_VarLiquidType;
- m_VarLiquidType = value;
- OnLiquidTypeChanged(old,value);
- SetVariableMask(VARIABLE_LIQUIDTYPE);
- }
-
- int GetLiquidTypeInit()
- {
- return ConfigGetInt("varLiquidTypeInit");
- }
-
- override int GetLiquidType()
- {
- return m_VarLiquidType;
- }
-
- protected void OnLiquidTypeChanged(int oldType, int newType)
- {
- if (newType == LIQUID_NONE && GetIsFrozen())
- SetFrozen(false);
- }
- //! To be called on moving item within character's inventory; 'player' should never be null
- void UpdateQuickbarShortcutVisibility(PlayerBase player)
- {
- player.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
- }
-
- // -------------------------------------------------------------------------
- //! Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
- void OnInventoryEnter(Man player)
- {
- PlayerBase nplayer;
- if (PlayerBase.CastTo(nplayer, player))
- {
- m_CanPlayImpactSound = true;
- //nplayer.OnItemInventoryEnter(this);
- nplayer.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
- }
- }
-
- // -------------------------------------------------------------------------
- //! Event called on item when it is removed from the player(Man) inventory, passes the old owner as a parameter
- void OnInventoryExit(Man player)
- {
- PlayerBase nplayer;
- if (PlayerBase.CastTo(nplayer,player))
- {
- //nplayer.OnItemInventoryExit(this);
- nplayer.SetEnableQuickBarEntityShortcut(this,false);
- }
-
- //if (!GetGame().IsDedicatedServer())
- player.GetHumanInventory().ClearUserReservedLocationForContainer(this);
-
-
- if (HasEnergyManager())
- {
- GetCompEM().UpdatePlugState(); // Unplug the el. device if it's necesarry.
- }
- }
- // ADVANCED PLACEMENT EVENTS
- override void OnPlacementStarted(Man player)
- {
- super.OnPlacementStarted(player);
-
- SetTakeable(false);
- }
-
- override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
- {
- if (m_AdminLog)
- {
- m_AdminLog.OnPlacementComplete(player, this);
- }
- if (GetGame().IsServer())
- {
- SetIsDeploySound(true);
- }
- super.OnPlacementComplete(player, position, orientation);
- }
-
- //-----------------------------
- // AGENT SYSTEM
- //-----------------------------
- //--------------------------------------------------------------------------
- bool ContainsAgent(int agent_id)
- {
- if (agent_id & m_AttachedAgents)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //--------------------------------------------------------------------------
- override void RemoveAgent(int agent_id)
- {
- if (ContainsAgent(agent_id))
- {
- m_AttachedAgents = ~agent_id & m_AttachedAgents;
- }
- }
- //--------------------------------------------------------------------------
- override void RemoveAllAgents()
- {
- m_AttachedAgents = 0;
- }
- //--------------------------------------------------------------------------
- override void RemoveAllAgentsExcept(int agents_to_keep_mask)
- {
- m_AttachedAgents = m_AttachedAgents & agent_to_keep;
- }
- // -------------------------------------------------------------------------
- override void InsertAgent(int agent, float count = 1)
- {
- if (count < 1)
- return;
- //Debug.Log("Inserting Agent on item: " + agent.ToString() +" count: " + count.ToString());
- m_AttachedAgents = (agent | m_AttachedAgents);
- }
-
- //!transfer agents from another item
- void TransferAgents(int agents)
- {
- m_AttachedAgents = (m_AttachedAgents | agents);
- }
-
- // -------------------------------------------------------------------------
- override int GetAgents()
- {
- return m_AttachedAgents;
- }
- //----------------------------------------------------------------------
-
- /*int GetContaminationType()
- {
- int contamination_type;
-
- const int CONTAMINATED_MASK = eAgents.CHOLERA | eAgents.INFLUENZA | eAgents.SALMONELLA | eAgents.BRAIN;
- const int POISONED_MASK = eAgents.FOOD_POISON | eAgents.CHEMICAL_POISON;
- const int NERVE_GAS_MASK = eAgents.CHEMICAL_POISON;
- const int DIRTY_MASK = eAgents.WOUND_AGENT;
-
- Edible_Base edible = Edible_Base.Cast(this);
- int agents = GetAgents();
- if (edible)
- {
- NutritionalProfile profile = Edible_Base.GetNutritionalProfile(edible);
- if (profile)
- {
- agents = agents | profile.GetAgents();//merge item's agents with nutritional agents
- }
- }
- if (agents & CONTAMINATED_MASK)
- {
- contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_CONTAMINATED;
- }
- if (agents & POISONED_MASK)
- {
- contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_POISONED;
- }
- if (agents & NERVE_GAS_MASK)
- {
- contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_NERVE_GAS;
- }
- if (agents & DIRTY_MASK)
- {
- contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_DIRTY;
- }
-
- return agents;
- }*/
-
- // -------------------------------------------------------------------------
- bool LoadAgents(ParamsReadContext ctx, int version)
- {
- if (!ctx.Read(m_AttachedAgents))
- return false;
- return true;
- }
- // -------------------------------------------------------------------------
- void SaveAgents(ParamsWriteContext ctx)
- {
-
- ctx.Write(m_AttachedAgents);
- }
- // -------------------------------------------------------------------------
-
- //! Roof check for entity, limited by time (anti-spam solution)
- override void CheckForRoofLimited(float timeTresholdMS = 3000)
- {
- super.CheckForRoofLimited(timeTresholdMS);
-
- float time = GetGame().GetTime();
- if ((time - m_PreviousRoofTestTime) >= timeTresholdMS)
- {
- m_PreviousRoofTestTime = time;
- SetRoofAbove(MiscGameplayFunctions.IsUnderRoof(this));
- }
- }
-
- // returns item's protection level against enviromental hazard, for masks with filters, returns the filters protection for valid filter, otherwise 0
- float GetProtectionLevel(int type, bool consider_filter = false, int system = 0)
- {
- if (IsDamageDestroyed() || (HasQuantity() && GetQuantity() <= 0))
- {
- return 0;
- }
-
- if (GetInventory().GetAttachmentSlotsCount() != 0)//is it an item with attachable filter ?
- {
- ItemBase filter = ItemBase.Cast(FindAttachmentBySlotName("GasMaskFilter"));
- if (filter)
- return filter.GetProtectionLevel(type, false, system);//it's a valid filter, return the protection
- else
- return 0;//otherwise return 0 when no filter attached
- }
- string subclassPath, entryName;
- switch (type)
- {
- case DEF_BIOLOGICAL:
- entryName = "biological";
- break;
- case DEF_CHEMICAL:
- entryName = "chemical";
- break;
- default:
- entryName = "biological";
- break;
- }
-
- subclassPath = "CfgVehicles " + this.GetType() + " Protection ";
-
- return GetGame().ConfigGetFloat(subclassPath + entryName);
- }
-
-
-
- //! Called when entity is being created as new by CE/ Debug
- override void EEOnCECreate()
- {
- if (!IsMagazine())
- SetCEBasedQuantity();
- SetZoneDamageCEInit();
- }
-
-
- //-------------------------
- // OPEN/CLOSE USER ACTIONS
- //-------------------------
- //! Implementations only
- void Open();
- void Close();
- bool IsOpen()
- {
- return true;
- }
- override bool CanDisplayCargo()
- {
- return IsOpen();
- }
-
-
- // ------------------------------------------------------------
- // CONDITIONS
- // ------------------------------------------------------------
- override bool CanPutInCargo(EntityAI parent)
- {
- if (parent)
- {
- if (parent.IsInherited(DayZInfected))
- return true;
- if (!parent.IsRuined())
- return true;
- }
-
- return true;
- }
-
- override bool CanPutAsAttachment(EntityAI parent)
- {
- if (!super.CanPutAsAttachment(parent))
- {
- return false;
- }
-
- if (!IsRuined() && !parent.IsRuined())
- {
- return true;
- }
- return false;
- }
- override bool CanReceiveItemIntoCargo(EntityAI item)
- {
- //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
- //if (GetHealthLevel() == GameConstants.STATE_RUINED)
- // return false;
-
- return super.CanReceiveItemIntoCargo(item);
- }
- override bool CanReceiveAttachment(EntityAI attachment, int slotId)
- {
- //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
- //if (GetHealthLevel() == GameConstants.STATE_RUINED)
- // return false;
-
- GameInventory attachmentInv = attachment.GetInventory();
- if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
- {
- if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
- return false;
- }
-
- InventoryLocation loc = new InventoryLocation();
- attachment.GetInventory().GetCurrentInventoryLocation(loc);
- if (loc && loc.IsValid() && !GetInventory().AreChildrenAccessible())
- return false;
-
- return super.CanReceiveAttachment(attachment, slotId);
- }
-
- override bool CanReleaseAttachment(EntityAI attachment)
- {
- if (!super.CanReleaseAttachment(attachment))
- return false;
-
- return GetInventory().AreChildrenAccessible();
- }
-
- /*override bool CanLoadAttachment(EntityAI attachment)
- {
- //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
- //if (GetHealthLevel() == GameConstants.STATE_RUINED)
- // return false;
-
- GameInventory attachmentInv = attachment.GetInventory();
- if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
- {
- bool boo = (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase));
- ErrorEx("CanLoadAttachment | this: " + this + " | attachment: " + attachment + " | boo: " + boo,ErrorExSeverity.INFO);
-
- if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
- return false;
- }
-
- return super.CanLoadAttachment(attachment);
- }*/
-
- // Plays muzzle flash particle effects
- static void PlayFireParticles(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- int id = muzzle_owner.GetMuzzleID();
- array<ref WeaponParticlesOnFire> WPOF_array = m_OnFireEffect.Get(id);
-
- if (WPOF_array)
- {
- for (int i = 0; i < WPOF_array.Count(); i++)
- {
- WeaponParticlesOnFire WPOF = WPOF_array.Get(i);
-
- if (WPOF)
- {
- WPOF.OnActivate(weapon, muzzle_index, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
- }
- }
-
- // Plays bullet eject particle effects (usually just smoke, the bullet itself is a 3D model and is not part of this function)
- static void PlayBulletCasingEjectParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- int id = muzzle_owner.GetMuzzleID();
- array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = m_OnBulletCasingEjectEffect.Get(id);
-
- if (WPOBE_array)
- {
- for (int i = 0; i < WPOBE_array.Count(); i++)
- {
- WeaponParticlesOnBulletCasingEject WPOBE = WPOBE_array.Get(i);
-
- if (WPOBE)
- {
- WPOBE.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
- }
- }
-
- // Plays all weapon overheating particles
- static void PlayOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- int id = muzzle_owner.GetMuzzleID();
- array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
-
- if (WPOOH_array)
- {
- for (int i = 0; i < WPOOH_array.Count(); i++)
- {
- WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
-
- if (WPOOH)
- {
- WPOOH.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
- }
- }
-
- // Updates all weapon overheating particles
- static void UpdateOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- int id = muzzle_owner.GetMuzzleID();
- array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
-
- if (WPOOH_array)
- {
- for (int i = 0; i < WPOOH_array.Count(); i++)
- {
- WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
-
- if (WPOOH)
- {
- WPOOH.OnUpdate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
- }
- }
-
- // Stops overheating particles
- static void StopOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
- {
- int id = muzzle_owner.GetMuzzleID();
- array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
-
- if (WPOOH_array)
- {
- for (int i = 0; i < WPOOH_array.Count(); i++)
- {
- WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
-
- if (WPOOH)
- {
- WPOOH.OnDeactivate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
- }
- }
- }
- }
-
- //----------------------------------------------------------------
- //Item Behaviour - unified approach
- override bool IsHeavyBehaviour()
- {
- if (m_ItemBehaviour == 0)
- {
- return true;
- }
-
- return false;
- }
-
- override bool IsOneHandedBehaviour()
- {
- if (m_ItemBehaviour == 1)
- {
- return true;
- }
-
- return false;
- }
-
- override bool IsTwoHandedBehaviour()
- {
- if (m_ItemBehaviour == 2)
- {
- return true;
- }
-
- return false;
- }
-
- bool IsDeployable()
- {
- return false;
- }
-
- //!how long it takes to deploy this item in seconds
- float GetDeployTime()
- {
- return UATimeSpent.DEFAULT_DEPLOY;
- }
-
- //----------------------------------------------------------------
- // Item Targeting (User Actions)
- override void SetTakeable(bool pState)
- {
- m_IsTakeable = pState;
- SetSynchDirty();
- }
- override bool IsTakeable()
- {
- return m_IsTakeable;
- }
-
- // For cases where we want to show object widget which cant be taken to hands
- bool IsActionTargetVisible()
- {
- return false;
- }
- //! Attachment Sound Type getting from config file
- protected void PreLoadSoundAttachmentType()
- {
- string att_type = "None";
- if (ConfigIsExisting("soundAttType"))
- {
- att_type = ConfigGetString("soundAttType");
- }
-
- m_SoundAttType = att_type;
- }
-
- override string GetAttachmentSoundType()
- {
- return m_SoundAttType;
- }
-
- //----------------------------------------------------------------
- //SOUNDS FOR ADVANCED PLACEMNT
- //----------------------------------------------------------------
-
- void SoundSynchRemoteReset()
- {
- m_IsSoundSynchRemote = false;
-
- SetSynchDirty();
- }
-
- void SoundSynchRemote()
- {
- m_IsSoundSynchRemote = true;
-
- SetSynchDirty();
- }
-
- bool IsSoundSynchRemote()
- {
- return m_IsSoundSynchRemote;
- }
-
- string GetDeploySoundset();
- string GetPlaceSoundset();
- string GetLoopDeploySoundset();
- string GetDeployFinishSoundset();
-
- void SetIsPlaceSound(bool is_place_sound)
- {
- m_IsPlaceSound = is_place_sound;
- }
-
- bool IsPlaceSound()
- {
- return m_IsPlaceSound;
- }
-
- void SetIsDeploySound(bool is_deploy_sound)
- {
- m_IsDeploySound = is_deploy_sound;
- }
-
- bool IsDeploySound()
- {
- return m_IsDeploySound;
- }
-
- void PlayDeployLoopSoundEx()
- {
- if (!GetGame().IsDedicatedServer() && !m_DeployLoopSoundEx)
- {
- m_DeployLoopSoundEx = SEffectManager.PlaySound(GetLoopDeploySoundset(), GetPosition());
- if (m_DeployLoopSoundEx)
- m_DeployLoopSoundEx.SetAutodestroy(true);
- else
- Debug.Log("null m_DeployLoopSoundEx from sound set: " + GetLoopDeploySoundset());
- }
- }
-
- void StopDeployLoopSoundEx()
- {
- if (!GetGame().IsDedicatedServer())
- {
- m_DeployLoopSoundEx.SetSoundFadeOut(0.5);
- m_DeployLoopSoundEx.SoundStop();
- }
- }
-
- void PlayDeploySound()
- {
- if (!GetGame().IsDedicatedServer() && !m_SoundDeploy)
- {
- m_SoundDeploy = SEffectManager.PlaySound(GetDeploySoundset(), GetPosition());
- if (m_SoundDeploy)
- m_SoundDeploy.SetAutodestroy(true);
- else
- Debug.Log("null m_SoundDeploy from sound set: " + GetDeploySoundset());
- }
- }
-
- void PlayDeployFinishSound()
- {
- if (!GetGame().IsDedicatedServer() && !m_SoundDeployFinish)
- {
- m_SoundDeployFinish = SEffectManager.PlaySound(GetDeployFinishSoundset(), GetPosition());
- if (m_SoundDeployFinish)
- m_SoundDeployFinish.SetAutodestroy(true);
- else
- Debug.Log("null m_SoundDeployFinish from sound set: " + GetDeployFinishSoundset());
- }
- }
-
- void PlayPlaceSound()
- {
- if (!GetGame().IsDedicatedServer() && !m_SoundPlace)
- {
- m_SoundPlace = SEffectManager.PlaySound(GetPlaceSoundset(), GetPosition());
- if (m_SoundPlace)
- m_SoundPlace.SetAutodestroy(true);
- else
- Debug.Log("null m_SoundPlace from sound set: " + GetPlaceSoundset());
- }
- }
-
- bool CanPlayDeployLoopSound()
- {
- return IsBeingPlaced() && IsSoundSynchRemote();
- }
-
- //! Plays sound on item attach. Be advised, the config structure may slightly change in 1.11 update to allow for more complex use.
- void PlayAttachSound(string slot_type)
- {
- if (!GetGame().IsDedicatedServer())
- {
- if (ConfigIsExisting("attachSoundSet"))
- {
- string cfg_path = "";
- string soundset = "";
- string type_name = GetType();
-
- TStringArray cfg_soundset_array = new TStringArray;
- TStringArray cfg_slot_array = new TStringArray;
- ConfigGetTextArray("attachSoundSet",cfg_soundset_array);
- ConfigGetTextArray("attachSoundSlot",cfg_slot_array);
-
- if (cfg_soundset_array.Count() > 0 && cfg_soundset_array.Count() == cfg_slot_array.Count())
- {
- for (int i = 0; i < cfg_soundset_array.Count(); i++)
- {
- if (cfg_slot_array[i] == slot_type)
- {
- soundset = cfg_soundset_array[i];
- break;
- }
- }
- }
-
- if (soundset != "")
- {
- EffectSound sound = SEffectManager.PlaySound(soundset, GetPosition());
- sound.SetAutodestroy(true);
- }
- }
- }
- }
-
- void PlayDetachSound(string slot_type)
- {
- //TODO - evaluate if needed and devise universal config structure if so
- }
-
- void OnApply(PlayerBase player);
-
- float GetBandagingEffectivity()
- {
- return 1.0;
- };
- //returns applicable selection
- array<string> GetHeadHidingSelection()
- {
- return m_HeadHidingSelections;
- }
-
- bool HidesSelectionBySlot()
- {
- return m_HideSelectionsBySlot;
- }
-
- WrittenNoteData GetWrittenNoteData() {};
-
- void StopItemDynamicPhysics()
- {
- SetDynamicPhysicsLifeTime(0.01);
- m_ItemBeingDroppedPhys = false;
- }
-
- void PerformDamageSystemReinit()
- {
- array<string> zone_names = new array<string>;
- GetDamageZones(zone_names);
- for (int i = 0; i < zone_names.Count(); i++)
- {
- SetHealthMax(zone_names.Get(i),"Health");
- }
- SetHealthMax("","Health");
- }
-
- //! Sets zone damages to match randomized global health set by CE (CE spawn only)
- void SetZoneDamageCEInit()
- {
- float global_health = GetHealth01("","Health");
- array<string> zones = new array<string>;
- GetDamageZones(zones);
- //set damage of all zones to match global health level
- for (int i = 0; i < zones.Count(); i++)
- {
- SetHealth01(zones.Get(i),"Health",global_health);
- }
- }
-
- //!DEPRECATED in use, but returns correct values nontheless. Check performed elsewhere
- bool IsCoverFaceForShave(string slot_name)
- {
- return IsExclusionFlagPresent(PlayerBase.GetFaceCoverageShaveValues());
- }
-
- void ProcessItemWetness(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
- {
- if (!hasRootAsPlayer)
- {
- if (refParentIB)
- {
- // parent is wet
- if ((refParentIB.GetWet() >= GameConstants.STATE_SOAKING_WET) && (m_VarWet < m_VarWetMax))
- AddWet(delta * GameConstants.WETNESS_RATE_WETTING_INSIDE);
- // parent has liquid inside
- else if ((refParentIB.GetLiquidType() != 0) && (refParentIB.GetQuantity() > 0) && (m_VarWet < m_VarWetMax))
- AddWet(delta * GameConstants.WETNESS_RATE_WETTING_LIQUID);
- // drying
- else if (m_VarWet > m_VarWetMin)
- AddWet(-1 * delta * GetDryingIncrement("ground") * 2);
- }
- else
- {
- // drying on ground or inside non-itembase (car, ...)
- if (m_VarWet > m_VarWetMin)
- AddWet(-1 * delta * GetDryingIncrement("ground"));
- }
- }
- }
-
- void ProcessItemTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
- {
- if (CanHaveTemperature() && !IsSelfAdjustingTemperature() && !GetHierarchyRoot().IsSelfAdjustingTemperature())
- {
- float target = g_Game.GetMission().GetWorldData().GetBaseEnvTemperatureAtObject(this);
- if (GetTemperature() != target)
- {
- float heatPermCoef = 1.0;
- EntityAI ent = this;
- while (ent)
- {
- heatPermCoef *= ent.GetHeatPermeabilityCoef();
- ent = ent.GetHierarchyParent();
- }
-
- SetTemperatureEx(new TemperatureDataInterpolated(target,ETemperatureAccessTypes.ACCESS_WORLD,delta,GameConstants.TEMP_COEF_WORLD,heatPermCoef));
- }
- }
- }
-
- void HierarchyCheck(out bool hasParent, out bool hasRootAsPlayer, out ItemBase refParentIB)
- {
- // hierarchy check for an item to decide whether it has some parent and it is in some player inventory
- EntityAI parent = GetHierarchyParent();
- if (!parent)
- {
- hasParent = false;
- hasRootAsPlayer = false;
- }
- else
- {
- hasParent = true;
- hasRootAsPlayer = (GetHierarchyRootPlayer() != null);
- refParentIB = ItemBase.Cast(parent);
- }
- }
-
- protected void ProcessDecay(float delta, bool hasRootAsPlayer)
- {
- // this is stub, implemented on Edible_Base
- }
-
- bool CanDecay()
- {
- // return true used on selected food clases so they can decay
- return false;
- }
-
- protected bool CanProcessDecay()
- {
- // this is stub, implemented on Edible_Base class
- // used to determine whether it is still necessary for the food to decay
- return false;
- }
-
- protected bool CanHaveWetness()
- {
- // return true used on selected items that have a wetness effect
- return false;
- }
-
- override void ProcessVariables()
- {
- bool hasParent = false, hasRootAsPlayer = false;
- ItemBase refParentIB;
-
- bool wwtu = g_Game.IsWorldWetTempUpdateEnabled();
- bool foodDecay = g_Game.IsFoodDecayEnabled();
-
- if (wwtu || foodDecay)
- {
- bool processWetness = wwtu && CanHaveWetness();
- bool processTemperature = wwtu && CanHaveTemperature();
- bool processDecay = foodDecay && CanDecay() && CanProcessDecay();
-
- if (processWetness || processTemperature || processDecay)
- {
- HierarchyCheck(hasParent, hasRootAsPlayer, refParentIB);
-
- if (processWetness)
- ProcessItemWetness(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
-
- if (processTemperature)
- ProcessItemTemperature(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
-
- if (processDecay)
- ProcessDecay(m_ElapsedSinceLastUpdate, hasRootAsPlayer);
- }
- }
- }
-
- //! Used in heat comfort calculations only!
- float GetTemperaturePerQuantityWeight()
- {
- return m_TemperaturePerQuantityWeight * GameConstants.ITEM_TEMPERATURE_QUANTITY_WEIGHT_MULTIPLIER;
- }
-
- override float GetTemperatureFreezeThreshold()
- {
- if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
- return Liquid.GetFreezeThreshold(GetLiquidType());
-
- return super.GetTemperatureFreezeThreshold();
- }
-
- override float GetTemperatureThawThreshold()
- {
- if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
- return Liquid.GetThawThreshold(GetLiquidType());
-
- return super.GetTemperatureThawThreshold();
- }
-
- override float GetItemOverheatThreshold()
- {
- if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
- return Liquid.GetBoilThreshold(GetLiquidType());
-
- return super.GetItemOverheatThreshold();
- }
-
- override float GetTemperatureFreezeTime()
- {
- if (HasQuantity())
- return Math.Lerp(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureFreezeTime()),GetQuantityNormalized());
-
- return super.GetTemperatureFreezeTime();
- }
-
- override float GetTemperatureThawTime()
- {
- if (HasQuantity())
- return Math.Lerp(GameConstants.TEMPERATURE_TIME_THAW_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureThawTime()),GetQuantityNormalized());
-
- return super.GetTemperatureThawTime();
- }
-
- void AffectLiquidContainerOnFill(int liquid_type, float amount);
-
- bool IsCargoException4x3(EntityAI item)
- {
- return (item.IsKindOf("Cauldron") || item.IsKindOf("Pot") || item.IsKindOf("FryingPan") || item.IsKindOf("SmallProtectorCase") || (item.IsKindOf("PortableGasStove") && item.FindAttachmentBySlotName("CookingEquipment")));
- }
-
- void CopyScriptPropertiesFrom(EntityAI oldItem)
- {
- MiscGameplayFunctions.TransferItemProperties(oldItem, this);
- }
-
- //! Adds a light source child
- void AddLightSourceItem(ItemBase lightsource)
- {
- m_LightSourceItem = lightsource;
- }
-
- void RemoveLightSourceItem()
- {
- m_LightSourceItem = null;
- }
-
- ItemBase GetLightSourceItem()
- {
- return m_LightSourceItem;
- }
-
- //! returns an array of possible finishers
- array<int> GetValidFinishers()
- {
- return null;
- }
-
- //! If we need a different (handheld)item action widget displayed, the logic goes in here
- bool GetActionWidgetOverride(out typename name)
- {
- return false;
- }
-
- bool PairWithDevice(notnull ItemBase otherDevice)
- {
- if (GetGame().IsServer())
- {
- ItemBase explosive = otherDevice;
- RemoteDetonatorTrigger trg = RemoteDetonatorTrigger.Cast(this);
- if (!trg)
- {
- trg = RemoteDetonatorTrigger.Cast(otherDevice);
- explosive = this;
- }
-
- explosive.PairRemote(trg);
- trg.SetControlledDevice(explosive);
-
- int persistentID = RemotelyActivatedItemBehaviour.GeneratePersistentID();
- trg.SetPersistentPairID(persistentID);
- explosive.SetPersistentPairID(persistentID);
-
- return true;
- }
- return false;
- }
-
- //! generic effectivity as a bait for animal catching
- float GetBaitEffectivity()
- {
- float ret = 1.0;
- if (HasQuantity())
- ret *= GetQuantityNormalized();
- ret *= GetHealth01();
-
- return ret;
- }
- #ifdef DEVELOPER
- override void SetDebugItem()
- {
- super.SetDebugItem();
- _itemBase = this;
- }
-
- override string GetDebugText()
- {
- string text = super.GetDebugText();
-
- text += string.Format("Heat isolation(raw): %1\n", GetHeatIsolation());
- text += string.Format("Heat isolation(modified): %1\n", MiscGameplayFunctions.GetCurrentItemHeatIsolation(this));
- return text;
- }
- #endif
-
- bool CanBeUsedForSuicide()
- {
- return true;
- }
-
- ///////////////////
- //DEPRECATED BELOW
- //////////////////
- // Backwards compatibility
- void ProcessItemWetnessAndTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
- {
- ProcessItemWetness(delta, hasParent, hasRootAsPlayer, refParentIB);
- ProcessItemTemperature(delta, hasParent, hasRootAsPlayer, refParentIB);
- }
- }
- EntityAI SpawnItemOnLocation(string object_name, notnull InventoryLocation loc, bool full_quantity)
- {
- EntityAI entity = SpawnEntity(object_name, loc, ECE_IN_INVENTORY, RF_DEFAULT);
- if (entity)
- {
- bool is_item = entity.IsInherited(ItemBase);
- if (is_item && full_quantity)
- {
- ItemBase item = ItemBase.Cast(entity);
- item.SetQuantity(item.GetQuantityInit());
- }
- }
- else
- {
- ErrorEx("Cannot spawn entity: " + object_name,ErrorExSeverity.INFO);
- return NULL;
- }
- return entity;
- }
- void SetupSpawnedItem(ItemBase item, float health, float quantity)
- {
- if (item)
- {
- if (health > 0)
- item.SetHealth("", "", health);
-
- if (item.CanHaveTemperature())
- {
- item.SetTemperatureDirect(GameConstants.ITEM_TEMPERATURE_NEUTRAL_ZONE_MIDDLE);
- if (item.CanFreeze())
- item.SetFrozen(false);
- }
-
- if (item.HasEnergyManager())
- {
- if (quantity >= 0)
- {
- item.GetCompEM().SetEnergy0To1(quantity);
- }
- else
- {
- item.GetCompEM().SetEnergy(Math.AbsFloat(quantity));
- }
- }
- else if (item.IsMagazine())
- {
- Magazine mag = Magazine.Cast(item);
- if (quantity >= 0)
- {
- mag.ServerSetAmmoCount(mag.GetAmmoMax() * quantity);
- }
- else
- {
- mag.ServerSetAmmoCount(Math.AbsFloat(quantity));
- }
-
- }
- else
- {
- if (quantity >= 0)
- {
- item.SetQuantityNormalized(quantity, false);
- }
- else
- {
- item.SetQuantity(Math.AbsFloat(quantity));
- }
-
- }
- }
- }
- #ifdef DEVELOPER
- ItemBase _itemBase;//watched item goes here(LCTRL+RMB->Watch)
- #endif
|