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