Esempio n. 1
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;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// process balistic movement for a single system
        /// currently is not affected by gravity.
        /// </summary>
        /// <param name="manager">the system to process</param>
        internal static void Process(EntityManager manager)
        {
            TimeSpan orbitCycle = manager.Game.Settings.OrbitCycleTime;
            DateTime toDate     = manager.ManagerSubpulses.SystemLocalDateTime + orbitCycle;

            manager.ManagerSubpulses.AddSystemInterupt(toDate + orbitCycle, PulseActionEnum.BalisticMoveProcessor);

            List <Entity>     RemoveList   = new List <Entity>();
            List <StarSystem> RemoveSystem = new List <StarSystem>();

            foreach (Entity objectEntity in manager.GetAllEntitiesWithDataBlob <NewtonBalisticDB>())
            {
                NewtonBalisticDB balisticDB = objectEntity.GetDataBlob <NewtonBalisticDB>();
                PositionDB       position   = objectEntity.GetDataBlob <PositionDB>();
                position.RelativePosition += Distance.KmToAU(balisticDB.CurrentSpeed * orbitCycle.TotalSeconds);

                Entity     myTarget  = manager.GetLocalEntityByGuid(balisticDB.TargetGuid);
                PositionDB targetPos = myTarget.GetDataBlob <PositionDB>();

                if (targetPos.AbsolutePosition == position.AbsolutePosition)
                {
                    //do something in damage processor for asteroid hitting a planet?
                    DamageProcessor.OnTakingDamage(myTarget, 1000000); ///one. million. damage points.

                    StarSystem mySystem;
                    if (!manager.Game.Systems.TryGetValue(position.SystemGuid, out mySystem))
                    {
                        throw new GuidNotFoundException(position.SystemGuid);
                    }

                    RemoveList.Add(objectEntity);
                    RemoveSystem.Add(mySystem);

                    mySystem.SystemManager.RemoveEntity(objectEntity); //get rid of the asteroid
                }
            }

            /// <summary>
            /// Clean up the asteroids that have hit something and been put in the remove list.
            /// </summary>
            for (int removeIterator = 0; removeIterator < RemoveList.Count; removeIterator++)
            {
                RemoveSystem[removeIterator].SystemManager.RemoveEntity(RemoveList[removeIterator]);
            }

            /// <summary>
            /// This may not be necessary but clear these two lists.
            /// </summary>
            RemoveList.Clear();
            RemoveSystem.Clear();
        }
Esempio n. 3
0
        public static void FireBeamWeapons(StarSystem starSys, Entity beamWeapon)
        {
            WeaponStateDB stateInfo = beamWeapon.GetDataBlob <WeaponStateDB>();
            FireControlInstanceAbilityDB fireControl = stateInfo.FireControl.GetDataBlob <FireControlInstanceAbilityDB>();

            // only fire if the beam weapon is finished with its cooldown
            if (stateInfo.CoolDown <= TimeSpan.FromSeconds(0) && stateInfo.FireControl != null && fireControl.IsEngaging)
            {
                //TODO chance to hit
                //int damageAmount = 10;//TODO damageAmount calc
                int damageAmount = beamWeapon.GetDataBlob <BeamWeaponAtbDB>().BaseDamage; // TODO: Better damage calculation

                double range = fireControl.Target.GetDataBlob <PositionDB>().GetDistanceTo(beamWeapon.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity.GetDataBlob <PositionDB>());

                // only fire if target is in range
                if (range <= Math.Min(beamWeapon.GetDataBlob <BeamWeaponAtbDB>().MaxRange, stateInfo.FireControl.GetDataBlob <BeamFireControlAtbDB>().Range))
                {
                    DamageProcessor.OnTakingDamage(stateInfo.FireControl, damageAmount);
                    stateInfo.CoolDown = TimeSpan.FromSeconds(beamWeapon.GetDataBlob <BeamWeaponAtbDB>().PowerRechargeRate);
                    starSys.SystemManager.ManagerSubpulses.AddEntityInterupt(starSys.SystemManager.ManagerSubpulses.SystemLocalDateTime + stateInfo.CoolDown, PulseActionEnum.SomeOtherProcessor, beamWeapon);
                }
            }
        }