Example #1
0
        internal override void ProcessEntity(Entity beamWeapon, DateTime atDate)
        {
            WeaponInstanceStateDB stateInfo = beamWeapon.GetDataBlob <WeaponInstanceStateDB>();

            if (stateInfo.FireControl != null)
            {
                FireControlInstanceStateDB fireControl = stateInfo.FireControl.GetDataBlob <FireControlInstanceStateDB>();
                if (fireControl.IsEngaging)
                {
                    if (!stateInfo.ReadyToFire)
                    {
                        if (stateInfo.CoolDown <= atDate)
                        {
                            stateInfo.ReadyToFire = true;
                            FireBeamWeapons(beamWeapon, atDate);
                        }
                    }
                    else
                    {
                        FireBeamWeapons(beamWeapon, atDate);
                    }
                    if (fireControl.IsEngaging)
                    {
                        beamWeapon.Manager.ManagerSubpulses.AddEntityInterupt(stateInfo.CoolDown, nameof(WeaponProcessor), beamWeapon);
                    }
                }
            }
        }
Example #2
0
        public static void FireBeamWeapons(Entity beamWeapon, DateTime atDate)
        {
            WeaponInstanceStateDB      stateInfo   = beamWeapon.GetDataBlob <WeaponInstanceStateDB>();
            FireControlInstanceStateDB fireControl = stateInfo.FireControl.GetDataBlob <FireControlInstanceStateDB>();

            if (!fireControl.Target.IsValid)
            {
                fireControl.Target     = null;
                fireControl.IsEngaging = false;
                return;
            }

            var myPos     = beamWeapon.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>();
            var targetPos = fireControl.Target.GetDataBlob <PositionDB>();


            //TODO chance to hit
            //int damageAmount = 10;//TODO damageAmount calc
            var designAtb    = beamWeapon.GetDataBlob <DesignInfoDB>().DesignEntity.GetDataBlob <SimpleBeamWeaponAtbDB>();
            int damageAmount = designAtb.DamageAmount; // TODO: Better damage calculation

            double range = myPos.GetDistanceTo(targetPos);

            // only fire if target is in range TODO: fire anyway, but miss. TODO: this will be wrong if we do movement last, this needs to be done after movement.
            if (range <= designAtb.MaxRange)//TODO: firecontrol shoudl have max range too?: Math.Min(designAtb.MaxRange, stateInfo.FireControl.GetDataBlob<BeamFireControlAtbDB>().Range))
            {
                DamageProcessor.OnTakingDamage(fireControl.Target, damageAmount, atDate);
                int reloadRate = designAtb.ReloadRate;
                stateInfo.CoolDown    = atDate + TimeSpan.FromSeconds(reloadRate);
                stateInfo.ReadyToFire = false;
            }
        }
Example #3
0
 public WeaponInstanceStateDB(WeaponInstanceStateDB db)
 {
     CoolDown    = db.CoolDown;
     FireControl = db.FireControl;
 }