1[
EntityEditorProps(
"GameScripted/Gadgets", description:
"Mortar shell that can be picked up.")]
7 [
Attribute(
"15",
desc:
"Minimal time in seconds that this projectile can be set to [s]",
params:
"1 inf")]
8 protected float m_fMinFuzeTime;
10 [
Attribute(
"15",
desc:
"Maximal time in seconds that this projectile can be set to [s]",
params:
"1 inf")]
11 protected float m_fMaxFuzeTime;
13 [
Attribute(
"100",
desc:
"What altitude in meters above the impact point should be used for automatically setting the detonation time [m]",
params:
"1 inf")]
14 protected float m_fDetonationAltitude;
16 [
Attribute(
"1",
desc:
"Fuze time offset applied based on the time that it takes to travel the distance specified in Detonation Altitude attribute [s]",
params:
"0.01 inf")]
17 protected float m_fVerticalImpactTimeOffset;
19 [
Attribute(
desc:
"1. Number of charge rings.\n2. Projectile speed coef.\n3. Is this the default amount of charge rings.",
params:
"0 inf")]
31 return m_fMinFuzeTime;
37 return m_fMaxFuzeTime;
69 return m_fDetonationAltitude;
75 return m_fVerticalImpactTimeOffset;
108 if (
float.AlmostEqual(config[2], 0))
111 foundConfig = config;
118 if (foundConfig == -
vector.One)
121 Print(
"SCR_MortarShellGadgetComponent.FindDefaultChargeRingConfig: WARNING! There is not default config, as all configs have Z set to value different than 1! First config is going to be used as default for now, but this must be fixed in the prefab!",
LogLevel.ERROR);
128class SCR_MortarShellGadgetComponent : SCR_GadgetComponent
130 [
RplProp(onRplName:
"OnChargeRingReplicated")]
131 protected int m_iChargeRingConfigIndex;
134 protected SCR_MortarMuzzleComponent m_MortarMuzzleComp;
135 protected SlotManagerComponent m_SlotManagerComp;
136 protected string m_sRegisteredActionName;
137 protected float m_fFuzeTime;
138 protected bool m_bCustomFuzeTimeSet;
139 protected bool m_bCustomChargeRingSet;
141 static const protected string CHARGE_RING_CONFIG_MEMBER_NAME =
"m_aChargeRingConfig";
163 array <float> output = {};
164 array <vector> chargeRingConfigs = {};
165 defaultConfigId = -1;
166 for (
int i, componentsCount = entitySrc.GetComponentCount(); i < componentsCount; i++)
168 componentSrc = entitySrc.GetComponent(i);
172 if (!componentSrc.GetClassName().ToType().IsInherited(SCR_MortarShellGadgetComponent))
175 componentSrc.Get(CHARGE_RING_CONFIG_MEMBER_NAME, chargeRingConfigs);
176 if (!chargeRingConfigs || chargeRingConfigs.IsEmpty())
179 foreach (
vector entry : chargeRingConfigs)
181 output.Insert(entry[1]);
182 if (defaultConfigId == -1 && !
float.AlmostEqual(entry[2], 0))
195 return EGadgetType.NONE;
217 return m_OnShellUsed;
235 return data.IsUsingTimeFuze();
253 return data.GetMinFuzeTime();
264 return data.GetMaxFuzeTime();
275 return data.GetDetonationAltitude();
286 return data.GetNumberOfChargeRingConfigurations();
297 return data.GetChargeRingConfig(m_iChargeRingConfigIndex);
304 return m_iChargeRingConfigIndex;
315 return data.GetChargeRingConfig(
id);
336 vector previousConfig =
data.GetChargeRingConfig(m_iChargeRingConfigIndex);
337 vector newConfig =
data.GetChargeRingConfig(configId);
338 m_bCustomChargeRingSet =
true;
339 if (newConfig == -
vector.One)
341 configId =
data.FindDefaultChargeRingConfig(newConfig);
345 m_bCustomChargeRingSet =
false;
348 int chargeRingDif = newConfig[0] - previousConfig[0];
349 m_iChargeRingConfigIndex = configId;
356 moveComp.SetBulletCoef(newConfig[1]);
361 if (chargeRingDif > 0)
363 else if (chargeRingDif < 0)
371 if (!rplComp || !rplComp.IsOwner())
382 SCR_VisibleInventoryItemComponent inventoryItemComp = SCR_VisibleInventoryItemComponent.Cast(
GetOwner().FindComponent(SCR_VisibleInventoryItemComponent));
383 if (inventoryItemComp)
384 inventoryItemComp.SetHiddenInVicinity(
true);
395 array<EntitySlotInfo> outSlotInfos = {};
396 if (!m_SlotManagerComp || m_SlotManagerComp.GetSlotInfos(outSlotInfos) < 1)
405 chargeRing = slot.GetAttachedEntity();
409 if (i < numberOfChargeRings)
422 bool SetLoadedState(
bool state, SCR_MortarMuzzleComponent mortarMuzzle = null,
string fireActionName =
"",
IEntity user = null)
424 m_bActivated = state;
425 m_MortarMuzzleComp = mortarMuzzle;
432 if (!user || fireActionName.IsEmpty())
438 m_sRegisteredActionName = fireActionName;
455 if (state && m_OnShellUsed)
456 m_OnShellUsed.Invoke();
458 if(m_MortarMuzzleComp)
460 m_MortarMuzzleComp.SetLoadingState(
false);
468 super.ModeSwitch(mode, charOwner);
470 if (mode != EGadgetMode.IN_HAND)
473 if (m_bCustomChargeRingSet)
500 if (mode != EGadgetMode.IN_HAND)
503 if (!m_MortarMuzzleComp)
506 m_MortarMuzzleComp.SetLoadingState(
false);
518 if (!
data.IsUsingTimeFuze())
521 m_fFuzeTime =
Math.Clamp(time,
data.GetMinFuzeTime(),
data.GetMaxFuzeTime());
523 TimerTriggerComponent trigger = TimerTriggerComponent.Cast(
GetOwner().FindComponent(TimerTriggerComponent));
527 trigger.SetTimer(m_fFuzeTime);
566 vector chargeConfig =
data.GetChargeRingConfig(m_iChargeRingConfigIndex);
567 angle = angle *
Math.DEG2RAD;
568 float distance1, distance2, travelTime1, travelTime2;
569 distance1 =
BallisticTable.GetDistanceOfProjectileSource(angle, travelTime1, entitySrc, chargeConfig[1], isDirectFire);
571 float detonationAltitude =
data.GetDetonationAltitude();
572 distance2 = distance1 + detonationAltitude * 0.5;
574 distance2 = distance1 - detonationAltitude * 0.5;
576 BallisticTable.GetHeightFromProjectileSource(distance1, travelTime1, entitySrc, chargeConfig[1], isDirectFire);
577 BallisticTable.GetHeightFromProjectileSource(distance2, travelTime2, entitySrc, chargeConfig[1], isDirectFire);
581 distance2 = distance1 - detonationAltitude * 0.5;
583 distance2 = distance1 + detonationAltitude * 0.5;
585 BallisticTable.GetHeightFromProjectileSource(distance2, travelTime2, entitySrc, chargeConfig[1], isDirectFire);
586 travelTime2 =
Math.Lerp(travelTime1, travelTime1 -
Math.AbsFloat(travelTime1 - travelTime2), 0.9);
589 return travelTime2 -
Math.Max(
data.GetVerticalImpactTimeOffset() -
Math.AbsFloat(travelTime1 - travelTime2), 0);
595 super.EOnInit(owner);
602 Print(
"SCR_MortarShellGadgetComponent.EOnInit: WARNING! "+owner.
GetPrefabData().GetPrefabName()+
" is missing TimerTriggerComponent and because of that fuze adjustment will not be avialable!",
LogLevel.ERROR);
603 data.OverrideTimeFuzeConfig(
false);
606 if (
data.GetMaxFuzeTime() <
data.GetMinFuzeTime())
608 Print(
"SCR_MortarShellGadgetComponent.EOnInit: WARNING! MaxFuzeTime is less than MinFuzeTime for "+owner.
GetPrefabData().GetPrefabName()+
". Please fix this in the actual prefab data!",
LogLevel.WARNING);
609 data.OverrideTimeFuzeConfig(
data.IsUsingTimeFuze(),
data.GetMaxFuzeTime(),
data.GetMinFuzeTime());
612 if (
data.GetMaxFuzeTime() ==
data.GetMinFuzeTime())
614 Print(
"SCR_MortarShellGadgetComponent.EOnInit: WARNING! Prefab "+owner.
GetPrefabData().GetPrefabName()+
" has IsUsingTimeFuze set to true, while MIN and MAX times are the same. Because of that fuze time adjustment will not be avialable!.",
LogLevel.ERROR);
615 data.OverrideTimeFuzeConfig(
false);
623 m_SlotManagerComp = SlotManagerComponent.Cast(owner.
FindComponent(SlotManagerComponent));
624 m_iChargeRingConfigIndex =
data.FindDefaultChargeRingConfig();
626 m_bCustomChargeRingSet =
false;
634 writer.WriteFloat(m_fFuzeTime);
636 writer.WriteBool(m_bCustomChargeRingSet);
638 bool hiddenInVicinity =
false;
639 SCR_VisibleInventoryItemComponent inventoryItemComp = SCR_VisibleInventoryItemComponent.Cast(
GetOwner().FindComponent(SCR_VisibleInventoryItemComponent));
640 if (inventoryItemComp)
641 hiddenInVicinity = inventoryItemComp.ShouldHideInVicinity();
643 writer.WriteBool(hiddenInVicinity);
645 return super.RplSave(writer);
654 reader.ReadFloat(m_fFuzeTime);
658 bool hiddenInVicinity;
659 reader.ReadBool(m_bCustomChargeRingSet);
660 reader.ReadBool(hiddenInVicinity);
662 SCR_VisibleInventoryItemComponent inventoryItemComp = SCR_VisibleInventoryItemComponent.Cast(
GetOwner().FindComponent(SCR_VisibleInventoryItemComponent));
664 if (inventoryItemComp && hiddenInVicinity)
667 return super.RplLoad(reader);
ArmaReforgerScripted GetGame()
ResourceName resourceName
override bool RplLoad(ScriptBitReader reader)
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
override bool RplSave(ScriptBitWriter writer)
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override bool IsVisibleEquipped()
override bool CanBeRaised()
Get all prefabs that have the spawner data
void ToggleActive()
Toggle map light.
void SetChargeRingConfig(int configId, bool silent=false, bool replicate=true)
void SetFuzeTime(float time)
float GetTimeToDetonation(float angle, bool isDirectFire)
Retrieves information about the time of flight for this shell prefab.
SCR_ShellConfig GetSavedConfig(notnull ChimeraCharacter character)
Retrieves locally saved data about manual adjustment of the fuze that player set for this shell type.
void VisualiseChargeRings(int numberOfChargeRings)
vector GetCurentChargeRingConfig()
void OnShellFired(notnull BaseMuzzleComponent muzzle)
ScriptInvokerVoid GetOnShellUsed()
void UseShellCB()
Callback used to tell if user wants to fire the shell now.
vector GetChargeRingConfig(int id)
float GetDetonationAltitude()
int GetCurentChargeRingConfigId()
void OnChargeRingReplicated()
Callback method that will be triggered when m_iChargeRingConfigIndex is bumped for replication.
bool SetLoadedState(bool state, SCR_MortarMuzzleComponent mortarMuzzle=null, string fireActionName="", IEntity user=null)
int GetNumberOfChargeRingConfigurations()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Adds ability to attach an object to a slot.
proto external Managed FindComponent(typename typeName)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external EntityPrefabData GetPrefabData()
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Object holding reference to resource. In destructor release the resource.
SCR_ShellConfig GetSavedShellConfig(notnull EntityPrefabData shellPrefab)
void SyncShellChargeRingConfig(notnull SCR_MortarShellGadgetComponent shellComp, int configId)
static RplComponent GetEntityRplComponent(notnull IEntity entity)
int FindDefaultChargeRingConfig(out vector foundConfig=-vector.One)
ref array< vector > m_aChargeRingConfig
float GetDetonationAltitude()
vector GetChargeRingConfig(int id)
void OverrideTimeFuzeConfig(bool shouldBeUsed=false, float min=0, float max=0)
float GetVerticalImpactTimeOffset()
int GetNumberOfChargeRingConfigurations()
static IEntity GetLocalControlledEntity()
int GetChargeRingConfigId()
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.