How to make an NPC use a fire scattern pattern

Started by MightyMonte88, December 14, 2020, 01:03:35 PM

MightyMonte88

Hey i setup my NPC system exactly as kallvin did with BasicNPC, however i have been unable to setup a mob to fire anything other than a single projectile...., below is a snippet of the weapon file the mob is using. This mod is supposed to fire pellet rounds from a military shotgun, but still fires a single projectile, any help would be greatly appreciated .




namespace AtomicTorch.CBND.CoreMod.Items.Weapons.MobWeapons
{
    using System.Collections.Generic;
    using AtomicTorch.CBND.CoreMod.Items.Ammo;
    using AtomicTorch.CBND.CoreMod.Systems.Weapons;
    using AtomicTorch.CBND.GameApi.Data.Weapons;
    using AtomicTorch.CBND.GameApi.Data.World;
    using AtomicTorch.CBND.CoreMod.SoundPresets;

    public class ItemWeaponMobShotgun_01 : ProtoItemMobWeaponArmed
    {
        public override string Name => "Military Shotgun";
        public override double FireInterval => 6;
        public override double DamageApplyDelay => 4;
        public override double AmmoReloadDuration => 3;
        public override double CharacterAnimationAimingRecoilDuration => 0.4;
        public override double CharacterAnimationAimingRecoilPower => 1.1;
        public override double FireAnimationDuration => 0.6;
        public override string CharacterAnimationAimingName => "WeaponRifleAiming";
        public override void SharedOnHit(
            WeaponFinalCache weaponCache,
            IWorldObject damagedObject,
            double damage,
            WeaponHitData hitData,
            out bool isDamageStop)
        {
            base.SharedOnHit(weaponCache,
                             damagedObject,
                             damage,
                             hitData,
                             out isDamageStop);
        }

        protected override WeaponFirePatternPreset PrepareFirePatternPreset()
        {
            return new WeaponFirePatternPreset(

                initialSequence: new[] { 0.0, 1.5 },
                cycledSequence: new[] { 3.0, 4.0, 5.0, 5.0 });
        }

        protected override void PrepareMuzzleFlashDescription(MuzzleFlashDescription description)
        {
            description.Set(MuzzleFlashPresets.ModernShotgun)
                       .Set(textureScreenOffset: (17, 10));
        }

        protected override void PrepareProtoWeaponRanged(
            out IEnumerable<IProtoItemAmmo> compatibleAmmoProtos,
            ref DamageDescription overrideDamageDescription)
        {
            compatibleAmmoProtos = null;

            var damageDistribution = new DamageDistribution()
                                     .Set(DamageType.Kinetic, 1);

            overrideDamageDescription = new DamageDescription(
                damageValue: 12,
                armorPiercingCoef: 0.2,
                finalDamageMultiplier: 5,
                rangeMax: 7,
                damageDistribution: damageDistribution);
        }
        protected override WeaponFireTracePreset PrepareFireTracePreset()
        {
            return WeaponFireTracePresets.Pellets;
        }
        protected override ReadOnlySoundPreset<WeaponSound> PrepareSoundPresetWeapon()
        {
            return WeaponsSoundPresets.WeaponRangedShotgunMilitary;
        }

    }
}

SavingPrivatePyle

While at it, is it possible to add an accuracy variable to them?  The rifle NPCs are crazy strong once they get into range because they hit every unobstructed shot.

ai_enabled

Hello!

To fire multiple projectiles, you need to override PrepareFireScatterPreset method. For example, see how the plasma rifle is implemented: https://github.com/AtomicTorchStudio/CryoFall/blob/4a652eb58121d9ff37711e2ee7323c6cae94d09c/Core.cpk/Scripts/Items/Weapons/Ranged/ItemPlasmaRifle.cs#L29

Regarding the randomized accuracy, override method SharedUpdateAndGetFirePatternCurrentSpreadAngleDeg like we've done for Fire Lizard poison spits:
https://github.com/AtomicTorchStudio/CryoFall/blob/4a652eb58121d9ff37711e2ee7323c6cae94d09c/Core.cpk/Scripts/Items/Weapons/MobWeapons/ItemWeaponLizardPoison.cs#L52

Regards!

MightyMonte88