示例#1
0
 public Projectile(ICanFire firingObject, int projectileID)
 {
     ID           = projectileID;
     FiringObject = firingObject;
     CreationTime = TimeKeeper.MsSinceInitialization;
     Lifetime     = 20000;
 }
示例#2
0
        //protected override float _rotation { get { return _body.Rotated; } set { _body.Rotated = _rotation; } }
        //public override float Rotated { get { return _body.Rotated; } set { _body.Rotated = value; } }


        public Missile(CollisionManager collisionManager, World w, int ID, ICanFire firingObj, bool isLocalSim, ParticleManager pm, byte firingWeaponSlot)
            : base(collisionManager, ID, firingWeaponSlot)
        {
            Stats = new StatType();

            Debugging.AddStack.Push(this.ToString());
            Body              = BodyFactory.CreateCircle(w, .1f, 10);
            Body.IsKinematic  = true;
            Body.IsBullet     = false;
            Body.IsStatic     = false;
            Body.UserData     = new ProjectileBodyDataObject(BodyTypes.Missile, ID, firingObj, this);
            Body.OnCollision += _body_OnCollision;
            _world            = w;

            FiringObj = firingObj;

            _particleManager = pm;

            Health = 100;


            TerminationEffect = ParticleEffectType.ExplosionEffect;
            IsLocalSim        = isLocalSim;
            //_pilot = new MissilePilot(this, 5);
            _pilot = new MissilePilotLv2(this, 5);

            PotentialTargets = new Dictionary <int, ITargetable>();
            Teams            = firingObj.Teams;
            _currentTurnRate = Stats.BaseTurnRate;
            _currentThrust   = Stats.BaseThrust;
            _creationTime    = TimeKeeper.MsSinceInitialization;
        }
示例#3
0
        /// <summary>
        /// Does nothing if object is dead
        /// </summary>
        /// <param name="hitObject"></param>
        /// <param name="firingObject"></param>
        /// <param name="projectileType"></param>
        /// <param name="pctCharge"></param>
        /// <param name="weaponSlot"></param>
        /// <param name="projectileID"></param>
        void DamageObject(ICollidable hitObject, ICanFire firingObject, ProjectileTypes projectileType, byte pctCharge, byte weaponSlot, int projectileID)
        {
            hitObject.TimeOfLastCollision = TimeKeeper.MsSinceInitialization;
            float multiplier = 1;

            if (firingObject is IShip)
            {
                multiplier = ((IShip)firingObject).StatBonuses[StatBonusTypes.Damage] / (1 + ((IShip)firingObject).Debuffs[DebuffTypes.Damage]);
            }

            Weapon firingWeapon = firingObject.GetWeapon(weaponSlot);
            Dictionary <DebuffTypes, int> debuffsAdded = null;

            if (firingWeapon != null && firingWeapon.DebuffType != DebuffTypes.None)
            {
                debuffsAdded = new Dictionary <DebuffTypes, int>();
                debuffsAdded.Add(firingWeapon.DebuffType, firingWeapon.DebuffCount);
                hitObject.Debuffs.AddDebuff(firingWeapon.DebuffType, firingWeapon.DebuffCount, TimeKeeper.MsSinceInitialization);
            }

            //WARNING: Concurrent processing may cause this to take damage more than once for the same collision
            bool isDead = hitObject.TakeDamage(projectileType, pctCharge, multiplier);

            if (isDead && hitObject is IKillable)
            {
                _killManager.Kill((IKillable)hitObject, firingObject);
            }
            else
            {
                if (hitObject is IShip)
                {
                    _messageManager.SendShipDamage((IShip)hitObject, debuffsAdded);
                }
            }
        }
示例#4
0
 public Weapon(ProjectileManager projectileManager, byte slot, ICanFire holdingObj)
 {
     DebuffType         = DebuffTypes.None;
     Slot               = slot;
     HoldingObj         = holdingObj;
     _projectileManager = projectileManager;
     timeSinceLastShot  = float.MaxValue;
 }
示例#5
0
        public PlasmaCannon(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
            : base(projectileManager, slot, holdingObj)
        {
            if (!(holdingObj is Ship))
            {
                ConsoleManager.WriteLine("WARNING: Chargable weapons are not yet implemented for non-ship objects! Crashes imminent!", ConsoleMessageType.Warning);
            }

            Stats = new PlasmaCannonStats();
        }
示例#6
0
 /// <summary>
 /// ProjectileIDs must be unique
 /// </summary>
 /// <param name="firingObject"></param>
 /// <param name="firingRotation">rotation of fired weapon</param>
 /// <param name="firingWeaponSlot"></param>
 /// <param name="pctCharge"></param>
 /// <param name="sendToServer"></param>
 /// <param name="projectileType"></param>
 public ProjectileRequest(ICanFire firingObject, float firingRotation, byte firingWeaponSlot, byte pctCharge, bool sendToServer, ProjectileTypes projectileType)
 {
     _projectileData  = new List <ProjectileData>();
     _projectileIDs   = new List <int>();
     FiringObj        = firingObject;
     SendToServer     = sendToServer;
     FiringWeaponSlot = firingWeaponSlot;
     PctCharge        = pctCharge;
     ProjectileType   = projectileType;
     FiringRotation   = firingRotation;
 }
示例#7
0
        /// <summary>
        /// Creates a projectile, returns projectileID
        /// If there is a projectileID collision, the projectile will simply be discarded
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        public int CreateProjectile(ICanFire ship, int projectileID)
        {
            var tempProj = new Projectile(ship, projectileID);

            if (!idToProjectile.TryAdd(tempProj.ID, tempProj))
            {
                ConsoleManager.WriteLine("Proj Collision " + tempProj.ID, ConsoleMessageType.Warning);
            }
            //ConsoleManager.WriteToFreeLine("Projectiles: " + idToProjectile.Count.ToString());

            return(projectileID);
        }
示例#8
0
        public virtual void StructureFired(ICanFire firingStructure, float rotation, List <int> projectileIDs, IProjectileManager pm, byte percentCharge, byte weaponSlot)
        {
            foreach (var id in projectileIDs)
            {
                pm.CreateProjectile(firingStructure, id);
            }

            var messageData = new MessageObjectFired {
                ObjectType = FiringObjectTypes.Structure, FiringObjectID = firingStructure.Id, PercentCharge = percentCharge, Rotation = rotation, WeaponSlot = weaponSlot, ProjectileIDs = projectileIDs
            };

            BroadcastMessage(new NetworkMessageContainer(messageData, MessageTypes.ObjectFired), null);
        }
示例#9
0
        public IKillable Kill(IKillable obj, ICanFire killingObject)
        {
            if (obj is IShip)
            {
                KillShip((IShip)obj, killingObject);
            }
            else if (obj is Turret)
            {
                KillTurret((Turret)obj);
            }
            else
            {
                throw new Exception("Kill not implemented in KillManager for object of type " + obj.GetType());
            }


            return(obj);
        }
示例#10
0
 void Awake()
 {
     fireInput         = GetComponent <ICanFire>();
     fireInput.OnFire += HandleFire;
 }
示例#11
0
        public void CreateProjectile(ProjectileTypes type,
                                     Vector2 position, Vector2 velocityOffset, float rotation,
                                     int projectileID, ICanFire firingObj, float charge, byte firingWeaponSlot)
        {
            IProjectile proj = null;

            Vector2 projectileVelocity = new Vector2(velocityOffset.X / 1000f + (float)(Math.Sin(rotation)) * _flyweights[type].BaseSpeed / 1000f,
                                                     velocityOffset.Y / 1000f - (float)(Math.Cos(rotation)) * _flyweights[type].BaseSpeed / 1000f);


            if (firingObj is Turret)
            {
                proj = new TurretLaser(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, ((Turret)firingObj).TurretType, _world);

                proj.BodyData = new ProjectileBodyDataObject(BodyTypes.Projectile, projectileID, firingObj, proj);
            }
            else
            {
                switch (type)
                {
                case ProjectileTypes.Laser:
                    proj = new LaserProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world);

                    break;

                case ProjectileTypes.LaserWave:
                    proj = new LaserWaveProjectile(_collisionManager, _particleManager, projectileVelocity, _spriteBatch, projectileID, firingWeaponSlot, _world);

                    break;

                case ProjectileTypes.PlasmaCannon:
                    proj = new PlasmaCannonProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world, charge);

                    break;

                case ProjectileTypes.BC_Laser:
                    proj = new BC_LaserProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world);
                    break;

                case ProjectileTypes.GravityBomb:
                    proj = new GravityBombProjectile(_collisionManager, _particleManager, projectileVelocity, firingObj, _world, projectileID, firingWeaponSlot, position);
                    break;

                case ProjectileTypes.MineSplash:
                    proj = new MineSplash(position, _world, _collisionManager, projectileID, firingWeaponSlot);
                    break;

                default:
                    ConsoleManager.WriteLine("ERROR: ProjectileType " + type + " not implemented in ProjectileManager.CreateProjectile().", ConsoleMessageType.Error);
                    break;
                }

                // Proj could be null here, but it should be an easy catch if we forget to add a switch case and it breaks
                proj.BodyData = new ProjectileBodyDataObject(BodyTypes.Projectile, projectileID, firingObj, proj);
            }



            proj.LinearVelocity = projectileVelocity;
            proj.Rotation       = rotation;
            proj.Position       = position;
            proj.Id             = projectileID;

            _projectileList.Add(proj);
        }
示例#12
0
        public void CreateMissile(ProjectileTypes projectileType,
                                  Vector2 position, Vector2 velocityOffset, float rotation,
                                  int projectileID, ICanFire firingObj, bool isLocalSim, byte firingWeaponSlot)
        {
            IMissile proj = null;


            if (firingObj is Turret)
            {
                ConsoleManager.WriteLine("ERROR: Missiles not implemented for turrets in ProjectileManager.CreateMissile().", ConsoleMessageType.Error);
            }
            else
            {
                switch (projectileType)
                {
                case ProjectileTypes.AmbassadorMissile:
                {
                    proj = new Missile <AmbassadorProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }


                case ProjectileTypes.HellHoundMissile:
                {
                    proj = new Missile <HellhoundProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }

                case ProjectileTypes.MissileType1:
                {
                    proj = new Missile <MissileType1ProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }

                case ProjectileTypes.MissileType2:
                {
                    proj = new Missile <MissileType2ProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }

                case ProjectileTypes.MissileType3:
                {
                    proj = new Missile <MissileType3ProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }

                case ProjectileTypes.MissileType4:
                {
                    proj = new Missile <MissileType4ProjectileStats>(_collisionManager, _world, projectileID, firingObj, isLocalSim, _particleManager, firingWeaponSlot);
                    _simulationManager.StartSimulating(proj);
                    _targetingManager.RegisterObject(proj);
                    break;
                }

                default:
                    ConsoleManager.WriteLine("ERROR: ProjectileType " + projectileType + " not implemented in ProjectileManager.CreateProjectile().", ConsoleMessageType.Error);
                    break;
                }
                velocityOffset = new Vector2(velocityOffset.X / 1000f + (float)(Math.Sin(rotation)) * _flyweights[projectileType].BaseSpeed / 1000f,
                                             velocityOffset.Y / 1000f - (float)(Math.Cos(rotation)) * _flyweights[projectileType].BaseSpeed / 1000f);

                //Proj could be null here, but it should be an easy catch if we forget to add a switch case and it breaks
                proj.BodyData = new ProjectileBodyDataObject(BodyTypes.Projectile, projectileID, firingObj, proj);
            }



            proj.LinearVelocity    = velocityOffset;
            proj.Rotation          = rotation;
            proj.Position          = position;
            ((IProjectile)proj).Id = projectileID;
            _projectileList.Add(proj);
        }
示例#13
0
 public GravBomber(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, holdingObj, slot)
 {
     Stats = new GravBomberStats();
 }
示例#14
0
 public MineWeapon(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, slot, holdingObj)
 {
     Stats = new MineWeaponStats();
 }
示例#15
0
 public LaserWave(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, slot, holdingObj)
 {
     Stats = new LaserWaveStats();
 }
示例#16
0
 public HurrDurr(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, holdingObj, slot)
 {
     Stats = new HurrDurrStats();
 }
示例#17
0
 public ProjectileBodyDataObject(BodyTypes type, int ID, ICanFire ship, IProjectile bullet)
     : base(bullet, type)
 {
     this.FiringObj = ship;
     this.Bullet    = bullet;
 }
示例#18
0
 public BC_Laser(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, holdingObj, slot)
 {
     Stats = new BC_LaserStats();
 }
示例#19
0
        public IShip KillShip(IShip s, ICanFire killingObject)
        {
            if (s.IsDead)
            {
                ConsoleManager.WriteLine("Killing a ship which was already dead.", ConsoleMessageType.Warning);
                return(s);
            }


            s.IsDead           = true;
            s.KillTimeStamp    = TimeKeeper.MsSinceInitialization;
            s.RespawnTimeDelay = 3000;//TODO: This will be a problem later, if a IShip warps into a new system where a dead IShip is waiting to respawn, the warping IShip will see a live ship. Needs to be fully implemented.
            s.CurrentHealth    = 0;

            if (s.GetPlayer().IsTrading)
            {
                _tradeTerminator.TerminateTrade(s.Id, true);
            }

            var currentArea = s.GetArea();

            if (currentArea.NumOnlinePlayers > 0)
            {
                MessageRemoveKillRevive msgData = new MessageRemoveKillRevive();
                msgData.ActionType = ActionType.Kill;
                msgData.ObjectType = RemovableObjectTypes.Ship;
                msgData.ObjectIDs.Add(s.Id);

                currentArea.BroadcastMessage(new NetworkMessageContainer(msgData, MessageTypes.RemoveKillRevive));

                // Send chat messages
                if (killingObject is IShip)
                {
                    ((IShip)killingObject).GetPlayer().PlayersKilled++;
                    var killingPlayer = ((IShip)killingObject).GetPlayer();

                    killingPlayer.PlayersKilled++;

                    var killText = string.Format("{0} was shot down by {1}!", s.GetPlayer().Username, killingPlayer.Username);

                    _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None);
                }
                else if (killingObject is Turret)
                {
                    _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.PlayersKilled++;

                    var killedPlayer = s.GetPlayer();

                    var defensesOwner = _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.Username;

                    var killText = string.Format("{0} was shot down by defenses of {1}!", killedPlayer.Username, defensesOwner);

                    _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None);
                }
            }

            #region Modules
            //For now, just make the ship drop one mod to space. Later we'll figure out how many to destroy/keep with the ship
            var moduleToRemove = s.Cargo.GetAnyStatefulCargo(StatefulCargoTypes.Module);
            if (moduleToRemove != null)
            {
                var ct = new TransactionRemoveStatefulCargo(s, StatefulCargoTypes.Module, moduleToRemove.Id);
                ct.OnCompletion += s.CargoRemoved;
                ct.OnCompletion += _messageManager.NotifyCargoRemoved;
                ct.OnCompletion += _addCargoToArea;


                var mod = moduleToRemove as Module;
                mod.PosX       = s.PosX;
                mod.PosY       = s.PosY;
                mod.Rotation   = s.Rotation;
                mod.NextAreaID = (int)s.CurrentAreaId;

                _cargoSynchronizer.RequestTransaction(ct);
            }


            #endregion


            s.CurrentHealth = s.ShipStats.MaxHealth;
            //s.IsDead = false;
            float tempx = 0;
            float tempy = 0;
            SpatialOperations.GetRandomPointInRadius(ref tempx, ref tempy, 10, 20);

            s.PosX = tempx;
            s.PosY = tempy;


            return(s);
        }
示例#20
0
        public GravityBombProjectile(CollisionManager collisionManager, ParticleManager particleManager, Vector2 velocity, ICanFire firingObj, World world, int id, byte firingWeaponSlot, Vector2 position)
            : base(collisionManager, id, firingWeaponSlot)
        {
            _particleManager = particleManager;
            Debugging.AddStack.Push(this.ToString());
            Body                = BodyFactory.CreateCircle(world, 1, 1);
            Body.UserData       = new ProjectileBodyDataObject(BodyTypes.Projectile, id, firingObj, this);
            Body.OnCollision   += Body_OnCollision;
            Body.LinearVelocity = velocity;



            _gravityObject = new GravityObject(position, Stats.InitialGravityVal);
            bodiesInArea   = new List <Body>();

            //This is kind of cheating, but it should be OK for now. Just make sure to check if the body is valid (check body.IsDisposed) before doing anything with it to avoid farseer exceptions
            foreach (Body b in world.BodyList)
            {
                CollisionDataObject bdo = b.UserData as CollisionDataObject;

                if (bdo != null)
                {
                    if (bdo.BodyType == BodyTypes.Ship || bdo.BodyType == BodyTypes.NetworkShip || bdo.BodyType == BodyTypes.PlayerShip || bdo.BodyType == BodyTypes.Missile)
                    {
                        bodiesInArea.Add(b);
                    }
                }
            }


            flipPoints = new List <float>(Stats.NumFlips);
            for (int i = 0; i < Stats.NumFlips; i++)
            {
                flipPoints.Add(Stats.NonGravityFraction + ((1 - Stats.NonGravityFraction) / Stats.NumFlips * (i + 1)));
            }
        }
示例#21
0
 public ChargableWeapon(ProjectileManager projectileManager, byte slot, ICanFire holdingObj) : base(projectileManager, slot, holdingObj)
 {
 }
示例#22
0
 public NullWeapon(ICanFire holdingObject)
     : base(null, 0, holdingObject)
 {
     Stats = new NoneWeaponStats();
 }
示例#23
0
 public void Initialize(Vector2 velocityTarget, float dragCoefficient, ICanFire fireInputController)
 {
     Initialize(velocityTarget, dragCoefficient);
     fireInput            = fireInputController;
     fireInput.OnAltFire += DetonateSelf;
 }
示例#24
0
 public NaniteLauncher(ProjectileManager projectileManager, ICanFire holdingObj, byte slot)
     : base(projectileManager, slot, holdingObj)
 {
     Stats = new NaniteLauncherStats();
 }