예제 #1
0
 public void Fire(ServerShip ship, bool isLeft, int number, int idTarget, Ecm jammer)
 {
     lock (m_locker)
     {
         if (ship.Missiles == 0)
         {
             return;
         }
         var target = Ships.ById(idTarget);
         if (target == null || isLeft != ship.IsLeftBoard(target))
         {
             return;
         }
         var board        = isLeft ? ship.Left : ship.Right;
         var missileClass = board.GetRack(number).MissileClass;
         if (!board.Fire(number))
         {
             return;
         }
         ship.Missiles--;
         int id      = Interlocked.Increment(ref IdNext);
         var missile = new Missile
         {
             Id           = id,
             Position     = ship.Position,
             Speed        = ship.Speed,
             Acceleration = ship.Acceleration,
         };
         var control = new MissileControl
         {
             Id          = id,
             Arrow       = missile,
             Origin      = ship,
             Target      = target,
             IdOrigin    = ship.Id,
             IdTarget    = target.Id,
             Jammer      = jammer,
             Thrust      = missileClass.Acceleration,
             Remaining   = missileClass.FlyTime,
             HitDistance = missileClass.HitDistance,
             Started     = Time.TotalSeconds,
         };
         Missiles.Add(id, control);
     }
 }
예제 #2
0
        private void DamageShip(ServerShip ship, double damage)
        {
            var damages = new double[]
            {
                ship.ControlShip.EngineDamage,
                ship.ControlShip.NavigationDamage,
                ship.ControlShip.AttackDamage,
                ship.ControlShip.DefenseDamage,
            };

            for (int i = 0; i < damages.Length; i++)
            {
                damages[i] = Math.Min(1, damages[i] + damage * Random.NextDouble());
            }
            ship.ControlShip.EngineDamage     = damages[0];
            ship.ControlShip.NavigationDamage = damages[1];
            ship.ControlShip.AttackDamage     = damages[2];
            ship.ControlShip.DefenseDamage    = damages[3];
            ship.VolatileShip.HealthRate      = 1 - damages.Sum() / damages.Length;
            ship.UpdateHealth(Time.TotalSeconds);
        }
예제 #3
0
 private void DestroyShip(ServerShip ship)
 {
     ship.VolatileShip = null;
 }
예제 #4
0
 public void Logout()
 {
     ship = null;
 }