itembase.c 130 KB

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