itembase.c 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858
  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. override void SplitIntoStackMaxClient(EntityAI destination_entity, int slot_id )
  1321. {
  1322. if (!CanBeSplit())
  1323. return;
  1324. if (GetGame().IsClient())
  1325. {
  1326. if (ScriptInputUserData.CanStoreInputUserData())
  1327. {
  1328. ScriptInputUserData ctx = new ScriptInputUserData;
  1329. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1330. ctx.Write(1);
  1331. ItemBase i1 = this; // @NOTE: workaround for correct serialization
  1332. ctx.Write(i1);
  1333. ctx.Write(destination_entity);
  1334. ctx.Write(true);
  1335. ctx.Write(slot_id);
  1336. ctx.Send();
  1337. }
  1338. }
  1339. else if (!GetGame().IsMultiplayer())
  1340. {
  1341. SplitIntoStackMax(destination_entity, slot_id, PlayerBase.Cast(GetGame().GetPlayer()));
  1342. }
  1343. }
  1344. void SplitIntoStackMax(EntityAI destination_entity, int slot_id, PlayerBase player)
  1345. {
  1346. if (!CanBeSplit())
  1347. return;
  1348. float split_quantity_new;
  1349. ref ItemBase new_item;
  1350. float quantity = GetQuantity();
  1351. float stack_max = GetTargetQuantityMax(slot_id);
  1352. InventoryLocation loc = new InventoryLocation;
  1353. if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
  1354. {
  1355. if (stack_max <= GetQuantity())
  1356. split_quantity_new = stack_max;
  1357. else
  1358. split_quantity_new = GetQuantity();
  1359. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
  1360. if (new_item)
  1361. {
  1362. new_item.SetResultOfSplit(true);
  1363. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1364. AddQuantity(-split_quantity_new);
  1365. new_item.SetQuantity(split_quantity_new);
  1366. }
  1367. }
  1368. else if (destination_entity && slot_id == -1)
  1369. {
  1370. if (quantity > stack_max)
  1371. split_quantity_new = stack_max;
  1372. else
  1373. split_quantity_new = quantity;
  1374. if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
  1375. {
  1376. Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
  1377. new_item = ItemBase.Cast(o);
  1378. }
  1379. if (new_item)
  1380. {
  1381. new_item.SetResultOfSplit(true);
  1382. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1383. AddQuantity(-split_quantity_new);
  1384. new_item.SetQuantity(split_quantity_new);
  1385. }
  1386. }
  1387. else
  1388. {
  1389. if (stack_max != 0)
  1390. {
  1391. if (stack_max < GetQuantity())
  1392. {
  1393. split_quantity_new = GetQuantity() - stack_max;
  1394. }
  1395. if (split_quantity_new == 0)
  1396. {
  1397. if (!GetGame().IsMultiplayer())
  1398. player.PhysicalPredictiveDropItem(this);
  1399. else
  1400. player.ServerDropEntity(this);
  1401. return;
  1402. }
  1403. new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(), player.GetWorldPosition(), ECE_PLACE_ON_SURFACE));
  1404. if (new_item)
  1405. {
  1406. new_item.SetResultOfSplit(true);
  1407. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1408. SetQuantity(split_quantity_new);
  1409. new_item.SetQuantity(stack_max);
  1410. new_item.PlaceOnSurface();
  1411. }
  1412. }
  1413. }
  1414. }
  1415. override void SplitIntoStackMaxEx(EntityAI destination_entity, int slot_id)
  1416. {
  1417. if (!CanBeSplit())
  1418. return;
  1419. float split_quantity_new;
  1420. ref ItemBase new_item;
  1421. float quantity = GetQuantity();
  1422. float stack_max = GetTargetQuantityMax(slot_id);
  1423. InventoryLocation loc = new InventoryLocation;
  1424. if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id))
  1425. {
  1426. if (stack_max <= GetQuantity())
  1427. split_quantity_new = stack_max;
  1428. else
  1429. split_quantity_new = GetQuantity();
  1430. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id));
  1431. if (new_item)
  1432. {
  1433. new_item.SetResultOfSplit(true);
  1434. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1435. AddQuantity(-split_quantity_new);
  1436. new_item.SetQuantity(split_quantity_new);
  1437. }
  1438. }
  1439. else if (destination_entity && slot_id == -1)
  1440. {
  1441. if (quantity > stack_max)
  1442. split_quantity_new = stack_max;
  1443. else
  1444. split_quantity_new = quantity;
  1445. if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc))
  1446. {
  1447. Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT);
  1448. new_item = ItemBase.Cast(o);
  1449. }
  1450. if (new_item)
  1451. {
  1452. new_item.SetResultOfSplit(true);
  1453. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1454. AddQuantity(-split_quantity_new);
  1455. new_item.SetQuantity(split_quantity_new);
  1456. }
  1457. }
  1458. else
  1459. {
  1460. if (stack_max != 0)
  1461. {
  1462. if (stack_max < GetQuantity())
  1463. {
  1464. split_quantity_new = GetQuantity() - stack_max;
  1465. }
  1466. new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(),GetWorldPosition(), ECE_PLACE_ON_SURFACE));
  1467. if (new_item)
  1468. {
  1469. new_item.SetResultOfSplit(true);
  1470. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1471. SetQuantity(split_quantity_new);
  1472. new_item.SetQuantity(stack_max);
  1473. new_item.PlaceOnSurface();
  1474. }
  1475. }
  1476. }
  1477. }
  1478. void SplitIntoStackMaxToInventoryLocationClient(notnull InventoryLocation dst)
  1479. {
  1480. if (!CanBeSplit())
  1481. return;
  1482. if (GetGame().IsClient())
  1483. {
  1484. if (ScriptInputUserData.CanStoreInputUserData())
  1485. {
  1486. ScriptInputUserData ctx = new ScriptInputUserData;
  1487. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1488. ctx.Write(4);
  1489. ItemBase thiz = this; // @NOTE: workaround for correct serialization
  1490. ctx.Write(thiz);
  1491. dst.WriteToContext(ctx);
  1492. ctx.Send();
  1493. }
  1494. }
  1495. else if (!GetGame().IsMultiplayer())
  1496. {
  1497. SplitIntoStackMaxToInventoryLocation(dst);
  1498. }
  1499. }
  1500. void SplitIntoStackMaxCargoClient(EntityAI destination_entity, int idx, int row, int col)
  1501. {
  1502. if (!CanBeSplit())
  1503. return;
  1504. if (GetGame().IsClient())
  1505. {
  1506. if (ScriptInputUserData.CanStoreInputUserData())
  1507. {
  1508. ScriptInputUserData ctx = new ScriptInputUserData;
  1509. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1510. ctx.Write(2);
  1511. ItemBase dummy = this; // @NOTE: workaround for correct serialization
  1512. ctx.Write(dummy);
  1513. ctx.Write(destination_entity);
  1514. ctx.Write(true);
  1515. ctx.Write(idx);
  1516. ctx.Write(row);
  1517. ctx.Write(col);
  1518. ctx.Send();
  1519. }
  1520. }
  1521. else if (!GetGame().IsMultiplayer())
  1522. {
  1523. SplitIntoStackMaxCargo(destination_entity, idx, row, col);
  1524. }
  1525. }
  1526. void SplitIntoStackMaxToInventoryLocation(notnull InventoryLocation dst)
  1527. {
  1528. SplitIntoStackMaxToInventoryLocationEx(dst);
  1529. }
  1530. ItemBase SplitIntoStackMaxToInventoryLocationEx(notnull InventoryLocation dst)
  1531. {
  1532. if (!CanBeSplit())
  1533. return this;
  1534. float quantity = GetQuantity();
  1535. float split_quantity_new;
  1536. ItemBase new_item;
  1537. if (dst.IsValid())
  1538. {
  1539. int slot_id = dst.GetSlot();
  1540. float stack_max = GetTargetQuantityMax(slot_id);
  1541. if (quantity > stack_max)
  1542. split_quantity_new = stack_max;
  1543. else
  1544. split_quantity_new = quantity;
  1545. new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, this.GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
  1546. if (new_item)
  1547. {
  1548. new_item.SetResultOfSplit(true);
  1549. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1550. AddQuantity(-split_quantity_new);
  1551. new_item.SetQuantity(split_quantity_new);
  1552. }
  1553. return new_item;
  1554. }
  1555. return null;
  1556. }
  1557. void SplitIntoStackMaxCargo(EntityAI destination_entity, int idx, int row, int col)
  1558. {
  1559. if (!CanBeSplit())
  1560. return;
  1561. float quantity = GetQuantity();
  1562. float split_quantity_new;
  1563. ref ItemBase new_item;
  1564. if (destination_entity)
  1565. {
  1566. float stackable = GetTargetQuantityMax();
  1567. if (quantity > stackable)
  1568. split_quantity_new = stackable;
  1569. else
  1570. split_quantity_new = quantity;
  1571. new_item = ItemBase.Cast(destination_entity.GetInventory().CreateEntityInCargoEx(this.GetType(), idx, row, col, false));
  1572. if (new_item)
  1573. {
  1574. new_item.SetResultOfSplit(true);
  1575. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1576. AddQuantity(-split_quantity_new);
  1577. new_item.SetQuantity(split_quantity_new);
  1578. }
  1579. }
  1580. }
  1581. void SplitIntoStackMaxHandsClient(PlayerBase player)
  1582. {
  1583. if (!CanBeSplit())
  1584. return;
  1585. if (GetGame().IsClient())
  1586. {
  1587. if (ScriptInputUserData.CanStoreInputUserData())
  1588. {
  1589. ScriptInputUserData ctx = new ScriptInputUserData;
  1590. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1591. ctx.Write(3);
  1592. ItemBase i1 = this; // @NOTE: workaround for correct serialization
  1593. ctx.Write(i1);
  1594. ItemBase destination_entity = this;
  1595. ctx.Write(destination_entity);
  1596. ctx.Write(true);
  1597. ctx.Write(0);
  1598. ctx.Send();
  1599. }
  1600. }
  1601. else if (!GetGame().IsMultiplayer())
  1602. {
  1603. SplitIntoStackMaxHands(player);
  1604. }
  1605. }
  1606. void SplitIntoStackMaxHands(PlayerBase player)
  1607. {
  1608. if (!CanBeSplit())
  1609. return;
  1610. float quantity = GetQuantity();
  1611. float split_quantity_new;
  1612. ref ItemBase new_item;
  1613. if (player)
  1614. {
  1615. float stackable = GetTargetQuantityMax();
  1616. if (quantity > stackable)
  1617. split_quantity_new = stackable;
  1618. else
  1619. split_quantity_new = quantity;
  1620. EntityAI in_hands = player.GetHumanInventory().CreateInHands(this.GetType());
  1621. new_item = ItemBase.Cast(in_hands);
  1622. if (new_item)
  1623. {
  1624. new_item.SetResultOfSplit(true);
  1625. MiscGameplayFunctions.TransferItemProperties(this,new_item);
  1626. AddQuantity(-split_quantity_new);
  1627. new_item.SetQuantity(split_quantity_new);
  1628. }
  1629. }
  1630. }
  1631. void SplitItemToInventoryLocation(notnull InventoryLocation dst)
  1632. {
  1633. if (!CanBeSplit())
  1634. return;
  1635. float quantity = GetQuantity();
  1636. float split_quantity_new = Math.Floor(quantity * 0.5);
  1637. ItemBase new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT));
  1638. if (new_item)
  1639. {
  1640. if (new_item.GetQuantityMax() < split_quantity_new)
  1641. {
  1642. split_quantity_new = new_item.GetQuantityMax();
  1643. }
  1644. new_item.SetResultOfSplit(true);
  1645. MiscGameplayFunctions.TransferItemProperties(this, new_item);
  1646. if (dst.IsValid() && dst.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
  1647. {
  1648. AddQuantity(-1);
  1649. new_item.SetQuantity(1);
  1650. }
  1651. else
  1652. {
  1653. AddQuantity(-split_quantity_new);
  1654. new_item.SetQuantity(split_quantity_new);
  1655. }
  1656. }
  1657. }
  1658. void SplitItem(PlayerBase player)
  1659. {
  1660. if (!CanBeSplit())
  1661. return;
  1662. float quantity = GetQuantity();
  1663. float split_quantity_new = Math.Floor(quantity / 2);
  1664. InventoryLocation invloc = new InventoryLocation;
  1665. bool found = player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.ATTACHMENT, invloc);
  1666. ItemBase new_item;
  1667. new_item = player.CreateCopyOfItemInInventoryOrGroundEx(this, true);
  1668. if (new_item)
  1669. {
  1670. if (new_item.GetQuantityMax() < split_quantity_new)
  1671. {
  1672. split_quantity_new = new_item.GetQuantityMax();
  1673. }
  1674. if (found && invloc.IsValid() && invloc.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1)
  1675. {
  1676. AddQuantity(-1);
  1677. new_item.SetQuantity(1);
  1678. }
  1679. else
  1680. {
  1681. AddQuantity(-split_quantity_new);
  1682. new_item.SetQuantity(split_quantity_new);
  1683. }
  1684. }
  1685. }
  1686. //! Called on server side when this item's quantity is changed. Call super.OnQuantityChanged(); first when overriding this event.
  1687. void OnQuantityChanged(float delta)
  1688. {
  1689. SetWeightDirty();
  1690. ItemBase parent = ItemBase.Cast(GetHierarchyParent());
  1691. if (parent)
  1692. parent.OnAttachmentQuantityChangedEx(this, delta);
  1693. if (IsLiquidContainer())
  1694. {
  1695. if (GetQuantityNormalized() <= 0.0)
  1696. {
  1697. SetLiquidType(LIQUID_NONE);
  1698. }
  1699. else if (GetLiquidType() == LIQUID_NONE)
  1700. {
  1701. ErrorEx("Undefined liquid type quantity changed, please define liquid type first! Using init value.",ErrorExSeverity.INFO);
  1702. SetLiquidType(GetLiquidTypeInit());
  1703. }
  1704. }
  1705. }
  1706. //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
  1707. void OnAttachmentQuantityChanged(ItemBase item)
  1708. {
  1709. // insert code here
  1710. }
  1711. //! Called on server side when some attachment's quantity is changed. Call super.OnAttachmentQuantityChanged(item); first when overriding this event.
  1712. void OnAttachmentQuantityChangedEx(ItemBase item , float delta)
  1713. {
  1714. OnAttachmentQuantityChanged(item);
  1715. }
  1716. override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
  1717. {
  1718. super.EEHealthLevelChanged(oldLevel,newLevel,zone);
  1719. if (GetGame().IsServer())
  1720. {
  1721. if (newLevel == GameConstants.STATE_RUINED)
  1722. {
  1723. //! drops content of container when ruined in fireplace
  1724. EntityAI parent = GetHierarchyParent();
  1725. if (parent && parent.IsFireplace())
  1726. {
  1727. CargoBase cargo = GetInventory().GetCargo();
  1728. if (cargo)
  1729. {
  1730. for (int i = 0; i < cargo.GetItemCount(); ++i)
  1731. {
  1732. parent.GetInventory().TakeEntityToInventory(InventoryMode.SERVER, FindInventoryLocationType.CARGO, cargo.GetItem(i));
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if (IsResultOfSplit())
  1738. {
  1739. // reset the splitting result flag, return to normal item behavior
  1740. SetResultOfSplit(false);
  1741. return;
  1742. }
  1743. if (m_Cleanness != 0 && oldLevel < newLevel && newLevel != 0)
  1744. {
  1745. SetCleanness(0);//unclean the item upon damage dealt
  1746. }
  1747. }
  1748. }
  1749. // just the split? TODO: verify
  1750. override void OnRightClick()
  1751. {
  1752. super.OnRightClick();
  1753. if (CanBeSplit() && !GetDayZGame().IsLeftCtrlDown() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(this,null))
  1754. {
  1755. if (GetGame().IsClient())
  1756. {
  1757. if (ScriptInputUserData.CanStoreInputUserData())
  1758. {
  1759. vector m4[4];
  1760. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  1761. EntityAI root = GetHierarchyRoot();
  1762. InventoryLocation dst = new InventoryLocation;
  1763. if (!player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.CARGO, dst))
  1764. {
  1765. if (root)
  1766. {
  1767. root.GetTransform(m4);
  1768. dst.SetGround(this, m4);
  1769. }
  1770. else
  1771. GetInventory().GetCurrentInventoryLocation(dst);
  1772. }
  1773. else
  1774. {
  1775. dst.SetCargo(dst.GetParent(), this, dst.GetIdx(), dst.GetRow(), dst.GetCol(), dst.GetFlip());
  1776. /* hacky solution to check reservation of "this" item instead of null since the gamecode is checking null against null and returning reservation=true incorrectly
  1777. this shouldnt cause issues within this scope*/
  1778. if (GetGame().GetPlayer().GetInventory().HasInventoryReservation(this, dst))
  1779. {
  1780. if (root)
  1781. {
  1782. root.GetTransform(m4);
  1783. dst.SetGround(this, m4);
  1784. }
  1785. else
  1786. GetInventory().GetCurrentInventoryLocation(dst);
  1787. }
  1788. else
  1789. {
  1790. GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(null, dst, GameInventory.c_InventoryReservationTimeoutShortMS);
  1791. }
  1792. }
  1793. ScriptInputUserData ctx = new ScriptInputUserData;
  1794. ctx.Write(INPUT_UDT_ITEM_MANIPULATION);
  1795. ctx.Write(4);
  1796. ItemBase thiz = this; // @NOTE: workaround for correct serialization
  1797. ctx.Write(thiz);
  1798. dst.WriteToContext(ctx);
  1799. ctx.Write(true); // dummy
  1800. ctx.Send();
  1801. }
  1802. }
  1803. else if (!GetGame().IsMultiplayer())
  1804. {
  1805. SplitItem(PlayerBase.Cast(GetGame().GetPlayer()));
  1806. }
  1807. }
  1808. }
  1809. override bool CanBeCombined(EntityAI other_item, bool reservation_check = true, bool stack_max_limit = false)
  1810. {
  1811. //TODO: delete check zero quantity check after fix double posts hands fsm events
  1812. if (!other_item || GetType() != other_item.GetType() || (IsFullQuantity() && other_item.GetQuantity() > 0) || other_item == this)
  1813. return false;
  1814. if (GetHealthLevel() == GameConstants.STATE_RUINED || other_item.GetHealthLevel() == GameConstants.STATE_RUINED)
  1815. return false;
  1816. //can_this_be_combined = ConfigGetBool("canBeSplit");
  1817. if (!can_this_be_combined)
  1818. return false;
  1819. Magazine mag = Magazine.Cast(this);
  1820. if (mag)
  1821. {
  1822. if (mag.GetAmmoCount() >= mag.GetAmmoMax())
  1823. return false;
  1824. if (stack_max_limit)
  1825. {
  1826. Magazine other_mag = Magazine.Cast(other_item);
  1827. if (other_item)
  1828. {
  1829. if (mag.GetAmmoCount() + other_mag.GetAmmoCount() > mag.GetAmmoMax())
  1830. return false;
  1831. }
  1832. }
  1833. }
  1834. else
  1835. {
  1836. //TODO: delete check zero quantity check after fix double posts hands fsm events
  1837. if (GetQuantity() >= GetQuantityMax() && other_item.GetQuantity() > 0 )
  1838. return false;
  1839. if (stack_max_limit && (GetQuantity() + other_item.GetQuantity() > GetQuantityMax()))
  1840. return false;
  1841. }
  1842. PlayerBase player = null;
  1843. if (CastTo(player, GetHierarchyRootPlayer())) //false when attached to player's attachment slot
  1844. {
  1845. if (player.GetInventory().HasAttachment(this))
  1846. return false;
  1847. if (player.IsItemsToDelete())
  1848. return false;
  1849. }
  1850. if (reservation_check && (GetInventory().HasInventoryReservation(this, null) || other_item.GetInventory().HasInventoryReservation(other_item, null)))
  1851. return false;
  1852. int slotID;
  1853. string slotName;
  1854. if (GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName) && GetHierarchyParent().GetInventory().GetSlotLock(slotID))
  1855. return false;
  1856. return true;
  1857. }
  1858. bool IsCombineAll(ItemBase other_item, bool use_stack_max = false)
  1859. {
  1860. return ComputeQuantityUsed(other_item, use_stack_max) == other_item.GetQuantity();
  1861. }
  1862. bool IsResultOfSplit()
  1863. {
  1864. return m_IsResultOfSplit;
  1865. }
  1866. void SetResultOfSplit(bool value)
  1867. {
  1868. m_IsResultOfSplit = value;
  1869. }
  1870. int ComputeQuantityUsed(ItemBase other_item, bool use_stack_max = true)
  1871. {
  1872. return ComputeQuantityUsedEx(other_item, use_stack_max);
  1873. }
  1874. float ComputeQuantityUsedEx(ItemBase other_item, bool use_stack_max = true)
  1875. {
  1876. float other_item_quantity = other_item.GetQuantity();
  1877. float this_free_space;
  1878. float stack_max = GetQuantityMax();
  1879. this_free_space = stack_max - GetQuantity();
  1880. if (other_item_quantity > this_free_space)
  1881. {
  1882. return this_free_space;
  1883. }
  1884. else
  1885. {
  1886. return other_item_quantity;
  1887. }
  1888. }
  1889. override void CombineItemsEx(EntityAI entity2, bool use_stack_max = true)
  1890. {
  1891. CombineItems(ItemBase.Cast(entity2),use_stack_max);
  1892. }
  1893. void CombineItems(ItemBase other_item, bool use_stack_max = true)
  1894. {
  1895. if (!CanBeCombined(other_item, false))
  1896. return;
  1897. if (!IsMagazine() && other_item)
  1898. {
  1899. float quantity_used = ComputeQuantityUsedEx(other_item,use_stack_max);
  1900. if (quantity_used != 0)
  1901. {
  1902. float hp1 = GetHealth01("","");
  1903. float hp2 = other_item.GetHealth01("","");
  1904. float hpResult = ((hp1*GetQuantity()) + (hp2*quantity_used));
  1905. hpResult = hpResult / (GetQuantity() + quantity_used);
  1906. hpResult *= GetMaxHealth();
  1907. Math.Round(hpResult);
  1908. SetHealth("", "Health", hpResult);
  1909. AddQuantity(quantity_used);
  1910. other_item.AddQuantity(-quantity_used);
  1911. }
  1912. }
  1913. OnCombine(other_item);
  1914. }
  1915. void OnCombine(ItemBase other_item)
  1916. {
  1917. #ifdef SERVER
  1918. if (!GetHierarchyRootPlayer() && GetHierarchyParent())
  1919. GetHierarchyParent().IncreaseLifetimeUp();
  1920. #endif
  1921. };
  1922. void GetRecipesActions(Man player, out TSelectableActionInfoArray outputList)
  1923. {
  1924. PlayerBase p = PlayerBase.Cast(player);
  1925. array<int> recipesIds = p.m_Recipes;
  1926. PluginRecipesManager moduleRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  1927. if (moduleRecipesManager)
  1928. {
  1929. EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands();
  1930. moduleRecipesManager.GetValidRecipes(ItemBase.Cast(this), ItemBase.Cast(itemInHands), recipesIds, p);
  1931. }
  1932. for (int i = 0;i < recipesIds.Count(); i++)
  1933. {
  1934. int key = recipesIds.Get(i);
  1935. string recipeName = moduleRecipesManager.GetRecipeName(key);
  1936. outputList.Insert(new TSelectableActionInfo(SAT_CRAFTING, key, recipeName));
  1937. }
  1938. }
  1939. // -------------------------------------------------------------------------
  1940. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  1941. {
  1942. super.GetDebugActions(outputList);
  1943. //quantity
  1944. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_QUANTITY, "Quantity +20%", FadeColors.LIGHT_GREY));
  1945. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_QUANTITY, "Quantity -20%", FadeColors.LIGHT_GREY));
  1946. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_QUANTITY_0, "Set Quantity 0", FadeColors.LIGHT_GREY));
  1947. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_MAX_QUANTITY, "Set Quantity Max", FadeColors.LIGHT_GREY));
  1948. //health
  1949. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_HEALTH, "Health +20%", FadeColors.LIGHT_GREY));
  1950. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_HEALTH, "Health -20%", FadeColors.LIGHT_GREY));
  1951. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DESTROY_HEALTH, "Health 0", FadeColors.LIGHT_GREY));
  1952. //temperature
  1953. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_TEMPERATURE, "Temperature +20", FadeColors.LIGHT_GREY));
  1954. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_TEMPERATURE, "Temperature -20", FadeColors.LIGHT_GREY));
  1955. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FLIP_FROZEN, "Toggle Frozen", FadeColors.LIGHT_GREY));
  1956. //wet
  1957. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_WETNESS, "Wetness +20", FadeColors.LIGHT_GREY));
  1958. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_WETNESS, "Wetness -20", FadeColors.LIGHT_GREY));
  1959. //liquidtype
  1960. if (IsLiquidContainer())
  1961. {
  1962. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_UP, "LiquidType Next", FadeColors.LIGHT_GREY));
  1963. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_DOWN, "LiquidType Previous", FadeColors.LIGHT_GREY));
  1964. }
  1965. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.MAKE_SPECIAL, "Make Special", FadeColors.LIGHT_GREY));
  1966. // watch
  1967. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_ITEM, "Watch (CTRL-Z)", FadeColors.LIGHT_GREY));
  1968. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_PLAYER, "Watch Player", FadeColors.LIGHT_GREY));
  1969. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
  1970. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
  1971. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED));
  1972. }
  1973. // -------------------------------------------------------------------------
  1974. // -------------------------------------------------------------------------
  1975. // -------------------------------------------------------------------------
  1976. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  1977. {
  1978. super.OnAction(action_id, player, ctx);
  1979. if (action_id >= EActions.RECIPES_RANGE_START && action_id < EActions.RECIPES_RANGE_END)
  1980. {
  1981. PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  1982. int idWithoutOffset = action_id - EActions.RECIPES_RANGE_START;
  1983. PlayerBase p = PlayerBase.Cast(player);
  1984. if (EActions.RECIPES_RANGE_START < 1000)
  1985. {
  1986. float anim_length = plugin_recipes_manager.GetRecipeLengthInSecs(idWithoutOffset);
  1987. float specialty_weight = plugin_recipes_manager.GetRecipeSpecialty(idWithoutOffset);
  1988. }
  1989. }
  1990. #ifndef SERVER
  1991. else if (action_id == EActions.WATCH_PLAYER)
  1992. {
  1993. PluginDeveloper.SetDeveloperItemClientEx(player);
  1994. }
  1995. #endif
  1996. if (GetGame().IsServer())
  1997. {
  1998. if (action_id >= EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START && action_id < EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_END)
  1999. {
  2000. int id = action_id - EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START;
  2001. OnDebugButtonPressServer(id + 1);
  2002. }
  2003. else if (action_id >= EActions.DEBUG_AGENTS_RANGE_INJECT_START && action_id < EActions.DEBUG_AGENTS_RANGE_INJECT_END)
  2004. {
  2005. int agent_id = action_id - EActions.DEBUG_AGENTS_RANGE_INJECT_START;
  2006. InsertAgent(agent_id,100);
  2007. }
  2008. else if (action_id >= EActions.DEBUG_AGENTS_RANGE_REMOVE_START && action_id < EActions.DEBUG_AGENTS_RANGE_REMOVE_END)
  2009. {
  2010. int agent_id2 = action_id - EActions.DEBUG_AGENTS_RANGE_REMOVE_START;
  2011. RemoveAgent(agent_id2);
  2012. }
  2013. else if (action_id == EActions.ADD_QUANTITY)
  2014. {
  2015. if (IsMagazine())
  2016. {
  2017. Magazine mag = Magazine.Cast(this);
  2018. mag.ServerSetAmmoCount(mag.GetAmmoCount() + mag.GetAmmoMax() * 0.2);
  2019. }
  2020. else
  2021. {
  2022. AddQuantity(GetQuantityMax() * 0.2);
  2023. }
  2024. if (m_EM)
  2025. {
  2026. m_EM.AddEnergy(m_EM.GetEnergyMax() * 0.2);
  2027. }
  2028. //PrintVariables();
  2029. }
  2030. else if (action_id == EActions.REMOVE_QUANTITY) //Quantity -20%
  2031. {
  2032. if (IsMagazine())
  2033. {
  2034. Magazine mag2 = Magazine.Cast(this);
  2035. mag2.ServerSetAmmoCount(mag2.GetAmmoCount() - mag2.GetAmmoMax() * 0.2);
  2036. }
  2037. else
  2038. {
  2039. AddQuantity(- GetQuantityMax() * 0.2);
  2040. }
  2041. if (m_EM)
  2042. {
  2043. m_EM.AddEnergy(- m_EM.GetEnergyMax() * 0.2);
  2044. }
  2045. //PrintVariables();
  2046. }
  2047. else if (action_id == EActions.SET_QUANTITY_0) //SetMaxQuantity
  2048. {
  2049. SetQuantity(0);
  2050. if (m_EM)
  2051. {
  2052. m_EM.SetEnergy(0);
  2053. }
  2054. }
  2055. else if (action_id == EActions.SET_MAX_QUANTITY) //SetMaxQuantity
  2056. {
  2057. SetQuantityMax();
  2058. if (m_EM)
  2059. {
  2060. m_EM.SetEnergy(m_EM.GetEnergyMax());
  2061. }
  2062. }
  2063. else if (action_id == EActions.ADD_HEALTH)
  2064. {
  2065. AddHealth("","",GetMaxHealth("","Health")/5);
  2066. }
  2067. else if (action_id == EActions.REMOVE_HEALTH)
  2068. {
  2069. AddHealth("","",-GetMaxHealth("","Health")/5);
  2070. }
  2071. else if (action_id == EActions.DESTROY_HEALTH)
  2072. {
  2073. SetHealth01("","",0);
  2074. }
  2075. else if (action_id == EActions.WATCH_ITEM)
  2076. {
  2077. PluginItemDiagnostic mid = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
  2078. mid.RegisterDebugItem(ItemBase.Cast(this), PlayerBase.Cast(player));
  2079. #ifdef DEVELOPER
  2080. SetDebugDeveloper_item(this);
  2081. #endif
  2082. }
  2083. else if (action_id == EActions.ADD_TEMPERATURE)
  2084. {
  2085. AddTemperature(20);
  2086. //PrintVariables();
  2087. }
  2088. else if (action_id == EActions.REMOVE_TEMPERATURE)
  2089. {
  2090. AddTemperature(-20);
  2091. //PrintVariables();
  2092. }
  2093. else if (action_id == EActions.FLIP_FROZEN)
  2094. {
  2095. SetFrozen(!GetIsFrozen());
  2096. //PrintVariables();
  2097. }
  2098. else if (action_id == EActions.ADD_WETNESS)
  2099. {
  2100. AddWet(GetWetMax()/5);
  2101. //PrintVariables();
  2102. }
  2103. else if (action_id == EActions.REMOVE_WETNESS)
  2104. {
  2105. AddWet(-GetWetMax()/5);
  2106. //PrintVariables();
  2107. }
  2108. else if (action_id == EActions.LIQUIDTYPE_UP)
  2109. {
  2110. int curr_type = GetLiquidType();
  2111. SetLiquidType(curr_type * 2);
  2112. //AddWet(1);
  2113. //PrintVariables();
  2114. }
  2115. else if (action_id == EActions.LIQUIDTYPE_DOWN)
  2116. {
  2117. int curr_type2 = GetLiquidType();
  2118. SetLiquidType(curr_type2 / 2);
  2119. }
  2120. else if (action_id == EActions.MAKE_SPECIAL)
  2121. {
  2122. auto debugParams = DebugSpawnParams.WithPlayer(player);
  2123. OnDebugSpawnEx(debugParams);
  2124. }
  2125. else if (action_id == EActions.DELETE)
  2126. {
  2127. Delete();
  2128. }
  2129. }
  2130. return false;
  2131. }
  2132. // -------------------------------------------------------------------------
  2133. //! DEPRECATED use OnActivatedByItem below
  2134. //! Called when this item is activated from a trip wire that was stepped on.
  2135. void OnActivatedByTripWire();
  2136. //! Called when this item is activated by other
  2137. void OnActivatedByItem(notnull ItemBase item);
  2138. //----------------------------------------------------------------
  2139. //returns true if item is able to explode when put in fire
  2140. bool CanExplodeInFire()
  2141. {
  2142. return false;
  2143. }
  2144. //----------------------------------------------------------------
  2145. bool CanEat()
  2146. {
  2147. return true;
  2148. }
  2149. //----------------------------------------------------------------
  2150. override bool IsIgnoredByConstruction()
  2151. {
  2152. return true;
  2153. }
  2154. //----------------------------------------------------------------
  2155. //has FoodStages in config?
  2156. bool HasFoodStage()
  2157. {
  2158. string config_path = string.Format("CfgVehicles %1 Food FoodStages", GetType());
  2159. return GetGame().ConfigIsExisting(config_path);
  2160. }
  2161. //! overridden on Edible_Base; so we don't have to parse configs all the time
  2162. FoodStage GetFoodStage()
  2163. {
  2164. return null;
  2165. }
  2166. bool CanBeCooked()
  2167. {
  2168. return false;
  2169. }
  2170. bool CanBeCookedOnStick()
  2171. {
  2172. return false;
  2173. }
  2174. //! cooking-related effect methods
  2175. void RefreshAudioVisualsOnClient( CookingMethodType cooking_method, bool is_done, bool is_empty, bool is_burned );
  2176. void RemoveAudioVisualsOnClient();
  2177. //----------------------------------------------------------------
  2178. bool CanRepair(ItemBase item_repair_kit)
  2179. {
  2180. PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
  2181. return module_repairing.CanRepair(this, item_repair_kit);
  2182. }
  2183. //----------------------------------------------------------------
  2184. bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight)
  2185. {
  2186. PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing));
  2187. return module_repairing.Repair(player, this, item_repair_kit, specialty_weight);
  2188. }
  2189. //----------------------------------------------------------------
  2190. int GetItemSize()
  2191. {
  2192. /*
  2193. vector v_size = this.ConfigGetVector("itemSize");
  2194. int v_size_x = v_size[0];
  2195. int v_size_y = v_size[1];
  2196. int size = v_size_x * v_size_y;
  2197. return size;
  2198. */
  2199. return 1;
  2200. }
  2201. //----------------------------------------------------------------
  2202. //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
  2203. bool CanBeMovedOverride()
  2204. {
  2205. return m_CanBeMovedOverride;
  2206. }
  2207. //----------------------------------------------------------------
  2208. //Override for allowing seemingly unallowed moves when two clients send a conflicting message simultaneously
  2209. void SetCanBeMovedOverride(bool setting)
  2210. {
  2211. m_CanBeMovedOverride = setting;
  2212. }
  2213. //----------------------------------------------------------------
  2214. /**
  2215. \brief Send message to owner player in grey color
  2216. \return \p void
  2217. @code
  2218. item_stone.MessageToOwnerStatus("Some Status Message");
  2219. @endcode
  2220. */
  2221. void MessageToOwnerStatus(string text)
  2222. {
  2223. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2224. if (player)
  2225. {
  2226. player.MessageStatus(text);
  2227. }
  2228. }
  2229. //----------------------------------------------------------------
  2230. /**
  2231. \brief Send message to owner player in yellow color
  2232. \return \p void
  2233. @code
  2234. item_stone.MessageToOwnerAction("Some Action Message");
  2235. @endcode
  2236. */
  2237. void MessageToOwnerAction(string text)
  2238. {
  2239. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2240. if (player)
  2241. {
  2242. player.MessageAction(text);
  2243. }
  2244. }
  2245. //----------------------------------------------------------------
  2246. /**
  2247. \brief Send message to owner player in green color
  2248. \return \p void
  2249. @code
  2250. item_stone.MessageToOwnerFriendly("Some Friendly Message");
  2251. @endcode
  2252. */
  2253. void MessageToOwnerFriendly(string text)
  2254. {
  2255. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2256. if (player)
  2257. {
  2258. player.MessageFriendly(text);
  2259. }
  2260. }
  2261. //----------------------------------------------------------------
  2262. /**
  2263. \brief Send message to owner player in red color
  2264. \return \p void
  2265. @code
  2266. item_stone.MessageToOwnerImportant("Some Important Message");
  2267. @endcode
  2268. */
  2269. void MessageToOwnerImportant(string text)
  2270. {
  2271. PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer());
  2272. if (player)
  2273. {
  2274. player.MessageImportant(text);
  2275. }
  2276. }
  2277. override bool IsItemBase()
  2278. {
  2279. return true;
  2280. }
  2281. // Checks if item is of questioned kind
  2282. override bool KindOf(string tag)
  2283. {
  2284. bool found = false;
  2285. string item_name = this.GetType();
  2286. ref TStringArray item_tag_array = new TStringArray;
  2287. GetGame().ConfigGetTextArray("cfgVehicles " + item_name + " itemInfo", item_tag_array);
  2288. int array_size = item_tag_array.Count();
  2289. for (int i = 0; i < array_size; i++)
  2290. {
  2291. if (item_tag_array.Get(i) == tag)
  2292. {
  2293. found = true;
  2294. break;
  2295. }
  2296. }
  2297. return found;
  2298. }
  2299. override void OnRPC(PlayerIdentity sender, int rpc_type,ParamsReadContext ctx)
  2300. {
  2301. //Debug.Log("OnRPC called");
  2302. super.OnRPC(sender, rpc_type,ctx);
  2303. //Play soundset for attachment locking (ActionLockAttachment.c)
  2304. switch (rpc_type)
  2305. {
  2306. #ifndef SERVER
  2307. case ERPCs.RPC_SOUND_LOCK_ATTACH:
  2308. Param2<bool, string> p = new Param2<bool, string>(false, "");
  2309. if (!ctx.Read(p))
  2310. return;
  2311. bool play = p.param1;
  2312. string soundSet = p.param2;
  2313. if (play)
  2314. {
  2315. if (m_LockingSound)
  2316. {
  2317. if (!m_LockingSound.IsSoundPlaying())
  2318. {
  2319. m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
  2320. }
  2321. }
  2322. else
  2323. {
  2324. m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true);
  2325. }
  2326. }
  2327. else
  2328. {
  2329. SEffectManager.DestroyEffect(m_LockingSound);
  2330. }
  2331. break;
  2332. #endif
  2333. }
  2334. if (GetWrittenNoteData())
  2335. {
  2336. GetWrittenNoteData().OnRPC(sender, rpc_type,ctx);
  2337. }
  2338. }
  2339. //-----------------------------
  2340. // VARIABLE MANIPULATION SYSTEM
  2341. //-----------------------------
  2342. int NameToID(string name)
  2343. {
  2344. PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
  2345. return plugin.GetID(name);
  2346. }
  2347. string IDToName(int id)
  2348. {
  2349. PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables));
  2350. return plugin.GetName(id);
  2351. }
  2352. //! DEPRECATED (most likely)
  2353. void OnSyncVariables(ParamsReadContext ctx)//with ID optimization
  2354. {
  2355. //Debug.Log("OnSyncVariables called for item: "+ ToString(this.GetType()),"varSync");
  2356. //read the flags
  2357. int varFlags;
  2358. if (!ctx.Read(varFlags))
  2359. return;
  2360. if (varFlags & ItemVariableFlags.FLOAT)
  2361. {
  2362. ReadVarsFromCTX(ctx);
  2363. }
  2364. }
  2365. override void SerializeNumericalVars(array<float> floats_out)
  2366. {
  2367. //some variables handled on EntityAI level already!
  2368. super.SerializeNumericalVars(floats_out);
  2369. // the order of serialization must be the same as the order of de-serialization
  2370. //--------------------------------------------
  2371. if (IsVariableSet(VARIABLE_QUANTITY))
  2372. {
  2373. floats_out.Insert(m_VarQuantity);
  2374. }
  2375. //--------------------------------------------
  2376. if (IsVariableSet(VARIABLE_WET))
  2377. {
  2378. floats_out.Insert(m_VarWet);
  2379. }
  2380. //--------------------------------------------
  2381. if (IsVariableSet(VARIABLE_LIQUIDTYPE))
  2382. {
  2383. floats_out.Insert(m_VarLiquidType);
  2384. }
  2385. //--------------------------------------------
  2386. if (IsVariableSet(VARIABLE_COLOR))
  2387. {
  2388. floats_out.Insert(m_ColorComponentR);
  2389. floats_out.Insert(m_ColorComponentG);
  2390. floats_out.Insert(m_ColorComponentB);
  2391. floats_out.Insert(m_ColorComponentA);
  2392. }
  2393. //--------------------------------------------
  2394. if (IsVariableSet(VARIABLE_CLEANNESS))
  2395. {
  2396. floats_out.Insert(m_Cleanness);
  2397. }
  2398. }
  2399. override void DeSerializeNumericalVars(array<float> floats)
  2400. {
  2401. //some variables handled on EntityAI level already!
  2402. super.DeSerializeNumericalVars(floats);
  2403. // the order of serialization must be the same as the order of de-serialization
  2404. int index = 0;
  2405. int mask = Math.Round(floats.Get(index));
  2406. index++;
  2407. //--------------------------------------------
  2408. if (mask & VARIABLE_QUANTITY)
  2409. {
  2410. if (m_IsStoreLoad)
  2411. {
  2412. SetStoreLoadedQuantity(floats.Get(index));
  2413. }
  2414. else
  2415. {
  2416. float quantity = floats.Get(index);
  2417. SetQuantity(quantity, true, false, false, false);
  2418. }
  2419. index++;
  2420. }
  2421. //--------------------------------------------
  2422. if (mask & VARIABLE_WET)
  2423. {
  2424. float wet = floats.Get(index);
  2425. SetWet(wet);
  2426. index++;
  2427. }
  2428. //--------------------------------------------
  2429. if (mask & VARIABLE_LIQUIDTYPE)
  2430. {
  2431. int liquidtype = Math.Round(floats.Get(index));
  2432. SetLiquidType(liquidtype);
  2433. index++;
  2434. }
  2435. //--------------------------------------------
  2436. if (mask & VARIABLE_COLOR)
  2437. {
  2438. m_ColorComponentR = Math.Round(floats.Get(index));
  2439. index++;
  2440. m_ColorComponentG = Math.Round(floats.Get(index));
  2441. index++;
  2442. m_ColorComponentB = Math.Round(floats.Get(index));
  2443. index++;
  2444. m_ColorComponentA = Math.Round(floats.Get(index));
  2445. index++;
  2446. }
  2447. //--------------------------------------------
  2448. if (mask & VARIABLE_CLEANNESS)
  2449. {
  2450. int cleanness = Math.Round(floats.Get(index));
  2451. SetCleanness(cleanness);
  2452. index++;
  2453. }
  2454. }
  2455. override void WriteVarsToCTX(ParamsWriteContext ctx)
  2456. {
  2457. super.WriteVarsToCTX(ctx);
  2458. //--------------------------------------------
  2459. if (IsVariableSet(VARIABLE_QUANTITY))
  2460. {
  2461. ctx.Write(GetQuantity());
  2462. }
  2463. //--------------------------------------------
  2464. if (IsVariableSet(VARIABLE_WET))
  2465. {
  2466. ctx.Write(GetWet());
  2467. }
  2468. //--------------------------------------------
  2469. if (IsVariableSet(VARIABLE_LIQUIDTYPE))
  2470. {
  2471. ctx.Write(GetLiquidType());
  2472. }
  2473. //--------------------------------------------
  2474. if (IsVariableSet(VARIABLE_COLOR))
  2475. {
  2476. int r,g,b,a;
  2477. GetColor(r,g,b,a);
  2478. ctx.Write(r);
  2479. ctx.Write(g);
  2480. ctx.Write(b);
  2481. ctx.Write(a);
  2482. }
  2483. //--------------------------------------------
  2484. if (IsVariableSet(VARIABLE_CLEANNESS))
  2485. {
  2486. ctx.Write(GetCleanness());
  2487. }
  2488. }
  2489. override bool ReadVarsFromCTX(ParamsReadContext ctx, int version = -1)//with ID optimization
  2490. {
  2491. if (!super.ReadVarsFromCTX(ctx,version))
  2492. return false;
  2493. int intValue;
  2494. float value;
  2495. if (version < 140)
  2496. {
  2497. if (!ctx.Read(intValue))
  2498. return false;
  2499. m_VariablesMask = intValue;
  2500. }
  2501. if (m_VariablesMask & VARIABLE_QUANTITY)
  2502. {
  2503. if (!ctx.Read(value))
  2504. return false;
  2505. if (IsStoreLoad())
  2506. {
  2507. SetStoreLoadedQuantity(value);
  2508. }
  2509. else
  2510. {
  2511. SetQuantity(value, true, false, false, false);
  2512. }
  2513. }
  2514. //--------------------------------------------
  2515. if (version < 140)
  2516. {
  2517. if (m_VariablesMask & VARIABLE_TEMPERATURE)
  2518. {
  2519. if (!ctx.Read(value))
  2520. return false;
  2521. SetTemperatureDirect(value);
  2522. }
  2523. }
  2524. //--------------------------------------------
  2525. if (m_VariablesMask & VARIABLE_WET)
  2526. {
  2527. if (!ctx.Read(value))
  2528. return false;
  2529. SetWet(value);
  2530. }
  2531. //--------------------------------------------
  2532. if (m_VariablesMask & VARIABLE_LIQUIDTYPE)
  2533. {
  2534. if (!ctx.Read(intValue))
  2535. return false;
  2536. SetLiquidType(intValue);
  2537. }
  2538. //--------------------------------------------
  2539. if (m_VariablesMask & VARIABLE_COLOR)
  2540. {
  2541. int r,g,b,a;
  2542. if (!ctx.Read(r))
  2543. return false;
  2544. if (!ctx.Read(g))
  2545. return false;
  2546. if (!ctx.Read(b))
  2547. return false;
  2548. if (!ctx.Read(a))
  2549. return false;
  2550. SetColor(r,g,b,a);
  2551. }
  2552. //--------------------------------------------
  2553. if (m_VariablesMask & VARIABLE_CLEANNESS)
  2554. {
  2555. if (!ctx.Read(intValue))
  2556. return false;
  2557. SetCleanness(intValue);
  2558. }
  2559. //--------------------------------------------
  2560. if (version >= 138 && version < 140)
  2561. {
  2562. if (m_VariablesMask & VARIABLE_TEMPERATURE)
  2563. {
  2564. if (!ctx.Read(intValue))
  2565. return false;
  2566. SetFrozen(intValue);
  2567. }
  2568. }
  2569. return true;
  2570. }
  2571. //----------------------------------------------------------------
  2572. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  2573. {
  2574. m_IsStoreLoad = true;
  2575. if (GetDamageSystemVersionChange() != -1 && version < GetDamageSystemVersionChange())
  2576. {
  2577. m_FixDamageSystemInit = true;
  2578. }
  2579. if (!super.OnStoreLoad(ctx, version))
  2580. {
  2581. m_IsStoreLoad = false;
  2582. return false;
  2583. }
  2584. if (version >= 114)
  2585. {
  2586. bool hasQuickBarIndexSaved;
  2587. if (!ctx.Read(hasQuickBarIndexSaved))
  2588. {
  2589. m_IsStoreLoad = false;
  2590. return false;
  2591. }
  2592. if (hasQuickBarIndexSaved)
  2593. {
  2594. int itmQBIndex;
  2595. //Load quickbar item bind
  2596. if (!ctx.Read(itmQBIndex))
  2597. {
  2598. m_IsStoreLoad = false;
  2599. return false;
  2600. }
  2601. PlayerBase parentPlayer = PlayerBase.Cast(GetHierarchyRootPlayer());
  2602. if (itmQBIndex != -1 && parentPlayer)
  2603. parentPlayer.SetLoadedQuickBarItemBind(this, itmQBIndex);
  2604. }
  2605. }
  2606. else
  2607. {
  2608. // Backup of how it used to be
  2609. PlayerBase player;
  2610. int itemQBIndex;
  2611. if (version == int.MAX)
  2612. {
  2613. if (!ctx.Read(itemQBIndex))
  2614. {
  2615. m_IsStoreLoad = false;
  2616. return false;
  2617. }
  2618. }
  2619. else if (Class.CastTo(player, GetHierarchyRootPlayer()))
  2620. {
  2621. //Load quickbar item bind
  2622. if (!ctx.Read(itemQBIndex))
  2623. {
  2624. m_IsStoreLoad = false;
  2625. return false;
  2626. }
  2627. if (itemQBIndex != -1 && player)
  2628. player.SetLoadedQuickBarItemBind(this,itemQBIndex);
  2629. }
  2630. }
  2631. if (version < 140)
  2632. {
  2633. // variable management system
  2634. if (!LoadVariables(ctx, version))
  2635. {
  2636. m_IsStoreLoad = false;
  2637. return false;
  2638. }
  2639. }
  2640. //agent trasmission system
  2641. if (!LoadAgents(ctx, version))
  2642. {
  2643. m_IsStoreLoad = false;
  2644. return false;
  2645. }
  2646. if (version >= 132)
  2647. {
  2648. RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
  2649. if (raib)
  2650. {
  2651. if (!raib.OnStoreLoad(ctx,version))
  2652. {
  2653. m_IsStoreLoad = false;
  2654. return false;
  2655. }
  2656. }
  2657. }
  2658. m_IsStoreLoad = false;
  2659. return true;
  2660. }
  2661. //----------------------------------------------------------------
  2662. override void OnStoreSave(ParamsWriteContext ctx)
  2663. {
  2664. super.OnStoreSave(ctx);
  2665. PlayerBase player;
  2666. if (PlayerBase.CastTo(player,GetHierarchyRootPlayer()))
  2667. {
  2668. ctx.Write(true); // Keep track of if we should actually read this in or not
  2669. //Save quickbar item bind
  2670. int itemQBIndex = -1;
  2671. itemQBIndex = player.FindQuickBarEntityIndex(this);
  2672. ctx.Write(itemQBIndex);
  2673. }
  2674. else
  2675. {
  2676. ctx.Write(false); // Keep track of if we should actually read this in or not
  2677. }
  2678. SaveAgents(ctx);//agent trasmission system
  2679. RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
  2680. if (raib)
  2681. {
  2682. raib.OnStoreSave(ctx);
  2683. }
  2684. }
  2685. //----------------------------------------------------------------
  2686. override void AfterStoreLoad()
  2687. {
  2688. super.AfterStoreLoad();
  2689. if (m_FixDamageSystemInit)
  2690. {
  2691. PerformDamageSystemReinit();
  2692. }
  2693. if (GetStoreLoadedQuantity() != float.LOWEST)
  2694. {
  2695. SetQuantity(GetStoreLoadedQuantity());
  2696. 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
  2697. }
  2698. }
  2699. override void EEOnAfterLoad()
  2700. {
  2701. super.EEOnAfterLoad();
  2702. if (m_FixDamageSystemInit)
  2703. {
  2704. m_FixDamageSystemInit = false;
  2705. }
  2706. if (GetRemotelyActivatedItemBehaviour())
  2707. GetRemotelyActivatedItemBehaviour().OnAfterLoad();
  2708. }
  2709. bool CanBeDisinfected()
  2710. {
  2711. return false;
  2712. }
  2713. //----------------------------------------------------------------
  2714. override void OnVariablesSynchronized()
  2715. {
  2716. if (m_Initialized)
  2717. {
  2718. #ifdef PLATFORM_CONSOLE
  2719. //bruteforce it is
  2720. if (IsSplitable())
  2721. {
  2722. UIScriptedMenu menu = GetGame().GetUIManager().FindMenu(MENU_INVENTORY);
  2723. if (menu)
  2724. {
  2725. menu.Refresh();
  2726. }
  2727. }
  2728. #endif
  2729. }
  2730. if (!dBodyIsDynamic(this) && m_WantPlayImpactSound)
  2731. {
  2732. PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash);
  2733. m_WantPlayImpactSound = false;
  2734. }
  2735. if (m_VarQuantity != m_VarQuantityPrev)
  2736. {
  2737. SetWeightDirty();
  2738. m_VarQuantityPrev = m_VarQuantity;
  2739. }
  2740. if (m_VarWet != m_VarWetPrev)
  2741. {
  2742. OnWetChanged(m_VarWet,m_VarWetPrev);
  2743. m_VarWetPrev = m_VarWet;
  2744. }
  2745. if (m_SoundSyncPlay != 0)
  2746. {
  2747. m_ItemSoundHandler.PlayItemSoundClient(m_SoundSyncPlay);
  2748. m_SoundSyncPlay = 0;
  2749. }
  2750. if (m_SoundSyncStop != 0)
  2751. {
  2752. m_ItemSoundHandler.StopItemSoundClient(m_SoundSyncStop);
  2753. m_SoundSyncStop = 0;
  2754. }
  2755. super.OnVariablesSynchronized();
  2756. }
  2757. //------------------------- Quantity
  2758. //----------------------------------------------------------------
  2759. //! 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
  2760. override bool SetQuantity(float value, bool destroy_config = true, bool destroy_forced = false, bool allow_client = false, bool clamp_to_stack_max = true)
  2761. {
  2762. if (!IsServerCheck(allow_client))
  2763. return false;
  2764. if (!HasQuantity())
  2765. return false;
  2766. float min = GetQuantityMin();
  2767. float max = GetQuantityMax();
  2768. if (value <= (min + 0.001))
  2769. value = min;
  2770. if (value == min)
  2771. {
  2772. if (destroy_config)
  2773. {
  2774. bool dstr = ConfigGetBool("varQuantityDestroyOnMin");
  2775. if (dstr)
  2776. {
  2777. m_VarQuantity = Math.Clamp(value, min, max);
  2778. this.Delete();
  2779. return true;
  2780. }
  2781. }
  2782. else if (destroy_forced)
  2783. {
  2784. m_VarQuantity = Math.Clamp(value, min, max);
  2785. this.Delete();
  2786. return true;
  2787. }
  2788. // we get here if destroy_config IS true AND dstr(config destroy param) IS false;
  2789. RemoveAllAgents();//we remove all agents when we got to the min value, but the item is not getting deleted
  2790. }
  2791. float delta = m_VarQuantity;
  2792. m_VarQuantity = Math.Clamp(value, min, max);
  2793. if (GetStoreLoadedQuantity() == float.LOWEST)//any other value means we are setting quantity from storage
  2794. {
  2795. delta = m_VarQuantity - delta;
  2796. if (delta)
  2797. OnQuantityChanged(delta);
  2798. }
  2799. SetVariableMask(VARIABLE_QUANTITY);
  2800. return false;
  2801. }
  2802. //----------------------------------------------------------------
  2803. //! 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
  2804. bool AddQuantity(float value, bool destroy_config = true, bool destroy_forced = false)
  2805. {
  2806. return SetQuantity(GetQuantity() + value, destroy_config, destroy_forced);
  2807. }
  2808. //----------------------------------------------------------------
  2809. void SetQuantityMax()
  2810. {
  2811. float max = GetQuantityMax();
  2812. SetQuantity(max);
  2813. }
  2814. override void SetQuantityToMinimum()
  2815. {
  2816. float min = GetQuantityMin();
  2817. SetQuantity(min);
  2818. }
  2819. //----------------------------------------------------------------
  2820. //! 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)
  2821. void SetQuantityNormalized(float value, bool destroy_config = true, bool destroy_forced = false)
  2822. {
  2823. float value_clamped = Math.Clamp(value, 0, 1);//just to make sure
  2824. int result = Math.Round(Math.Lerp(GetQuantityMin(), GetQuantityMax(), value_clamped));
  2825. SetQuantity(result, destroy_config, destroy_forced);
  2826. }
  2827. //----------------------------------------------------------------
  2828. //! 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)
  2829. override float GetQuantityNormalized()
  2830. {
  2831. return Math.InverseLerp(GetQuantityMin(), GetQuantityMax(),m_VarQuantity);
  2832. }
  2833. float GetQuantityNormalizedScripted()
  2834. {
  2835. return GetQuantityNormalized();
  2836. }
  2837. /*void SetAmmoNormalized(float value)
  2838. {
  2839. float value_clamped = Math.Clamp(value, 0, 1);
  2840. Magazine this_mag = Magazine.Cast(this);
  2841. int max_rounds = this_mag.GetAmmoMax();
  2842. int result = value * max_rounds;//can the rounded if higher precision is required
  2843. this_mag.SetAmmoCount(result);
  2844. }*/
  2845. //----------------------------------------------------------------
  2846. override int GetQuantityMax()
  2847. {
  2848. int slot = -1;
  2849. if (GetInventory())
  2850. {
  2851. InventoryLocation il = new InventoryLocation;
  2852. GetInventory().GetCurrentInventoryLocation(il);
  2853. slot = il.GetSlot();
  2854. }
  2855. return GetTargetQuantityMax(slot);
  2856. }
  2857. override int GetTargetQuantityMax(int attSlotID = -1)
  2858. {
  2859. float quantity_max = 0;
  2860. if (IsSplitable()) //only stackable/splitable items can check for stack size
  2861. {
  2862. if (attSlotID != -1)
  2863. quantity_max = InventorySlots.GetStackMaxForSlotId(attSlotID);
  2864. if (quantity_max <= 0)
  2865. quantity_max = m_VarStackMax;
  2866. }
  2867. if (quantity_max <= 0)
  2868. quantity_max = m_VarQuantityMax;
  2869. return quantity_max;
  2870. }
  2871. //----------------------------------------------------------------
  2872. override int GetQuantityMin()
  2873. {
  2874. return m_VarQuantityMin;
  2875. }
  2876. //----------------------------------------------------------------
  2877. int GetQuantityInit()
  2878. {
  2879. return m_VarQuantityInit;
  2880. }
  2881. //----------------------------------------------------------------
  2882. override bool HasQuantity()
  2883. {
  2884. return !(GetQuantityMax() - GetQuantityMin() == 0);
  2885. }
  2886. override float GetQuantity()
  2887. {
  2888. return m_VarQuantity;
  2889. }
  2890. bool IsFullQuantity()
  2891. {
  2892. return GetQuantity() >= GetQuantityMax();
  2893. }
  2894. //Calculates weight of single item without attachments and cargo
  2895. override float GetSingleInventoryItemWeightEx()
  2896. {
  2897. //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
  2898. float weightEx = GetWeightEx();//overall weight of the item
  2899. float special = GetInventoryAndCargoWeight();//cargo and attachment weight
  2900. return weightEx - special;
  2901. }
  2902. // Obsolete, use GetSingleInventoryItemWeightEx() instead
  2903. float GetSingleInventoryItemWeight()
  2904. {
  2905. return GetSingleInventoryItemWeightEx();
  2906. }
  2907. override protected float GetWeightSpecialized(bool forceRecalc = false)
  2908. {
  2909. if (IsSplitable()) //quantity determines size of the stack
  2910. {
  2911. #ifdef DEVELOPER
  2912. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2913. {
  2914. WeightDebugData data1 = WeightDebug.GetWeightDebug(this);
  2915. data1.SetCalcDetails("TIB1: " + GetConfigWeightModifiedDebugText() +" * " + GetQuantity()+"(quantity)");
  2916. }
  2917. #endif
  2918. return GetQuantity() * GetConfigWeightModified();
  2919. }
  2920. else if (HasEnergyManager())// items with energy manager
  2921. {
  2922. #ifdef DEVELOPER
  2923. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2924. {
  2925. WeightDebugData data2 = WeightDebug.GetWeightDebug(this);
  2926. data2.SetCalcDetails("TIB2: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetCompEM().GetEnergy()+"(energy) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit)");
  2927. }
  2928. #endif
  2929. return super.GetWeightSpecialized(forceRecalc) + (GetCompEM().GetEnergy() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
  2930. }
  2931. else//everything else
  2932. {
  2933. #ifdef DEVELOPER
  2934. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  2935. {
  2936. WeightDebugData data3 = WeightDebug.GetWeightDebug(this);
  2937. data3.SetCalcDetails("TIB3: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetQuantity()+"(quantity) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit))");
  2938. }
  2939. #endif
  2940. return super.GetWeightSpecialized(forceRecalc) + (GetQuantity() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified());
  2941. }
  2942. }
  2943. //! Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
  2944. int GetNumberOfItems()
  2945. {
  2946. int item_count = 0;
  2947. ItemBase item;
  2948. if (GetInventory().GetCargo() != NULL)
  2949. {
  2950. item_count = GetInventory().GetCargo().GetItemCount();
  2951. }
  2952. for (int i = 0; i < GetInventory().AttachmentCount(); i++)
  2953. {
  2954. Class.CastTo(item,GetInventory().GetAttachmentFromIndex(i));
  2955. if (item)
  2956. item_count += item.GetNumberOfItems();
  2957. }
  2958. return item_count;
  2959. }
  2960. //! Obsolete, use GetWeightEx instead
  2961. float GetUnitWeight(bool include_wetness = true)
  2962. {
  2963. float weight = 0;
  2964. float wetness = 1;
  2965. if (include_wetness)
  2966. wetness += GetWet();
  2967. if (IsSplitable()) //quantity determines size of the stack
  2968. {
  2969. weight = wetness * m_ConfigWeight;
  2970. }
  2971. else if (IsLiquidContainer()) //is a liquid container, default liquid weight is set to 1. May revisit later?
  2972. {
  2973. weight = 1;
  2974. }
  2975. return weight;
  2976. }
  2977. //-----------------------------------------------------------------
  2978. override void ClearInventory()
  2979. {
  2980. if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && GetInventory())
  2981. {
  2982. GameInventory inv = GetInventory();
  2983. array<EntityAI> items = new array<EntityAI>;
  2984. inv.EnumerateInventory(InventoryTraversalType.INORDER, items);
  2985. for (int i = 0; i < items.Count(); i++)
  2986. {
  2987. ItemBase item = ItemBase.Cast(items.Get(i));
  2988. if (item)
  2989. {
  2990. GetGame().ObjectDelete(item);
  2991. }
  2992. }
  2993. }
  2994. }
  2995. //------------------------- Energy
  2996. //----------------------------------------------------------------
  2997. float GetEnergy()
  2998. {
  2999. float energy = 0;
  3000. if (HasEnergyManager())
  3001. {
  3002. energy = GetCompEM().GetEnergy();
  3003. }
  3004. return energy;
  3005. }
  3006. override void OnEnergyConsumed()
  3007. {
  3008. super.OnEnergyConsumed();
  3009. ConvertEnergyToQuantity();
  3010. }
  3011. override void OnEnergyAdded()
  3012. {
  3013. super.OnEnergyAdded();
  3014. ConvertEnergyToQuantity();
  3015. }
  3016. // Converts energy (from Energy Manager) to quantity, if enabled.
  3017. void ConvertEnergyToQuantity()
  3018. {
  3019. if (GetGame().IsServer() && HasEnergyManager() && GetCompEM().HasConversionOfEnergyToQuantity())
  3020. {
  3021. if (HasQuantity())
  3022. {
  3023. float energy_0to1 = GetCompEM().GetEnergy0To1();
  3024. SetQuantityNormalized(energy_0to1);
  3025. }
  3026. }
  3027. }
  3028. //----------------------------------------------------------------
  3029. float GetHeatIsolationInit()
  3030. {
  3031. return ConfigGetFloat("heatIsolation");
  3032. }
  3033. float GetHeatIsolation()
  3034. {
  3035. return m_HeatIsolation;
  3036. }
  3037. float GetDryingIncrement(string pIncrementName)
  3038. {
  3039. string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Drying %2", GetType(), pIncrementName);
  3040. if (GetGame().ConfigIsExisting(paramPath))
  3041. return GetGame().ConfigGetFloat(paramPath);
  3042. return 0.0;
  3043. }
  3044. float GetSoakingIncrement(string pIncrementName)
  3045. {
  3046. string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Soaking %2", GetType(), pIncrementName);
  3047. if (GetGame().ConfigIsExisting(paramPath))
  3048. return GetGame().ConfigGetFloat(paramPath);
  3049. return 0.0;
  3050. }
  3051. //----------------------------------------------------------------
  3052. override void SetWet(float value, bool allow_client = false)
  3053. {
  3054. if (!IsServerCheck(allow_client))
  3055. return;
  3056. float min = GetWetMin();
  3057. float max = GetWetMax();
  3058. float previousValue = m_VarWet;
  3059. m_VarWet = Math.Clamp(value, min, max);
  3060. if (previousValue != m_VarWet)
  3061. {
  3062. SetVariableMask(VARIABLE_WET);
  3063. OnWetChanged(m_VarWet, previousValue);
  3064. }
  3065. }
  3066. //----------------------------------------------------------------
  3067. override void AddWet(float value)
  3068. {
  3069. SetWet(GetWet() + value);
  3070. }
  3071. //----------------------------------------------------------------
  3072. override void SetWetMax()
  3073. {
  3074. SetWet(m_VarWetMax);
  3075. }
  3076. //----------------------------------------------------------------
  3077. override float GetWet()
  3078. {
  3079. return m_VarWet;
  3080. }
  3081. //----------------------------------------------------------------
  3082. override float GetWetMax()
  3083. {
  3084. return m_VarWetMax;
  3085. }
  3086. //----------------------------------------------------------------
  3087. override float GetWetMin()
  3088. {
  3089. return m_VarWetMin;
  3090. }
  3091. //----------------------------------------------------------------
  3092. override float GetWetInit()
  3093. {
  3094. return m_VarWetInit;
  3095. }
  3096. //----------------------------------------------------------------
  3097. override void OnWetChanged(float newVal, float oldVal)
  3098. {
  3099. EWetnessLevel newLevel = GetWetLevelInternal(newVal);
  3100. EWetnessLevel oldLevel = GetWetLevelInternal(oldVal);
  3101. if (newLevel != oldLevel)
  3102. {
  3103. OnWetLevelChanged(newLevel,oldLevel);
  3104. }
  3105. }
  3106. override void OnWetLevelChanged(EWetnessLevel newLevel, EWetnessLevel oldLevel)
  3107. {
  3108. SetWeightDirty();
  3109. }
  3110. override EWetnessLevel GetWetLevel()
  3111. {
  3112. return GetWetLevelInternal(m_VarWet);
  3113. }
  3114. //----------------------------------------------------------------
  3115. override void SetStoreLoad(bool value)
  3116. {
  3117. m_IsStoreLoad = value;
  3118. }
  3119. override bool IsStoreLoad()
  3120. {
  3121. return m_IsStoreLoad;
  3122. }
  3123. override void SetStoreLoadedQuantity(float value)
  3124. {
  3125. m_StoreLoadedQuantity = value;
  3126. }
  3127. override float GetStoreLoadedQuantity()
  3128. {
  3129. return m_StoreLoadedQuantity;
  3130. }
  3131. //----------------------------------------------------------------
  3132. float GetItemModelLength()
  3133. {
  3134. if (ConfigIsExisting("itemModelLength"))
  3135. {
  3136. return ConfigGetFloat("itemModelLength");
  3137. }
  3138. return 0;
  3139. }
  3140. float GetItemAttachOffset()
  3141. {
  3142. if (ConfigIsExisting("itemAttachOffset"))
  3143. {
  3144. return ConfigGetFloat("itemAttachOffset");
  3145. }
  3146. return 0;
  3147. }
  3148. override void SetCleanness(int value, bool allow_client = false)
  3149. {
  3150. if (!IsServerCheck(allow_client))
  3151. return;
  3152. int previousValue = m_Cleanness;
  3153. m_Cleanness = Math.Clamp(value, m_CleannessMin, m_CleannessMax);
  3154. if (previousValue != m_Cleanness)
  3155. SetVariableMask(VARIABLE_CLEANNESS);
  3156. }
  3157. override int GetCleanness()
  3158. {
  3159. return m_Cleanness;
  3160. }
  3161. bool AllowFoodConsumption()
  3162. {
  3163. return true;
  3164. }
  3165. //----------------------------------------------------------------
  3166. // ATTACHMENT LOCKING
  3167. // Getters relevant to generic ActionLockAttachment
  3168. int GetLockType()
  3169. {
  3170. return m_LockType;
  3171. }
  3172. string GetLockSoundSet()
  3173. {
  3174. return m_LockSoundSet;
  3175. }
  3176. //----------------------------------------------------------------
  3177. //------------------------- Color
  3178. // sets items color variable given color components
  3179. override void SetColor(int r, int g, int b, int a)
  3180. {
  3181. m_ColorComponentR = r;
  3182. m_ColorComponentG = g;
  3183. m_ColorComponentB = b;
  3184. m_ColorComponentA = a;
  3185. SetVariableMask(VARIABLE_COLOR);
  3186. }
  3187. //! gets item's color variable as components
  3188. override void GetColor(out int r,out int g,out int b,out int a)
  3189. {
  3190. r = m_ColorComponentR;
  3191. g = m_ColorComponentG;
  3192. b = m_ColorComponentB;
  3193. a = m_ColorComponentA;
  3194. }
  3195. bool IsColorSet()
  3196. {
  3197. return IsVariableSet(VARIABLE_COLOR);
  3198. }
  3199. //! Returns item's PROCEDURAL color as formated string, i.e. "#(argb,8,8,3)color(0.15,0.15,0.15,1.0,CO)"
  3200. string GetColorString()
  3201. {
  3202. int r,g,b,a;
  3203. GetColor(r,g,b,a);
  3204. r = r/255;
  3205. g = g/255;
  3206. b = b/255;
  3207. a = a/255;
  3208. return MiscGameplayFunctions.GetColorString(r, g, b, a);
  3209. }
  3210. //----------------------------------------------------------------
  3211. //------------------------- LiquidType
  3212. override void SetLiquidType(int value, bool allow_client = false)
  3213. {
  3214. if (!IsServerCheck(allow_client))
  3215. return;
  3216. int old = m_VarLiquidType;
  3217. m_VarLiquidType = value;
  3218. OnLiquidTypeChanged(old,value);
  3219. SetVariableMask(VARIABLE_LIQUIDTYPE);
  3220. }
  3221. int GetLiquidTypeInit()
  3222. {
  3223. return ConfigGetInt("varLiquidTypeInit");
  3224. }
  3225. override int GetLiquidType()
  3226. {
  3227. return m_VarLiquidType;
  3228. }
  3229. protected void OnLiquidTypeChanged(int oldType, int newType)
  3230. {
  3231. if (newType == LIQUID_NONE && GetIsFrozen())
  3232. SetFrozen(false);
  3233. }
  3234. //! To be called on moving item within character's inventory; 'player' should never be null
  3235. void UpdateQuickbarShortcutVisibility(PlayerBase player)
  3236. {
  3237. player.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
  3238. }
  3239. // -------------------------------------------------------------------------
  3240. //! Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
  3241. void OnInventoryEnter(Man player)
  3242. {
  3243. PlayerBase nplayer;
  3244. if (PlayerBase.CastTo(nplayer, player))
  3245. {
  3246. m_CanPlayImpactSound = true;
  3247. //nplayer.OnItemInventoryEnter(this);
  3248. nplayer.SetEnableQuickBarEntityShortcut(this,!GetHierarchyParent() || GetHierarchyParent().GetInventory().AreChildrenAccessible());
  3249. }
  3250. }
  3251. // -------------------------------------------------------------------------
  3252. //! Event called on item when it is removed from the player(Man) inventory, passes the old owner as a parameter
  3253. void OnInventoryExit(Man player)
  3254. {
  3255. PlayerBase nplayer;
  3256. if (PlayerBase.CastTo(nplayer,player))
  3257. {
  3258. //nplayer.OnItemInventoryExit(this);
  3259. nplayer.SetEnableQuickBarEntityShortcut(this,false);
  3260. }
  3261. //if (!GetGame().IsDedicatedServer())
  3262. player.GetHumanInventory().ClearUserReservedLocationForContainer(this);
  3263. if (HasEnergyManager())
  3264. {
  3265. GetCompEM().UpdatePlugState(); // Unplug the el. device if it's necesarry.
  3266. }
  3267. }
  3268. // ADVANCED PLACEMENT EVENTS
  3269. override void OnPlacementStarted(Man player)
  3270. {
  3271. super.OnPlacementStarted(player);
  3272. SetTakeable(false);
  3273. }
  3274. override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
  3275. {
  3276. if (m_AdminLog)
  3277. {
  3278. m_AdminLog.OnPlacementComplete(player, this);
  3279. }
  3280. super.OnPlacementComplete(player, position, orientation);
  3281. }
  3282. //-----------------------------
  3283. // AGENT SYSTEM
  3284. //-----------------------------
  3285. //--------------------------------------------------------------------------
  3286. bool ContainsAgent(int agent_id)
  3287. {
  3288. if (agent_id & m_AttachedAgents)
  3289. {
  3290. return true;
  3291. }
  3292. else
  3293. {
  3294. return false;
  3295. }
  3296. }
  3297. //--------------------------------------------------------------------------
  3298. override void RemoveAgent(int agent_id)
  3299. {
  3300. if (ContainsAgent(agent_id))
  3301. {
  3302. m_AttachedAgents = ~agent_id & m_AttachedAgents;
  3303. }
  3304. }
  3305. //--------------------------------------------------------------------------
  3306. override void RemoveAllAgents()
  3307. {
  3308. m_AttachedAgents = 0;
  3309. }
  3310. //--------------------------------------------------------------------------
  3311. override void RemoveAllAgentsExcept(int agent_to_keep)
  3312. {
  3313. m_AttachedAgents = m_AttachedAgents & agent_to_keep;
  3314. }
  3315. // -------------------------------------------------------------------------
  3316. override void InsertAgent(int agent, float count = 1)
  3317. {
  3318. if (count < 1)
  3319. return;
  3320. //Debug.Log("Inserting Agent on item: " + agent.ToString() +" count: " + count.ToString());
  3321. m_AttachedAgents = (agent | m_AttachedAgents);
  3322. }
  3323. //!transfer agents from another item
  3324. void TransferAgents(int agents)
  3325. {
  3326. m_AttachedAgents = (m_AttachedAgents | agents);
  3327. }
  3328. // -------------------------------------------------------------------------
  3329. override int GetAgents()
  3330. {
  3331. return m_AttachedAgents;
  3332. }
  3333. //----------------------------------------------------------------------
  3334. /*int GetContaminationType()
  3335. {
  3336. int contamination_type;
  3337. const int CONTAMINATED_MASK = eAgents.CHOLERA | eAgents.INFLUENZA | eAgents.SALMONELLA | eAgents.BRAIN;
  3338. const int POISONED_MASK = eAgents.FOOD_POISON | eAgents.CHEMICAL_POISON;
  3339. const int NERVE_GAS_MASK = eAgents.CHEMICAL_POISON;
  3340. const int DIRTY_MASK = eAgents.WOUND_AGENT;
  3341. Edible_Base edible = Edible_Base.Cast(this);
  3342. int agents = GetAgents();
  3343. if (edible)
  3344. {
  3345. NutritionalProfile profile = Edible_Base.GetNutritionalProfile(edible);
  3346. if (profile)
  3347. {
  3348. agents = agents | profile.GetAgents();//merge item's agents with nutritional agents
  3349. }
  3350. }
  3351. if (agents & CONTAMINATED_MASK)
  3352. {
  3353. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_CONTAMINATED;
  3354. }
  3355. if (agents & POISONED_MASK)
  3356. {
  3357. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_POISONED;
  3358. }
  3359. if (agents & NERVE_GAS_MASK)
  3360. {
  3361. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_NERVE_GAS;
  3362. }
  3363. if (agents & DIRTY_MASK)
  3364. {
  3365. contamination_type = contamination_type | EContaminationTypes.ITEM_BADGE_DIRTY;
  3366. }
  3367. return agents;
  3368. }*/
  3369. // -------------------------------------------------------------------------
  3370. bool LoadAgents(ParamsReadContext ctx, int version)
  3371. {
  3372. if (!ctx.Read(m_AttachedAgents))
  3373. return false;
  3374. return true;
  3375. }
  3376. // -------------------------------------------------------------------------
  3377. void SaveAgents(ParamsWriteContext ctx)
  3378. {
  3379. ctx.Write(m_AttachedAgents);
  3380. }
  3381. // -------------------------------------------------------------------------
  3382. //! Roof check for entity, limited by time (anti-spam solution)
  3383. override void CheckForRoofLimited(float timeTresholdMS = 3000)
  3384. {
  3385. super.CheckForRoofLimited(timeTresholdMS);
  3386. float time = GetGame().GetTime();
  3387. if ((time - m_PreviousRoofTestTime) >= timeTresholdMS)
  3388. {
  3389. m_PreviousRoofTestTime = time;
  3390. SetRoofAbove(MiscGameplayFunctions.IsUnderRoof(this));
  3391. }
  3392. }
  3393. // returns item's protection level against enviromental hazard, for masks with filters, returns the filters protection for valid filter, otherwise 0
  3394. float GetProtectionLevel(int type, bool consider_filter = false, int system = 0)
  3395. {
  3396. if (IsDamageDestroyed() || (HasQuantity() && GetQuantity() <= 0))
  3397. {
  3398. return 0;
  3399. }
  3400. if (GetInventory().GetAttachmentSlotsCount() != 0)//is it an item with attachable filter ?
  3401. {
  3402. ItemBase filter = ItemBase.Cast(FindAttachmentBySlotName("GasMaskFilter"));
  3403. if (filter)
  3404. return filter.GetProtectionLevel(type, false, system);//it's a valid filter, return the protection
  3405. else
  3406. return 0;//otherwise return 0 when no filter attached
  3407. }
  3408. string subclassPath, entryName;
  3409. switch (type)
  3410. {
  3411. case DEF_BIOLOGICAL:
  3412. entryName = "biological";
  3413. break;
  3414. case DEF_CHEMICAL:
  3415. entryName = "chemical";
  3416. break;
  3417. default:
  3418. entryName = "biological";
  3419. break;
  3420. }
  3421. subclassPath = "CfgVehicles " + this.GetType() + " Protection ";
  3422. return GetGame().ConfigGetFloat(subclassPath + entryName);
  3423. }
  3424. //! Called when entity is being created as new by CE/ Debug
  3425. override void EEOnCECreate()
  3426. {
  3427. if (!IsMagazine())
  3428. SetCEBasedQuantity();
  3429. SetZoneDamageCEInit();
  3430. }
  3431. //-------------------------
  3432. // OPEN/CLOSE USER ACTIONS
  3433. //-------------------------
  3434. //! Implementations only
  3435. void Open();
  3436. void Close();
  3437. bool IsOpen()
  3438. {
  3439. return true;
  3440. }
  3441. override bool CanDisplayCargo()
  3442. {
  3443. return IsOpen();
  3444. }
  3445. // ------------------------------------------------------------
  3446. // CONDITIONS
  3447. // ------------------------------------------------------------
  3448. override bool CanPutInCargo(EntityAI parent)
  3449. {
  3450. if (parent)
  3451. {
  3452. if (parent.IsInherited(DayZInfected))
  3453. return true;
  3454. if (!parent.IsRuined())
  3455. return true;
  3456. }
  3457. return true;
  3458. }
  3459. override bool CanPutAsAttachment(EntityAI parent)
  3460. {
  3461. if (!super.CanPutAsAttachment(parent))
  3462. {
  3463. return false;
  3464. }
  3465. if (!IsRuined() && !parent.IsRuined())
  3466. {
  3467. return true;
  3468. }
  3469. return false;
  3470. }
  3471. override bool CanReceiveItemIntoCargo(EntityAI item)
  3472. {
  3473. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3474. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3475. // return false;
  3476. return super.CanReceiveItemIntoCargo(item);
  3477. }
  3478. override bool CanReceiveAttachment(EntityAI attachment, int slotId)
  3479. {
  3480. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3481. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3482. // return false;
  3483. GameInventory attachmentInv = attachment.GetInventory();
  3484. if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
  3485. {
  3486. if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
  3487. return false;
  3488. }
  3489. InventoryLocation loc = new InventoryLocation();
  3490. attachment.GetInventory().GetCurrentInventoryLocation(loc);
  3491. if (loc && loc.IsValid() && !GetInventory().AreChildrenAccessible())
  3492. return false;
  3493. return super.CanReceiveAttachment(attachment, slotId);
  3494. }
  3495. override bool CanReleaseAttachment(EntityAI attachment)
  3496. {
  3497. if (!super.CanReleaseAttachment(attachment))
  3498. return false;
  3499. return GetInventory().AreChildrenAccessible();
  3500. }
  3501. /*override bool CanLoadAttachment(EntityAI attachment)
  3502. {
  3503. //removed 15.06. coz of loading from storage -> after load items in cargo was lost -> waiting for proper solution
  3504. //if (GetHealthLevel() == GameConstants.STATE_RUINED)
  3505. // return false;
  3506. GameInventory attachmentInv = attachment.GetInventory();
  3507. if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0)
  3508. {
  3509. bool boo = (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase));
  3510. ErrorEx("CanLoadAttachment | this: " + this + " | attachment: " + attachment + " | boo: " + boo,ErrorExSeverity.INFO);
  3511. if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase))
  3512. return false;
  3513. }
  3514. return super.CanLoadAttachment(attachment);
  3515. }*/
  3516. // Plays muzzle flash particle effects
  3517. static void PlayFireParticles(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3518. {
  3519. int id = muzzle_owner.GetMuzzleID();
  3520. array<ref WeaponParticlesOnFire> WPOF_array = m_OnFireEffect.Get(id);
  3521. if (WPOF_array)
  3522. {
  3523. for (int i = 0; i < WPOF_array.Count(); i++)
  3524. {
  3525. WeaponParticlesOnFire WPOF = WPOF_array.Get(i);
  3526. if (WPOF)
  3527. {
  3528. WPOF.OnActivate(weapon, muzzle_index, ammoType, muzzle_owner, suppressor, config_to_search);
  3529. }
  3530. }
  3531. }
  3532. }
  3533. // Plays bullet eject particle effects (usually just smoke, the bullet itself is a 3D model and is not part of this function)
  3534. static void PlayBulletCasingEjectParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3535. {
  3536. int id = muzzle_owner.GetMuzzleID();
  3537. array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = m_OnBulletCasingEjectEffect.Get(id);
  3538. if (WPOBE_array)
  3539. {
  3540. for (int i = 0; i < WPOBE_array.Count(); i++)
  3541. {
  3542. WeaponParticlesOnBulletCasingEject WPOBE = WPOBE_array.Get(i);
  3543. if (WPOBE)
  3544. {
  3545. WPOBE.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
  3546. }
  3547. }
  3548. }
  3549. }
  3550. // Plays all weapon overheating particles
  3551. static void PlayOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3552. {
  3553. int id = muzzle_owner.GetMuzzleID();
  3554. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3555. if (WPOOH_array)
  3556. {
  3557. for (int i = 0; i < WPOOH_array.Count(); i++)
  3558. {
  3559. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3560. if (WPOOH)
  3561. {
  3562. WPOOH.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
  3563. }
  3564. }
  3565. }
  3566. }
  3567. // Updates all weapon overheating particles
  3568. static void UpdateOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3569. {
  3570. int id = muzzle_owner.GetMuzzleID();
  3571. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3572. if (WPOOH_array)
  3573. {
  3574. for (int i = 0; i < WPOOH_array.Count(); i++)
  3575. {
  3576. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3577. if (WPOOH)
  3578. {
  3579. WPOOH.OnUpdate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  3580. }
  3581. }
  3582. }
  3583. }
  3584. // Stops overheating particles
  3585. static void StopOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
  3586. {
  3587. int id = muzzle_owner.GetMuzzleID();
  3588. array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id);
  3589. if (WPOOH_array)
  3590. {
  3591. for (int i = 0; i < WPOOH_array.Count(); i++)
  3592. {
  3593. WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i);
  3594. if (WPOOH)
  3595. {
  3596. WPOOH.OnDeactivate(weapon, ammoType, muzzle_owner, suppressor, config_to_search);
  3597. }
  3598. }
  3599. }
  3600. }
  3601. //----------------------------------------------------------------
  3602. //Item Behaviour - unified approach
  3603. override bool IsHeavyBehaviour()
  3604. {
  3605. if (m_ItemBehaviour == 0)
  3606. {
  3607. return true;
  3608. }
  3609. return false;
  3610. }
  3611. override bool IsOneHandedBehaviour()
  3612. {
  3613. if (m_ItemBehaviour == 1)
  3614. {
  3615. return true;
  3616. }
  3617. return false;
  3618. }
  3619. override bool IsTwoHandedBehaviour()
  3620. {
  3621. if (m_ItemBehaviour == 2)
  3622. {
  3623. return true;
  3624. }
  3625. return false;
  3626. }
  3627. bool IsDeployable()
  3628. {
  3629. return false;
  3630. }
  3631. //!how long it takes to deploy this item in seconds
  3632. float GetDeployTime()
  3633. {
  3634. return UATimeSpent.DEFAULT_DEPLOY;
  3635. }
  3636. //----------------------------------------------------------------
  3637. // Item Targeting (User Actions)
  3638. override void SetTakeable(bool pState)
  3639. {
  3640. m_IsTakeable = pState;
  3641. SetSynchDirty();
  3642. }
  3643. override bool IsTakeable()
  3644. {
  3645. return m_IsTakeable;
  3646. }
  3647. // For cases where we want to show object widget which cant be taken to hands
  3648. bool IsActionTargetVisible()
  3649. {
  3650. return false;
  3651. }
  3652. //! Attachment Sound Type getting from config file
  3653. protected void PreLoadSoundAttachmentType()
  3654. {
  3655. string att_type = "None";
  3656. if (ConfigIsExisting("soundAttType"))
  3657. {
  3658. att_type = ConfigGetString("soundAttType");
  3659. }
  3660. m_SoundAttType = att_type;
  3661. }
  3662. override string GetAttachmentSoundType()
  3663. {
  3664. return m_SoundAttType;
  3665. }
  3666. //----------------------------------------------------------------
  3667. //SOUNDS - ItemSoundHandler
  3668. //----------------------------------------------------------------
  3669. string GetPlaceSoundset(); // played when deploy starts
  3670. string GetLoopDeploySoundset(); // played when deploy starts and stopped when it finishes
  3671. string GetDeploySoundset(); // played when deploy sucessfully finishes
  3672. ItemSoundHandler GetItemSoundHandler()
  3673. {
  3674. if (!m_ItemSoundHandler)
  3675. m_ItemSoundHandler = new ItemSoundHandler(this);
  3676. return m_ItemSoundHandler;
  3677. }
  3678. // override to initialize sounds
  3679. protected void InitItemSounds()
  3680. {
  3681. if (GetPlaceSoundset() == string.Empty && GetDeploySoundset() == string.Empty && GetLoopDeploySoundset() == string.Empty)
  3682. return;
  3683. ItemSoundHandler handler = GetItemSoundHandler();
  3684. if (GetPlaceSoundset() != string.Empty)
  3685. handler.AddSound(SoundConstants.ITEM_PLACE, GetPlaceSoundset());
  3686. if (GetDeploySoundset() != string.Empty)
  3687. handler.AddSound(SoundConstants.ITEM_DEPLOY, GetDeploySoundset());
  3688. SoundParameters params = new SoundParameters();
  3689. params.m_Loop = true;
  3690. if (GetLoopDeploySoundset() != string.Empty)
  3691. handler.AddSound(SoundConstants.ITEM_DEPLOY_LOOP, GetLoopDeploySoundset(), params);
  3692. }
  3693. // Start sound using ItemSoundHandler
  3694. void StartItemSoundServer(int id)
  3695. {
  3696. if (!GetGame().IsServer())
  3697. return;
  3698. m_SoundSyncPlay = id;
  3699. SetSynchDirty();
  3700. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(ClearStartItemSoundServer); // in case one is queued already
  3701. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ClearStartItemSoundServer, 100);
  3702. }
  3703. // Stop sound using ItemSoundHandler
  3704. void StopItemSoundServer(int id)
  3705. {
  3706. if (!GetGame().IsServer())
  3707. return;
  3708. m_SoundSyncStop = id;
  3709. SetSynchDirty();
  3710. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(ClearStopItemSoundServer); // in case one is queued already
  3711. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ClearStopItemSoundServer, 100);
  3712. }
  3713. protected void ClearStartItemSoundServer()
  3714. {
  3715. m_SoundSyncPlay = 0;
  3716. }
  3717. protected void ClearStopItemSoundServer()
  3718. {
  3719. m_SoundSyncStop = 0;
  3720. }
  3721. //! Plays sound on item attach. Be advised, the config structure may slightly change in 1.11 update to allow for more complex use.
  3722. void PlayAttachSound(string slot_type)
  3723. {
  3724. if (!GetGame().IsDedicatedServer())
  3725. {
  3726. if (ConfigIsExisting("attachSoundSet"))
  3727. {
  3728. string cfg_path = "";
  3729. string soundset = "";
  3730. string type_name = GetType();
  3731. TStringArray cfg_soundset_array = new TStringArray;
  3732. TStringArray cfg_slot_array = new TStringArray;
  3733. ConfigGetTextArray("attachSoundSet",cfg_soundset_array);
  3734. ConfigGetTextArray("attachSoundSlot",cfg_slot_array);
  3735. if (cfg_soundset_array.Count() > 0 && cfg_soundset_array.Count() == cfg_slot_array.Count())
  3736. {
  3737. for (int i = 0; i < cfg_soundset_array.Count(); i++)
  3738. {
  3739. if (cfg_slot_array[i] == slot_type)
  3740. {
  3741. soundset = cfg_soundset_array[i];
  3742. break;
  3743. }
  3744. }
  3745. }
  3746. if (soundset != "")
  3747. {
  3748. EffectSound sound = SEffectManager.PlaySound(soundset, GetPosition());
  3749. sound.SetAutodestroy(true);
  3750. }
  3751. }
  3752. }
  3753. }
  3754. void PlayDetachSound(string slot_type)
  3755. {
  3756. //TODO - evaluate if needed and devise universal config structure if so
  3757. }
  3758. void OnApply(PlayerBase player);
  3759. float GetBandagingEffectivity()
  3760. {
  3761. return 1.0;
  3762. };
  3763. //returns applicable selection
  3764. array<string> GetHeadHidingSelection()
  3765. {
  3766. return m_HeadHidingSelections;
  3767. }
  3768. bool HidesSelectionBySlot()
  3769. {
  3770. return m_HideSelectionsBySlot;
  3771. }
  3772. WrittenNoteData GetWrittenNoteData() {};
  3773. void StopItemDynamicPhysics()
  3774. {
  3775. SetDynamicPhysicsLifeTime(0.01);
  3776. m_ItemBeingDroppedPhys = false;
  3777. }
  3778. void PerformDamageSystemReinit()
  3779. {
  3780. array<string> zone_names = new array<string>;
  3781. GetDamageZones(zone_names);
  3782. for (int i = 0; i < zone_names.Count(); i++)
  3783. {
  3784. SetHealthMax(zone_names.Get(i),"Health");
  3785. }
  3786. SetHealthMax("","Health");
  3787. }
  3788. //! Sets zone damages to match randomized global health set by CE (CE spawn only)
  3789. void SetZoneDamageCEInit()
  3790. {
  3791. float global_health = GetHealth01("","Health");
  3792. array<string> zones = new array<string>;
  3793. GetDamageZones(zones);
  3794. //set damage of all zones to match global health level
  3795. for (int i = 0; i < zones.Count(); i++)
  3796. {
  3797. SetHealth01(zones.Get(i),"Health",global_health);
  3798. }
  3799. }
  3800. //!DEPRECATED in use, but returns correct values nontheless. Check performed elsewhere
  3801. bool IsCoverFaceForShave(string slot_name)
  3802. {
  3803. return IsExclusionFlagPresent(PlayerBase.GetFaceCoverageShaveValues());
  3804. }
  3805. void ProcessItemWetness(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  3806. {
  3807. if (!hasRootAsPlayer)
  3808. {
  3809. if (refParentIB)
  3810. {
  3811. // parent is wet
  3812. if ((refParentIB.GetWet() >= GameConstants.STATE_SOAKING_WET) && (m_VarWet < m_VarWetMax))
  3813. AddWet(delta * GameConstants.WETNESS_RATE_WETTING_INSIDE);
  3814. // parent has liquid inside
  3815. else if ((refParentIB.GetLiquidType() != 0) && (refParentIB.GetQuantity() > 0) && (m_VarWet < m_VarWetMax))
  3816. AddWet(delta * GameConstants.WETNESS_RATE_WETTING_LIQUID);
  3817. // drying
  3818. else if (m_VarWet > m_VarWetMin)
  3819. AddWet(-1 * delta * GetDryingIncrement("ground") * 2);
  3820. }
  3821. else
  3822. {
  3823. // drying on ground or inside non-itembase (car, ...)
  3824. if (m_VarWet > m_VarWetMin)
  3825. AddWet(-1 * delta * GetDryingIncrement("ground"));
  3826. }
  3827. }
  3828. }
  3829. void ProcessItemTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  3830. {
  3831. if (CanHaveTemperature() && !IsSelfAdjustingTemperature() && !GetHierarchyRoot().IsSelfAdjustingTemperature())
  3832. {
  3833. float target = g_Game.GetMission().GetWorldData().GetBaseEnvTemperatureAtObject(this);
  3834. if (GetTemperature() != target || !IsFreezeThawProgressFinished())
  3835. {
  3836. float heatPermCoef = 1.0;
  3837. EntityAI ent = this;
  3838. while (ent)
  3839. {
  3840. heatPermCoef *= ent.GetHeatPermeabilityCoef();
  3841. ent = ent.GetHierarchyParent();
  3842. }
  3843. SetTemperatureEx(new TemperatureDataInterpolated(target,ETemperatureAccessTypes.ACCESS_WORLD,delta,GameConstants.TEMP_COEF_WORLD,heatPermCoef));
  3844. }
  3845. }
  3846. }
  3847. void HierarchyCheck(out bool hasParent, out bool hasRootAsPlayer, out ItemBase refParentIB)
  3848. {
  3849. // hierarchy check for an item to decide whether it has some parent and it is in some player inventory
  3850. EntityAI parent = GetHierarchyParent();
  3851. if (!parent)
  3852. {
  3853. hasParent = false;
  3854. hasRootAsPlayer = false;
  3855. }
  3856. else
  3857. {
  3858. hasParent = true;
  3859. hasRootAsPlayer = (GetHierarchyRootPlayer() != null);
  3860. refParentIB = ItemBase.Cast(parent);
  3861. }
  3862. }
  3863. protected void ProcessDecay(float delta, bool hasRootAsPlayer)
  3864. {
  3865. // this is stub, implemented on Edible_Base
  3866. }
  3867. bool CanDecay()
  3868. {
  3869. // return true used on selected food clases so they can decay
  3870. return false;
  3871. }
  3872. protected bool CanProcessDecay()
  3873. {
  3874. // this is stub, implemented on Edible_Base class
  3875. // used to determine whether it is still necessary for the food to decay
  3876. return false;
  3877. }
  3878. protected bool CanHaveWetness()
  3879. {
  3880. // return true used on selected items that have a wetness effect
  3881. return false;
  3882. }
  3883. //! Items cannot be consumed if frozen by default. Override for exceptions.
  3884. bool CanBeConsumed(ConsumeConditionData data = null)
  3885. {
  3886. return !GetIsFrozen() && IsOpen();
  3887. }
  3888. override void ProcessVariables()
  3889. {
  3890. bool hasParent = false, hasRootAsPlayer = false;
  3891. ItemBase refParentIB;
  3892. bool wwtu = g_Game.IsWorldWetTempUpdateEnabled();
  3893. bool foodDecay = g_Game.IsFoodDecayEnabled();
  3894. if (wwtu || foodDecay)
  3895. {
  3896. bool processWetness = wwtu && CanHaveWetness();
  3897. bool processTemperature = wwtu && CanHaveTemperature();
  3898. bool processDecay = foodDecay && CanDecay() && CanProcessDecay();
  3899. if (processWetness || processTemperature || processDecay)
  3900. {
  3901. HierarchyCheck(hasParent, hasRootAsPlayer, refParentIB);
  3902. if (processWetness)
  3903. ProcessItemWetness(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
  3904. if (processTemperature)
  3905. ProcessItemTemperature(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB);
  3906. if (processDecay)
  3907. ProcessDecay(m_ElapsedSinceLastUpdate, hasRootAsPlayer);
  3908. }
  3909. }
  3910. }
  3911. //! Used in heat comfort calculations only!
  3912. float GetTemperaturePerQuantityWeight()
  3913. {
  3914. return m_TemperaturePerQuantityWeight * GameConstants.ITEM_TEMPERATURE_QUANTITY_WEIGHT_MULTIPLIER;
  3915. }
  3916. override float GetTemperatureFreezeThreshold()
  3917. {
  3918. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3919. return Liquid.GetFreezeThreshold(GetLiquidType());
  3920. return super.GetTemperatureFreezeThreshold();
  3921. }
  3922. override float GetTemperatureThawThreshold()
  3923. {
  3924. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3925. return Liquid.GetThawThreshold(GetLiquidType());
  3926. return super.GetTemperatureThawThreshold();
  3927. }
  3928. override float GetItemOverheatThreshold()
  3929. {
  3930. if (IsLiquidContainer() && GetLiquidType() != LIQUID_NONE)
  3931. return Liquid.GetBoilThreshold(GetLiquidType());
  3932. return super.GetItemOverheatThreshold();
  3933. }
  3934. override float GetTemperatureFreezeTime()
  3935. {
  3936. if (HasQuantity())
  3937. return Math.Lerp(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureFreezeTime()),GetQuantityNormalized());
  3938. return super.GetTemperatureFreezeTime();
  3939. }
  3940. override float GetTemperatureThawTime()
  3941. {
  3942. if (HasQuantity())
  3943. return Math.Lerp(GameConstants.TEMPERATURE_TIME_THAW_MIN,Math.Max(GameConstants.TEMPERATURE_TIME_FREEZE_MIN,super.GetTemperatureThawTime()),GetQuantityNormalized());
  3944. return super.GetTemperatureThawTime();
  3945. }
  3946. //! from enviro source
  3947. void AffectLiquidContainerOnFill(int liquid_type, float amount);
  3948. //! from other liquid container source
  3949. void AffectLiquidContainerOnTransfer(int liquidType, float amount, float sourceLiquidTemperature);
  3950. bool IsCargoException4x3(EntityAI item)
  3951. {
  3952. return (item.IsKindOf("Cauldron") || item.IsKindOf("Pot") || item.IsKindOf("FryingPan") || item.IsKindOf("SmallProtectorCase") || (item.IsKindOf("PortableGasStove") && item.FindAttachmentBySlotName("CookingEquipment")));
  3953. }
  3954. void CopyScriptPropertiesFrom(EntityAI oldItem)
  3955. {
  3956. MiscGameplayFunctions.TransferItemProperties(oldItem, this);
  3957. }
  3958. //! Adds a light source child
  3959. void AddLightSourceItem(ItemBase lightsource)
  3960. {
  3961. m_LightSourceItem = lightsource;
  3962. }
  3963. void RemoveLightSourceItem()
  3964. {
  3965. m_LightSourceItem = null;
  3966. }
  3967. ItemBase GetLightSourceItem()
  3968. {
  3969. return m_LightSourceItem;
  3970. }
  3971. //! returns an array of possible finishers
  3972. array<int> GetValidFinishers()
  3973. {
  3974. return null;
  3975. }
  3976. //! If we need a different (handheld)item action widget displayed, the logic goes in here
  3977. bool GetActionWidgetOverride(out typename name)
  3978. {
  3979. return false;
  3980. }
  3981. bool PairWithDevice(notnull ItemBase otherDevice)
  3982. {
  3983. if (GetGame().IsServer())
  3984. {
  3985. ItemBase explosive = otherDevice;
  3986. RemoteDetonatorTrigger trg = RemoteDetonatorTrigger.Cast(this);
  3987. if (!trg)
  3988. {
  3989. trg = RemoteDetonatorTrigger.Cast(otherDevice);
  3990. explosive = this;
  3991. }
  3992. explosive.PairRemote(trg);
  3993. trg.SetControlledDevice(explosive);
  3994. int persistentID = RemotelyActivatedItemBehaviour.GeneratePersistentID();
  3995. trg.SetPersistentPairID(persistentID);
  3996. explosive.SetPersistentPairID(persistentID);
  3997. return true;
  3998. }
  3999. return false;
  4000. }
  4001. //! generic effectivity as a bait for animal catching
  4002. float GetBaitEffectivity()
  4003. {
  4004. float ret = 1.0;
  4005. if (HasQuantity())
  4006. ret *= GetQuantityNormalized();
  4007. ret *= GetHealth01();
  4008. return ret;
  4009. }
  4010. #ifdef DEVELOPER
  4011. override void SetDebugItem()
  4012. {
  4013. super.SetDebugItem();
  4014. _itemBase = this;
  4015. }
  4016. override string GetDebugText()
  4017. {
  4018. string text = super.GetDebugText();
  4019. text += string.Format("Heat isolation(raw): %1\n", GetHeatIsolation());
  4020. text += string.Format("Heat isolation(modified): %1\n", MiscGameplayFunctions.GetCurrentItemHeatIsolation(this));
  4021. return text;
  4022. }
  4023. #endif
  4024. bool CanBeUsedForSuicide()
  4025. {
  4026. return true;
  4027. }
  4028. ///////////////////
  4029. //DEPRECATED BELOW
  4030. //////////////////
  4031. // Backwards compatibility
  4032. void ProcessItemWetnessAndTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB)
  4033. {
  4034. ProcessItemWetness(delta, hasParent, hasRootAsPlayer, refParentIB);
  4035. ProcessItemTemperature(delta, hasParent, hasRootAsPlayer, refParentIB);
  4036. }
  4037. // replaced by ItemSoundHandler
  4038. protected EffectSound m_SoundDeployFinish;
  4039. protected EffectSound m_SoundPlace;
  4040. protected EffectSound m_DeployLoopSoundEx;
  4041. protected EffectSound m_SoundDeploy;
  4042. bool m_IsPlaceSound;
  4043. bool m_IsDeploySound;
  4044. bool m_IsSoundSynchRemote;
  4045. string GetDeployFinishSoundset();
  4046. void PlayDeploySound();
  4047. void PlayDeployFinishSound();
  4048. void PlayPlaceSound();
  4049. void PlayDeployLoopSoundEx();
  4050. void StopDeployLoopSoundEx();
  4051. void SoundSynchRemoteReset();
  4052. void SoundSynchRemote();
  4053. bool UsesGlobalDeploy(){return false;}
  4054. bool CanPlayDeployLoopSound(){return false;}
  4055. bool IsSoundSynchRemote(){return m_IsSoundSynchRemote;}
  4056. bool IsPlaceSound(){return m_IsPlaceSound;}
  4057. bool IsDeploySound(){return m_IsDeploySound;}
  4058. void SetIsPlaceSound(bool is_place_sound);
  4059. void SetIsDeploySound(bool is_deploy_sound);
  4060. }
  4061. EntityAI SpawnItemOnLocation(string object_name, notnull InventoryLocation loc, bool full_quantity)
  4062. {
  4063. EntityAI entity = SpawnEntity(object_name, loc, ECE_IN_INVENTORY, RF_DEFAULT);
  4064. if (entity)
  4065. {
  4066. bool is_item = entity.IsInherited(ItemBase);
  4067. if (is_item && full_quantity)
  4068. {
  4069. ItemBase item = ItemBase.Cast(entity);
  4070. item.SetQuantity(item.GetQuantityInit());
  4071. }
  4072. }
  4073. else
  4074. {
  4075. ErrorEx("Cannot spawn entity: " + object_name,ErrorExSeverity.INFO);
  4076. return NULL;
  4077. }
  4078. return entity;
  4079. }
  4080. void SetupSpawnedItem(ItemBase item, float health, float quantity)
  4081. {
  4082. if (item)
  4083. {
  4084. if (health > 0)
  4085. item.SetHealth("", "", health);
  4086. if (item.CanHaveTemperature())
  4087. {
  4088. item.SetTemperatureDirect(GameConstants.ITEM_TEMPERATURE_NEUTRAL_ZONE_MIDDLE);
  4089. if (item.CanFreeze())
  4090. item.SetFrozen(false);
  4091. }
  4092. if (item.HasEnergyManager())
  4093. {
  4094. if (quantity >= 0)
  4095. {
  4096. item.GetCompEM().SetEnergy0To1(quantity);
  4097. }
  4098. else
  4099. {
  4100. item.GetCompEM().SetEnergy(Math.AbsFloat(quantity));
  4101. }
  4102. }
  4103. else if (item.IsMagazine())
  4104. {
  4105. Magazine mag = Magazine.Cast(item);
  4106. if (quantity >= 0)
  4107. {
  4108. mag.ServerSetAmmoCount(mag.GetAmmoMax() * quantity);
  4109. }
  4110. else
  4111. {
  4112. mag.ServerSetAmmoCount(Math.AbsFloat(quantity));
  4113. }
  4114. }
  4115. else
  4116. {
  4117. if (quantity >= 0)
  4118. {
  4119. item.SetQuantityNormalized(quantity, false);
  4120. }
  4121. else
  4122. {
  4123. item.SetQuantity(Math.AbsFloat(quantity));
  4124. }
  4125. }
  4126. }
  4127. }
  4128. #ifdef DEVELOPER
  4129. ItemBase _itemBase;//watched item goes here(LCTRL+RMB->Watch)
  4130. #endif