itembase.c 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854
  1. typedef ItemBase Inventory_Base;
  2. typedef map<typename,ref ActionOverrideData> TActionAnimOverrideMap;
  3. class DummyItem extends ItemBase
  4. {
  5. override bool CanPutAsAttachment(EntityAI parent)
  6. {
  7. return true;
  8. }
  9. };
  10. //const bool QUANTITY_DEBUG_REMOVE_ME = false;
  11. class ItemBase extends InventoryItem
  12. {
  13. static ref map<typename, ref TInputActionMap> m_ItemTypeActionsMap = new map<typename, ref TInputActionMap>;
  14. TInputActionMap m_InputActionMap;
  15. static ref map<typename, ref TActionAnimOverrideMap> m_ItemActionOverrides = new map<typename, ref TActionAnimOverrideMap>;
  16. bool m_ActionsInitialize;
  17. static int m_DebugActionsMask;
  18. bool m_RecipesInitialized;
  19. // ============================================
  20. // Variable Manipulation System
  21. // ============================================
  22. // Quantity
  23. float m_VarQuantity;
  24. float m_VarQuantityPrev;//for client to know quantity changed during synchronization
  25. int m_VarQuantityInit;
  26. int m_VarQuantityMin;
  27. int m_VarQuantityMax;
  28. int m_Count;
  29. float m_VarStackMax;
  30. float m_StoreLoadedQuantity = float.LOWEST;
  31. // Wet
  32. float m_VarWet;
  33. float m_VarWetPrev;//for client to know wetness changed during synchronization
  34. float m_VarWetInit;
  35. float m_VarWetMin;
  36. float m_VarWetMax;
  37. // Cleanness
  38. int m_Cleanness;
  39. int m_CleannessInit;
  40. int m_CleannessMin;
  41. int m_CleannessMax;
  42. // impact sounds
  43. bool m_WantPlayImpactSound;
  44. bool m_CanPlayImpactSound = true;
  45. float m_ImpactSpeed;
  46. int m_ImpactSoundSurfaceHash;
  47. //
  48. float m_HeatIsolation;
  49. float m_ItemModelLength;
  50. float m_ItemAttachOffset; // Offset length for when the item is attached e.g. to weapon
  51. int m_LiquidContainerMask;
  52. int m_VarLiquidType;
  53. int m_ItemBehaviour; // -1 = not specified; 0 = heavy item; 1= onehanded item; 2 = twohanded item
  54. int m_QuickBarBonus;
  55. bool m_IsBeingPlaced;
  56. bool m_IsHologram;
  57. bool m_IsPlaceSound;
  58. bool m_IsDeploySound;
  59. bool m_IsTakeable;
  60. bool m_IsSoundSynchRemote;
  61. bool m_ThrowItemOnDrop;
  62. bool m_ItemBeingDroppedPhys;
  63. bool m_CanBeMovedOverride;
  64. bool m_FixDamageSystemInit = false; //can be changed on storage version check
  65. bool can_this_be_combined; //Check if item can be combined
  66. bool m_CanThisBeSplit; //Check if item can be split
  67. bool m_IsStoreLoad = false;
  68. bool m_CanShowQuantity;
  69. bool m_HasQuantityBar;
  70. protected bool m_CanBeDigged;
  71. protected bool m_IsResultOfSplit //! distinguish if item has been created as new or it came from splitting (server only flag)
  72. protected EffectSound m_DeployLoopSoundEx;
  73. string m_SoundAttType;
  74. // items color variables
  75. int m_ColorComponentR;
  76. int m_ColorComponentG;
  77. int m_ColorComponentB;
  78. int m_ColorComponentA;
  79. //-------------------------------------------------------
  80. // light source managing
  81. ItemBase m_LightSourceItem;
  82. ref TIntArray m_SingleUseActions;
  83. ref TIntArray m_ContinuousActions;
  84. ref TIntArray m_InteractActions;
  85. //==============================================
  86. // agent system
  87. private int m_AttachedAgents;
  88. //! appears to be deprecated, legacy code
  89. void TransferModifiers(PlayerBase reciever);
  90. // Weapons & suppressors particle effects
  91. ref static map<int, ref array<ref WeaponParticlesOnFire>> m_OnFireEffect;
  92. ref static map<int, ref array<ref WeaponParticlesOnBulletCasingEject>> m_OnBulletCasingEjectEffect;
  93. ref map<int, ref array<ref WeaponParticlesOnOverheating>> m_OnOverheatingEffect;
  94. ref static map<string, int> m_WeaponTypeToID;
  95. static int m_LastRegisteredWeaponID = 0;
  96. // Overheating effects
  97. bool m_IsOverheatingEffectActive;
  98. float m_OverheatingShots;
  99. ref Timer m_CheckOverheating;
  100. int m_ShotsToStartOverheating = 0; // After these many shots, the overheating effect begins
  101. int m_MaxOverheatingValue = 0; // Limits the number of shots that will be tracked
  102. float m_OverheatingDecayInterval = 1; // Timer's interval for decrementing overheat effect's lifespan
  103. ref array <ref OverheatingParticle> m_OverheatingParticles;
  104. protected ref TStringArray m_HeadHidingSelections;
  105. protected bool m_HideSelectionsBySlot;
  106. // Admin Log
  107. PluginAdminLog m_AdminLog;
  108. // misc
  109. ref Timer m_PhysDropTimer;
  110. // Attachment Locking variables
  111. ref array<int> m_CompatibleLocks;
  112. protected int m_LockType;
  113. protected ref EffectSound m_LockingSound;
  114. protected string m_LockSoundSet;
  115. protected EffectSound m_SoundPlace;
  116. protected EffectSound m_SoundDeploy;
  117. protected EffectSound m_SoundDeployFinish;
  118. //temperature
  119. private float m_TemperaturePerQuantityWeight;
  120. // -------------------------------------------------------------------------
  121. void ItemBase()
  122. {
  123. SetEventMask(EntityEvent.INIT); // Enable EOnInit event
  124. m_SingleUseActions = new TIntArray;
  125. m_ContinuousActions = new TIntArray;
  126. m_InteractActions = new TIntArray;
  127. if (!GetGame().IsDedicatedServer())
  128. {
  129. if (HasMuzzle())
  130. {
  131. LoadParticleConfigOnFire(GetMuzzleID());
  132. if (m_ShotsToStartOverheating == 0)
  133. {
  134. LoadParticleConfigOnOverheating(GetMuzzleID());
  135. }
  136. }
  137. PreLoadSoundAttachmentType();
  138. m_ActionsInitialize = false;
  139. }
  140. m_OldLocation = null;
  141. if (GetGame().IsServer())
  142. {
  143. m_AdminLog = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
  144. }
  145. if (ConfigIsExisting("headSelectionsToHide"))
  146. {
  147. m_HeadHidingSelections = new TStringArray;
  148. ConfigGetTextArray("headSelectionsToHide",m_HeadHidingSelections);
  149. }
  150. m_HideSelectionsBySlot = false;
  151. if (ConfigIsExisting("hideSelectionsByinventorySlot"))
  152. {
  153. m_HideSelectionsBySlot = ConfigGetBool("hideSelectionsByinventorySlot");
  154. }
  155. m_QuickBarBonus = Math.Max(0, ConfigGetInt("quickBarBonus"));
  156. m_IsResultOfSplit = false;
  157. SetActionAnimOverrides();
  158. }
  159. override void InitItemVariables()
  160. {
  161. super.InitItemVariables();
  162. m_VarQuantityInit = ConfigGetInt("varQuantityInit");
  163. m_VarQuantity = m_VarQuantityInit;//should be by the CE, this is just a precaution
  164. m_VarQuantityMin = ConfigGetInt("varQuantityMin");
  165. m_VarQuantityMax = ConfigGetInt("varQuantityMax");
  166. m_VarStackMax = ConfigGetFloat("varStackMax");
  167. m_Count = ConfigGetInt("count");
  168. m_CanShowQuantity = ConfigGetBool("quantityShow");
  169. m_HasQuantityBar = ConfigGetBool("quantityBar");
  170. m_CleannessInit = ConfigGetInt("varCleannessInit");
  171. m_Cleanness = m_CleannessInit;
  172. m_CleannessMin = ConfigGetInt("varCleannessMin");
  173. m_CleannessMax = ConfigGetInt("varCleannessMax");
  174. m_WantPlayImpactSound = false;
  175. m_ImpactSpeed = 0.0;
  176. m_VarWetInit = ConfigGetFloat("varWetInit");
  177. m_VarWet = m_VarWetInit;
  178. m_VarWetMin = ConfigGetFloat("varWetMin");
  179. m_VarWetMax = ConfigGetFloat("varWetMax");
  180. m_LiquidContainerMask = ConfigGetInt("liquidContainerType");
  181. if (IsLiquidContainer() && GetQuantity() != 0)
  182. m_VarLiquidType = GetLiquidTypeInit();
  183. m_IsBeingPlaced = false;
  184. m_IsHologram = false;
  185. m_IsPlaceSound = false;
  186. m_IsDeploySound = false;
  187. m_IsTakeable = true;
  188. m_IsSoundSynchRemote = false;
  189. m_CanBeMovedOverride = false;
  190. m_HeatIsolation = GetHeatIsolationInit();
  191. m_ItemModelLength = GetItemModelLength();
  192. m_ItemAttachOffset = GetItemAttachOffset();
  193. m_CanBeDigged = ConfigGetBool("canBeDigged");
  194. m_CompatibleLocks = new array<int>();
  195. ConfigGetIntArray("compatibleLocks", m_CompatibleLocks);
  196. m_LockType = ConfigGetInt("lockType");
  197. //Define if item can be split and set ability to be combined accordingly
  198. m_CanThisBeSplit = false;
  199. can_this_be_combined = false;
  200. if (ConfigIsExisting("canBeSplit"))
  201. {
  202. can_this_be_combined = ConfigGetBool("canBeSplit");
  203. m_CanThisBeSplit = can_this_be_combined;
  204. }
  205. m_ItemBehaviour = -1;
  206. if (ConfigIsExisting("itemBehaviour"))
  207. m_ItemBehaviour = ConfigGetInt("itemBehaviour");
  208. //RegisterNetSyncVariableInt("m_VariablesMask");
  209. if (HasQuantity()) RegisterNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
  210. RegisterNetSyncVariableFloat("m_VarWet", GetWetMin(), GetWetMax(), 2);
  211. RegisterNetSyncVariableInt("m_VarLiquidType");
  212. RegisterNetSyncVariableInt("m_Cleanness",0,1);
  213. RegisterNetSyncVariableBoolSignal("m_WantPlayImpactSound");
  214. RegisterNetSyncVariableFloat("m_ImpactSpeed");
  215. RegisterNetSyncVariableInt("m_ImpactSoundSurfaceHash");
  216. RegisterNetSyncVariableInt("m_ColorComponentR", 0, 255);
  217. RegisterNetSyncVariableInt("m_ColorComponentG", 0, 255);
  218. RegisterNetSyncVariableInt("m_ColorComponentB", 0, 255);
  219. RegisterNetSyncVariableInt("m_ColorComponentA", 0, 255);
  220. RegisterNetSyncVariableBool("m_IsBeingPlaced");
  221. RegisterNetSyncVariableBool("m_IsTakeable");
  222. RegisterNetSyncVariableBool("m_IsHologram");
  223. if (UsesGlobalDeploy())
  224. {
  225. RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
  226. RegisterNetSyncVariableBool("m_IsDeploySound");
  227. }
  228. m_LockSoundSet = ConfigGetString("lockSoundSet");
  229. m_TemperaturePerQuantityWeight = 1.0;;
  230. if (ConfigIsExisting("temperaturePerQuantityWeight"))
  231. m_TemperaturePerQuantityWeight = ConfigGetFloat("temperaturePerQuantityWeight");
  232. }
  233. // allows for checking whether or not we can safely register net sync variables without causing VMEs for duplicate registration
  234. protected bool UsesGlobalDeploy()
  235. {
  236. return false;
  237. }
  238. override int GetQuickBarBonus()
  239. {
  240. return m_QuickBarBonus;
  241. }
  242. void InitializeActions()
  243. {
  244. m_InputActionMap = m_ItemTypeActionsMap.Get(this.Type());
  245. if (!m_InputActionMap)
  246. {
  247. TInputActionMap iam = new TInputActionMap;
  248. m_InputActionMap = iam;
  249. SetActions();
  250. m_ItemTypeActionsMap.Insert(this.Type(), m_InputActionMap);
  251. }
  252. }
  253. override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
  254. {
  255. if (!m_ActionsInitialize)
  256. {
  257. m_ActionsInitialize = true;
  258. InitializeActions();
  259. }
  260. actions = m_InputActionMap.Get(action_input_type);
  261. }
  262. void SetActions()
  263. {
  264. AddAction(ActionTakeItem);
  265. AddAction(ActionTakeItemToHands);
  266. AddAction(ActionWorldCraft);
  267. AddAction(ActionDropItem);
  268. AddAction(ActionAttachWithSwitch);
  269. }
  270. void SetActionAnimOverrides(); // Override action animation for specific item
  271. void AddAction(typename actionName)
  272. {
  273. ActionBase action = ActionManagerBase.GetAction(actionName);
  274. if (!action)
  275. {
  276. Debug.LogError("Action " + actionName + " dosn't exist!");
  277. return;
  278. }
  279. typename ai = action.GetInputType();
  280. if (!ai)
  281. {
  282. m_ActionsInitialize = false;
  283. return;
  284. }
  285. array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
  286. if (!action_array)
  287. {
  288. action_array = new array<ActionBase_Basic>;
  289. m_InputActionMap.Insert(ai, action_array);
  290. }
  291. if (LogManager.IsActionLogEnable())
  292. {
  293. Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action");
  294. }
  295. if (action_array.Find(action) != -1)
  296. {
  297. Debug.Log("Action " + action.Type() + " already added to " + this + ", skipping!");
  298. }
  299. else
  300. {
  301. action_array.Insert(action);
  302. }
  303. }
  304. void RemoveAction(typename actionName)
  305. {
  306. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  307. ActionBase action = player.GetActionManager().GetAction(actionName);
  308. typename ai = action.GetInputType();
  309. array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
  310. if (action_array)
  311. {
  312. action_array.RemoveItem(action);
  313. }
  314. }
  315. // Allows override of default action command per item, defined in the SetActionAnimOverrides() of the item's class
  316. // Set -1 for params which should stay in default state
  317. void OverrideActionAnimation(typename action, int commandUID, int stanceMask = -1, int commandUIDProne = -1)
  318. {
  319. ActionOverrideData overrideData = new ActionOverrideData();
  320. overrideData.m_CommandUID = commandUID;
  321. overrideData.m_CommandUIDProne = commandUIDProne;
  322. overrideData.m_StanceMask = stanceMask;
  323. TActionAnimOverrideMap actionMap = m_ItemActionOverrides.Get(action);
  324. if (!actionMap) // create new map of action > overidables map
  325. {
  326. actionMap = new TActionAnimOverrideMap();
  327. m_ItemActionOverrides.Insert(action, actionMap);
  328. }
  329. actionMap.Insert(this.Type(), overrideData); // insert item -> overrides
  330. }
  331. void OnItemInHandsPlayerSwimStart(PlayerBase player);
  332. ScriptedLightBase GetLight();
  333. // Loads muzzle flash particle configuration from config and saves it to a map for faster access
  334. void LoadParticleConfigOnFire(int id)
  335. {
  336. if (!m_OnFireEffect)
  337. m_OnFireEffect = new map<int, ref array<ref WeaponParticlesOnFire>>;
  338. if (!m_OnBulletCasingEjectEffect)
  339. m_OnBulletCasingEjectEffect = new map<int, ref array<ref WeaponParticlesOnBulletCasingEject>>;
  340. string config_to_search = "CfgVehicles";
  341. string muzzle_owner_config;
  342. if (!m_OnFireEffect.Contains(id))
  343. {
  344. if (IsInherited(Weapon))
  345. config_to_search = "CfgWeapons";
  346. muzzle_owner_config = config_to_search + " " + GetType() + " ";
  347. string config_OnFire_class = muzzle_owner_config + "Particles " + "OnFire ";
  348. int config_OnFire_subclass_count = GetGame().ConfigGetChildrenCount(config_OnFire_class);
  349. if (config_OnFire_subclass_count > 0)
  350. {
  351. array<ref WeaponParticlesOnFire> WPOF_array = new array<ref WeaponParticlesOnFire>;
  352. for (int i = 0; i < config_OnFire_subclass_count; i++)
  353. {
  354. string particle_class = "";
  355. GetGame().ConfigGetChildName(config_OnFire_class, i, particle_class);
  356. string config_OnFire_entry = config_OnFire_class + particle_class;
  357. WeaponParticlesOnFire WPOF = new WeaponParticlesOnFire(this, config_OnFire_entry);
  358. WPOF_array.Insert(WPOF);
  359. }
  360. m_OnFireEffect.Insert(id, WPOF_array);
  361. }
  362. }
  363. if (!m_OnBulletCasingEjectEffect.Contains(id))
  364. {
  365. config_to_search = "CfgWeapons"; // Bullet Eject efect is supported on weapons only.
  366. muzzle_owner_config = config_to_search + " " + GetType() + " ";
  367. string config_OnBulletCasingEject_class = muzzle_owner_config + "Particles " + "OnBulletCasingEject ";
  368. int config_OnBulletCasingEject_count = GetGame().ConfigGetChildrenCount(config_OnBulletCasingEject_class);
  369. if (config_OnBulletCasingEject_count > 0 && IsInherited(Weapon))
  370. {
  371. array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = new array<ref WeaponParticlesOnBulletCasingEject>;
  372. for (i = 0; i < config_OnBulletCasingEject_count; i++)
  373. {
  374. string particle_class2 = "";
  375. GetGame().ConfigGetChildName(config_OnBulletCasingEject_class, i, particle_class2);
  376. string config_OnBulletCasingEject_entry = config_OnBulletCasingEject_class + particle_class2;
  377. WeaponParticlesOnBulletCasingEject WPOBE = new WeaponParticlesOnBulletCasingEject(this, config_OnBulletCasingEject_entry);
  378. WPOBE_array.Insert(WPOBE);
  379. }
  380. m_OnBulletCasingEjectEffect.Insert(id, WPOBE_array);
  381. }
  382. }
  383. }
  384. // Loads muzzle flash particle configuration from config and saves it to a map for faster access
  385. void LoadParticleConfigOnOverheating(int id)
  386. {
  387. if (!m_OnOverheatingEffect)
  388. m_OnOverheatingEffect = new map<int, ref array<ref WeaponParticlesOnOverheating>>;
  389. if (!m_OnOverheatingEffect.Contains(id))
  390. {
  391. string config_to_search = "CfgVehicles";
  392. if (IsInherited(Weapon))
  393. config_to_search = "CfgWeapons";
  394. string muzzle_owner_config = config_to_search + " " + GetType() + " ";
  395. string config_OnOverheating_class = muzzle_owner_config + "Particles " + "OnOverheating ";
  396. if (GetGame().ConfigIsExisting(config_OnOverheating_class))
  397. {
  398. m_ShotsToStartOverheating = GetGame().ConfigGetFloat(config_OnOverheating_class + "shotsToStartOverheating");
  399. if (m_ShotsToStartOverheating == 0)
  400. {
  401. m_ShotsToStartOverheating = -1; // This prevents futher readings from config for future creations of this item
  402. string error = "Error reading config " + GetType() + ">Particles>OnOverheating - Parameter shotsToStartOverheating is configured wrong or is missing! Its value must be 1 or higher!";
  403. Error(error);
  404. return;
  405. }
  406. m_OverheatingDecayInterval = GetGame().ConfigGetFloat(config_OnOverheating_class + "overheatingDecayInterval");
  407. m_MaxOverheatingValue = GetGame().ConfigGetFloat(config_OnOverheating_class + "maxOverheatingValue");
  408. int config_OnOverheating_subclass_count = GetGame().ConfigGetChildrenCount(config_OnOverheating_class);
  409. array<ref WeaponParticlesOnOverheating> WPOOH_array = new array<ref WeaponParticlesOnOverheating>;
  410. for (int i = 0; i < config_OnOverheating_subclass_count; i++)
  411. {
  412. string particle_class = "";
  413. GetGame().ConfigGetChildName(config_OnOverheating_class, i, particle_class);
  414. string config_OnOverheating_entry = config_OnOverheating_class + particle_class;
  415. int entry_type = GetGame().ConfigGetType(config_OnOverheating_entry);
  416. if (entry_type == CT_CLASS)
  417. {
  418. WeaponParticlesOnOverheating WPOF = new WeaponParticlesOnOverheating(this, config_OnOverheating_entry);
  419. WPOOH_array.Insert(WPOF);
  420. }
  421. }
  422. m_OnOverheatingEffect.Insert(id, WPOOH_array);
  423. }
  424. }
  425. }
  426. float GetOverheatingValue()
  427. {
  428. return m_OverheatingShots;
  429. }
  430. void IncreaseOverheating(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  431. {
  432. if (m_MaxOverheatingValue > 0)
  433. {
  434. m_OverheatingShots++;
  435. if (!m_CheckOverheating)
  436. m_CheckOverheating = new Timer(CALL_CATEGORY_SYSTEM);
  437. m_CheckOverheating.Stop();
  438. m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay");
  439. CheckOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  440. }
  441. }
  442. void CheckOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
  443. {
  444. if (m_OverheatingShots >= m_ShotsToStartOverheating && IsOverheatingEffectActive())
  445. UpdateOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  446. if (m_OverheatingShots >= m_ShotsToStartOverheating && !IsOverheatingEffectActive())
  447. StartOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  448. if (m_OverheatingShots < m_ShotsToStartOverheating && IsOverheatingEffectActive())
  449. StopOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  450. if (m_OverheatingShots > m_MaxOverheatingValue)
  451. {
  452. m_OverheatingShots = m_MaxOverheatingValue;
  453. }
  454. }
  455. bool IsOverheatingEffectActive()
  456. {
  457. return m_IsOverheatingEffectActive;
  458. }
  459. void OnOverheatingDecay()
  460. {
  461. if (m_MaxOverheatingValue > 0)
  462. m_OverheatingShots -= 1 + m_OverheatingShots / m_MaxOverheatingValue; // The hotter a barrel is, the faster it needs to cool down.
  463. else
  464. m_OverheatingShots--;
  465. if (m_OverheatingShots <= 0)
  466. {
  467. m_CheckOverheating.Stop();
  468. m_OverheatingShots = 0;
  469. }
  470. else
  471. {
  472. if (!m_CheckOverheating)
  473. m_CheckOverheating = new Timer(CALL_CATEGORY_GAMEPLAY);
  474. m_CheckOverheating.Stop();
  475. m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay");
  476. }
  477. CheckOverheating(this, "", this);
  478. }
  479. void StartOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
  480. {
  481. m_IsOverheatingEffectActive = true;
  482. ItemBase.PlayOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons");
  483. }
  484. void UpdateOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
  485. {
  486. KillAllOverheatingParticles();
  487. ItemBase.UpdateOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons");
  488. UpdateAllOverheatingParticles();
  489. }
  490. void StopOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "")
  491. {
  492. m_IsOverheatingEffectActive = false;
  493. ItemBase.StopOverheatingParticles(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  494. }
  495. void RegisterOverheatingParticle(Particle p, float min_heat_coef, float max_heat_coef, int particle_id, Object parent, vector local_pos, vector local_ori)
  496. {
  497. if (!m_OverheatingParticles)
  498. m_OverheatingParticles = new array<ref OverheatingParticle>;
  499. OverheatingParticle OP = new OverheatingParticle();
  500. OP.RegisterParticle(p);
  501. OP.SetOverheatingLimitMin(min_heat_coef);
  502. OP.SetOverheatingLimitMax(max_heat_coef);
  503. OP.SetParticleParams(particle_id, parent, local_pos, local_ori);
  504. m_OverheatingParticles.Insert(OP);
  505. }
  506. float GetOverheatingCoef()
  507. {
  508. if (m_MaxOverheatingValue > 0)
  509. return (m_OverheatingShots - m_ShotsToStartOverheating) / m_MaxOverheatingValue;
  510. return -1;
  511. }
  512. void UpdateAllOverheatingParticles()
  513. {
  514. if (m_OverheatingParticles)
  515. {
  516. float overheat_coef = GetOverheatingCoef();
  517. int count = m_OverheatingParticles.Count();
  518. for (int i = count; i > 0; --i)
  519. {
  520. int id = i - 1;
  521. OverheatingParticle OP = m_OverheatingParticles.Get(id);
  522. Particle p = OP.GetParticle();
  523. float overheat_min = OP.GetOverheatingLimitMin();
  524. float overheat_max = OP.GetOverheatingLimitMax();
  525. if (overheat_coef < overheat_min && overheat_coef >= overheat_max)
  526. {
  527. if (p)
  528. {
  529. p.Stop();
  530. OP.RegisterParticle(null);
  531. }
  532. }
  533. }
  534. }
  535. }
  536. void KillAllOverheatingParticles()
  537. {
  538. if (m_OverheatingParticles)
  539. {
  540. for (int i = m_OverheatingParticles.Count(); i > 0; i--)
  541. {
  542. int id = i - 1;
  543. OverheatingParticle OP = m_OverheatingParticles.Get(id);
  544. if (OP)
  545. {
  546. Particle p = OP.GetParticle();
  547. if (p)
  548. {
  549. p.Stop();
  550. }
  551. delete OP;
  552. }
  553. }
  554. m_OverheatingParticles.Clear();
  555. delete m_OverheatingParticles;
  556. }
  557. }
  558. //! 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
  559. float GetInfectionChance(int system = 0, Param param = null)
  560. {
  561. return 0.0;
  562. }
  563. float GetDisinfectQuantity(int system = 0, Param param1 = null)
  564. {
  565. return 250;//default value
  566. }
  567. float GetFilterDamageRatio()
  568. {
  569. return 0;
  570. }
  571. //! Returns true if this item has a muzzle (weapons, suppressors)
  572. bool HasMuzzle()
  573. {
  574. if (IsInherited(Weapon) || IsInherited(SuppressorBase))
  575. return true;
  576. return false;
  577. }
  578. //! Returns global muzzle ID. If not found, then it gets automatically registered.
  579. int GetMuzzleID()
  580. {
  581. if (!m_WeaponTypeToID)
  582. m_WeaponTypeToID = new map<string, int>;
  583. if (m_WeaponTypeToID.Contains(GetType()))
  584. {
  585. return m_WeaponTypeToID.Get(GetType());
  586. }
  587. else
  588. {
  589. // Register new weapon ID
  590. m_WeaponTypeToID.Insert(GetType(), ++m_LastRegisteredWeaponID);
  591. }
  592. return m_LastRegisteredWeaponID;
  593. }
  594. /**
  595. \brief Re-sets DamageSystem changes
  596. \return storage version on which the config changes occured (default -1, to be overriden!)
  597. \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).
  598. */
  599. int GetDamageSystemVersionChange()
  600. {
  601. return -1;
  602. }
  603. // -------------------------------------------------------------------------
  604. void ~ItemBase()
  605. {
  606. #ifndef SERVER
  607. if (m_DeployLoopSoundEx)
  608. m_DeployLoopSoundEx.SoundStop();
  609. #endif
  610. if (GetGame() && GetGame().GetPlayer() && (!GetGame().IsDedicatedServer()))
  611. {
  612. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  613. int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this);
  614. if (r_index >= 0)
  615. {
  616. InventoryLocation r_il = new InventoryLocation;
  617. player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
  618. player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
  619. int r_type = r_il.GetType();
  620. if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
  621. {
  622. r_il.GetParent().GetOnReleaseLock().Invoke(this);
  623. }
  624. else if (r_type == InventoryLocationType.ATTACHMENT)
  625. {
  626. r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
  627. }
  628. }
  629. player.GetHumanInventory().ClearUserReservedLocation(this);
  630. }
  631. if (m_LockingSound)
  632. SEffectManager.DestroyEffect(m_LockingSound);
  633. }
  634. // -------------------------------------------------------------------------
  635. static int GetDebugActionsMask()
  636. {
  637. return ItemBase.m_DebugActionsMask;
  638. }
  639. static bool HasDebugActionsMask(int mask)
  640. {
  641. return ItemBase.m_DebugActionsMask & mask;
  642. }
  643. static void SetDebugActionsMask(int mask)
  644. {
  645. ItemBase.m_DebugActionsMask = mask;
  646. }
  647. static void AddDebugActionsMask(int mask)
  648. {
  649. ItemBase.m_DebugActionsMask |= mask;
  650. }
  651. static void RemoveDebugActionsMask(int mask)
  652. {
  653. ItemBase.m_DebugActionsMask &= ~mask;
  654. }
  655. static void ToggleDebugActionsMask(int mask)
  656. {
  657. if (HasDebugActionsMask(mask))
  658. {
  659. RemoveDebugActionsMask(mask);
  660. }
  661. else
  662. {
  663. AddDebugActionsMask(mask);
  664. }
  665. }
  666. // -------------------------------------------------------------------------
  667. void SetCEBasedQuantity()
  668. {
  669. if (GetEconomyProfile())
  670. {
  671. float q_max = GetEconomyProfile().GetQuantityMax();
  672. if (q_max > 0)
  673. {
  674. float q_min = GetEconomyProfile().GetQuantityMin();
  675. float quantity_randomized = Math.RandomFloatInclusive(q_min, q_max);
  676. if (HasComponent(COMP_TYPE_ENERGY_MANAGER))//more direct access for speed
  677. {
  678. ComponentEnergyManager comp = GetCompEM();
  679. 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
  680. {
  681. comp.SetEnergy0To1(quantity_randomized);
  682. }
  683. }
  684. else if (HasQuantity())
  685. {
  686. SetQuantityNormalized(quantity_randomized, false);
  687. //PrintString("<==> Normalized quantity for item: "+ GetType()+", qmin:"+q_min.ToString()+"; qmax:"+q_max.ToString()+";quantity:" +quantity_randomized.ToString());
  688. }
  689. }
  690. }
  691. }
  692. //! Locks this item in it's current attachment slot of its parent. This makes the "locked" icon visible in inventory over this item.
  693. void LockToParent()
  694. {
  695. EntityAI parent = GetHierarchyParent();
  696. if (parent)
  697. {
  698. InventoryLocation inventory_location_to_lock = new InventoryLocation;
  699. GetInventory().GetCurrentInventoryLocation(inventory_location_to_lock);
  700. parent.GetInventory().SetSlotLock(inventory_location_to_lock.GetSlot(), true);
  701. }
  702. }
  703. //! Unlocks this item from its attachment slot of its parent.
  704. void UnlockFromParent()
  705. {
  706. EntityAI parent = GetHierarchyParent();
  707. if (parent)
  708. {
  709. InventoryLocation inventory_location_to_unlock = new InventoryLocation;
  710. GetInventory().GetCurrentInventoryLocation(inventory_location_to_unlock);
  711. parent.GetInventory().SetSlotLock(inventory_location_to_unlock.GetSlot(), false);
  712. }
  713. }
  714. override void CombineItemsClient(EntityAI entity2, bool use_stack_max = true)
  715. {
  716. /*
  717. ref Param1<EntityAI> item = new Param1<EntityAI>(entity2);
  718. RPCSingleParam(ERPCs.RPC_ITEM_COMBINE, item, GetGame().GetPlayer());
  719. */
  720. ItemBase item2 = ItemBase.Cast(entity2);
  721. if (GetGame().IsClient())
  722. {
  723. if (ScriptInputUserData.CanStoreInputUserData())
  724. {
  725. ScriptInputUserData ctx = new ScriptInputUserData;
  726. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  727. ctx.Write(-1);
  728. ItemBase i1 = this; // @NOTE: workaround for correct serialization
  729. ctx.Write(i1);
  730. ctx.Write(item2);
  731. ctx.Write(use_stack_max);
  732. ctx.Write(-1);
  733. ctx.Send();
  734. if (IsCombineAll(item2, use_stack_max))
  735. {
  736. GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(item2,null,GameInventory.c_InventoryReservationTimeoutShortMS);
  737. }
  738. }
  739. }
  740. else if (!GetGame().IsMultiplayer())
  741. {
  742. CombineItems(item2, use_stack_max);
  743. }
  744. }
  745. bool IsLiquidPresent()
  746. {
  747. return (GetLiquidType() != 0 && HasQuantity());
  748. }
  749. bool IsLiquidContainer()
  750. {
  751. return m_LiquidContainerMask != 0;
  752. }
  753. int GetLiquidContainerMask()
  754. {
  755. return m_LiquidContainerMask;
  756. }
  757. bool IsBloodContainer()
  758. {
  759. //m_LiquidContainerMask & GROUP_LIQUID_BLOOD ???
  760. return false;
  761. }
  762. bool IsNVG()
  763. {
  764. return false;
  765. }
  766. //! explosive
  767. //! ------------
  768. bool IsExplosive()
  769. {
  770. return false;
  771. }
  772. string GetExplosiveTriggerSlotName()
  773. {
  774. return "";
  775. }
  776. //! ------------
  777. bool IsLightSource()
  778. {
  779. return false;
  780. }
  781. bool CanBeRepairedByCrafting()
  782. {
  783. return true;
  784. }
  785. //--- ACTION CONDITIONS
  786. //direction
  787. bool IsFacingPlayer(PlayerBase player, string selection)
  788. {
  789. return true;
  790. }
  791. bool IsPlayerInside(PlayerBase player, string selection)
  792. {
  793. return true;
  794. }
  795. override bool CanObstruct()
  796. {
  797. PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
  798. return !player || !IsPlayerInside(player, "");
  799. }
  800. override bool IsBeingPlaced()
  801. {
  802. return m_IsBeingPlaced;
  803. }
  804. void SetIsBeingPlaced(bool is_being_placed)
  805. {
  806. m_IsBeingPlaced = is_being_placed;
  807. if (!is_being_placed)
  808. OnEndPlacement();
  809. SetSynchDirty();
  810. }
  811. //server-side
  812. void OnEndPlacement() {}
  813. override bool IsHologram()
  814. {
  815. return m_IsHologram;
  816. }
  817. bool CanBeDigged()
  818. {
  819. return m_CanBeDigged;
  820. }
  821. int GetOnDigWormsAmount()
  822. {
  823. return 1;
  824. }
  825. bool CanMakeGardenplot()
  826. {
  827. return false;
  828. }
  829. void SetIsHologram(bool is_hologram)
  830. {
  831. m_IsHologram = is_hologram;
  832. SetSynchDirty();
  833. }
  834. /*
  835. protected float GetNutritionalEnergy()
  836. {
  837. Edible_Base edible = Edible_Base.Cast(this);
  838. return edible.GetFoodEnergy();
  839. }
  840. protected float GetNutritionalWaterContent()
  841. {
  842. Edible_Base edible = Edible_Base.Cast(this);
  843. return edible.GetFoodWater();
  844. }
  845. protected float GetNutritionalIndex()
  846. {
  847. Edible_Base edible = Edible_Base.Cast(this);
  848. return edible.GetFoodNutritionalIndex();
  849. }
  850. protected float GetNutritionalFullnessIndex()
  851. {
  852. Edible_Base edible = Edible_Base.Cast(this);
  853. return edible.GetFoodTotalVolume();
  854. }
  855. protected float GetNutritionalToxicity()
  856. {
  857. Edible_Base edible = Edible_Base.Cast(this);
  858. return edible.GetFoodToxicity();
  859. }
  860. */
  861. // -------------------------------------------------------------------------
  862. override void OnMovedInsideCargo(EntityAI container)
  863. {
  864. super.OnMovedInsideCargo(container);
  865. MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base});
  866. }
  867. override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  868. {
  869. super.EEItemLocationChanged(oldLoc,newLoc);
  870. PlayerBase new_player = null;
  871. PlayerBase old_player = null;
  872. if (newLoc.GetParent())
  873. new_player = PlayerBase.Cast(newLoc.GetParent().GetHierarchyRootPlayer());
  874. if (oldLoc.GetParent())
  875. old_player = PlayerBase.Cast(oldLoc.GetParent().GetHierarchyRootPlayer());
  876. if (old_player && oldLoc.GetType() == InventoryLocationType.HANDS)
  877. {
  878. int r_index = old_player.GetHumanInventory().FindUserReservedLocationIndex(this);
  879. if (r_index >= 0)
  880. {
  881. InventoryLocation r_il = new InventoryLocation;
  882. old_player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
  883. old_player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
  884. int r_type = r_il.GetType();
  885. if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
  886. {
  887. r_il.GetParent().GetOnReleaseLock().Invoke(this);
  888. }
  889. else if (r_type == InventoryLocationType.ATTACHMENT)
  890. {
  891. r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
  892. }
  893. }
  894. }
  895. if (newLoc.GetType() == InventoryLocationType.HANDS)
  896. {
  897. if (new_player)
  898. new_player.ForceStandUpForHeavyItems(newLoc.GetItem());
  899. if (new_player == old_player)
  900. {
  901. if (oldLoc.GetParent() && new_player.GetHumanInventory().LocationGetEntity(oldLoc) == NULL)
  902. {
  903. if (oldLoc.GetType() == InventoryLocationType.CARGO)
  904. {
  905. if (oldLoc.GetParent().GetInventory().TestAddEntityInCargoExLoc(oldLoc, false, false, false, true, false, false))
  906. {
  907. new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc);
  908. }
  909. }
  910. else
  911. {
  912. new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc);
  913. }
  914. }
  915. if (new_player.GetHumanInventory().FindUserReservedLocationIndex(this) >= 0)
  916. {
  917. int type = oldLoc.GetType();
  918. if (type == InventoryLocationType.CARGO || type == InventoryLocationType.PROXYCARGO)
  919. {
  920. oldLoc.GetParent().GetOnSetLock().Invoke(this);
  921. }
  922. else if (type == InventoryLocationType.ATTACHMENT)
  923. {
  924. oldLoc.GetParent().GetOnAttachmentSetLock().Invoke(this, oldLoc.GetSlot());
  925. }
  926. }
  927. if (!m_OldLocation)
  928. {
  929. m_OldLocation = new InventoryLocation;
  930. }
  931. m_OldLocation.Copy(oldLoc);
  932. }
  933. else
  934. {
  935. if (m_OldLocation)
  936. {
  937. m_OldLocation.Reset();
  938. }
  939. }
  940. GetGame().GetAnalyticsClient().OnItemAttachedAtPlayer(this,"Hands");
  941. }
  942. else
  943. {
  944. if (new_player)
  945. {
  946. int res_index = new_player.GetHumanInventory().FindCollidingUserReservedLocationIndex(this, newLoc);
  947. if (res_index >= 0)
  948. {
  949. InventoryLocation il = new InventoryLocation;
  950. new_player.GetHumanInventory().GetUserReservedLocation(res_index,il);
  951. ItemBase it = ItemBase.Cast(il.GetItem());
  952. new_player.GetHumanInventory().ClearUserReservedLocationAtIndex(res_index);
  953. int rel_type = il.GetType();
  954. if (rel_type == InventoryLocationType.CARGO || rel_type == InventoryLocationType.PROXYCARGO)
  955. {
  956. il.GetParent().GetOnReleaseLock().Invoke(it);
  957. }
  958. else if (rel_type == InventoryLocationType.ATTACHMENT)
  959. {
  960. il.GetParent().GetOnAttachmentReleaseLock().Invoke(it, il.GetSlot());
  961. }
  962. //it.GetOnReleaseLock().Invoke(it);
  963. }
  964. }
  965. else if (old_player && newLoc.GetType() == InventoryLocationType.GROUND && m_ThrowItemOnDrop)
  966. {
  967. //ThrowPhysically(old_player, vector.Zero);
  968. m_ThrowItemOnDrop = false;
  969. }
  970. if (m_OldLocation)
  971. {
  972. m_OldLocation.Reset();
  973. }
  974. }
  975. }
  976. override void EOnContact(IEntity other, Contact extra)
  977. {
  978. if (m_CanPlayImpactSound)
  979. {
  980. int liquidType = -1;
  981. float impactSpeed = ProcessImpactSoundEx(other, extra, m_ConfigWeight, m_ImpactSoundSurfaceHash, liquidType);
  982. if (impactSpeed > 0.0)
  983. {
  984. m_ImpactSpeed = impactSpeed;
  985. #ifndef SERVER
  986. PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash);
  987. #else
  988. m_WantPlayImpactSound = true;
  989. SetSynchDirty();
  990. #endif
  991. m_CanPlayImpactSound = (liquidType == -1);// prevents further playing of the sound when the surface is a liquid type
  992. }
  993. }
  994. #ifdef SERVER
  995. if (GetCompEM() && GetCompEM().IsPlugged())
  996. {
  997. if (GetCompEM().GetCordLength() < vector.Distance(GetPosition(), GetCompEM().GetEnergySource().GetPosition()))
  998. GetCompEM().UnplugThis();
  999. }
  1000. #endif
  1001. }
  1002. void RefreshPhysics();
  1003. override void OnCreatePhysics()
  1004. {
  1005. RefreshPhysics();
  1006. }
  1007. override void OnItemAttachmentSlotChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  1008. {
  1009. }
  1010. // -------------------------------------------------------------------------
  1011. override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
  1012. {
  1013. super.OnItemLocationChanged(old_owner, new_owner);
  1014. PlayerBase relatedPlayer = PlayerBase.Cast(old_owner);
  1015. PlayerBase playerNew = PlayerBase.Cast(new_owner);
  1016. if (!relatedPlayer && playerNew)
  1017. relatedPlayer = playerNew;
  1018. if (relatedPlayer && relatedPlayer.GetPerformedActionID() != -1)
  1019. {
  1020. ActionManagerBase actionMgr = relatedPlayer.GetActionManager();
  1021. if (actionMgr)
  1022. {
  1023. ActionBase currentAction = actionMgr.GetRunningAction();
  1024. if (currentAction)
  1025. currentAction.OnItemLocationChanged(this);
  1026. }
  1027. }
  1028. Man ownerPlayerOld = null;
  1029. Man ownerPlayerNew = null;
  1030. if (old_owner)
  1031. {
  1032. if (old_owner.IsMan())
  1033. {
  1034. ownerPlayerOld = Man.Cast(old_owner);
  1035. }
  1036. else
  1037. {
  1038. ownerPlayerOld = Man.Cast(old_owner.GetHierarchyRootPlayer());
  1039. }
  1040. }
  1041. else
  1042. {
  1043. if (new_owner && IsElectricAppliance() && GetCompEM() && GetCompEM().IsPlugged())
  1044. {
  1045. ActionBase action = ActionManagerBase.GetAction(ActionRepositionPluggedItem);
  1046. if (!action || !playerNew || playerNew.GetPerformedActionID() != action.GetID())
  1047. {
  1048. GetCompEM().UnplugThis();
  1049. }
  1050. }
  1051. }
  1052. if (new_owner)
  1053. {
  1054. if (new_owner.IsMan())
  1055. {
  1056. ownerPlayerNew = Man.Cast(new_owner);
  1057. }
  1058. else
  1059. {
  1060. ownerPlayerNew = Man.Cast(new_owner.GetHierarchyRootPlayer());
  1061. }
  1062. }
  1063. if (ownerPlayerOld != ownerPlayerNew)
  1064. {
  1065. if (ownerPlayerOld)
  1066. {
  1067. array<EntityAI> subItemsExit = new array<EntityAI>;
  1068. GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsExit);
  1069. for (int i = 0; i < subItemsExit.Count(); i++)
  1070. {
  1071. ItemBase itemExit = ItemBase.Cast(subItemsExit.Get(i));
  1072. itemExit.OnInventoryExit(ownerPlayerOld);
  1073. }
  1074. }
  1075. if (ownerPlayerNew)
  1076. {
  1077. array<EntityAI> subItemsEnter = new array<EntityAI>;
  1078. GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsEnter);
  1079. for (int j = 0; j < subItemsEnter.Count(); j++)
  1080. {
  1081. ItemBase itemEnter = ItemBase.Cast(subItemsEnter.Get(j));
  1082. itemEnter.OnInventoryEnter(ownerPlayerNew);
  1083. }
  1084. }
  1085. }
  1086. else if (ownerPlayerNew != null)
  1087. {
  1088. PlayerBase nplayer;
  1089. if (PlayerBase.CastTo(nplayer, ownerPlayerNew))
  1090. {
  1091. array<EntityAI> subItemsUpdate = new array<EntityAI>;
  1092. GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsUpdate);
  1093. for (int k = 0; k < subItemsUpdate.Count(); k++)
  1094. {
  1095. ItemBase itemUpdate = ItemBase.Cast(subItemsUpdate.Get(k));
  1096. itemUpdate.UpdateQuickbarShortcutVisibility(nplayer);
  1097. }
  1098. }
  1099. }
  1100. if (old_owner)
  1101. old_owner.OnChildItemRemoved(this);
  1102. if (new_owner)
  1103. new_owner.OnChildItemReceived(this);
  1104. }
  1105. // -------------------------------------------------------------------------------
  1106. override void EEDelete(EntityAI parent)
  1107. {
  1108. super.EEDelete(parent);
  1109. PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
  1110. if (player)
  1111. {
  1112. OnInventoryExit(player);
  1113. if (player.IsAlive())
  1114. {
  1115. int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this);
  1116. if (r_index >= 0)
  1117. {
  1118. InventoryLocation r_il = new InventoryLocation;
  1119. player.GetHumanInventory().GetUserReservedLocation(r_index,r_il);
  1120. player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index);
  1121. int r_type = r_il.GetType();
  1122. if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
  1123. {
  1124. r_il.GetParent().GetOnReleaseLock().Invoke(this);
  1125. }
  1126. else if (r_type == InventoryLocationType.ATTACHMENT)
  1127. {
  1128. r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot());
  1129. }
  1130. }
  1131. player.RemoveQuickBarEntityShortcut(this);
  1132. }
  1133. }
  1134. }
  1135. // -------------------------------------------------------------------------------
  1136. override void EEKilled(Object killer)
  1137. {
  1138. super.EEKilled(killer);
  1139. //! item is able to explode in fire
  1140. if (killer && killer.IsFireplace() && CanExplodeInFire())
  1141. {
  1142. if (GetTemperature() >= GameConstants.ITEM_TEMPERATURE_TO_EXPLODE_MIN)
  1143. {
  1144. if (IsMagazine())
  1145. {
  1146. if (Magazine.Cast(this).GetAmmoCount() > 0)
  1147. {
  1148. ExplodeAmmo();
  1149. }
  1150. }
  1151. else
  1152. {
  1153. Explode(DamageType.EXPLOSION);
  1154. }
  1155. }
  1156. }
  1157. }
  1158. override void OnWasAttached(EntityAI parent, int slot_id)
  1159. {
  1160. MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base});
  1161. super.OnWasAttached(parent, slot_id);
  1162. if (HasQuantity())
  1163. UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
  1164. PlayAttachSound(InventorySlots.GetSlotName(slot_id));
  1165. }
  1166. override void OnWasDetached(EntityAI parent, int slot_id)
  1167. {
  1168. super.OnWasDetached(parent, slot_id);
  1169. if (HasQuantity())
  1170. UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax);
  1171. }
  1172. override string ChangeIntoOnAttach(string slot)
  1173. {
  1174. int idx;
  1175. TStringArray inventory_slots = new TStringArray;
  1176. TStringArray attach_types = new TStringArray;
  1177. ConfigGetTextArray("ChangeInventorySlot",inventory_slots);
  1178. if (inventory_slots.Count() < 1) //is string
  1179. {
  1180. inventory_slots.Insert(ConfigGetString("ChangeInventorySlot"));
  1181. attach_types.Insert(ConfigGetString("ChangeIntoOnAttach"));
  1182. }
  1183. else //is array
  1184. {
  1185. ConfigGetTextArray("ChangeIntoOnAttach",attach_types);
  1186. }
  1187. idx = inventory_slots.Find(slot);
  1188. if (idx < 0)
  1189. return "";
  1190. return attach_types.Get(idx);
  1191. }
  1192. override string ChangeIntoOnDetach()
  1193. {
  1194. int idx = -1;
  1195. string slot;
  1196. TStringArray inventory_slots = new TStringArray;
  1197. TStringArray detach_types = new TStringArray;
  1198. this.ConfigGetTextArray("ChangeInventorySlot",inventory_slots);
  1199. if (inventory_slots.Count() < 1) //is string
  1200. {
  1201. inventory_slots.Insert(this.ConfigGetString("ChangeInventorySlot"));
  1202. detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach"));
  1203. }
  1204. else //is array
  1205. {
  1206. this.ConfigGetTextArray("ChangeIntoOnDetach",detach_types);
  1207. if (detach_types.Count() < 1)
  1208. detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach"));
  1209. }
  1210. for (int i = 0; i < inventory_slots.Count(); i++)
  1211. {
  1212. slot = inventory_slots.Get(i);
  1213. }
  1214. if (slot != "")
  1215. {
  1216. if (detach_types.Count() == 1)
  1217. idx = 0;
  1218. else
  1219. idx = inventory_slots.Find(slot);
  1220. }
  1221. if (idx < 0)
  1222. return "";
  1223. return detach_types.Get(idx);
  1224. }
  1225. void ExplodeAmmo()
  1226. {
  1227. //timer
  1228. ref Timer explode_timer = new Timer(CALL_CATEGORY_SYSTEM);
  1229. //min/max time
  1230. float min_time = 1;
  1231. float max_time = 3;
  1232. float delay = Math.RandomFloat(min_time, max_time);
  1233. explode_timer.Run(delay, this, "DoAmmoExplosion");
  1234. }
  1235. void DoAmmoExplosion()
  1236. {
  1237. Magazine magazine = Magazine.Cast(this);
  1238. int pop_sounds_count = 6;
  1239. string pop_sounds[ 6 ] = { "ammopops_1","ammopops_2","ammopops_3","ammopops_4","ammopops_5","ammopops_6" };
  1240. //play sound
  1241. int sound_idx = Math.RandomInt(0, pop_sounds_count - 1);
  1242. string sound_name = pop_sounds[ sound_idx ];
  1243. GetGame().CreateSoundOnObject(this, sound_name, 20, false);
  1244. //remove ammo count
  1245. magazine.ServerAddAmmoCount(-1);
  1246. //if condition then repeat -> ExplodeAmmo
  1247. float min_temp_to_explode = 100; //min temperature for item to explode
  1248. if (magazine.GetAmmoCount() > 0 && GetTemperature() >= min_temp_to_explode) //TODO ? add check for parent -> fireplace
  1249. {
  1250. ExplodeAmmo();
  1251. }
  1252. }
  1253. // -------------------------------------------------------------------------------
  1254. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  1255. {
  1256. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  1257. const int CHANCE_DAMAGE_CARGO = 4;
  1258. const int CHANCE_DAMAGE_ATTACHMENT = 1;
  1259. const int CHANCE_DAMAGE_NOTHING = 2;
  1260. if (IsClothing() || IsContainer() || IsItemTent())
  1261. {
  1262. float dmg = damageResult.GetDamage("","Health") * -0.5;
  1263. int chances;
  1264. int rnd;
  1265. if (GetInventory().GetCargo())
  1266. {
  1267. chances = CHANCE_DAMAGE_CARGO + CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING;
  1268. rnd = Math.RandomInt(0,chances);
  1269. if (rnd < CHANCE_DAMAGE_CARGO)
  1270. {
  1271. DamageItemInCargo(dmg);
  1272. }
  1273. else if (rnd < (chances - CHANCE_DAMAGE_NOTHING))
  1274. {
  1275. DamageItemAttachments(dmg);
  1276. }
  1277. }
  1278. else
  1279. {
  1280. chances = CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING;
  1281. rnd = Math.RandomInt(0,chances);
  1282. if (rnd < CHANCE_DAMAGE_ATTACHMENT)
  1283. {
  1284. DamageItemAttachments(dmg);
  1285. }
  1286. }
  1287. }
  1288. }
  1289. bool DamageItemInCargo(float damage)
  1290. {
  1291. if (GetInventory().GetCargo())
  1292. {
  1293. int item_count = GetInventory().GetCargo().GetItemCount();
  1294. if (item_count > 0)
  1295. {
  1296. int random_pick = Math.RandomInt(0, item_count);
  1297. ItemBase item = ItemBase.Cast(GetInventory().GetCargo().GetItem(random_pick));
  1298. if (!item.IsExplosive())
  1299. {
  1300. item.AddHealth("","",damage);
  1301. return true;
  1302. }
  1303. }
  1304. }
  1305. return false;
  1306. }
  1307. bool DamageItemAttachments(float damage)
  1308. {
  1309. int attachment_count = GetInventory().AttachmentCount();
  1310. if (attachment_count > 0)
  1311. {
  1312. int random_pick = Math.RandomInt(0, attachment_count);
  1313. ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(random_pick));
  1314. if (!attachment.IsExplosive())
  1315. {
  1316. attachment.AddHealth("","",damage);
  1317. return true;
  1318. }
  1319. }
  1320. return false;
  1321. }
  1322. override bool IsSplitable()
  1323. {
  1324. return m_CanThisBeSplit;
  1325. }
  1326. //----------------
  1327. override bool CanBeSplit()
  1328. {
  1329. if (IsSplitable() && (GetQuantity() > 1))
  1330. return GetInventory().CanRemoveEntity();
  1331. return false;
  1332. }
  1333. override void SplitIntoStackMaxClient(EntityAI destination_entity, int slot_id )
  1334. {
  1335. if (GetGame().IsClient())
  1336. {
  1337. if (ScriptInputUserData.CanStoreInputUserData())
  1338. {
  1339. ScriptInputUserData ctx = new ScriptInputUserData;
  1340. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1341. ctx.Write(1);
  1342. ItemBase i1 = this; // @NOTE: workaround for correct serialization
  1343. ctx.Write(i1);
  1344. ctx.Write(destination_entity);
  1345. ctx.Write(true);
  1346. ctx.Write(slot_id);
  1347. ctx.Send();
  1348. }
  1349. }
  1350. else if (!GetGame().IsMultiplayer())
  1351. {
  1352. SplitIntoStackMax(destination_entity, slot_id, PlayerBase.Cast(GetGame().GetPlayer()));
  1353. }
  1354. }
  1355. void SplitIntoStackMax(EntityAI destination_entity, int slot_id, PlayerBase player)
  1356. {
  1357. float split_quantity_new;
  1358. ref ItemBase new_item;
  1359. float quantity = GetQuantity();
  1360. float stack_max = GetTargetQuantityMax(slot_id);
  1361. InventoryLocation loc = new InventoryLocation;
  1362. if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
  1363. {
  1364. if (stack_max <= GetQuantity())
  1365. split_quantity_new = stack_max;
  1366. else
  1367. split_quantity_new = GetQuantity();
  1368. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
  1369. if (new_item)
  1370. {
  1371. new_item.SetResultOfSplit(true);
  1372. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1373. AddQuantity(-split_quantity_new);
  1374. new_item.SetQuantity(split_quantity_new);
  1375. }
  1376. }
  1377. else if (destination_entity && slot_id == -1)
  1378. {
  1379. if (quantity > stack_max)
  1380. split_quantity_new = stack_max;
  1381. else
  1382. split_quantity_new = quantity;
  1383. if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
  1384. {
  1385. Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
  1386. new_item = ItemBase.Cast(o);
  1387. }
  1388. if (new_item)
  1389. {
  1390. new_item.SetResultOfSplit(true);
  1391. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1392. AddQuantity(-split_quantity_new);
  1393. new_item.SetQuantity(split_quantity_new);
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if (stack_max != 0)
  1399. {
  1400. if (stack_max < GetQuantity())
  1401. {
  1402. split_quantity_new = GetQuantity() - stack_max;
  1403. }
  1404. if (split_quantity_new == 0)
  1405. {
  1406. if (!GetGame().IsMultiplayer())
  1407. player.PhysicalPredictiveDropItem(this);
  1408. else
  1409. player.ServerDropEntity(this);
  1410. return;
  1411. }
  1412. new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(), player.GetWorldPosition(), ECE_PLACE_ON_SURFACE));
  1413. if (new_item)
  1414. {
  1415. new_item.SetResultOfSplit(true);
  1416. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1417. SetQuantity(split_quantity_new);
  1418. new_item.SetQuantity(stack_max);
  1419. new_item.PlaceOnSurface();
  1420. }
  1421. }
  1422. }
  1423. }
  1424. override void SplitIntoStackMaxEx(EntityAI destination_entity, int slot_id)
  1425. {
  1426. float split_quantity_new;
  1427. ref ItemBase new_item;
  1428. float quantity = GetQuantity();
  1429. float stack_max = GetTargetQuantityMax(slot_id);
  1430. InventoryLocation loc = new InventoryLocation;
  1431. if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
  1432. {
  1433. if (stack_max <= GetQuantity())
  1434. split_quantity_new = stack_max;
  1435. else
  1436. split_quantity_new = GetQuantity();
  1437. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
  1438. if (new_item)
  1439. {
  1440. new_item.SetResultOfSplit(true);
  1441. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1442. AddQuantity(-split_quantity_new);
  1443. new_item.SetQuantity(split_quantity_new);
  1444. }
  1445. }
  1446. else if (destination_entity && slot_id == -1)
  1447. {
  1448. if (quantity > stack_max)
  1449. split_quantity_new = stack_max;
  1450. else
  1451. split_quantity_new = quantity;
  1452. if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
  1453. {
  1454. Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
  1455. new_item = ItemBase.Cast(o);
  1456. }
  1457. if (new_item)
  1458. {
  1459. new_item.SetResultOfSplit(true);
  1460. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1461. AddQuantity(-split_quantity_new);
  1462. new_item.SetQuantity(split_quantity_new);
  1463. }
  1464. }
  1465. else
  1466. {
  1467. if (stack_max != 0)
  1468. {
  1469. if (stack_max < GetQuantity())
  1470. {
  1471. split_quantity_new = GetQuantity() - stack_max;
  1472. }
  1473. new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(),GetWorldPosition(), ECE_PLACE_ON_SURFACE));
  1474. if (new_item)
  1475. {
  1476. new_item.SetResultOfSplit(true);
  1477. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1478. SetQuantity(split_quantity_new);
  1479. new_item.SetQuantity(stack_max);
  1480. new_item.PlaceOnSurface();
  1481. }
  1482. }
  1483. }
  1484. }
  1485. void SplitIntoStackMaxToInventoryLocationClient(notnull InventoryLocation dst)
  1486. {
  1487. if (GetGame().IsClient())
  1488. {
  1489. if (ScriptInputUserData.CanStoreInputUserData())
  1490. {
  1491. ScriptInputUserData ctx = new ScriptInputUserData;
  1492. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1493. ctx.Write(4);
  1494. ItemBase thiz = this; // @NOTE: workaround for correct serialization
  1495. ctx.Write(thiz);
  1496. dst.WriteToContext(ctx);
  1497. ctx.Send();
  1498. }
  1499. }
  1500. else if (!GetGame().IsMultiplayer())
  1501. {
  1502. SplitIntoStackMaxToInventoryLocation(dst);
  1503. }
  1504. }
  1505. void SplitIntoStackMaxCargoClient(EntityAI destination_entity, int idx, int row, int col)
  1506. {
  1507. if (GetGame().IsClient())
  1508. {
  1509. if (ScriptInputUserData.CanStoreInputUserData())
  1510. {
  1511. ScriptInputUserData ctx = new ScriptInputUserData;
  1512. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1513. ctx.Write(2);
  1514. ItemBase dummy = this; // @NOTE: workaround for correct serialization
  1515. ctx.Write(dummy);
  1516. ctx.Write(destination_entity);
  1517. ctx.Write(true);
  1518. ctx.Write(idx);
  1519. ctx.Write(row);
  1520. ctx.Write(col);
  1521. ctx.Send();
  1522. }
  1523. }
  1524. else if (!GetGame().IsMultiplayer())
  1525. {
  1526. SplitIntoStackMaxCargo(destination_entity, idx, row, col);
  1527. }
  1528. }
  1529. void SplitIntoStackMaxToInventoryLocation(notnull InventoryLocation dst)
  1530. {
  1531. SplitIntoStackMaxToInventoryLocationEx(dst);
  1532. }
  1533. ItemBase SplitIntoStackMaxToInventoryLocationEx(notnull InventoryLocation dst)
  1534. {
  1535. float quantity = GetQuantity();
  1536. float split_quantity_new;
  1537. ItemBase new_item;
  1538. if (dst.IsValid())
  1539. {
  1540. int slot_id = dst.GetSlot();
  1541. float stack_max = GetTargetQuantityMax(slot_id);
  1542. if (quantity > stack_max)
  1543. split_quantity_new = stack_max;
  1544. else
  1545. split_quantity_new = quantity;
  1546. new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, this.GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
  1547. if (new_item)
  1548. {
  1549. new_item.SetResultOfSplit(true);
  1550. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1551. AddQuantity(-split_quantity_new);
  1552. new_item.SetQuantity(split_quantity_new);
  1553. }
  1554. return new_item;
  1555. }
  1556. return null;
  1557. }
  1558. void SplitIntoStackMaxCargo(EntityAI destination_entity, int idx, int row, int col)
  1559. {
  1560. float quantity = GetQuantity();
  1561. float split_quantity_new;
  1562. ref ItemBase new_item;
  1563. if (destination_entity)
  1564. {
  1565. float stackable = GetTargetQuantityMax();
  1566. if (quantity > stackable)
  1567. split_quantity_new = stackable;
  1568. else
  1569. split_quantity_new = quantity;
  1570. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateEntityInCargoEx(this.GetType(), idx, row, col, false));
  1571. if (new_item)
  1572. {
  1573. new_item.SetResultOfSplit(true);
  1574. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1575. AddQuantity(-split_quantity_new);
  1576. new_item.SetQuantity(split_quantity_new);
  1577. }
  1578. }
  1579. }
  1580. void SplitIntoStackMaxHandsClient(PlayerBase player)
  1581. {
  1582. if (GetGame().IsClient())
  1583. {
  1584. if (ScriptInputUserData.CanStoreInputUserData())
  1585. {
  1586. ScriptInputUserData ctx = new ScriptInputUserData;
  1587. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1588. ctx.Write(3);
  1589. ItemBase i1 = this; // @NOTE: workaround for correct serialization
  1590. ctx.Write(i1);
  1591. ItemBase destination_entity = this;
  1592. ctx.Write(destination_entity);
  1593. ctx.Write(true);
  1594. ctx.Write(0);
  1595. ctx.Send();
  1596. }
  1597. }
  1598. else if (!GetGame().IsMultiplayer())
  1599. {
  1600. SplitIntoStackMaxHands(player);
  1601. }
  1602. }
  1603. void SplitIntoStackMaxHands(PlayerBase player)
  1604. {
  1605. float quantity = GetQuantity();
  1606. float split_quantity_new;
  1607. ref ItemBase new_item;
  1608. if (player)
  1609. {
  1610. float stackable = GetTargetQuantityMax();
  1611. if (quantity > stackable)
  1612. split_quantity_new = stackable;
  1613. else
  1614. split_quantity_new = quantity;
  1615. EntityAI in_hands = player.GetHumanInventory().CreateInHands(this.GetType());
  1616. new_item = ItemBase.Cast(in_hands);
  1617. if (new_item)
  1618. {
  1619. new_item.SetResultOfSplit(true);
  1620. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1621. AddQuantity(-split_quantity_new);
  1622. new_item.SetQuantity(split_quantity_new);
  1623. }
  1624. }
  1625. }
  1626. void SplitItemToInventoryLocation(notnull InventoryLocation dst)
  1627. {
  1628. if (!CanBeSplit())
  1629. return;
  1630. float quantity = GetQuantity();
  1631. float split_quantity_new = Math.Floor(quantity * 0.5);
  1632. ItemBase new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
  1633. if (new_item)
  1634. {
  1635. if (new_item.GetQuantityMax() < split_quantity_new)
  1636. {
  1637. split_quantity_new = new_item.GetQuantityMax();
  1638. }
  1639. new_item.SetResultOfSplit(true);
  1640. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1641. if (dst.IsValid() && dst.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
  1642. {
  1643. AddQuantity(-1);
  1644. new_item.SetQuantity(1);
  1645. }
  1646. else
  1647. {
  1648. AddQuantity(-split_quantity_new);
  1649. new_item.SetQuantity(split_quantity_new);
  1650. }
  1651. }
  1652. }
  1653. void SplitItem(PlayerBase player)
  1654. {
  1655. if (!CanBeSplit())
  1656. {
  1657. return;
  1658. }
  1659. float quantity = GetQuantity();
  1660. float split_quantity_new = Math.Floor(quantity / 2);
  1661. InventoryLocation invloc = new InventoryLocation;
  1662. bool found = player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.ATTACHMENT, invloc);
  1663. ItemBase new_item;
  1664. new_item = player.CreateCopyOfItemInInventoryOrGroundEx(this, true);
  1665. if (new_item)
  1666. {
  1667. if (new_item.GetQuantityMax() < split_quantity_new)
  1668. {
  1669. split_quantity_new = new_item.GetQuantityMax();
  1670. }
  1671. if (found && invloc.IsValid() && invloc.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
  1672. {
  1673. AddQuantity(-1);
  1674. new_item.SetQuantity(1);
  1675. }
  1676. else
  1677. {
  1678. AddQuantity(-split_quantity_new);
  1679. new_item.SetQuantity(split_quantity_new);
  1680. }
  1681. }
  1682. }
  1683. //! Called on server side when this item's quantity is changed. Call super.OnQuantityChanged(); first when overriding this event.
  1684. void OnQuantityChanged(float delta)
  1685. {
  1686. SetWeightDirty();
  1687. ItemBase parent = ItemBase.Cast(GetHierarchyParent());
  1688. if (parent)
  1689. parent.OnAttachmentQuantityChangedEx(this, delta);
  1690. if (IsLiquidContainer())
  1691. {
  1692. if (GetQuantityNormalized() <= 0.0)
  1693. {
  1694. SetLiquidType(LIQUID_NONE);
  1695. }
  1696. else if (GetLiquidType() == LIQUID_NONE)
  1697. {
  1698. ErrorEx("Undefined liquid type quantity changed, please define liquid type first! Using init value.",ErrorExSeverity.INFO);
  1699. SetLiquidType(GetLiquidTypeInit());
  1700. }
  1701. }
  1702. }
  1703. //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
  1704. void OnAttachmentQuantityChanged(ItemBase item)
  1705. {
  1706. // insert code here
  1707. }
  1708. //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
  1709. void OnAttachmentQuantityChangedEx(ItemBase item , float delta)
  1710. {
  1711. OnAttachmentQuantityChanged(item);
  1712. }
  1713. override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
  1714. {
  1715. super.EEHealthLevelChanged(oldLevel,newLevel,zone);
  1716. if (GetGame().IsServer())
  1717. {
  1718. if (newLevel == GameConstants.STATE_RUINED)
  1719. {
  1720. //! drops content of container when ruined in fireplace
  1721. EntityAI parent = GetHierarchyParent();
  1722. if (parent && parent.IsFireplace())
  1723. {
  1724. CargoBase cargo = GetInventory().GetCargo();
  1725. if (cargo)
  1726. {
  1727. for (int i = 0; i < cargo.GetItemCount(); ++i)
  1728. {
  1729. parent.GetInventory().TakeEntityToInventory(InventoryMode.SERVER, FindInventoryLocationType.CARGO, cargo.GetItem(i));
  1730. }
  1731. }
  1732. }
  1733. }
  1734. if (IsResultOfSplit())
  1735. {
  1736. // reset the splitting result flag, return to normal item behavior
  1737. SetResultOfSplit(false);
  1738. return;
  1739. }
  1740. if (m_Cleanness != 0 && oldLevel < newLevel && newLevel != 0)
  1741. {
  1742. SetCleanness(0);//unclean the item upon damage dealt
  1743. }
  1744. }
  1745. }
  1746. // just the split? TODO: verify
  1747. override void OnRightClick()
  1748. {
  1749. super.OnRightClick();
  1750. if (CanBeSplit() && !GetDayZGame().IsLeftCtrlDown() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(this,null))
  1751. {
  1752. if (GetGame().IsClient())
  1753. {
  1754. if (ScriptInputUserData.CanStoreInputUserData())
  1755. {
  1756. vector m4[4];
  1757. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  1758. EntityAI root = GetHierarchyRoot();
  1759. InventoryLocation dst = new InventoryLocation;
  1760. if (!player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.CARGO, dst))
  1761. {
  1762. if (root)
  1763. {
  1764. root.GetTransform(m4);
  1765. dst.SetGround(this, m4);
  1766. }
  1767. else
  1768. GetInventory().GetCurrentInventoryLocation(dst);
  1769. }
  1770. else
  1771. {
  1772. dst.SetCargo(dst.GetParent(), this, dst.GetIdx(), dst.GetRow(), dst.GetCol(), dst.GetFlip());
  1773. if (GetGame().GetPlayer().GetInventory().HasInventoryReservation(null, dst))
  1774. {
  1775. if (root)
  1776. {
  1777. root.GetTransform(m4);
  1778. dst.SetGround(this, m4);
  1779. }
  1780. else
  1781. GetInventory().GetCurrentInventoryLocation(dst);
  1782. }
  1783. else
  1784. {
  1785. GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(null, dst, GameInventory.c_InventoryReservationTimeoutShortMS);
  1786. }
  1787. }
  1788. ScriptInputUserData ctx = new ScriptInputUserData;
  1789. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1790. ctx.Write(4);
  1791. ItemBase thiz = this; // @NOTE: workaround for correct serialization
  1792. ctx.Write(thiz);
  1793. dst.WriteToContext(ctx);
  1794. ctx.Write(true); // dummy
  1795. ctx.Send();
  1796. }
  1797. }
  1798. else if (!GetGame().IsMultiplayer())
  1799. {
  1800. SplitItem(PlayerBase.Cast(GetGame().GetPlayer()));
  1801. }
  1802. }
  1803. }
  1804. override bool CanBeCombined(EntityAI other_item, bool reservation_check = true, bool stack_max_limit = false)
  1805. {
  1806. //TODO: delete check zero quantity check after fix double posts hands fsm events
  1807. if (!other_item || GetType() != other_item.GetType() || (IsFullQuantity() && other_item.GetQuantity() > 0) || other_item == this)
  1808. return false;
  1809. if (GetHealthLevel() == GameConstants.STATE_RUINED || other_item.GetHealthLevel() == GameConstants.STATE_RUINED)
  1810. return false;
  1811. //can_this_be_combined = ConfigGetBool("canBeSplit");
  1812. if (!can_this_be_combined)
  1813. return false;
  1814. Magazine mag = Magazine.Cast(this);
  1815. if (mag)
  1816. {
  1817. if (mag.GetAmmoCount() >= mag.GetAmmoMax())
  1818. return false;
  1819. if (stack_max_limit)
  1820. {
  1821. Magazine other_mag = Magazine.Cast(other_item);
  1822. if (other_item)
  1823. {
  1824. if (mag.GetAmmoCount() + other_mag.GetAmmoCount() > mag.GetAmmoMax())
  1825. return false;
  1826. }
  1827. }
  1828. }
  1829. else
  1830. {
  1831. //TODO: delete check zero quantity check after fix double posts hands fsm events
  1832. if (GetQuantity() >= GetQuantityMax() && other_item.GetQuantity() > 0 )
  1833. return false;
  1834. if (stack_max_limit && (GetQuantity() + other_item.GetQuantity() > GetQuantityMax()))
  1835. return false;
  1836. }
  1837. PlayerBase player = null;
  1838. if (CastTo(player, GetHierarchyRootPlayer())) //false when attached to player's attachment slot
  1839. {
  1840. if (player.GetInventory().HasAttachment(this))
  1841. return false;
  1842. if (player.IsItemsToDelete())
  1843. return false;
  1844. }
  1845. if (reservation_check && (GetInventory().HasInventoryReservation(this, null) || other_item.GetInventory().HasInventoryReservation(other_item, null)))
  1846. return false;
  1847. int slotID;
  1848. string slotName;
  1849. if (GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName) && GetHierarchyParent().GetInventory().GetSlotLock(slotID))
  1850. return false;
  1851. return true;
  1852. }
  1853. bool IsCombineAll(ItemBase other_item, bool use_stack_max = false)
  1854. {
  1855. return ComputeQuantityUsed(other_item, use_stack_max) == other_item.GetQuantity();
  1856. }
  1857. bool IsResultOfSplit()
  1858. {
  1859. return m_IsResultOfSplit;
  1860. }
  1861. void SetResultOfSplit(bool value)
  1862. {
  1863. m_IsResultOfSplit = value;
  1864. }
  1865. int ComputeQuantityUsed(ItemBase other_item, bool use_stack_max = true)
  1866. {
  1867. return ComputeQuantityUsedEx(other_item, use_stack_max);
  1868. }
  1869. float ComputeQuantityUsedEx(ItemBase other_item, bool use_stack_max = true)
  1870. {
  1871. float other_item_quantity = other_item.GetQuantity();
  1872. float this_free_space;
  1873. float stack_max = GetQuantityMax();
  1874. this_free_space = stack_max - GetQuantity();
  1875. if (other_item_quantity > this_free_space)
  1876. {
  1877. return this_free_space;
  1878. }
  1879. else
  1880. {
  1881. return other_item_quantity;
  1882. }
  1883. }
  1884. override void CombineItemsEx(EntityAI entity2, bool use_stack_max = true)
  1885. {
  1886. CombineItems(ItemBase.Cast(entity2),use_stack_max);
  1887. }
  1888. void CombineItems(ItemBase other_item, bool use_stack_max = true)
  1889. {
  1890. if (!CanBeCombined(other_item, false))
  1891. return;
  1892. if (!IsMagazine() && other_item)
  1893. {
  1894. float quantity_used = ComputeQuantityUsedEx(other_item,use_stack_max);
  1895. if (quantity_used != 0)
  1896. {
  1897. float hp1 = GetHealth01("","");
  1898. float hp2 = other_item.GetHealth01("","");
  1899. float hpResult = ((hp1*GetQuantity()) + (hp2*quantity_used));
  1900. hpResult = hpResult / (GetQuantity() + quantity_used);
  1901. hpResult *= GetMaxHealth();
  1902. Math.Round(hpResult);
  1903. SetHealth("", "Health", hpResult);
  1904. AddQuantity(quantity_used);
  1905. other_item.AddQuantity(-quantity_used);
  1906. }
  1907. }
  1908. OnCombine(other_item);
  1909. }
  1910. void OnCombine(ItemBase other_item)
  1911. {
  1912. #ifdef SERVER
  1913. if (!GetHierarchyRootPlayer() && GetHierarchyParent())
  1914. GetHierarchyParent().IncreaseLifetimeUp();
  1915. #endif
  1916. };
  1917. void GetRecipesActions(Man player, out TSelectableActionInfoArray outputList)
  1918. {
  1919. PlayerBase p = PlayerBase.Cast(player);
  1920. array<int> recipesIds = p.m_Recipes;
  1921. PluginRecipesManager moduleRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  1922. if (moduleRecipesManager)
  1923. {
  1924. EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands();
  1925. moduleRecipesManager.GetValidRecipes(ItemBase.Cast(this), ItemBase.Cast(itemInHands), recipesIds, p);
  1926. }
  1927. for (int i = 0;i < recipesIds.Count(); i++)
  1928. {
  1929. int key = recipesIds.Get(i);
  1930. string recipeName = moduleRecipesManager.GetRecipeName(key);
  1931. outputList.Insert(new TSelectableActionInfo(SAT_CRAFTING, key, recipeName));
  1932. }
  1933. }
  1934. // -------------------------------------------------------------------------
  1935. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  1936. {
  1937. super.GetDebugActions(outputList);
  1938. //quantity
  1939. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_QUANTITY, "Quantity +20%", FadeColors.LIGHT_GREY));
  1940. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_QUANTITY, "Quantity -20%", FadeColors.LIGHT_GREY));
  1941. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_QUANTITY_0, "Set Quantity 0", FadeColors.LIGHT_GREY));
  1942. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_MAX_QUANTITY, "Set Quantity Max", FadeColors.LIGHT_GREY));
  1943. //health
  1944. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_HEALTH, "Health +20%", FadeColors.LIGHT_GREY));
  1945. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_HEALTH, "Health -20%", FadeColors.LIGHT_GREY));
  1946. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DESTROY_HEALTH, "Health 0", FadeColors.LIGHT_GREY));
  1947. //temperature
  1948. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_TEMPERATURE, "Temperature +20", FadeColors.LIGHT_GREY));
  1949. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_TEMPERATURE, "Temperature -20", FadeColors.LIGHT_GREY));
  1950. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FLIP_FROZEN, "Toggle Frozen", FadeColors.LIGHT_GREY));
  1951. //wet
  1952. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_WETNESS, "Wetness +20", FadeColors.LIGHT_GREY));
  1953. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_WETNESS, "Wetness -20", FadeColors.LIGHT_GREY));
  1954. //liquidtype
  1955. if (IsLiquidContainer())
  1956. {
  1957. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_UP, "LiquidType Next", FadeColors.LIGHT_GREY));
  1958. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_DOWN, "LiquidType Previous", FadeColors.LIGHT_GREY));
  1959. }
  1960. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.MAKE_SPECIAL, "Make Special", FadeColors.LIGHT_GREY));
  1961. // watch
  1962. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_ITEM, "Watch (CTRL-Z)", FadeColors.LIGHT_GREY));
  1963. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_PLAYER, "Watch Player", FadeColors.LIGHT_GREY));
  1964. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
  1965. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
  1966. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
  1967. }
  1968. // -------------------------------------------------------------------------
  1969. // -------------------------------------------------------------------------
  1970. // -------------------------------------------------------------------------
  1971. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  1972. {
  1973. super.OnAction(action_id, player, ctx);
  1974. if (action_id >= EActions.RECIPES_RANGE_START && action_id < EActions.RECIPES_RANGE_END)
  1975. {
  1976. PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  1977. int idWithoutOffset = action_id - EActions.RECIPES_RANGE_START;
  1978. PlayerBase p = PlayerBase.Cast(player);
  1979. if (EActions.RECIPES_RANGE_START < 1000)
  1980. {
  1981. float anim_length = plugin_recipes_manager.GetRecipeLengthInSecs(idWithoutOffset);
  1982. float specialty_weight = plugin_recipes_manager.GetRecipeSpecialty(idWithoutOffset);
  1983. }
  1984. }
  1985. #ifndef SERVER
  1986. else if (action_id == EActions.WATCH_PLAYER)
  1987. {
  1988. PluginDeveloper.SetDeveloperItemClientEx(player);
  1989. }
  1990. #endif
  1991. if (GetGame().IsServer())
  1992. {
  1993. if (action_id >= EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START && action_id < EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_END)
  1994. {
  1995. int id = action_id - EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START;
  1996. OnDebugButtonPressServer(id + 1);
  1997. }
  1998. else if (action_id >= EActions.DEBUG_AGENTS_RANGE_INJECT_START && action_id < EActions.DEBUG_AGENTS_RANGE_INJECT_END)
  1999. {
  2000. int agent_id = action_id - EActions.DEBUG_AGENTS_RANGE_INJECT_START;
  2001. InsertAgent(agent_id,100);
  2002. }
  2003. else if (action_id >= EActions.DEBUG_AGENTS_RANGE_REMOVE_START && action_id < EActions.DEBUG_AGENTS_RANGE_REMOVE_END)
  2004. {
  2005. int agent_id2 = action_id - EActions.DEBUG_AGENTS_RANGE_REMOVE_START;
  2006. RemoveAgent(agent_id2);
  2007. }
  2008. else if (action_id == EActions.ADD_QUANTITY)
  2009. {
  2010. if (IsMagazine())
  2011. {
  2012. Magazine mag = Magazine.Cast(this);
  2013. mag.ServerSetAmmoCount(mag.GetAmmoCount() + mag.GetAmmoMax() * 0.2);
  2014. }
  2015. else
  2016. {
  2017. AddQuantity(GetQuantityMax() * 0.2);
  2018. }
  2019. if (m_EM)
  2020. {
  2021. m_EM.AddEnergy(m_EM.GetEnergyMax() * 0.2);
  2022. }
  2023. //PrintVariables();
  2024. }
  2025. else if (action_id == EActions.REMOVE_QUANTITY) //Quantity -20%
  2026. {
  2027. if (IsMagazine())
  2028. {
  2029. Magazine mag2 = Magazine.Cast(this);
  2030. mag2.ServerSetAmmoCount(mag2.GetAmmoCount() - mag2.GetAmmoMax() * 0.2);
  2031. }
  2032. else
  2033. {
  2034. AddQuantity(- GetQuantityMax() * 0.2);
  2035. }
  2036. if (m_EM)
  2037. {
  2038. m_EM.AddEnergy(- m_EM.GetEnergyMax() * 0.2);
  2039. }
  2040. //PrintVariables();
  2041. }
  2042. else if (action_id == EActions.SET_QUANTITY_0) //SetMaxQuantity
  2043. {
  2044. SetQuantity(0);
  2045. if (m_EM)
  2046. {
  2047. m_EM.SetEnergy(0);
  2048. }
  2049. }
  2050. else if (action_id == EActions.SET_MAX_QUANTITY) //SetMaxQuantity
  2051. {
  2052. SetQuantityMax();
  2053. if (m_EM)
  2054. {
  2055. m_EM.SetEnergy(m_EM.GetEnergyMax());
  2056. }
  2057. }
  2058. else if (action_id == EActions.ADD_HEALTH)
  2059. {
  2060. AddHealth("","",GetMaxHealth("","Health")/5);
  2061. }
  2062. else if (action_id == EActions.REMOVE_HEALTH)
  2063. {
  2064. AddHealth("","",-GetMaxHealth("","Health")/5);
  2065. }
  2066. else if (action_id == EActions.DESTROY_HEALTH)
  2067. {
  2068. SetHealth01("","",0);
  2069. }
  2070. else if (action_id == EActions.WATCH_ITEM)
  2071. {
  2072. PluginItemDiagnostic mid = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  2073. mid.RegisterDebugItem(ItemBase.Cast(this), PlayerBase.Cast(player));
  2074. #ifdef DEVELOPER
  2075. SetDebugDeveloper_item(this);
  2076. #endif
  2077. }
  2078. else if (action_id == EActions.ADD_TEMPERATURE)
  2079. {
  2080. AddTemperature(20);
  2081. //PrintVariables();
  2082. }
  2083. else if (action_id == EActions.REMOVE_TEMPERATURE)
  2084. {
  2085. AddTemperature(-20);
  2086. //PrintVariables();
  2087. }
  2088. else if (action_id == EActions.FLIP_FROZEN)
  2089. {
  2090. SetFrozen(!GetIsFrozen());
  2091. //PrintVariables();
  2092. }
  2093. else if (action_id == EActions.ADD_WETNESS)
  2094. {
  2095. AddWet(GetWetMax()/5);
  2096. //PrintVariables();
  2097. }
  2098. else if (action_id == EActions.REMOVE_WETNESS)
  2099. {
  2100. AddWet(-GetWetMax()/5);
  2101. //PrintVariables();
  2102. }
  2103. else if (action_id == EActions.LIQUIDTYPE_UP)
  2104. {
  2105. int curr_type = GetLiquidType();
  2106. SetLiquidType(curr_type * 2);
  2107. //AddWet(1);
  2108. //PrintVariables();
  2109. }
  2110. else if (action_id == EActions.LIQUIDTYPE_DOWN)
  2111. {
  2112. int curr_type2 = GetLiquidType();
  2113. SetLiquidType(curr_type2 / 2);
  2114. }
  2115. else if (action_id == EActions.MAKE_SPECIAL)
  2116. {
  2117. auto debugParams = DebugSpawnParams.WithPlayer(player);
  2118. OnDebugSpawnEx(debugParams);
  2119. }
  2120. else if (action_id == EActions.DELETE)
  2121. {
  2122. Delete();
  2123. }
  2124. }
  2125. return false;
  2126. }
  2127. // -------------------------------------------------------------------------
  2128. //! DEPRECATED use OnActivatedByItem below
  2129. //! Called when this item is activated from a trip wire that was stepped on.
  2130. void OnActivatedByTripWire();
  2131. //! Called when this item is activated by other
  2132. void OnActivatedByItem(notnull ItemBase item);
  2133. //----------------------------------------------------------------
  2134. //returns true if item is able to explode when put in fire
  2135. bool CanExplodeInFire()
  2136. {
  2137. return false;
  2138. }
  2139. //----------------------------------------------------------------
  2140. bool CanEat()
  2141. {
  2142. return true;
  2143. }
  2144. //----------------------------------------------------------------
  2145. override bool IsIgnoredByConstruction()
  2146. {
  2147. return true;
  2148. }
  2149. //----------------------------------------------------------------
  2150. //has FoodStages in config?
  2151. bool HasFoodStage()
  2152. {
  2153. string config_path = string.Format("CfgVehicles %1 Food FoodStages", GetType());
  2154. return GetGame().ConfigIsExisting(config_path);
  2155. }
  2156. //! overridden on Edible_Base; so we don't have to parse configs all the time
  2157. FoodStage GetFoodStage()
  2158. {
  2159. return null;
  2160. }
  2161. bool CanBeCooked()
  2162. {
  2163. return false;
  2164. }
  2165. bool CanBeCookedOnStick()
  2166. {
  2167. return false;
  2168. }
  2169. //----------------------------------------------------------------
  2170. bool CanRepair(ItemBase item_repair_kit)
  2171. {
  2172. PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
  2173. return module_repairing.CanRepair(this, item_repair_kit);
  2174. }
  2175. //----------------------------------------------------------------
  2176. bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight)
  2177. {
  2178. PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
  2179. return module_repairing.Repair(player, this, item_repair_kit, specialty_weight);
  2180. }
  2181. //----------------------------------------------------------------
  2182. int GetItemSize()
  2183. {
  2184. /*
  2185. vector v_size = this.ConfigGetVector("itemSize");
  2186. int v_size_x = v_size[0];
  2187. int v_size_y = v_size[1];
  2188. int size = v_size_x * v_size_y;
  2189. return size;
  2190. */
  2191. return 1;
  2192. }
  2193. //----------------------------------------------------------------
  2194. //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
  2195. bool CanBeMovedOverride()
  2196. {
  2197. return m_CanBeMovedOverride;
  2198. }
  2199. //----------------------------------------------------------------
  2200. //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
  2201. void SetCanBeMovedOverride(bool setting)
  2202. {
  2203. m_CanBeMovedOverride = setting;
  2204. }
  2205. //----------------------------------------------------------------
  2206. /**
  2207. \brief Send message to owner player in grey color
  2208. \return \p void
  2209. @code
  2210. item_stone.MessageToOwnerStatus("Some Status Message");
  2211. @endcode
  2212. */
  2213. void MessageToOwnerStatus(string text)
  2214. {
  2215. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2216. if (player)
  2217. {
  2218. player.MessageStatus(text);
  2219. }
  2220. }
  2221. //----------------------------------------------------------------
  2222. /**
  2223. \brief Send message to owner player in yellow color
  2224. \return \p void
  2225. @code
  2226. item_stone.MessageToOwnerAction("Some Action Message");
  2227. @endcode
  2228. */
  2229. void MessageToOwnerAction(string text)
  2230. {
  2231. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2232. if (player)
  2233. {
  2234. player.MessageAction(text);
  2235. }
  2236. }
  2237. //----------------------------------------------------------------
  2238. /**
  2239. \brief Send message to owner player in green color
  2240. \return \p void
  2241. @code
  2242. item_stone.MessageToOwnerFriendly("Some Friendly Message");
  2243. @endcode
  2244. */
  2245. void MessageToOwnerFriendly(string text)
  2246. {
  2247. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2248. if (player)
  2249. {
  2250. player.MessageFriendly(text);
  2251. }
  2252. }
  2253. //----------------------------------------------------------------
  2254. /**
  2255. \brief Send message to owner player in red color
  2256. \return \p void
  2257. @code
  2258. item_stone.MessageToOwnerImportant("Some Important Message");
  2259. @endcode
  2260. */
  2261. void MessageToOwnerImportant(string text)
  2262. {
  2263. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2264. if (player)
  2265. {
  2266. player.MessageImportant(text);
  2267. }
  2268. }
  2269. override bool IsItemBase()
  2270. {
  2271. return true;
  2272. }
  2273. // Checks if item is of questioned kind
  2274. override bool KindOf(string tag)
  2275. {
  2276. bool found = false;
  2277. string item_name = this.GetType();
  2278. ref TStringArray item_tag_array = new TStringArray;
  2279. GetGame().ConfigGetTextArray("cfgVehicles " + item_name + " itemInfo", item_tag_array);
  2280. int array_size = item_tag_array.Count();
  2281. for (int i = 0; i < array_size; i++)
  2282. {
  2283. if (item_tag_array.Get(i) == tag)
  2284. {
  2285. found = true;
  2286. break;
  2287. }
  2288. }
  2289. return found;
  2290. }
  2291. override void OnRPC(PlayerIdentity sender, int rpc_type,ParamsReadContext ctx)
  2292. {
  2293. //Debug.Log("OnRPC called");
  2294. super.OnRPC(sender, rpc_type,ctx);
  2295. //Play soundset for attachment locking (ActionLockAttachment.c)
  2296. switch (rpc_type)
  2297. {
  2298. #ifndef SERVER
  2299. case ERPCs.RPC_SOUND_LOCK_ATTACH:
  2300. Param2<bool, string> p = new Param2<bool, string>(false, "");
  2301. if (!ctx.Read(p))
  2302. return;
  2303. bool play = p.param1;
  2304. string soundSet = p.param2;
  2305. if (play)
  2306. {
  2307. if (m_LockingSound)
  2308. {
  2309. if (!m_LockingSound.IsSoundPlaying())
  2310. {
  2311. m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
  2312. }
  2313. }
  2314. else
  2315. {
  2316. m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
  2317. }
  2318. }
  2319. else
  2320. {
  2321. SEffectManager.DestroyEffect(m_LockingSound);
  2322. }
  2323. break;
  2324. #endif
  2325. }
  2326. if (GetWrittenNoteData())
  2327. {
  2328. GetWrittenNoteData().OnRPC(sender, rpc_type,ctx);
  2329. }
  2330. }
  2331. //-----------------------------
  2332. // VARIABLE MANIPULATION SYSTEM
  2333. //-----------------------------
  2334. int NameToID(string name)
  2335. {
  2336. PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
  2337. return plugin.GetID(name);
  2338. }
  2339. string IDToName(int id)
  2340. {
  2341. PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
  2342. return plugin.GetName(id);
  2343. }
  2344. //! DEPRECATED (most likely)
  2345. void OnSyncVariables(ParamsReadContext ctx)//with ID optimization
  2346. {
  2347. //Debug.Log("OnSyncVariables called for item: "+ ToString(this.GetType()),"varSync");
  2348. //read the flags
  2349. int varFlags;
  2350. if (!ctx.Read(varFlags))
  2351. return;
  2352. if (varFlags & ItemVariableFlags.FLOAT)
  2353. {
  2354. ReadVarsFromCTX(ctx);
  2355. }
  2356. }
  2357. override void SerializeNumericalVars(array<float> floats_out)
  2358. {
  2359. //some variables handled on EntityAI level already!
  2360. super.SerializeNumericalVars(floats_out);
  2361. // the order of serialization must be the same as the order of de-serialization
  2362. //--------------------------------------------
  2363. if (IsVariableSet(VARIABLE_QUANTITY))
  2364. {
  2365. floats_out.Insert(m_VarQuantity);
  2366. }
  2367. //--------------------------------------------
  2368. if (IsVariableSet(VARIABLE_WET))
  2369. {
  2370. floats_out.Insert(m_VarWet);
  2371. }
  2372. //--------------------------------------------
  2373. if (IsVariableSet(VARIABLE_LIQUIDTYPE))
  2374. {
  2375. floats_out.Insert(m_VarLiquidType);
  2376. }
  2377. //--------------------------------------------
  2378. if (IsVariableSet(VARIABLE_COLOR))
  2379. {
  2380. floats_out.Insert(m_ColorComponentR);
  2381. floats_out.Insert(m_ColorComponentG);
  2382. floats_out.Insert(m_ColorComponentB);
  2383. floats_out.Insert(m_ColorComponentA);
  2384. }
  2385. //--------------------------------------------
  2386. if (IsVariableSet(VARIABLE_CLEANNESS))
  2387. {
  2388. floats_out.Insert(m_Cleanness);
  2389. }
  2390. }
  2391. override void DeSerializeNumericalVars(array<float> floats)
  2392. {
  2393. //some variables handled on EntityAI level already!
  2394. super.DeSerializeNumericalVars(floats);
  2395. // the order of serialization must be the same as the order of de-serialization
  2396. int index = 0;
  2397. int mask = Math.Round(floats.Get(index));
  2398. index++;
  2399. //--------------------------------------------
  2400. if (mask & VARIABLE_QUANTITY)
  2401. {
  2402. if (m_IsStoreLoad)
  2403. {
  2404. SetStoreLoadedQuantity(floats.Get(index));
  2405. }
  2406. else
  2407. {
  2408. float quantity = floats.Get(index);
  2409. SetQuantity(quantity, true, false, false, false);
  2410. }
  2411. index++;
  2412. }
  2413. //--------------------------------------------
  2414. if (mask & VARIABLE_WET)
  2415. {
  2416. float wet = floats.Get(index);
  2417. SetWet(wet);
  2418. index++;
  2419. }
  2420. //--------------------------------------------
  2421. if (mask & VARIABLE_LIQUIDTYPE)
  2422. {
  2423. int liquidtype = Math.Round(floats.Get(index));
  2424. SetLiquidType(liquidtype);
  2425. index++;
  2426. }
  2427. //--------------------------------------------
  2428. if (mask & VARIABLE_COLOR)
  2429. {
  2430. m_ColorComponentR = Math.Round(floats.Get(index));
  2431. index++;
  2432. m_ColorComponentG = Math.Round(floats.Get(index));
  2433. index++;
  2434. m_ColorComponentB = Math.Round(floats.Get(index));
  2435. index++;
  2436. m_ColorComponentA = Math.Round(floats.Get(index));
  2437. index++;
  2438. }
  2439. //--------------------------------------------
  2440. if (mask & VARIABLE_CLEANNESS)
  2441. {
  2442. int cleanness = Math.Round(floats.Get(index));
  2443. SetCleanness(cleanness);
  2444. index++;
  2445. }
  2446. }
  2447. override void WriteVarsToCTX(ParamsWriteContext ctx)
  2448. {
  2449. super.WriteVarsToCTX(ctx);
  2450. //--------------------------------------------
  2451. if (IsVariableSet(VARIABLE_QUANTITY))
  2452. {
  2453. ctx.Write(GetQuantity());
  2454. }
  2455. //--------------------------------------------
  2456. if (IsVariableSet(VARIABLE_WET))
  2457. {
  2458. ctx.Write(GetWet());
  2459. }
  2460. //--------------------------------------------
  2461. if (IsVariableSet(VARIABLE_LIQUIDTYPE))
  2462. {
  2463. ctx.Write(GetLiquidType());
  2464. }
  2465. //--------------------------------------------
  2466. if (IsVariableSet(VARIABLE_COLOR))
  2467. {
  2468. int r,g,b,a;
  2469. GetColor(r,g,b,a);
  2470. ctx.Write(r);
  2471. ctx.Write(g);
  2472. ctx.Write(b);
  2473. ctx.Write(a);
  2474. }
  2475. //--------------------------------------------
  2476. if (IsVariableSet(VARIABLE_CLEANNESS))
  2477. {
  2478. ctx.Write(GetCleanness());
  2479. }
  2480. }
  2481. override bool ReadVarsFromCTX(ParamsReadContext ctx, int version = -1)//with ID optimization
  2482. {
  2483. if (!super.ReadVarsFromCTX(ctx,version))
  2484. return false;
  2485. int intValue;
  2486. float value;
  2487. if (version < 140)
  2488. {
  2489. if (!ctx.Read(intValue))
  2490. return false;
  2491. m_VariablesMask = intValue;
  2492. }
  2493. if (m_VariablesMask & VARIABLE_QUANTITY)
  2494. {
  2495. if (!ctx.Read(value))
  2496. return false;
  2497. if (IsStoreLoad())
  2498. {
  2499. SetStoreLoadedQuantity(value);
  2500. }
  2501. else
  2502. {
  2503. SetQuantity(value, true, false, false, false);
  2504. }
  2505. }
  2506. //--------------------------------------------
  2507. if (version < 140)
  2508. {
  2509. if (m_VariablesMask & VARIABLE_TEMPERATURE)
  2510. {
  2511. if (!ctx.Read(value))
  2512. return false;
  2513. SetTemperatureDirect(value);
  2514. }
  2515. }
  2516. //--------------------------------------------
  2517. if (m_VariablesMask & VARIABLE_WET)
  2518. {
  2519. if (!ctx.Read(value))
  2520. return false;
  2521. SetWet(value);
  2522. }
  2523. //--------------------------------------------
  2524. if (m_VariablesMask & VARIABLE_LIQUIDTYPE)
  2525. {
  2526. if (!ctx.Read(intValue))
  2527. return false;
  2528. SetLiquidType(intValue);
  2529. }
  2530. //--------------------------------------------
  2531. if (m_VariablesMask & VARIABLE_COLOR)
  2532. {
  2533. int r,g,b,a;
  2534. if (!ctx.Read(r))
  2535. return false;
  2536. if (!ctx.Read(g))
  2537. return false;
  2538. if (!ctx.Read(b))
  2539. return false;
  2540. if (!ctx.Read(a))
  2541. return false;
  2542. SetColor(r,g,b,a);
  2543. }
  2544. //--------------------------------------------
  2545. if (m_VariablesMask & VARIABLE_CLEANNESS)
  2546. {
  2547. if (!ctx.Read(intValue))
  2548. return false;
  2549. SetCleanness(intValue);
  2550. }
  2551. //--------------------------------------------
  2552. if (version >= 138 && version < 140)
  2553. {
  2554. if (m_VariablesMask & VARIABLE_TEMPERATURE)
  2555. {
  2556. if (!ctx.Read(intValue))
  2557. return false;
  2558. SetFrozen(intValue);
  2559. }
  2560. }
  2561. return true;
  2562. }
  2563. //----------------------------------------------------------------
  2564. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  2565. {
  2566. m_IsStoreLoad = true;
  2567. if (GetDamageSystemVersionChange() != -1 && version < GetDamageSystemVersionChange())
  2568. {
  2569. m_FixDamageSystemInit = true;
  2570. }
  2571. if (!super.OnStoreLoad(ctx, version))
  2572. {
  2573. m_IsStoreLoad = false;
  2574. return false;
  2575. }
  2576. if (version >= 114)
  2577. {
  2578. bool hasQuickBarIndexSaved;
  2579. if (!ctx.Read(hasQuickBarIndexSaved))
  2580. {
  2581. m_IsStoreLoad = false;
  2582. return false;
  2583. }
  2584. if (hasQuickBarIndexSaved)
  2585. {
  2586. int itmQBIndex;
  2587. //Load quickbar item bind
  2588. if (!ctx.Read(itmQBIndex))
  2589. {
  2590. m_IsStoreLoad = false;
  2591. return false;
  2592. }
  2593. PlayerBase parentPlayer = PlayerBase.Cast(GetHierarchyRootPlayer());
  2594. if (itmQBIndex != -1 && parentPlayer)
  2595. parentPlayer.SetLoadedQuickBarItemBind(this, itmQBIndex);
  2596. }
  2597. }
  2598. else
  2599. {
  2600. // Backup of how it used to be
  2601. PlayerBase player;
  2602. int itemQBIndex;
  2603. if (version == int.MAX)
  2604. {
  2605. if (!ctx.Read(itemQBIndex))
  2606. {
  2607. m_IsStoreLoad = false;
  2608. return false;
  2609. }
  2610. }
  2611. else if (Class.CastTo(player, GetHierarchyRootPlayer()))
  2612. {
  2613. //Load quickbar item bind
  2614. if (!ctx.Read(itemQBIndex))
  2615. {
  2616. m_IsStoreLoad = false;
  2617. return false;
  2618. }
  2619. if (itemQBIndex != -1 && player)
  2620. player.SetLoadedQuickBarItemBind(this,itemQBIndex);
  2621. }
  2622. }
  2623. if (version < 140)
  2624. {
  2625. // variable management system
  2626. if (!LoadVariables(ctx, version))
  2627. {
  2628. m_IsStoreLoad = false;
  2629. return false;
  2630. }
  2631. }
  2632. //agent trasmission system
  2633. if (!LoadAgents(ctx, version))
  2634. {
  2635. m_IsStoreLoad = false;
  2636. return false;
  2637. }
  2638. if (version >= 132)
  2639. {
  2640. RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
  2641. if (raib)
  2642. {
  2643. if (!raib.OnStoreLoad(ctx,version))
  2644. {
  2645. m_IsStoreLoad = false;
  2646. return false;
  2647. }
  2648. }
  2649. }
  2650. m_IsStoreLoad = false;
  2651. return true;
  2652. }
  2653. //----------------------------------------------------------------
  2654. override void OnStoreSave(ParamsWriteContext ctx)
  2655. {
  2656. super.OnStoreSave(ctx);
  2657. PlayerBase player;
  2658. if (PlayerBase.CastTo(player,GetHierarchyRootPlayer()))
  2659. {
  2660. ctx.Write(true); // Keep track of if we should actually read this in or not
  2661. //Save quickbar item bind
  2662. int itemQBIndex = -1;
  2663. itemQBIndex = player.FindQuickBarEntityIndex(this);
  2664. ctx.Write(itemQBIndex);
  2665. }
  2666. else
  2667. {
  2668. ctx.Write(false); // Keep track of if we should actually read this in or not
  2669. }
  2670. SaveAgents(ctx);//agent trasmission system
  2671. RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
  2672. if (raib)
  2673. {
  2674. raib.OnStoreSave(ctx);
  2675. }
  2676. }
  2677. //----------------------------------------------------------------
  2678. override void AfterStoreLoad()
  2679. {
  2680. super.AfterStoreLoad();
  2681. if (m_FixDamageSystemInit)
  2682. {
  2683. PerformDamageSystemReinit();
  2684. }
  2685. if (GetStoreLoadedQuantity() != float.LOWEST)
  2686. {
  2687. SetQuantity(GetStoreLoadedQuantity());
  2688. 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
  2689. }
  2690. }
  2691. override void EEOnAfterLoad()
  2692. {
  2693. super.EEOnAfterLoad();
  2694. if (m_FixDamageSystemInit)
  2695. {
  2696. m_FixDamageSystemInit = false;
  2697. }
  2698. if (GetRemotelyActivatedItemBehaviour())
  2699. GetRemotelyActivatedItemBehaviour().OnAfterLoad();
  2700. }
  2701. bool CanBeDisinfected()
  2702. {
  2703. return false;
  2704. }
  2705. //----------------------------------------------------------------
  2706. override void OnVariablesSynchronized()
  2707. {
  2708. if (m_Initialized)
  2709. {
  2710. #ifdef PLATFORM_CONSOLE
  2711. //bruteforce it is
  2712. if (IsSplitable())
  2713. {
  2714. UIScriptedMenu menu = GetGame().GetUIManager().FindMenu(MENU_INVENTORY);
  2715. if (menu)
  2716. {
  2717. menu.Refresh();
  2718. }
  2719. }
  2720. #endif
  2721. }
  2722. if (CanPlayDeployLoopSound())
  2723. {
  2724. PlayDeployLoopSoundEx();
  2725. }
  2726. if (m_DeployLoopSoundEx && !CanPlayDeployLoopSound())
  2727. {
  2728. StopDeployLoopSoundEx();
  2729. }
  2730. if (IsDeploySound())
  2731. {
  2732. PlayDeploySound();
  2733. }
  2734. if (!dBodyIsDynamic(this) && m_WantPlayImpactSound)
  2735. {
  2736. PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash);
  2737. m_WantPlayImpactSound = false;
  2738. }
  2739. if (m_VarQuantity != m_VarQuantityPrev)
  2740. {
  2741. SetWeightDirty();
  2742. m_VarQuantityPrev = m_VarQuantity;
  2743. }
  2744. if (m_VarWet != m_VarWetPrev)
  2745. {
  2746. OnWetChanged(m_VarWet,m_VarWetPrev);
  2747. m_VarWetPrev = m_VarWet;
  2748. }
  2749. super.OnVariablesSynchronized();
  2750. }
  2751. //------------------------- Quantity
  2752. //----------------------------------------------------------------
  2753. //! 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
  2754. override bool SetQuantity(float value, bool destroy_config = true, bool destroy_forced = false, bool allow_client = false, bool clamp_to_stack_max = true)
  2755. {
  2756. if (!IsServerCheck(allow_client))
  2757. return false;
  2758. if (!HasQuantity())
  2759. return false;
  2760. float min = GetQuantityMin();
  2761. float max = GetQuantityMax();
  2762. if (value <= (min + 0.001))
  2763. value = min;
  2764. if (value == min)
  2765. {
  2766. if (destroy_config)
  2767. {
  2768. bool dstr = ConfigGetBool("varQuantityDestroyOnMin");
  2769. if (dstr)
  2770. {
  2771. m_VarQuantity = Math.Clamp(value, min, max);
  2772. this.Delete();
  2773. return true;
  2774. }
  2775. }
  2776. else if (destroy_forced)
  2777. {
  2778. m_VarQuantity = Math.Clamp(value, min, max);
  2779. this.Delete();
  2780. return true;
  2781. }
  2782. // we get here if destroy_config IS true AND dstr(config destroy param) IS false;
  2783. RemoveAllAgents();//we remove all agents when we got to the min value, but the item is not getting deleted
  2784. }
  2785. float delta = m_VarQuantity;
  2786. m_VarQuantity = Math.Clamp(value, min, max);
  2787. if (GetStoreLoadedQuantity() == float.LOWEST)//any other value means we are setting quantity from storage
  2788. {
  2789. delta = m_VarQuantity - delta;
  2790. if (delta)
  2791. OnQuantityChanged(delta);
  2792. }
  2793. SetVariableMask(VARIABLE_QUANTITY);
  2794. return false;
  2795. }
  2796. //----------------------------------------------------------------
  2797. //! 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
  2798. bool AddQuantity(float value, bool destroy_config = true, bool destroy_forced = false)
  2799. {
  2800. return SetQuantity(GetQuantity() + value, destroy_config, destroy_forced);
  2801. }
  2802. //----------------------------------------------------------------
  2803. void SetQuantityMax()
  2804. {
  2805. float max = GetQuantityMax();
  2806. SetQuantity(max);
  2807. }
  2808. override void SetQuantityToMinimum()
  2809. {
  2810. float min = GetQuantityMin();
  2811. SetQuantity(min);
  2812. }
  2813. //----------------------------------------------------------------
  2814. //! 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)
  2815. void SetQuantityNormalized(float value, bool destroy_config = true, bool destroy_forced = false)
  2816. {
  2817. float value_clamped = Math.Clamp(value, 0, 1);//just to make sure
  2818. int result = Math.Round(Math.Lerp(GetQuantityMin(), GetQuantityMax(), value_clamped));
  2819. SetQuantity(result, destroy_config, destroy_forced);
  2820. }
  2821. //----------------------------------------------------------------
  2822. //! 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)
  2823. override float GetQuantityNormalized()
  2824. {
  2825. return Math.InverseLerp(GetQuantityMin(), GetQuantityMax(),m_VarQuantity);
  2826. }
  2827. float GetQuantityNormalizedScripted()
  2828. {
  2829. return GetQuantityNormalized();
  2830. }
  2831. /*void SetAmmoNormalized(float value)
  2832. {
  2833. float value_clamped = Math.Clamp(value, 0, 1);
  2834. Magazine this_mag = Magazine.Cast(this);
  2835. int max_rounds = this_mag.GetAmmoMax();
  2836. int result = value * max_rounds;//can the rounded if higher precision is required
  2837. this_mag.SetAmmoCount(result);
  2838. }*/
  2839. //----------------------------------------------------------------
  2840. override int GetQuantityMax()
  2841. {
  2842. int slot = -1;
  2843. if (GetInventory())
  2844. {
  2845. InventoryLocation il = new InventoryLocation;
  2846. GetInventory().GetCurrentInventoryLocation(il);
  2847. slot = il.GetSlot();
  2848. }
  2849. return GetTargetQuantityMax(slot);
  2850. }
  2851. override int GetTargetQuantityMax(int attSlotID = -1)
  2852. {
  2853. float quantity_max = 0;
  2854. if (IsSplitable()) //only stackable/splitable items can check for stack size
  2855. {
  2856. if (attSlotID != -1)
  2857. quantity_max = InventorySlots.GetStackMaxForSlotId(attSlotID);
  2858. if (quantity_max <= 0)
  2859. quantity_max = m_VarStackMax;
  2860. }
  2861. if (quantity_max <= 0)
  2862. quantity_max = m_VarQuantityMax;
  2863. return quantity_max;
  2864. }
  2865. //----------------------------------------------------------------
  2866. override int GetQuantityMin()
  2867. {
  2868. return m_VarQuantityMin;
  2869. }
  2870. //----------------------------------------------------------------
  2871. int GetQuantityInit()
  2872. {
  2873. return m_VarQuantityInit;
  2874. }
  2875. //----------------------------------------------------------------
  2876. override bool HasQuantity()
  2877. {
  2878. return !(GetQuantityMax() - GetQuantityMin() == 0);
  2879. }
  2880. override float GetQuantity()
  2881. {
  2882. return m_VarQuantity;
  2883. }
  2884. bool IsFullQuantity()
  2885. {
  2886. return GetQuantity() >= GetQuantityMax();
  2887. }
  2888. //Calculates weight of single item without attachments and cargo
  2889. override float GetSingleInventoryItemWeightEx()
  2890. {
  2891. //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
  2892. float weightEx = GetWeightEx();//overall weight of the item
  2893. float special = GetInventoryAndCargoWeight();//cargo and attachment weight
  2894. return weightEx - special;
  2895. }
  2896. // Obsolete, use GetSingleInventoryItemWeightEx() instead
  2897. float GetSingleInventoryItemWeight()
  2898. {
  2899. return GetSingleInventoryItemWeightEx();
  2900. }
  2901. override protected float GetWeightSpecialized(bool forceRecalc = false)
  2902. {
  2903. if (IsSplitable()) //quantity determines size of the stack
  2904. {
  2905. #ifdef DEVELOPER
  2906. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2907. {
  2908. WeightDebugData data1 = WeightDebug.GetWeightDebug(this);
  2909. data1.SetCalcDetails("TIB1: " + GetConfigWeightModifiedDebugText() +" * " + GetQuantity()+"(quantity)");
  2910. }
  2911. #endif
  2912. return GetQuantity() * GetConfigWeightModified();
  2913. }
  2914. else if (HasEnergyManager())// items with energy manager
  2915. {
  2916. #ifdef DEVELOPER
  2917. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2918. {
  2919. WeightDebugData data2 = WeightDebug.GetWeightDebug(this);
  2920. data2.SetCalcDetails("TIB2: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetCompEM().GetEnergy()+"(energy) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit)");
  2921. }
  2922. #endif
  2923. return super.GetWeightSpecialized(forceRecalc) + (GetCompEM().GetEnergy() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
  2924. }
  2925. else//everything else
  2926. {
  2927. #ifdef DEVELOPER
  2928. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2929. {
  2930. WeightDebugData data3 = WeightDebug.GetWeightDebug(this);
  2931. data3.SetCalcDetails("TIB3: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetQuantity()+"(quantity) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit))");
  2932. }
  2933. #endif
  2934. return super.GetWeightSpecialized(forceRecalc) + (GetQuantity() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
  2935. }
  2936. }
  2937. //! Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
  2938. int GetNumberOfItems()
  2939. {
  2940. int item_count = 0;
  2941. ItemBase item;
  2942. if (GetInventory().GetCargo() != NULL)
  2943. {
  2944. item_count = GetInventory().GetCargo().GetItemCount();
  2945. }
  2946. for (int i = 0; i < GetInventory().AttachmentCount(); i++)
  2947. {
  2948. Class.CastTo(item,GetInventory().GetAttachmentFromIndex(i));
  2949. if (item)
  2950. item_count += item.GetNumberOfItems();
  2951. }
  2952. return item_count;
  2953. }
  2954. //! Obsolete, use GetWeightEx instead
  2955. float GetUnitWeight(bool include_wetness = true)
  2956. {
  2957. float weight = 0;
  2958. float wetness = 1;
  2959. if (include_wetness)
  2960. wetness += GetWet();
  2961. if (IsSplitable()) //quantity determines size of the stack
  2962. {
  2963. weight = wetness * m_ConfigWeight;
  2964. }
  2965. else if (IsLiquidContainer()) //is a liquid container, default liquid weight is set to 1. May revisit later?
  2966. {
  2967. weight = 1;
  2968. }
  2969. return weight;
  2970. }
  2971. //-----------------------------------------------------------------
  2972. override void ClearInventory()
  2973. {
  2974. if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && GetInventory())
  2975. {
  2976. GameInventory inv = GetInventory();
  2977. array<EntityAI> items = new array<EntityAI>;
  2978. inv.EnumerateInventory(InventoryTraversalType.INORDER, items);
  2979. for (int i = 0; i < items.Count(); i++)
  2980. {
  2981. ItemBase item = ItemBase.Cast(items.Get(i));
  2982. if (item)
  2983. {
  2984. GetGame().ObjectDelete(item);
  2985. }
  2986. }
  2987. }
  2988. }
  2989. //------------------------- Energy
  2990. //----------------------------------------------------------------
  2991. float GetEnergy()
  2992. {
  2993. float energy = 0;
  2994. if (HasEnergyManager())
  2995. {
  2996. energy = GetCompEM().GetEnergy();
  2997. }
  2998. return energy;
  2999. }
  3000. override void OnEnergyConsumed()
  3001. {
  3002. super.OnEnergyConsumed();
  3003. ConvertEnergyToQuantity();
  3004. }
  3005. override void OnEnergyAdded()
  3006. {
  3007. super.OnEnergyAdded();
  3008. ConvertEnergyToQuantity();
  3009. }
  3010. // Converts energy (from Energy Manager) to quantity, if enabled.
  3011. void ConvertEnergyToQuantity()
  3012. {
  3013. if (GetGame().IsServer() && HasEnergyManager() && GetCompEM().HasConversionOfEnergyToQuantity())
  3014. {
  3015. if (HasQuantity())
  3016. {
  3017. float energy_0to1 = GetCompEM().GetEnergy0To1();
  3018. SetQuantityNormalized(energy_0to1);
  3019. }
  3020. }
  3021. }
  3022. //----------------------------------------------------------------
  3023. float GetHeatIsolationInit()
  3024. {
  3025. return ConfigGetFloat("heatIsolation");
  3026. }
  3027. float GetHeatIsolation()
  3028. {
  3029. return m_HeatIsolation;
  3030. }
  3031. float GetDryingIncrement(string pIncrementName)
  3032. {
  3033. string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Drying %2", GetType(), pIncrementName);
  3034. if (GetGame().ConfigIsExisting(paramPath))
  3035. return GetGame().ConfigGetFloat(paramPath);
  3036. return 0.0;
  3037. }
  3038. float GetSoakingIncrement(string pIncrementName)
  3039. {
  3040. string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Soaking %2", GetType(), pIncrementName);
  3041. if (GetGame().ConfigIsExisting(paramPath))
  3042. return GetGame().ConfigGetFloat(paramPath);
  3043. return 0.0;
  3044. }
  3045. //----------------------------------------------------------------
  3046. override void SetWet(float value, bool allow_client = false)
  3047. {
  3048. if (!IsServerCheck(allow_client))
  3049. return;
  3050. float min = GetWetMin();
  3051. float max = GetWetMax();
  3052. float previousValue = m_VarWet;
  3053. m_VarWet = Math.Clamp(value, min, max);
  3054. if (previousValue != m_VarWet)
  3055. {
  3056. SetVariableMask(VARIABLE_WET);
  3057. OnWetChanged(m_VarWet, previousValue);
  3058. }
  3059. }
  3060. //----------------------------------------------------------------
  3061. override void AddWet(float value)
  3062. {
  3063. SetWet(GetWet() + value);
  3064. }
  3065. //----------------------------------------------------------------
  3066. override void SetWetMax()
  3067. {
  3068. SetWet(m_VarWetMax);
  3069. }
  3070. //----------------------------------------------------------------
  3071. override float GetWet()
  3072. {
  3073. return m_VarWet;
  3074. }
  3075. //----------------------------------------------------------------
  3076. override float GetWetMax()
  3077. {
  3078. return m_VarWetMax;
  3079. }
  3080. //----------------------------------------------------------------
  3081. override float GetWetMin()
  3082. {
  3083. return m_VarWetMin;
  3084. }
  3085. //----------------------------------------------------------------
  3086. override float GetWetInit()
  3087. {
  3088. return m_VarWetInit;
  3089. }
  3090. //----------------------------------------------------------------
  3091. override void OnWetChanged(float newVal, float oldVal)
  3092. {
  3093. EWetnessLevel newLevel = GetWetLevelInternal(newVal);
  3094. EWetnessLevel oldLevel = GetWetLevelInternal(oldVal);
  3095. if (newLevel != oldLevel)
  3096. {
  3097. OnWetLevelChanged(newLevel,oldLevel);
  3098. }
  3099. }
  3100. override void OnWetLevelChanged(EWetnessLevel newLevel, EWetnessLevel oldLevel)
  3101. {
  3102. SetWeightDirty();
  3103. }
  3104. override EWetnessLevel GetWetLevel()
  3105. {
  3106. return GetWetLevelInternal(m_VarWet);
  3107. }
  3108. //----------------------------------------------------------------
  3109. override void SetStoreLoad(bool value)
  3110. {
  3111. m_IsStoreLoad = value;
  3112. }
  3113. override bool IsStoreLoad()
  3114. {
  3115. return m_IsStoreLoad;
  3116. }
  3117. override void SetStoreLoadedQuantity(float value)
  3118. {
  3119. m_StoreLoadedQuantity = value;
  3120. }
  3121. override float GetStoreLoadedQuantity()
  3122. {
  3123. return m_StoreLoadedQuantity;
  3124. }
  3125. //----------------------------------------------------------------
  3126. float GetItemModelLength()
  3127. {
  3128. if (ConfigIsExisting("itemModelLength"))
  3129. {
  3130. return ConfigGetFloat("itemModelLength");
  3131. }
  3132. return 0;
  3133. }
  3134. float GetItemAttachOffset()
  3135. {
  3136. if (ConfigIsExisting("itemAttachOffset"))
  3137. {
  3138. return ConfigGetFloat("itemAttachOffset");
  3139. }
  3140. return 0;
  3141. }
  3142. override void SetCleanness(int value, bool allow_client = false)
  3143. {
  3144. if (!IsServerCheck(allow_client))
  3145. return;
  3146. int previousValue = m_Cleanness;
  3147. m_Cleanness = Math.Clamp(value, m_CleannessMin, m_CleannessMax);
  3148. if (previousValue != m_Cleanness)
  3149. SetVariableMask(VARIABLE_CLEANNESS);
  3150. }
  3151. override int GetCleanness()
  3152. {
  3153. return m_Cleanness;
  3154. }
  3155. bool AllowFoodConsumption()
  3156. {
  3157. return true;
  3158. }
  3159. //----------------------------------------------------------------
  3160. // ATTACHMENT LOCKING
  3161. // Getters relevant to generic ActionLockAttachment
  3162. int GetLockType()
  3163. {
  3164. return m_LockType;
  3165. }
  3166. string GetLockSoundSet()
  3167. {
  3168. return m_LockSoundSet;
  3169. }
  3170. //----------------------------------------------------------------
  3171. //------------------------- Color
  3172. // sets items color variable given color components
  3173. override void SetColor(int r, int g, int b, int a)
  3174. {
  3175. m_ColorComponentR = r;
  3176. m_ColorComponentG = g;
  3177. m_ColorComponentB = b;
  3178. m_ColorComponentA = a;
  3179. SetVariableMask(VARIABLE_COLOR);
  3180. }
  3181. //! gets item's color variable as components
  3182. override void GetColor(out int r,out int g,out int b,out int a)
  3183. {
  3184. r = m_ColorComponentR;
  3185. g = m_ColorComponentG;
  3186. b = m_ColorComponentB;
  3187. a = m_ColorComponentA;
  3188. }
  3189. bool IsColorSet()
  3190. {
  3191. return IsVariableSet(VARIABLE_COLOR);
  3192. }
  3193. //! Returns item's PROCEDURAL color as formated string, i.e. "#(argb,8,8,3)color(0.15,0.15,0.15,1.0,CO)"
  3194. string GetColorString()
  3195. {
  3196. int r,g,b,a;
  3197. GetColor(r,g,b,a);
  3198. r = r/255;
  3199. g = g/255;
  3200. b = b/255;
  3201. a = a/255;
  3202. return MiscGameplayFunctions.GetColorString(r, g, b, a);
  3203. }
  3204. //----------------------------------------------------------------
  3205. //------------------------- LiquidType
  3206. override void SetLiquidType(int value, bool allow_client = false)
  3207. {
  3208. if (!IsServerCheck(allow_client))
  3209. return;
  3210. int old = m_VarLiquidType;
  3211. m_VarLiquidType = value;
  3212. OnLiquidTypeChanged(old,value);
  3213. SetVariableMask(VARIABLE_LIQUIDTYPE);
  3214. }
  3215. int GetLiquidTypeInit()
  3216. {
  3217. return ConfigGetInt("varLiquidTypeInit");
  3218. }
  3219. override int GetLiquidType()
  3220. {
  3221. return m_VarLiquidType;
  3222. }
  3223. protected void OnLiquidTypeChanged(int oldType, int newType)
  3224. {
  3225. if (newType == LIQUID_NONE && GetIsFrozen())
  3226. SetFrozen(false);
  3227. }
  3228. //! To be called on moving item within character's inventory; 'player' should never be null
  3229. void UpdateQuickbarShortcutVisibility(PlayerBase player)
  3230. {
  3231. player.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
  3232. }
  3233. // -------------------------------------------------------------------------
  3234. //! Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
  3235. void OnInventoryEnter(Man player)
  3236. {
  3237. PlayerBase nplayer;
  3238. if (PlayerBase.CastTo(nplayer, player))
  3239. {
  3240. m_CanPlayImpactSound = true;
  3241. //nplayer.OnItemInventoryEnter(this);
  3242. nplayer.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
  3243. }
  3244. }
  3245. // -------------------------------------------------------------------------
  3246. //! Event called on item when it is removed from the player(Man) inventory, passes the old owner as a parameter
  3247. void OnInventoryExit(Man player)
  3248. {
  3249. PlayerBase nplayer;
  3250. if (PlayerBase.CastTo(nplayer,player))
  3251. {
  3252. //nplayer.OnItemInventoryExit(this);
  3253. nplayer.SetEnableQuickBarEntityShortcut(this,false);
  3254. }
  3255. //if (!GetGame().IsDedicatedServer())
  3256. player.GetHumanInventory().ClearUserReservedLocationForContainer(this);
  3257. if (HasEnergyManager())
  3258. {
  3259. GetCompEM().UpdatePlugState(); // Unplug the el. device if it's necesarry.
  3260. }
  3261. }
  3262. // ADVANCED PLACEMENT EVENTS
  3263. override void OnPlacementStarted(Man player)
  3264. {
  3265. super.OnPlacementStarted(player);
  3266. SetTakeable(false);
  3267. }
  3268. override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
  3269. {
  3270. if (m_AdminLog)
  3271. {
  3272. m_AdminLog.OnPlacementComplete(player, this);
  3273. }
  3274. if (GetGame().IsServer())
  3275. {
  3276. SetIsDeploySound(true);
  3277. }
  3278. super.OnPlacementComplete(player, position, orientation);
  3279. }
  3280. //-----------------------------
  3281. // AGENT SYSTEM
  3282. //-----------------------------
  3283. //--------------------------------------------------------------------------
  3284. bool ContainsAgent(int agent_id)
  3285. {
  3286. if (agent_id & m_AttachedAgents)
  3287. {
  3288. return true;
  3289. }
  3290. else
  3291. {
  3292. return false;
  3293. }
  3294. }
  3295. //--------------------------------------------------------------------------
  3296. override void RemoveAgent(int agent_id)
  3297. {
  3298. if (ContainsAgent(agent_id))
  3299. {
  3300. m_AttachedAgents = ~agent_id & m_AttachedAgents;
  3301. }
  3302. }
  3303. //--------------------------------------------------------------------------
  3304. override void RemoveAllAgents()
  3305. {
  3306. m_AttachedAgents = 0;
  3307. }
  3308. //--------------------------------------------------------------------------
  3309. override void RemoveAllAgentsExcept(int agents_to_keep_mask)
  3310. {
  3311. m_AttachedAgents = m_AttachedAgents & agent_to_keep;
  3312. }
  3313. // -------------------------------------------------------------------------
  3314. override void InsertAgent(int agent, float count = 1)
  3315. {
  3316. if (count < 1)
  3317. return;
  3318. //Debug.Log("Inserting Agent on item: " + agent.ToString() +" count: " + count.ToString());
  3319. m_AttachedAgents = (agent | m_AttachedAgents);
  3320. }
  3321. //!transfer agents from another item
  3322. void TransferAgents(int agents)
  3323. {
  3324. m_AttachedAgents = (m_AttachedAgents | agents);
  3325. }
  3326. // -------------------------------------------------------------------------
  3327. override int GetAgents()
  3328. {
  3329. return m_AttachedAgents;
  3330. }
  3331. //----------------------------------------------------------------------
  3332. /*int GetContaminationType()
  3333. {
  3334. int contamination_type;
  3335. const int CONTAMINATED_MASK = eAgents.CHOLERA | eAgents.INFLUENZA | eAgents.SALMONELLA | eAgents.BRAIN;
  3336. const int POISONED_MASK = eAgents.FOOD_POISON | eAgents.CHEMICAL_POISON;
  3337. const int NERVE_GAS_MASK = eAgents.CHEMICAL_POISON;
  3338. const int DIRTY_MASK = eAgents.WOUND_AGENT;
  3339. Edible_Base edible = Edible_Base.Cast(this);
  3340. int agents = GetAgents();
  3341. if (edible)
  3342. {
  3343. NutritionalProfile profile = Edible_Base.GetNutritionalProfile(edible);
  3344. if (profile)
  3345. {
  3346. agents = agents | profile.GetAgents();//merge item's agents with nutritional agents
  3347. }
  3348. }
  3349. if (agents & CONTAMINATED_MASK)
  3350. {
  3351. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_CONTAMINATED;
  3352. }
  3353. if (agents & POISONED_MASK)
  3354. {
  3355. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_POISONED;
  3356. }
  3357. if (agents & NERVE_GAS_MASK)
  3358. {
  3359. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_NERVE_GAS;
  3360. }
  3361. if (agents & DIRTY_MASK)
  3362. {
  3363. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_DIRTY;
  3364. }
  3365. return agents;
  3366. }*/
  3367. // -------------------------------------------------------------------------
  3368. bool LoadAgents(ParamsReadContext ctx, int version)
  3369. {
  3370. if (!ctx.Read(m_AttachedAgents))
  3371. return false;
  3372. return true;
  3373. }
  3374. // -------------------------------------------------------------------------
  3375. void SaveAgents(ParamsWriteContext ctx)
  3376. {
  3377. ctx.Write(m_AttachedAgents);
  3378. }
  3379. // -------------------------------------------------------------------------
  3380. //! Roof check for entity, limited by time (anti-spam solution)
  3381. override void CheckForRoofLimited(float timeTresholdMS = 3000)
  3382. {
  3383. super.CheckForRoofLimited(timeTresholdMS);
  3384. float time = GetGame().GetTime();
  3385. if ((time - m_PreviousRoofTestTime) >= timeTresholdMS)
  3386. {
  3387. m_PreviousRoofTestTime = time;
  3388. SetRoofAbove(MiscGameplayFunctions.IsUnderRoof(this));
  3389. }
  3390. }
  3391. // returns item's protection level against enviromental hazard, for masks with filters, returns the filters protection for valid filter, otherwise 0
  3392. float GetProtectionLevel(int type, bool consider_filter = false, int system = 0)
  3393. {
  3394. if (IsDamageDestroyed() || (HasQuantity() && GetQuantity() <= 0))
  3395. {
  3396. return 0;
  3397. }
  3398. if (GetInventory().GetAttachmentSlotsCount() != 0)//is it an item with attachable filter ?
  3399. {
  3400. ItemBase filter = ItemBase.Cast(FindAttachmentBySlotName("GasMaskFilter"));
  3401. if (filter)
  3402. return filter.GetProtectionLevel(type, false, system);//it's a valid filter, return the protection
  3403. else
  3404. return 0;//otherwise return 0 when no filter attached
  3405. }
  3406. string subclassPath, entryName;
  3407. switch (type)
  3408. {
  3409. case DEF_BIOLOGICAL:
  3410. entryName = "biological";
  3411. break;
  3412. case DEF_CHEMICAL:
  3413. entryName = "chemical";
  3414. break;
  3415. default:
  3416. entryName = "biological";
  3417. break;
  3418. }
  3419. subclassPath = "CfgVehicles " + this.GetType() + " Protection ";
  3420. return GetGame().ConfigGetFloat(subclassPath + entryName);
  3421. }
  3422. //! Called when entity is being created as new by CE/ Debug
  3423. override void EEOnCECreate()
  3424. {
  3425. if (!IsMagazine())
  3426. SetCEBasedQuantity();
  3427. SetZoneDamageCEInit();
  3428. }
  3429. //-------------------------
  3430. // OPEN/CLOSE USER ACTIONS
  3431. //-------------------------
  3432. //! Implementations only
  3433. void Open();
  3434. void Close();
  3435. bool IsOpen()
  3436. {
  3437. return true;
  3438. }
  3439. override bool CanDisplayCargo()
  3440. {
  3441. return IsOpen();
  3442. }
  3443. // ------------------------------------------------------------
  3444. // CONDITIONS
  3445. // ------------------------------------------------------------
  3446. override bool CanPutInCargo(EntityAI parent)
  3447. {
  3448. if (parent)
  3449. {
  3450. if (parent.IsInherited(DayZInfected))
  3451. return true;
  3452. if (!parent.IsRuined())
  3453. return true;
  3454. }
  3455. return true;
  3456. }
  3457. override bool CanPutAsAttachment(EntityAI parent)
  3458. {
  3459. if (!super.CanPutAsAttachment(parent))
  3460. {
  3461. return false;
  3462. }
  3463. if (!IsRuined() && !parent.IsRuined())
  3464. {
  3465. return true;
  3466. }
  3467. return false;
  3468. }
  3469. override bool CanReceiveItemIntoCargo(EntityAI item)
  3470. {
  3471. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3472. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3473. // return false;
  3474. return super.CanReceiveItemIntoCargo(item);
  3475. }
  3476. override bool CanReceiveAttachment(EntityAI attachment, int slotId)
  3477. {
  3478. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3479. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3480. // return false;
  3481. GameInventory attachmentInv = attachment.GetInventory();
  3482. if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
  3483. {
  3484. if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
  3485. return false;
  3486. }
  3487. InventoryLocation loc = new InventoryLocation();
  3488. attachment.GetInventory().GetCurrentInventoryLocation(loc);
  3489. if (loc && loc.IsValid() && !GetInventory().AreChildrenAccessible())
  3490. return false;
  3491. return super.CanReceiveAttachment(attachment, slotId);
  3492. }
  3493. override bool CanReleaseAttachment(EntityAI attachment)
  3494. {
  3495. if (!super.CanReleaseAttachment(attachment))
  3496. return false;
  3497. return GetInventory().AreChildrenAccessible();
  3498. }
  3499. /*override bool CanLoadAttachment(EntityAI attachment)
  3500. {
  3501. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3502. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3503. // return false;
  3504. GameInventory attachmentInv = attachment.GetInventory();
  3505. if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
  3506. {
  3507. bool boo = (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase));
  3508. ErrorEx("CanLoadAttachment | this: " + this + " | attachment: " + attachment + " | boo: " + boo,ErrorExSeverity.INFO);
  3509. if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
  3510. return false;
  3511. }
  3512. return super.CanLoadAttachment(attachment);
  3513. }*/
  3514. // Plays muzzle flash particle effects
  3515. static void PlayFireParticles(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3516. {
  3517. int id = muzzle_owner.GetMuzzleID();
  3518. array<ref WeaponParticlesOnFire> WPOF_array = m_OnFireEffect.Get(id);
  3519. if (WPOF_array)
  3520. {
  3521. for (int i = 0; i < WPOF_array.Count(); i++)
  3522. {
  3523. WeaponParticlesOnFire WPOF = WPOF_array.Get(i);
  3524. if (WPOF)
  3525. {
  3526. WPOF.OnActivate(weapon, muzzle_index, ammoType, muzzle_owner, suppressor, config_to_search);
  3527. }
  3528. }
  3529. }
  3530. }
  3531. // Plays bullet eject particle effects (usually just smoke, the bullet itself is a 3D model and is not part of this function)
  3532. static void PlayBulletCasingEjectParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3533. {
  3534. int id = muzzle_owner.GetMuzzleID();
  3535. array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = m_OnBulletCasingEjectEffect.Get(id);
  3536. if (WPOBE_array)
  3537. {
  3538. for (int i = 0; i < WPOBE_array.Count(); i++)
  3539. {
  3540. WeaponParticlesOnBulletCasingEject WPOBE = WPOBE_array.Get(i);
  3541. if (WPOBE)
  3542. {
  3543. WPOBE.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
  3544. }
  3545. }
  3546. }
  3547. }
  3548. // Plays all weapon overheating particles
  3549. static void PlayOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3550. {
  3551. int id = muzzle_owner.GetMuzzleID();
  3552. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3553. if (WPOOH_array)
  3554. {
  3555. for (int i = 0; i < WPOOH_array.Count(); i++)
  3556. {
  3557. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3558. if (WPOOH)
  3559. {
  3560. WPOOH.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
  3561. }
  3562. }
  3563. }
  3564. }
  3565. // Updates all weapon overheating particles
  3566. static void UpdateOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3567. {
  3568. int id = muzzle_owner.GetMuzzleID();
  3569. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3570. if (WPOOH_array)
  3571. {
  3572. for (int i = 0; i < WPOOH_array.Count(); i++)
  3573. {
  3574. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3575. if (WPOOH)
  3576. {
  3577. WPOOH.OnUpdate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  3578. }
  3579. }
  3580. }
  3581. }
  3582. // Stops overheating particles
  3583. static void StopOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3584. {
  3585. int id = muzzle_owner.GetMuzzleID();
  3586. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3587. if (WPOOH_array)
  3588. {
  3589. for (int i = 0; i < WPOOH_array.Count(); i++)
  3590. {
  3591. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3592. if (WPOOH)
  3593. {
  3594. WPOOH.OnDeactivate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  3595. }
  3596. }
  3597. }
  3598. }
  3599. //----------------------------------------------------------------
  3600. //Item Behaviour - unified approach
  3601. override bool IsHeavyBehaviour()
  3602. {
  3603. if (m_ItemBehaviour == 0)
  3604. {
  3605. return true;
  3606. }
  3607. return false;
  3608. }
  3609. override bool IsOneHandedBehaviour()
  3610. {
  3611. if (m_ItemBehaviour == 1)
  3612. {
  3613. return true;
  3614. }
  3615. return false;
  3616. }
  3617. override bool IsTwoHandedBehaviour()
  3618. {
  3619. if (m_ItemBehaviour == 2)
  3620. {
  3621. return true;
  3622. }
  3623. return false;
  3624. }
  3625. bool IsDeployable()
  3626. {
  3627. return false;
  3628. }
  3629. //!how long it takes to deploy this item in seconds
  3630. float GetDeployTime()
  3631. {
  3632. return UATimeSpent.DEFAULT_DEPLOY;
  3633. }
  3634. //----------------------------------------------------------------
  3635. // Item Targeting (User Actions)
  3636. override void SetTakeable(bool pState)
  3637. {
  3638. m_IsTakeable = pState;
  3639. SetSynchDirty();
  3640. }
  3641. override bool IsTakeable()
  3642. {
  3643. return m_IsTakeable;
  3644. }
  3645. // For cases where we want to show object widget which cant be taken to hands
  3646. bool IsActionTargetVisible()
  3647. {
  3648. return false;
  3649. }
  3650. //! Attachment Sound Type getting from config file
  3651. protected void PreLoadSoundAttachmentType()
  3652. {
  3653. string att_type = "None";
  3654. if (ConfigIsExisting("soundAttType"))
  3655. {
  3656. att_type = ConfigGetString("soundAttType");
  3657. }
  3658. m_SoundAttType = att_type;
  3659. }
  3660. override string GetAttachmentSoundType()
  3661. {
  3662. return m_SoundAttType;
  3663. }
  3664. //----------------------------------------------------------------
  3665. //SOUNDS FOR ADVANCED PLACEMNT
  3666. //----------------------------------------------------------------
  3667. void SoundSynchRemoteReset()
  3668. {
  3669. m_IsSoundSynchRemote = false;
  3670. SetSynchDirty();
  3671. }
  3672. void SoundSynchRemote()
  3673. {
  3674. m_IsSoundSynchRemote = true;
  3675. SetSynchDirty();
  3676. }
  3677. bool IsSoundSynchRemote()
  3678. {
  3679. return m_IsSoundSynchRemote;
  3680. }
  3681. string GetDeploySoundset();
  3682. string GetPlaceSoundset();
  3683. string GetLoopDeploySoundset();
  3684. string GetDeployFinishSoundset();
  3685. void SetIsPlaceSound(bool is_place_sound)
  3686. {
  3687. m_IsPlaceSound = is_place_sound;
  3688. }
  3689. bool IsPlaceSound()
  3690. {
  3691. return m_IsPlaceSound;
  3692. }
  3693. void SetIsDeploySound(bool is_deploy_sound)
  3694. {
  3695. m_IsDeploySound = is_deploy_sound;
  3696. }
  3697. bool IsDeploySound()
  3698. {
  3699. return m_IsDeploySound;
  3700. }
  3701. void PlayDeployLoopSoundEx()
  3702. {
  3703. if (!GetGame().IsDedicatedServer() && !m_DeployLoopSoundEx)
  3704. {
  3705. m_DeployLoopSoundEx = SEffectManager.PlaySound(GetLoopDeploySoundset(), GetPosition());
  3706. if (m_DeployLoopSoundEx)
  3707. m_DeployLoopSoundEx.SetAutodestroy(true);
  3708. else
  3709. Debug.Log("null m_DeployLoopSoundEx from sound set: " + GetLoopDeploySoundset());
  3710. }
  3711. }
  3712. void StopDeployLoopSoundEx()
  3713. {
  3714. if (!GetGame().IsDedicatedServer())
  3715. {
  3716. m_DeployLoopSoundEx.SetSoundFadeOut(0.5);
  3717. m_DeployLoopSoundEx.SoundStop();
  3718. }
  3719. }
  3720. void PlayDeploySound()
  3721. {
  3722. if (!GetGame().IsDedicatedServer() && !m_SoundDeploy)
  3723. {
  3724. m_SoundDeploy = SEffectManager.PlaySound(GetDeploySoundset(), GetPosition());
  3725. if (m_SoundDeploy)
  3726. m_SoundDeploy.SetAutodestroy(true);
  3727. else
  3728. Debug.Log("null m_SoundDeploy from sound set: " + GetDeploySoundset());
  3729. }
  3730. }
  3731. void PlayDeployFinishSound()
  3732. {
  3733. if (!GetGame().IsDedicatedServer() && !m_SoundDeployFinish)
  3734. {
  3735. m_SoundDeployFinish = SEffectManager.PlaySound(GetDeployFinishSoundset(), GetPosition());
  3736. if (m_SoundDeployFinish)
  3737. m_SoundDeployFinish.SetAutodestroy(true);
  3738. else
  3739. Debug.Log("null m_SoundDeployFinish from sound set: " + GetDeployFinishSoundset());
  3740. }
  3741. }
  3742. void PlayPlaceSound()
  3743. {
  3744. if (!GetGame().IsDedicatedServer() && !m_SoundPlace)
  3745. {
  3746. m_SoundPlace = SEffectManager.PlaySound(GetPlaceSoundset(), GetPosition());
  3747. if (m_SoundPlace)
  3748. m_SoundPlace.SetAutodestroy(true);
  3749. else
  3750. Debug.Log("null m_SoundPlace from sound set: " + GetPlaceSoundset());
  3751. }
  3752. }
  3753. bool CanPlayDeployLoopSound()
  3754. {
  3755. return IsBeingPlaced() && IsSoundSynchRemote();
  3756. }
  3757. //! Plays sound on item attach. Be advised, the config structure may slightly change in 1.11 update to allow for more complex use.
  3758. void PlayAttachSound(string slot_type)
  3759. {
  3760. if (!GetGame().IsDedicatedServer())
  3761. {
  3762. if (ConfigIsExisting("attachSoundSet"))
  3763. {
  3764. string cfg_path = "";
  3765. string soundset = "";
  3766. string type_name = GetType();
  3767. TStringArray cfg_soundset_array = new TStringArray;
  3768. TStringArray cfg_slot_array = new TStringArray;
  3769. ConfigGetTextArray("attachSoundSet",cfg_soundset_array);
  3770. ConfigGetTextArray("attachSoundSlot",cfg_slot_array);
  3771. if (cfg_soundset_array.Count() > 0 && cfg_soundset_array.Count() == cfg_slot_array.Count())
  3772. {
  3773. for (int i = 0; i < cfg_soundset_array.Count(); i++)
  3774. {
  3775. if (cfg_slot_array[i] == slot_type)
  3776. {
  3777. soundset = cfg_soundset_array[i];
  3778. break;
  3779. }
  3780. }
  3781. }
  3782. if (soundset != "")
  3783. {
  3784. EffectSound sound = SEffectManager.PlaySound(soundset, GetPosition());
  3785. sound.SetAutodestroy(true);
  3786. }
  3787. }
  3788. }
  3789. }
  3790. void PlayDetachSound(string slot_type)
  3791. {
  3792. //TODO - evaluate if needed and devise universal config structure if so
  3793. }
  3794. void OnApply(PlayerBase player);
  3795. float GetBandagingEffectivity()
  3796. {
  3797. return 1.0;
  3798. };
  3799. //returns applicable selection
  3800. array<string> GetHeadHidingSelection()
  3801. {
  3802. return m_HeadHidingSelections;
  3803. }
  3804. bool HidesSelectionBySlot()
  3805. {
  3806. return m_HideSelectionsBySlot;
  3807. }
  3808. WrittenNoteData GetWrittenNoteData() {};
  3809. void StopItemDynamicPhysics()
  3810. {
  3811. SetDynamicPhysicsLifeTime(0.01);
  3812. m_ItemBeingDroppedPhys = false;
  3813. }
  3814. void PerformDamageSystemReinit()
  3815. {
  3816. array<string> zone_names = new array<string>;
  3817. GetDamageZones(zone_names);
  3818. for (int i = 0; i < zone_names.Count(); i++)
  3819. {
  3820. SetHealthMax(zone_names.Get(i),"Health");
  3821. }
  3822. SetHealthMax("","Health");
  3823. }
  3824. //! Sets zone damages to match randomized global health set by CE (CE spawn only)
  3825. void SetZoneDamageCEInit()
  3826. {
  3827. float global_health = GetHealth01("","Health");
  3828. array<string> zones = new array<string>;
  3829. GetDamageZones(zones);
  3830. //set damage of all zones to match global health level
  3831. for (int i = 0; i < zones.Count(); i++)
  3832. {
  3833. SetHealth01(zones.Get(i),"Health",global_health);
  3834. }
  3835. }
  3836. //!DEPRECATED in use, but returns correct values nontheless. Check performed elsewhere
  3837. bool IsCoverFaceForShave(string slot_name)
  3838. {
  3839. return IsExclusionFlagPresent(PlayerBase.GetFaceCoverageShaveValues());
  3840. }
  3841. void ProcessItemWetness(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  3842. {
  3843. if (!hasRootAsPlayer)
  3844. {
  3845. if (refParentIB)
  3846. {
  3847. // parent is wet
  3848. if ((refParentIB.GetWet() >= GameConstants.STATE_SOAKING_WET) && (m_VarWet < m_VarWetMax))
  3849. AddWet(delta * GameConstants.WETNESS_RATE_WETTING_INSIDE);
  3850. // parent has liquid inside
  3851. else if ((refParentIB.GetLiquidType() != 0) && (refParentIB.GetQuantity() > 0) && (m_VarWet < m_VarWetMax))
  3852. AddWet(delta * GameConstants.WETNESS_RATE_WETTING_LIQUID);
  3853. // drying
  3854. else if (m_VarWet > m_VarWetMin)
  3855. AddWet(-1 * delta * GetDryingIncrement("ground") * 2);
  3856. }
  3857. else
  3858. {
  3859. // drying on ground or inside non-itembase (car, ...)
  3860. if (m_VarWet > m_VarWetMin)
  3861. AddWet(-1 * delta * GetDryingIncrement("ground"));
  3862. }
  3863. }
  3864. }
  3865. void ProcessItemTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  3866. {
  3867. if (CanHaveTemperature() && !IsSelfAdjustingTemperature() && !GetHierarchyRoot().IsSelfAdjustingTemperature())
  3868. {
  3869. float target = g_Game.GetMission().GetWorldData().GetBaseEnvTemperatureAtObject(this);
  3870. if (GetTemperature() != target)
  3871. {
  3872. float heatPermCoef = 1.0;
  3873. EntityAI ent = this;
  3874. while (ent)
  3875. {
  3876. heatPermCoef *= ent.GetHeatPermeabilityCoef();
  3877. ent = ent.GetHierarchyParent();
  3878. }
  3879. SetTemperatureEx(new TemperatureDataInterpolated(target,ETemperatureAccessTypes.ACCESS_WORLD,delta,GameConstants.TEMP_COEF_WORLD,heatPermCoef));
  3880. }
  3881. }
  3882. }
  3883. void HierarchyCheck(out bool hasParent, out bool hasRootAsPlayer, out ItemBase refParentIB)
  3884. {
  3885. // hierarchy check for an item to decide whether it has some parent and it is in some player inventory
  3886. EntityAI parent = GetHierarchyParent();
  3887. if (!parent)
  3888. {
  3889. hasParent = false;
  3890. hasRootAsPlayer = false;
  3891. }
  3892. else
  3893. {
  3894. hasParent = true;
  3895. hasRootAsPlayer = (GetHierarchyRootPlayer() != null);
  3896. refParentIB = ItemBase.Cast(parent);
  3897. }
  3898. }
  3899. protected void ProcessDecay(float delta, bool hasRootAsPlayer)
  3900. {
  3901. // this is stub, implemented on Edible_Base
  3902. }
  3903. bool CanDecay()
  3904. {
  3905. // return true used on selected food clases so they can decay
  3906. return false;
  3907. }
  3908. protected bool CanProcessDecay()
  3909. {
  3910. // this is stub, implemented on Edible_Base class
  3911. // used to determine whether it is still necessary for the food to decay
  3912. return false;
  3913. }
  3914. protected bool CanHaveWetness()
  3915. {
  3916. // return true used on selected items that have a wetness effect
  3917. return false;
  3918. }
  3919. override void ProcessVariables()
  3920. {
  3921. bool hasParent = false, hasRootAsPlayer = false;
  3922. ItemBase refParentIB;
  3923. bool wwtu = g_Game.IsWorldWetTempUpdateEnabled();
  3924. bool foodDecay = g_Game.IsFoodDecayEnabled();
  3925. if (wwtu || foodDecay)
  3926. {
  3927. bool processWetness = wwtu && CanHaveWetness();
  3928. bool processTemperature = wwtu && CanHaveTemperature();
  3929. bool processDecay = foodDecay && CanDecay() && CanProcessDecay();
  3930. if (processWetness || processTemperature || processDecay)
  3931. {
  3932. HierarchyCheck(hasParent, hasRootAsPlayer, refParentIB);
  3933. if (processWetness)
  3934. ProcessItemWetness(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
  3935. if (processTemperature)
  3936. ProcessItemTemperature(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
  3937. if (processDecay)
  3938. ProcessDecay(m_ElapsedSinceLastUpdate, hasRootAsPlayer);
  3939. }
  3940. }
  3941. }
  3942. //! Used in heat comfort calculations only!
  3943. float GetTemperaturePerQuantityWeight()
  3944. {
  3945. return m_TemperaturePerQuantityWeight * GameConstants.ITEM_TEMPERATURE_QUANTITY_WEIGHT_MULTIPLIER;
  3946. }
  3947. override float GetTemperatureFreezeThreshold()
  3948. {
  3949. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3950. return Liquid.GetFreezeThreshold(GetLiquidType());
  3951. return super.GetTemperatureFreezeThreshold();
  3952. }
  3953. override float GetTemperatureThawThreshold()
  3954. {
  3955. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3956. return Liquid.GetThawThreshold(GetLiquidType());
  3957. return super.GetTemperatureThawThreshold();
  3958. }
  3959. override float GetItemOverheatThreshold()
  3960. {
  3961. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3962. return Liquid.GetBoilThreshold(GetLiquidType());
  3963. return super.GetItemOverheatThreshold();
  3964. }
  3965. override float GetTemperatureFreezeTime()
  3966. {
  3967. if (HasQuantity())
  3968. return Math.Lerp(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureFreezeTime()),GetQuantityNormalized());
  3969. return super.GetTemperatureFreezeTime();
  3970. }
  3971. override float GetTemperatureThawTime()
  3972. {
  3973. if (HasQuantity())
  3974. return Math.Lerp(GameConstants.TEMPERATURE_TIME_THAW_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureThawTime()),GetQuantityNormalized());
  3975. return super.GetTemperatureThawTime();
  3976. }
  3977. void AffectLiquidContainerOnFill(int liquid_type, float amount);
  3978. bool IsCargoException4x3(EntityAI item)
  3979. {
  3980. return (item.IsKindOf("Cauldron") || item.IsKindOf("Pot") || item.IsKindOf("FryingPan") || item.IsKindOf("SmallProtectorCase") || (item.IsKindOf("PortableGasStove") && item.FindAttachmentBySlotName("CookingEquipment")));
  3981. }
  3982. void CopyScriptPropertiesFrom(EntityAI oldItem)
  3983. {
  3984. MiscGameplayFunctions.TransferItemProperties(oldItem, this);
  3985. }
  3986. //! Adds a light source child
  3987. void AddLightSourceItem(ItemBase lightsource)
  3988. {
  3989. m_LightSourceItem = lightsource;
  3990. }
  3991. void RemoveLightSourceItem()
  3992. {
  3993. m_LightSourceItem = null;
  3994. }
  3995. ItemBase GetLightSourceItem()
  3996. {
  3997. return m_LightSourceItem;
  3998. }
  3999. //! returns an array of possible finishers
  4000. array<int> GetValidFinishers()
  4001. {
  4002. return null;
  4003. }
  4004. //! If we need a different (handheld)item action widget displayed, the logic goes in here
  4005. bool GetActionWidgetOverride(out typename name)
  4006. {
  4007. return false;
  4008. }
  4009. bool PairWithDevice(notnull ItemBase otherDevice)
  4010. {
  4011. if (GetGame().IsServer())
  4012. {
  4013. ItemBase explosive = otherDevice;
  4014. RemoteDetonatorTrigger trg = RemoteDetonatorTrigger.Cast(this);
  4015. if (!trg)
  4016. {
  4017. trg = RemoteDetonatorTrigger.Cast(otherDevice);
  4018. explosive = this;
  4019. }
  4020. explosive.PairRemote(trg);
  4021. trg.SetControlledDevice(explosive);
  4022. int persistentID = RemotelyActivatedItemBehaviour.GeneratePersistentID();
  4023. trg.SetPersistentPairID(persistentID);
  4024. explosive.SetPersistentPairID(persistentID);
  4025. return true;
  4026. }
  4027. return false;
  4028. }
  4029. //! generic effectivity as a bait for animal catching
  4030. float GetBaitEffectivity()
  4031. {
  4032. float ret = 1.0;
  4033. if (HasQuantity())
  4034. ret *= GetQuantityNormalized();
  4035. ret *= GetHealth01();
  4036. return ret;
  4037. }
  4038. #ifdef DEVELOPER
  4039. override void SetDebugItem()
  4040. {
  4041. super.SetDebugItem();
  4042. _itemBase = this;
  4043. }
  4044. override string GetDebugText()
  4045. {
  4046. string text = super.GetDebugText();
  4047. text += string.Format("Heat isolation(raw): %1\n", GetHeatIsolation());
  4048. text += string.Format("Heat isolation(modified): %1\n", MiscGameplayFunctions.GetCurrentItemHeatIsolation(this));
  4049. return text;
  4050. }
  4051. #endif
  4052. bool CanBeUsedForSuicide()
  4053. {
  4054. return true;
  4055. }
  4056. ///////////////////
  4057. //DEPRECATED BELOW
  4058. //////////////////
  4059. // Backwards compatibility
  4060. void ProcessItemWetnessAndTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  4061. {
  4062. ProcessItemWetness(delta, hasParent, hasRootAsPlayer, refParentIB);
  4063. ProcessItemTemperature(delta, hasParent, hasRootAsPlayer, refParentIB);
  4064. }
  4065. }
  4066. EntityAI SpawnItemOnLocation(string object_name, notnull InventoryLocation loc, bool full_quantity)
  4067. {
  4068. EntityAI entity = SpawnEntity(object_name, loc, ECE_IN_INVENTORY, RF_DEFAULT);
  4069. if (entity)
  4070. {
  4071. bool is_item = entity.IsInherited(ItemBase);
  4072. if (is_item && full_quantity)
  4073. {
  4074. ItemBase item = ItemBase.Cast(entity);
  4075. item.SetQuantity(item.GetQuantityInit());
  4076. }
  4077. }
  4078. else
  4079. {
  4080. ErrorEx("Cannot spawn entity: " + object_name,ErrorExSeverity.INFO);
  4081. return NULL;
  4082. }
  4083. return entity;
  4084. }
  4085. void SetupSpawnedItem(ItemBase item, float health, float quantity)
  4086. {
  4087. if (item)
  4088. {
  4089. if (health > 0)
  4090. item.SetHealth("", "", health);
  4091. if (item.CanHaveTemperature())
  4092. {
  4093. item.SetTemperatureDirect(GameConstants.ITEM_TEMPERATURE_NEUTRAL_ZONE_MIDDLE);
  4094. if (item.CanFreeze())
  4095. item.SetFrozen(false);
  4096. }
  4097. if (item.HasEnergyManager())
  4098. {
  4099. if (quantity >= 0)
  4100. {
  4101. item.GetCompEM().SetEnergy0To1(quantity);
  4102. }
  4103. else
  4104. {
  4105. item.GetCompEM().SetEnergy(Math.AbsFloat(quantity));
  4106. }
  4107. }
  4108. else if (item.IsMagazine())
  4109. {
  4110. Magazine mag = Magazine.Cast(item);
  4111. if (quantity >= 0)
  4112. {
  4113. mag.ServerSetAmmoCount(mag.GetAmmoMax() * quantity);
  4114. }
  4115. else
  4116. {
  4117. mag.ServerSetAmmoCount(Math.AbsFloat(quantity));
  4118. }
  4119. }
  4120. else
  4121. {
  4122. if (quantity >= 0)
  4123. {
  4124. item.SetQuantityNormalized(quantity, false);
  4125. }
  4126. else
  4127. {
  4128. item.SetQuantity(Math.AbsFloat(quantity));
  4129. }
  4130. }
  4131. }
  4132. }
  4133. #ifdef DEVELOPER
  4134. ItemBase _itemBase;//watched item goes here(LCTRL+RMB->Watch)
  4135. #endif