Exemplo n.º 1
0
 static void Prefix(Building_TurretGunCE __instance)
 {
     if (__instance.GetType().GetField("mannableComp", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) is CompMannable mannable &&
         __instance.CompAmmo.UseAmmo)
     {
         CompInventory inv = ThingCompUtility.TryGetComp <CompInventory>(mannable.ManningPawn);
         if (mannable.ManningPawn.IsColonist && inv != null)
         {
             Thing thing = inv.container.FirstOrDefault((Thing x) => x.def == __instance.CompAmmo.SelectedAmmo);
             if (thing == null)
             {
                 AmmoDef ammoDef = __instance.CompAmmo.SelectedAmmo;
                 if (ammoDef != null &&
                     CombatExtendedUtil.HasAmmo(ammoDef))
                 {
                     int magazineSize = __instance.CompAmmo.Props.magazineSize;
                     if (CombatExtendedUtil.TryRemoveAmmo(ammoDef, magazineSize, out Thing ammo))
                     {
                         inv.UpdateInventory();
                         if (!inv.container.TryAdd(ammo as ThingWithComps))
                         {
                             Log.Error("Failed to add ammo to pawn inventory");
                             CombatExtendedUtil.AddAmmo(ammo);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        private void DamageScales(AmmoDef ammoDef, out bool damageScaling, out bool fallOffScaling, out bool armorScaling, out bool customDamageScales, out Dictionary <MyDefinitionBase, float> customBlockDef, out bool selfDamage, out bool voxelDamage)
        {
            armorScaling       = false;
            customDamageScales = false;
            fallOffScaling     = false;
            var d = ammoDef.DamageScales;

            customBlockDef = null;
            if (d.Custom.Types != null && d.Custom.Types.Length > 0)
            {
                foreach (var def in MyDefinitionManager.Static.GetAllDefinitions())
                {
                    foreach (var customDef in d.Custom.Types)
                    {
                        if (customDef.Modifier >= 0 && def.Id.SubtypeId.String == customDef.SubTypeId)
                        {
                            if (customBlockDef == null)
                            {
                                customBlockDef = new Dictionary <MyDefinitionBase, float>();
                            }
                            customBlockDef.Add(def, customDef.Modifier);
                            customDamageScales = customBlockDef.Count > 0;
                        }
                    }
                }
            }
            damageScaling = d.FallOff.MinMultipler > 0 || d.MaxIntegrity > 0 || d.Armor.Armor >= 0 || d.Armor.NonArmor >= 0 || d.Armor.Heavy >= 0 || d.Armor.Light >= 0 || d.Grids.Large >= 0 || d.Grids.Small >= 0 || customDamageScales;
            if (damageScaling)
            {
                armorScaling   = d.Armor.Armor >= 0 || d.Armor.NonArmor >= 0 || d.Armor.Heavy >= 0 || d.Armor.Light >= 0;
                fallOffScaling = d.FallOff.MinMultipler > 0;
            }
            selfDamage  = ammoDef.DamageScales.SelfDamage && !IsBeamWeapon;
            voxelDamage = ammoDef.DamageScales.DamageVoxels;
        }
Exemplo n.º 3
0
        private void CollisionShape(AmmoDef ammoDef, out bool collisionIsLine, out double collisionSize, out double tracerLength)
        {
            var isLine = ammoDef.Shape.Shape == LineShape;
            var size   = ammoDef.Shape.Diameter;

            if (IsBeamWeapon)
            {
                tracerLength = MaxTrajectory;
            }
            else
            {
                tracerLength = ammoDef.AmmoGraphics.Lines.Tracer.Length > 0 ? ammoDef.AmmoGraphics.Lines.Tracer.Length : 0.1;
            }

            if (size <= 0)
            {
                if (!isLine)
                {
                    isLine = true;
                }
                size = 1;
            }
            else if (!isLine)
            {
                size *= 0.5;
            }

            collisionIsLine = isLine;
            collisionSize   = size;
        }
        private static Thing FindBestAmmo(Pawn pawn, Building_TurretGunCE reloadable)
        {
            //ThingFilter filter = refuelable.TryGetComp<CompRefuelable>().Props.fuelFilter;
            AmmoDef requestedAmmo = reloadable.CompAmmo.SelectedAmmo;
            // try to find currently selected ammo first
            var bestAmmo = FindBestAmmo(pawn, requestedAmmo);

            // this code is mostly for siege raids, so they can use all the ammo dropped (and get more ammo)
            // otherwise, they will wait forever for an HE ammo drop, without using the incendiary shells next to them
            if (bestAmmo == null && !pawn.IsColonist && requestedAmmo.AmmoSetDefs != null)
            {
                // if there isn't any, try to find some ammo from same ammo set
                foreach (AmmoSetDef set in requestedAmmo.AmmoSetDefs)
                {
                    foreach (AmmoLink link in set.ammoTypes)
                    {
                        bestAmmo = FindBestAmmo(pawn, link.ammo);
                        if (bestAmmo != null)
                        {
                            return(bestAmmo);
                        }
                    }
                }
            }
            return(bestAmmo);
        }
Exemplo n.º 5
0
 private void Beams(AmmoDef ammoDef, out bool isBeamWeapon, out bool virtualBeams, out bool rotateRealBeam, out bool convergeBeams, out bool oneHitParticle, out bool offsetEffect)
 {
     isBeamWeapon   = ammoDef.Beams.Enable;
     virtualBeams   = ammoDef.Beams.VirtualBeams && IsBeamWeapon;
     rotateRealBeam = ammoDef.Beams.RotateRealBeam && VirtualBeams;
     convergeBeams  = !RotateRealBeam && ammoDef.Beams.ConvergeBeams && VirtualBeams;
     oneHitParticle = ammoDef.Beams.OneParticle && IsBeamWeapon && VirtualBeams;
     offsetEffect   = ammoDef.AmmoGraphics.Lines.OffsetEffect.MaxOffset > 0;
 }
Exemplo n.º 6
0
 internal void Clean()
 {
     System     = null;
     HitPos     = Vector3D.Zero;
     Ai         = null;
     AmmoDef    = null;
     AttackerId = 0;
     Damage     = 0;
     Hits       = 0;
 }
        private static Thing FindBestAmmo(Pawn pawn, AmmoDef requestedAmmo)
        {
            Predicate <Thing> validator = (Thing potentialAmmo) =>
            {
                if (potentialAmmo.IsForbidden(pawn) || !pawn.CanReserve(potentialAmmo))
                {
                    return(false);
                }
                return(GetPathCost(pawn, potentialAmmo) <= MaxPathCost);
            };

            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(requestedAmmo), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, validator));
        }
Exemplo n.º 8
0
 private MyConcurrentPool <MyEntity> Models(AmmoDef ammoDef, WeaponDefinition wDef, out bool primeModel, out bool triggerModel, out string primeModelPath)
 {
     if (ammoDef.AreaEffect.AreaEffect > (AreaEffectType)3 && IsField)
     {
         triggerModel = true;
     }
     else
     {
         triggerModel = false;
     }
     primeModel     = ammoDef.AmmoGraphics.ModelName != string.Empty;
     primeModelPath = primeModel ? wDef.ModPath + ammoDef.AmmoGraphics.ModelName : string.Empty;
     return(primeModel ? new MyConcurrentPool <MyEntity>(256, PrimeEntityClear, 10000, PrimeEntityActivator) : null);
 }
Exemplo n.º 9
0
 internal void InitVirtual(WeaponSystem system, GridAi ai, AmmoDef ammodef, MyEntity primeEntity, MyEntity triggerEntity, Target target, int weaponId, int muzzleId, Vector3D origin, Vector3D virDirection)
 {
     System            = system;
     Ai                = ai;
     AmmoDef           = ammodef;
     PrimeEntity       = primeEntity;
     TriggerEntity     = triggerEntity;
     Target.Entity     = target.Entity;
     Target.Projectile = target.Projectile;
     Target.FiringCube = target.FiringCube;
     WeaponId          = weaponId;
     MuzzleId          = muzzleId;
     Direction         = virDirection;
     Origin            = origin;
 }
Exemplo n.º 10
0
 private void AreaEffects(AmmoDef ammoDef, out AreaEffectType areaEffect, out float areaEffectDamage, out double areaEffectSize, out float detonationDamage, out bool ammoAreaEffect, out double areaRadiusSmall, out double areaRadiusLarge, out double detonateRadiusSmall, out double detonateRadiusLarge, out bool eWar, out bool eWarEffect, out double eWarTriggerRange)
 {
     areaEffect          = ammoDef.AreaEffect.AreaEffect;
     areaEffectDamage    = ammoDef.AreaEffect.AreaEffectDamage;
     areaEffectSize      = ammoDef.AreaEffect.AreaEffectRadius;
     detonationDamage    = ammoDef.AreaEffect.Detonation.DetonationDamage;
     ammoAreaEffect      = ammoDef.AreaEffect.AreaEffect != AreaEffectType.Disabled;
     areaRadiusSmall     = Session.ModRadius(ammoDef.AreaEffect.AreaEffectRadius, false);
     areaRadiusLarge     = Session.ModRadius(ammoDef.AreaEffect.AreaEffectRadius, true);
     detonateRadiusSmall = Session.ModRadius(ammoDef.AreaEffect.Detonation.DetonationRadius, false);
     detonateRadiusLarge = Session.ModRadius(ammoDef.AreaEffect.Detonation.DetonationRadius, true);
     eWar             = areaEffect > (AreaEffectType)2;
     eWarEffect       = areaEffect > (AreaEffectType)3;
     eWarTriggerRange = eWar && Pulse && ammoDef.AreaEffect.EwarFields.TriggerRange > 0 ? ammoDef.AreaEffect.EwarFields.TriggerRange : 0;
 }
Exemplo n.º 11
0
        private bool GetAmmoDetails()
        {
            //Logger.MsgDebug(string.Format(" - Getting Ammo Details For Core Weapon: {0}", _block.CustomName), DebugTypeEnum.Weapon);
            var currentAmmo = RAI_SessionCore.Instance.WeaponCore.GetActiveAmmo(_block, _weaponId);

            //Logger.MsgDebug(string.Format(" - CurrentAmmo For Core Weapon {0}: {1}", _block.CustomName, currentAmmo ?? "N/A"), DebugTypeEnum.Weapon);

            if (_ammoRound != currentAmmo)
            {
                //Logger.MsgDebug(" - Create New Ammo Def", DebugTypeEnum.Weapon);
                var ammoDef = new AmmoDef();

                if (currentAmmo != null)
                {
                    //Logger.MsgDebug(" - Try Get From Ammo-To-Def", DebugTypeEnum.Weapon);
                    _ammoToDefinition.TryGetValue(currentAmmo, out ammoDef);
                    //Logger.MsgDebug(" - Try Get From Ammo-To-Def", DebugTypeEnum.Weapon);
                }
                else
                {
                    //Logger.MsgDebug(" - Try Get From Index 0", DebugTypeEnum.Weapon);
                    ammoDef = _weaponDefinition.Ammos[0];
                }

                if (!string.IsNullOrWhiteSpace(ammoDef?.AmmoRound))
                {
                    //Logger.MsgDebug(" - Populate Ammo Data", DebugTypeEnum.Weapon);
                    _ammoRound            = currentAmmo;
                    _currentAmmoMagazine  = new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), ammoDef.AmmoMagazine);
                    _requiresPhysicalAmmo = _currentAmmoMagazine.SubtypeName != "Energy";
                    _beamAmmo             = ammoDef.Beams.Enable;
                    _homingAmmo           = ammoDef.Trajectory.Guidance == AmmoDef.TrajectoryDef.GuidanceType.Smart || ammoDef.Trajectory.Guidance == AmmoDef.TrajectoryDef.GuidanceType.TravelTo;
                    _flareAmmo            = ammoDef.AreaEffect.AreaEffect == AmmoDef.AreaDamageDef.AreaEffectType.AntiSmart;
                    _ammoMaxTrajectory    = ammoDef.Trajectory.MaxTrajectory;
                    _ammoMaxVelocity      = _beamAmmo ? -1 : ammoDef.Trajectory.DesiredSpeed;
                    _ammoInitialVelocity  = _beamAmmo ? -1 : ammoDef.Trajectory.DesiredSpeed;
                    _ammoAcceleration     = _beamAmmo ? -1 : ammoDef.Trajectory.AccelPerSec;
                }
                else
                {
                    //Logger.MsgDebug(" - AmmoDef Was Null", DebugTypeEnum.Weapon);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        internal void Clean(uint expireTick)
        {
            Target.Reset(expireTick, Target.States.ProjectileClosed);
            HitList.Clear();

            if (PrimeEntity != null)
            {
                AmmoDef.Const.PrimeEntityPool.Return(PrimeEntity);
                PrimeEntity = null;
            }

            if (TriggerEntity != null)
            {
                Ai.Session.TriggerEntityPool.Return(TriggerEntity);
                TriggerEntity = null;
            }
            AvShot                 = null;
            System                 = null;
            Ai                     = null;
            AmmoDef                = null;
            WeaponCache            = null;
            LastHitShield          = false;
            IsShrapnel             = false;
            TriggeredPulse         = false;
            EwarActive             = false;
            ModelOnly              = false;
            LockOnFireState        = false;
            IsFiringPlayer         = false;
            ClientSent             = false;
            TriggerGrowthSteps     = 0;
            WeaponId               = 0;
            MuzzleId               = 0;
            Age                    = 0;
            ProjectileDisplacement = 0;
            MaxTrajectory          = 0;
            ShotFade               = 0;
            TracerLength           = 0;
            EnableGuidance         = true;
            Direction              = Vector3D.Zero;
            VisualDir              = Vector3D.Zero;
            Origin                 = Vector3D.Zero;
            ShooterVel             = Vector3D.Zero;
            TriggerMatrix          = MatrixD.Identity;
        }
Exemplo n.º 13
0
 static void Prefix(CompAmmoUser __instance)
 {
     if (__instance.turret == null &&
         __instance.Wielder != null &&
         __instance.HasMagazine)
     {
         AmmoDef ammoDef = __instance.SelectedAmmo;//__instance.GetType().GetProperty("CurrentAmmo", BindingFlags.Instance | BindingFlags.Public).GetValue(__instance, null) as Def;
         if (ammoDef != null &&
             CombatExtendedUtil.HasAmmo(ammoDef))
         {
             if (!__instance.TryFindAmmoInInventory(out Thing ammo))
             {
                 int magazineSize = __instance.Props.magazineSize;
                 if (CombatExtendedUtil.TryRemoveAmmo(ammoDef, magazineSize, out ammo))
                 {
                     __instance.CompInventory.ammoList.Add(ammo as ThingWithComps);
                 }
             }
         }
     }
 }
Exemplo n.º 14
0
        private void Sound(AmmoDef ammoDef, Session session, out bool hitSound, out bool ammoTravelSound, out float hitSoundDistSqr, out float ammoTravelSoundDistSqr, out float ammoSoundMaxDistSqr)
        {
            hitSound        = ammoDef.AmmoAudio.HitSound != string.Empty;
            ammoTravelSound = ammoDef.AmmoAudio.TravelSound != string.Empty;
            var hitSoundStr    = string.Concat(Arc, ammoDef.AmmoAudio.HitSound);
            var travelSoundStr = string.Concat(Arc, ammoDef.AmmoAudio.TravelSound);

            hitSoundDistSqr        = 0;
            ammoTravelSoundDistSqr = 0;
            ammoSoundMaxDistSqr    = 0;

            foreach (var def in session.SoundDefinitions)
            {
                var id = def.Id.SubtypeId.String;
                if (HitSound && id == hitSoundStr)
                {
                    var ob = def.GetObjectBuilder() as MyObjectBuilder_AudioDefinition;
                    if (ob != null)
                    {
                        hitSoundDistSqr = ob.MaxDistance * ob.MaxDistance;
                    }
                    if (hitSoundDistSqr > ammoSoundMaxDistSqr)
                    {
                        ammoSoundMaxDistSqr = hitSoundDistSqr;
                    }
                }
                else if (AmmoTravelSound && id == travelSoundStr)
                {
                    var ob = def.GetObjectBuilder() as MyObjectBuilder_AudioDefinition;
                    if (ob != null)
                    {
                        ammoTravelSoundDistSqr = ob.MaxDistance * ob.MaxDistance;
                    }
                    if (ammoTravelSoundDistSqr > ammoSoundMaxDistSqr)
                    {
                        ammoSoundMaxDistSqr = ammoTravelSoundDistSqr;
                    }
                }
            }
        }
Exemplo n.º 15
0
 internal void InitVirtual(Weapon weapon, AmmoDef ammodef, MyEntity primeEntity, MyEntity triggerEntity, Weapon.Muzzle muzzle, double maxTrajectory, float shotFade)
 {
     IsVirtual         = true;
     System            = weapon.System;
     Ai                = weapon.Comp.Ai;
     MyPlanet          = weapon.Comp.Ai.MyPlanet;
     MyShield          = weapon.Comp.Ai.MyShield;
     InPlanetGravity   = weapon.Comp.Ai.InPlanetGravity;
     AmmoDef           = ammodef;
     PrimeEntity       = primeEntity;
     TriggerEntity     = triggerEntity;
     Target.Entity     = weapon.Target.Entity;
     Target.Projectile = weapon.Target.Projectile;
     Target.FiringCube = weapon.Target.FiringCube;
     WeaponId          = weapon.WeaponId;
     MuzzleId          = muzzle.MuzzleId;
     UniqueMuzzleId    = muzzle.UniqueId;
     Direction         = muzzle.DeviatedDir;
     Origin            = muzzle.Position;
     MaxTrajectory     = maxTrajectory;
     ShotFade          = shotFade;
 }
        private static Thing FindBestAmmo(Pawn pawn, Building_TurretGunCE turret)
        {
            AmmoDef requestedAmmo = turret.CompAmmo.SelectedAmmo;
            var     bestAmmo      = FindBestAmmo(pawn, requestedAmmo);      // try to find currently selected ammo first

            if (bestAmmo == null && turret.CompAmmo.EmptyMagazine && requestedAmmo.AmmoSetDefs != null)
            {
                //Turret's selected ammo not available, and magazine is empty. Pick a new ammo from the set to load.
                foreach (AmmoSetDef set in requestedAmmo.AmmoSetDefs)
                {
                    foreach (AmmoLink link in set.ammoTypes)
                    {
                        bestAmmo = FindBestAmmo(pawn, link.ammo);
                        if (bestAmmo != null)
                        {
                            return(bestAmmo);
                        }
                    }
                }
            }
            return(bestAmmo);
        }
Exemplo n.º 17
0
 private void Fields(AmmoDef ammoDef, out int pulseInterval, out int pulseChance, out bool pulse)
 {
     pulseInterval = ammoDef.AreaEffect.Pulse.Interval;
     pulseChance   = ammoDef.AreaEffect.Pulse.PulseChance;
     pulse         = pulseInterval > 0 && pulseChance > 0;
 }
Exemplo n.º 18
0
        private void ComputeEffects(MyCubeGrid grid, AmmoDef ammoDef, float damagePool, ref float healthPool, long attackerId, int sysmteId, List <IMySlimBlock> blocks)
        {
            var largeGrid = grid.GridSizeEnum == MyCubeSize.Large;
            var eWarInfo  = ammoDef.AreaEffect.EwarFields;
            var duration  = (uint)eWarInfo.Duration;
            var stack     = eWarInfo.StackDuration;
            var maxStack  = eWarInfo.MaxStacks;
            var nextTick  = Tick + 1;
            var maxTick   = stack ? (uint)(nextTick + (duration * maxStack)) : nextTick + duration;
            var fieldType = ammoDef.AreaEffect.AreaEffect;
            var sync      = MpActive && (DedicatedServer || IsServer);

            foreach (var block in blocks)
            {
                var cubeBlock = block.FatBlock as MyCubeBlock;
                if (damagePool <= 0 || healthPool <= 0)
                {
                    break;
                }

                IMyFunctionalBlock funcBlock = null;
                if (fieldType != DotField)
                {
                    if (cubeBlock == null || cubeBlock.MarkedForClose)
                    {
                        continue;
                    }

                    funcBlock = cubeBlock as IMyFunctionalBlock;
                    var isConveyor = cubeBlock is MyConveyor;
                    var ewared     = EffectedCubes.ContainsKey(cubeBlock.EntityId);

                    if (funcBlock == null || isConveyor || !cubeBlock.IsWorking && !ewared || ewared && !stack)
                    {
                        continue;
                    }
                }

                var   blockHp       = block.Integrity;
                float damageScale   = 1;
                var   tmpDamagePool = damagePool;
                if (ammoDef.Const.DamageScaling)
                {
                    var d = ammoDef.DamageScales;
                    if (d.MaxIntegrity > 0 && blockHp > d.MaxIntegrity)
                    {
                        continue;
                    }

                    if (d.Grids.Large >= 0 && largeGrid)
                    {
                        damageScale *= d.Grids.Large;
                    }
                    else if (d.Grids.Small >= 0 && !largeGrid)
                    {
                        damageScale *= d.Grids.Small;
                    }

                    MyDefinitionBase blockDef = null;
                    if (ammoDef.Const.ArmorScaling)
                    {
                        blockDef = block.BlockDefinition;
                        var isArmor = AllArmorBaseDefinitions.Contains(blockDef) || CustomArmorSubtypes.Contains(blockDef.Id.SubtypeId);
                        if (isArmor && d.Armor.Armor >= 0)
                        {
                            damageScale *= d.Armor.Armor;
                        }
                        else if (!isArmor && d.Armor.NonArmor >= 0)
                        {
                            damageScale *= d.Armor.NonArmor;
                        }

                        if (isArmor && (d.Armor.Light >= 0 || d.Armor.Heavy >= 0))
                        {
                            var isHeavy = HeavyArmorBaseDefinitions.Contains(blockDef) || CustomHeavyArmorSubtypes.Contains(blockDef.Id.SubtypeId);
                            if (isHeavy && d.Armor.Heavy >= 0)
                            {
                                damageScale *= d.Armor.Heavy;
                            }
                            else if (!isHeavy && d.Armor.Light >= 0)
                            {
                                damageScale *= d.Armor.Light;
                            }
                        }
                    }
                    if (ammoDef.Const.CustomDamageScales)
                    {
                        if (blockDef == null)
                        {
                            blockDef = block.BlockDefinition;
                        }
                        float modifier;
                        var   found = ammoDef.Const.CustomBlockDefinitionBasesToScales.TryGetValue(blockDef, out modifier);

                        if (found)
                        {
                            damageScale *= modifier;
                        }
                        else if (ammoDef.DamageScales.Custom.IgnoreAllOthers)
                        {
                            continue;
                        }
                    }
                }

                var scaledDamage = tmpDamagePool * damageScale;

                var blockDisabled = false;
                if (scaledDamage <= blockHp)
                {
                    tmpDamagePool = 0;
                }
                else
                {
                    blockDisabled  = true;
                    tmpDamagePool -= blockHp;
                }

                if (fieldType == DotField && IsServer)
                {
                    block.DoDamage(scaledDamage, MyDamageType.Explosion, sync, null, attackerId);
                    continue;
                }

                if (funcBlock != null)
                {
                    BlockState blockState;
                    var        cubeId = cubeBlock.EntityId;
                    if (EffectedCubes.TryGetValue(cubeId, out blockState))
                    {
                        if (blockState.Health > 0)
                        {
                            damagePool = tmpDamagePool;
                        }
                        if (!blockDisabled && blockState.Health - scaledDamage > 0)
                        {
                            blockState.Health -= scaledDamage;
                            blockState.Endtick = Tick + (duration + 1);
                        }
                        else if (blockState.Endtick + (duration + 1) < maxTick)
                        {
                            blockState.Health   = 0;
                            healthPool         -= 1;
                            blockState.Endtick += (duration + 1);
                        }
                        else
                        {
                            blockState.Health  = 0;
                            healthPool        -= 1;
                            blockState.Endtick = maxTick;
                        }
                    }
                    else
                    {
                        damagePool            = tmpDamagePool;
                        blockState.FunctBlock = funcBlock;
                        var originState = blockState.FunctBlock.Enabled;
                        blockState.FirstTick  = Tick + 1;
                        blockState.FirstState = originState;
                        blockState.NextTick   = nextTick;
                        blockState.Endtick    = Tick + (duration + 1);
                        blockState.Session    = this;
                        blockState.AmmoDef    = ammoDef;
                        blockState.SystemId   = sysmteId;
                        if (!blockDisabled)
                        {
                            blockState.Health = blockHp - scaledDamage;
                        }
                        else
                        {
                            blockState.Health = 0;
                        }
                    }
                    EffectedCubes[cubeId] = blockState;
                }
            }

            if (!IsServer)
            {
                EffectedCubes.Clear();
            }
        }
Exemplo n.º 19
0
        public override void RefreshAmmoDetails()
        {
            var timeSpan = MyAPIGateway.Session.GameDateTime - _lastAmmoRefresh;

            if (timeSpan.TotalMilliseconds < 500)
            {
                return;
            }

            _lastAmmoRefresh = MyAPIGateway.Session.GameDateTime;

            var ammo = RAI_SessionCore.Instance.WeaponCore.GetActiveAmmo(_weaponBlock, _weaponIndex);

            if (string.IsNullOrWhiteSpace(ammo) && _weaponCoreAmmoDefinition.AmmoMagazine != "Energy")
            {
                Logger.MsgDebug("Ammo Is Null", DebugTypeEnum.WeaponCore);
                return;
            }

            if (ammo != _weaponCoreAmmoMagazineId || string.IsNullOrWhiteSpace(_weaponCoreAmmoMagazineId))
            {
                foreach (var ammoDef in _weaponCoreDefinition.Ammos)
                {
                    if (ammoDef.AmmoMagazine == "Energy")
                    {
                        ammo = "Energy";
                    }

                    if (ammoDef.AmmoMagazine == ammo)
                    {
                        _weaponCoreAmmoMagazineId = ammo;
                        _weaponCoreAmmoDefinition = ammoDef;
                        break;
                    }
                }
            }

            _weaponCurrentRange = _weaponCoreAmmoDefinition.Trajectory.MaxTrajectory;
            _weaponRateOfFire   = _weaponCoreDefinition.HardPoint.Loading.RateOfFire;

            if (ammo == "Energy")
            {
                _currentAmmoCount = 1;
            }
            else
            {
                GetTypesOfAmmoInInventory();
                var ammoId = new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), ammo);

                if (_ammoSubtypesInInventory.Contains(ammo))
                {
                    _currentAmmoCount = CountItemsInInventory(ammoId);
                }
                else
                {
                    _currentAmmoCount = 0;

                    if (_weaponSystem.UseAmmoReplenish && _ammoMagazinesReloads < _weaponSystem.MaxAmmoReplenishments)
                    {
                        MyAmmoMagazineDefinition ammoMagDef = null;

                        if (Utilities.NormalAmmoMagReferences.TryGetValue(ammoId, out ammoMagDef))
                        {
                            _ammoMagazineDefinition = ammoMagDef;
                            _ammoReloadPending      = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        internal void Clean()
        {
            if (Monitors?.Count > 0)
            {
                for (int i = 0; i < Monitors.Count; i++)
                {
                    Monitors[i].Invoke(Target.FiringCube.EntityId, WeaponId, Id, Target.TargetId, Hit.LastHit, false);
                }

                System.Session.MonitoredProjectiles.Remove(Id);
            }
            Monitors = null;

            Target.Reset(System.Session.Tick, Target.States.ProjectileClosed);
            HitList.Clear();
            if (IsShrapnel)
            {
                if (VoxelCache != null && System.Session != null)
                {
                    System.Session.NewVoxelCache = VoxelCache;
                }
                else
                {
                    Log.Line($"IsShrapnel voxelcache return failure");
                }
            }

            if (PrimeEntity != null)
            {
                AmmoDef.Const.PrimeEntityPool.Return(PrimeEntity);
                PrimeEntity = null;
            }

            if (TriggerEntity != null)
            {
                System.Session.TriggerEntityPool.Return(TriggerEntity);
                TriggerEntity = null;
            }

            AvShot                 = null;
            System                 = null;
            Ai                     = null;
            MyPlanet               = null;
            MyShield               = null;
            AmmoDef                = null;
            WeaponCache            = null;
            VoxelCache             = null;
            IsShrapnel             = false;
            EwarAreaPulse          = false;
            EwarActive             = false;
            ModelOnly              = false;
            LockOnFireState        = false;
            IsFiringPlayer         = false;
            ClientSent             = false;
            InPlanetGravity        = false;
            TriggerGrowthSteps     = 0;
            WeaponId               = 0;
            MuzzleId               = 0;
            Age                    = 0;
            ProjectileDisplacement = 0;
            MaxTrajectory          = 0;
            ShotFade               = 0;
            TracerLength           = 0;
            FireCounter            = 0;
            AiVersion              = 0;
            UniqueMuzzleId         = 0;
            EnableGuidance         = true;
            Hit                    = new Hit();
            Direction              = Vector3D.Zero;
            VisualDir              = Vector3D.Zero;
            Origin                 = Vector3D.Zero;
            ShooterVel             = Vector3D.Zero;
            TriggerMatrix          = MatrixD.Identity;
        }