Setting up a Range Skeleton Archer?

Started by ninekorn, September 30, 2019, 12:05:49 PM

ninekorn

Hi,

I am almost done setting up the Skeleton Archer, I have the animations ready for the front, the back will take me about 1-2 hours to finish but the shooting doesn't work. Im not sure in which script I would indicate that the archer actually needs to shoot arrows?

I've got 3 scripts for each MOBS data, not including the spawning of them.

*MobSkeletonArcher.cs => General Data
*SkeletonSkeletonArcher.cs => Skeleton Data
*ItemWeaponSkeletonBow.cs => Mob Weapon Data - its set as a range weapon as i checked the pistols and other range weapons but the Skeleton actually shoot anything and no damage is done to the character.


So i still would need to setup arrow projectiles to be shot from the bow and to make the scripts actually tell the SkeletonArcher to Shoot...

Please help!

nine

ai_enabled

Hello!

Currently, we've not implemented support for ranged weapons to be used by NPCs/mobs. All creatures are using only melee "mob weapons". However, it's possible to implement a mob ranged weapon. Here is an example "bow" class:

namespace AtomicTorch.CBND.CoreMod.Items.Weapons.MobWeapons
{
    using System.Collections.Generic;
    using AtomicTorch.CBND.CoreMod.CharacterStatusEffects;
    using AtomicTorch.CBND.CoreMod.CharacterStatusEffects.Debuffs;
    using AtomicTorch.CBND.CoreMod.Items.Ammo;
    using AtomicTorch.CBND.CoreMod.Skills;
    using AtomicTorch.CBND.CoreMod.SoundPresets;
    using AtomicTorch.CBND.GameApi.Data.Characters;
    using AtomicTorch.CBND.GameApi.Data.Weapons;
    using AtomicTorch.GameEngine.Common.Helpers;

    public class ItemWeaponMobBow : ProtoItemWeaponRanged
    {
        public override ushort AmmoCapacity => 0; // no ammo used

        public override double AmmoReloadDuration => 0; // no ammo used

        public override uint DurabilityMax => 0;

        public override double FireAnimationDuration => 0.6;

        public override double FireInterval => 1.5;

        protected override ProtoSkillWeapons WeaponSkill => GetSkill<SkillWeaponsConventional>();

        protected override void PrepareMuzzleFlashDescription(MuzzleFlashDescription description)
        {
            description.Set(MuzzleFlashPresets.Default.Clone()
                                              .Set(textureAtlas: MuzzleFlashAtlases.AtlasSmokeLarge,
                                                   textureScreenOffset: (57, 7.5),
                                                   // no light flash
                                                   lightPower: 0));
        }

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

            overrideDamageDescription = new DamageDescription(
                damageValue: 20,
                armorPiercingCoef: 0,
                finalDamageMultiplier: 1,
                rangeMax: 11,
                damageDistribution: new DamageDistribution(DamageType.Impact, 1));
        }

        protected override ReadOnlySoundPreset<ObjectSoundMaterial> PrepareSoundPresetHit()
        {
            return MaterialHitsSoundPresets.MeleeSoftTissuesOnly;
        }

        protected override void ServerOnSpecialEffect(ICharacter damagedCharacter, double damage)
        {
            if (RandomHelper.RollWithProbability(0.15))
            {
                damagedCharacter.ServerAddStatusEffect<StatusEffectBleeding>(intensity: 0.1);
                damagedCharacter.ServerAddStatusEffect<StatusEffectPain>(intensity: 0.15);
            }
        }

        public override string Name => "Mob Bow";

        public override string Description => Name;
    }
}


It has a damage range of 11 tiles. Probably you would need to adjust Mob update code to make it not come closer as it can attack from such large distance. However, there is no pathfinding for mobs yet so they're going straight to their target.

Projectiles are not implementedΓÇöall ranged weapons currently are hit-scan, without any projectile graphics or shot traces.

Regards!

ninekorn

#2
Hi ai_enabled, thank you very much for your reply. I have another question then related to the same subject.

You have trees/objects/minerals/character-Mob sprites that can be displayed on the map. The characterMOBs can change position. Is there any other types of sprites that can be created from code which can change position except for characterMobs?

Otherwise i will study the API to create "characterMob" sprites that will be used as projectiles. Sorry for wanting to "hack" the code of Cryofall already but if i can create characterMob sprites as projectiles instantly when a mob "init shooting" then i can probably also make the "characterMobProjectile" sprites move towards the victim at a certain rate.

I will attempt to do something with that tonight after work.

EDIT: And depending on how the physics collision system works, i might be able to work on "exploding" the projectile on collision... I gotta learn how the collision of Cryofall works too at this point.

ai_enabled

That's a bit too far stretching hacking :-)

In theory you can make characters to act as projectiles, but it's a bad idea as character class has so much stuff into it (such as healthbar) that it will require a lot of modification in order to make it work...

For the next version we're going to add new generic class which is a better match for this purpose ΓÇö dynamic objects (we're using it for vehicle but the idea is to use it for projectiles as well).

Regarding the physics engineΓÇöthere are no collision events (yet?). It just ensures that objects are not passing one through another (so, for example, it's not possible to walk or shoot through a wall). But the scripting API for physics space provides methods for physical tests with lines and other shapes to detect whether there are any physical bodies.

Regarding the projectiles there is another problem which makes projectiles a problemΓÇöthe network delay. In CryoFall we have an advanced client lag prediction system so a client can simulate client movement without waiting for the server (no movement/action delay when you press any key, even if you're playing with a very large ping). But projectiles fired on the server will be displayed to client "in the past" (as they're received from the server) so there will be a case when client doesn't perceive to be hit by a projectile (due to client movement simulation) while the server is detecting a hit. It's a major problem as players will not perceive it as a fair game. Resolving this is not trivial...for a first-person game it's usually less of an issue, but in our game it will be fairly obvious for the player that the game is lagging and server is detecting hits which client cannot see, making the gameplay quite frustrating.
If you have no idea what I'm ranting about please watch https://www.youtube.com/watch?v=6EwaW2iz4iA and other videos on the lag prediction. It's a major headache for us and creates serious limitations on some ideas which might appear pretty simple to implement...

Regards!

ninekorn

#4
I've fiddled in the code for 5 hours straight this morning and learned a couple (more like a ton) of very interesting API functions. But it seems also that i am able to create physics object or assign a physics circle for instance to an object. I didn't try it yet but i'm really looking forward to see the ton of things the API of Cryofall can provide. Im barely just touching the surface here ;)

For instance, took me a while to find it... until i noticed the console was actually telling me what was missing from my attempt to get the "SingletonInstance of an object" for a while lol for mobs shooting.


var characterNpcPrivateState = character.GetPrivateState<CharacterMobPrivateState>();
bool someFiring = characterNpcPrivateState.WeaponState.IsFiring;
int someFiring = (int)characterNpcPrivateState.WeaponState.ShotsDone;


some pretty cool stuff

Edit: It actually feels really familiar the objects data, well not all of it, but until i create an object from code and assign it a sprite and a collider, i prefer not say that i know how to do it.