private static void BuildHardPoints(IIdResolver resolver, Ship ship, IEnumerable<HardPointState> hardPoints) { if ( hardPoints == null ) return; ship._hardPoints.AddRange(hardPoints.Select(h => HardPoint.Builder.Build(resolver, ship, h))); }
public void TestMovesMaxPossible() { var ship = new Ship(new Corporation()); var hardPoint = new HardPoint(ship, HardPointPosition.Right); var aimAt = new Location(1, -1, 0); // 45* back Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved 45* Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4)); // assert we moved back Assert.Less(hardPoint.Orientation.Y, 0d); aimAt = new Location(1, 1, 0); // 45* forward Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved back to origin Assert.AreEqual(hardPoint.Origin, hardPoint.Orientation); aimAt = new Location(1, 1, 0); // 45* forward Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved 45* Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4)); // assert we moved back Assert.Greater(hardPoint.Orientation.Y, 0d); aimAt = new Location(1, -1, 0); // 45* back Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved back to origin Assert.AreEqual(hardPoint.Origin, hardPoint.Orientation); }
public void JumpGates() { var universe = new Universe(); var sol = new SolarSystem { Name = "Sol", Location = universe }; var outOfSol = new JumpGate(sol); sol.OrbitSun(outOfSol, 45d); var alphaCentauri = new SolarSystem {Name = "Alpha Centauri", UniversalCoordinates = new Vector(1000d, 0, 0), Location = universe }; var intoAlphaCentauri = new JumpGate(alphaCentauri); alphaCentauri.OrbitSun(intoAlphaCentauri, 45d); outOfSol.ConnectsTo = intoAlphaCentauri; var ship = new Ship(new Agent(new Corporation())) {Speed = 2d }; sol.EnterSystem(ship, outOfSol.LocalCoordinates); Assert.AreEqual(sol, ship.SolarSystem); Assert.AreEqual(outOfSol.UniversalCoordinates, ship.UniversalCoordinates); CollectionAssert.Contains(sol.Objects, ship); CollectionAssert.DoesNotContain(alphaCentauri.Objects, ship); outOfSol.Jump(ship); Assert.AreEqual(alphaCentauri, ship.SolarSystem); CollectionAssert.DoesNotContain(sol.Objects, ship); CollectionAssert.Contains(alphaCentauri.Objects, ship); Assert.AreEqual(intoAlphaCentauri.UniversalCoordinates, ship.UniversalCoordinates); }
public void CantUndockWithoutShipSkillLevel() { var structure = new Manufactory(); var ship = new Ship { Position = new Position(structure, Vector.Zero), ShipInfo = GetShipInfo() }; var pilot = new Agent { Skills = { { SkillCode.SpaceshipCommand, new Echo.Agents.Skills.SkillLevel { Level = 1 } } } }; _task.SetParameters(new UndockShipParameters(ship, pilot)); var result = (UndockShipResult)_task.Execute(); Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.MissingSkillRequirement)); }
public void CantJumpWhenNotInRange() { var position = new Position(new SolarSystem(), Vector.Parse("0,1,0")); var jumpGate = new JumpGate { Position = position }; var ship = new Ship { Position = position + Vector.Parse("1,0,0"), Pilot = new Agent() }; _task.SetParameters(new JumpShipParameters(ship, jumpGate)); var result = (JumpShipResult)_task.Execute(); Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.NotInPosition)); }
public bool Dock(Ship ship) { AssertShipInRange(ship, "dock with this station"); this.ships.Add(ship); this.personnel.Add(ship.Pilot); ship.Pilot = null; ship.ClearCurrentTask(); return true; }
public void CantUndockWithoutShipSkill() { var structure = new Manufactory(); var ship = new Ship { Position = new Position(structure, Vector.Zero), ShipInfo = GetShipInfo() }; var pilot = _universe.John.StandUp(); pilot.Skills[SkillCode.SpaceshipCommand].Level = 0; _task.SetParameters(new UndockShipParameters(ship, pilot)); var result = (UndockShipResult)_task.Execute(); Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.MissingSkillRequirement)); }
/// <summary>Jumps a ship away from this gate</summary> /// <param name="ship">Ship to jump</param> public void Jump(Ship ship) { if (ship == null) throw new ArgumentNullException("ship"); if (ConnectsTo == null) throw new InvalidOperationException("This gate is an incomming gate only"); ship.SolarSystem.LeaveSystem(ship); ConnectsTo.SolarSystem.EnterSystem(ship, ConnectsTo.LocalCoordinates); Universe.EventPump.RaiseEvent(ship, EventType.ShipJump, "Jumped from {0} to {1} in {2}", Name, ConnectsTo.Name, ConnectsTo.SolarSystem.Name); }
public void Extremes() { var ship = new Ship(new Corporation()); var hardPoint = new HardPoint(ship, HardPointPosition.Right); var aimAt = new Location(-1, 1, 0); // 135* forward Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); hardPoint = new HardPoint(ship, HardPointPosition.Front) { Speed = 1d }; aimAt = new Location(0, -1, 0); // 180* backward Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); }
public static ShipState Save(Ship ship) { return new ShipState { ObjectId = ship.Id, Name = ship.Name, Code = ship.ShipInfo.Code, Heading = ship.Heading, LocalCoordinates = ship.Position.LocalCoordinates, Statistics = ship.Statistics.Select(Save), HardPoints = ship.HardPoints.Save(), Pilot = ship.Pilot.Save(), }; }
public void CanUndockWithShipSkill() { var solarSystem = new SolarSystem(); var structure = new Manufactory { Position = new Position(solarSystem, Vector.Parse("0,1,0")) }; var ship = new Ship { Position = new Position(structure, Vector.Zero), ShipInfo = GetShipInfo() }; var pilot = new Agent { Skills = { { SkillCode.SpaceshipCommand, new Echo.Agents.Skills.SkillLevel { Level = 5 } } } }; _task.SetParameters(new UndockShipParameters(ship, pilot)); var result = _task.Execute(); Assert.That(result.Success, Is.True, result.StatusCode); Assert.That(ship.Position.LocalCoordinates, Is.EqualTo(structure.Position.LocalCoordinates)); Assert.That(ship.Position.Location, Is.EqualTo(solarSystem)); }
public void CanJumpWhenInRange() { var position = new Position(new SolarSystem(), Vector.Parse("0,1,0")); var ship = new Ship { Position = position, Pilot = new Agent() }; var target = new JumpGate {Position = new Position(new SolarSystem(), Vector.Parse("-1,1,0"))}; var jumpGate = new JumpGate { Position = position, ConnectsTo = target }; _task.SetParameters(new JumpShipParameters(ship, jumpGate)); var result = _task.Execute(); Assert.That(result.Success, Is.True, result.StatusCode); Assert.That(ship.Position.LocalCoordinates, Is.EqualTo(target.Position.LocalCoordinates)); Assert.That(ship.Position.Location, Is.EqualTo(target.Position.Location)); }
public void IntraSolarSystem() { var universe = new Universe(); var sol = new SolarSystem { Location = universe }; var ship = new Ship(new Agent(new Corporation())) {Speed = 2d, Name = "S1" }; sol.EnterSystem(ship, new Vector(10, 0, 0)); ship.Destination = Vector.Zero; for (int i=10; i >= 0; i-=2) { Assert.AreEqual(i, ship.DistanceToDestination, "Ship is heading in the wrong direction!"); ship.Tick((uint )i); } }
/// <summary>Mines this asteroid belt for ore</summary> /// <param name="ship">Ship to load ore onto</param> /// <returns>True if the ship has completed its mining operation (cargo hold is full)</returns> public bool Mine(Ship ship) { AssertShipInRange(ship, "mine this asteroid belt"); var ore = new Ore(); var oreQuantity = (uint) Math.Floor(ship.CargoHoldRemaining/ore.SizePerUnit); ore.Quantity = Min(Rand.Next(Richness / 2, Richness), oreQuantity, AmountRemaining); ore.Owner = ship.Owner; ship.AddCargo(ore); AmountRemaining -= ore.Quantity; Universe.EventPump.RaiseEvent(ship, EventType.ShipCargo, "Mined {0:n0} ore from {1}", ore.Quantity, Name); return (ship.CargoHoldRemaining < ore.SizePerUnit); }
public void CantUndockWhenNotDocked() { var ship = new Ship(); var pilot = new Agent(); _task.SetParameters(new UndockShipParameters(ship, pilot)); var result = (UndockShipResult )_task.Execute(); Assert.That(result.Success, Is.False); Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.NotDocked)); ITaskResult taskResult = result; Assert.That(taskResult.StatusCode, Is.EqualTo("NotDocked")); Assert.That(taskResult.ErrorParams, Has.Property("Ship").EqualTo(ship)); Assert.That(taskResult.ErrorParams, Has.Property("Pilot").Null); }
public void CantJumpWithNoPilot() { var ship = new Ship(); var jumpGate = new JumpGate(); _task.SetParameters(new JumpShipParameters(ship, jumpGate)); var result = (JumpShipResult )_task.Execute(); Assert.That(result.Success, Is.False); Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.NoPilot)); ITaskResult taskResult = result; Assert.That(taskResult.StatusCode, Is.EqualTo("NoPilot")); Assert.That(taskResult.ErrorParams, Has.Property("Ship").EqualTo(ship)); Assert.That(taskResult.ErrorParams, Has.Property("JumpGate").EqualTo(jumpGate)); Assert.That(taskResult.ErrorParams, Has.Property("Pilot").Null); }
public void MaxExtents() { var ship = new Ship(new Corporation()); var hardPoint = new HardPoint(ship, HardPointPosition.Right); var aimAt = new Location(1, 1, 0); // 45* forward Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); hardPoint.Reset(); aimAt = new Location(1, -1, 0); // 45* behind Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // now test we can't move further downward aimAt = new Location(1, -1.1d, 0); Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); }
public void SetUp() { _shieldInfo = new ShieldInfo() { Statistic = ShipStatistic.EnergyArmourStrength, RepairPerTick = 5d }; _ship = new Ship() { Statistics = new ShipStatistics(new[] { new StatisticValue<ShipStatistic, double>( ShipStatistic.EnergyArmourStrength, value: 100d ), new StatisticValue<ShipStatistic, double>( ShipStatistic.BallisticArmourStrength, value: 100d ), }) }; }
public void GetSolarSystem() { var s = new MockUniverse(); Assert.That(s.Universe.StarClusters, Is.Not.Empty); var builder = Universe.Builder.Build(s.Universe); builder.Add(Corporation.Builder.Build(s.MSCorp)); var u = builder.Materialise(); u.StarClusters.ShouldNotBeEmpty(); u.SolarSystems().ShouldNotBeEmpty(); var sol = u.SolarSystems().Single(x => x.Id == s.SolarSystem.ObjectId); var earth = u.Planets().Single(p => p.Id == s.Earth.ObjectId); earth.Position.GetSolarSystem().ShouldBe(sol); var ship = new Ship {Position = new Position(earth, new Vector(1, 1))}; ship.Position.GetSolarSystem().ShouldBe(sol); }
public void Repair(Ship ship, ShieldInfo shieldInfo) { var statistic = ship.Statistics[shieldInfo.Statistic]; var damage = statistic.Debuffs.OfType<Damage>().ToArray(); var delta = shieldInfo.RepairPerTick; foreach (var d in damage) { if (d.Value < delta) { statistic.Remove(d); delta -= d.Value; continue; } d.Value -= delta; break; } statistic.Recalculate(); }
public static ObjectBuilder<Ship> Build(ILocation location, ShipState state) { var ship = new Ship { Id = state.ObjectId, Name = state.Name, Heading = state.Heading, Position = new Position(location, state.LocalCoordinates), Statistics = new ShipStatistics(state.Statistics.Select(Build)), }; var builder = new ObjectBuilder<Ship>(ship) .Resolve((resolver, target) => BuildHardPoints(resolver, ship, state.HardPoints)) .Resolve((resolver, target) => target.ShipInfo = resolver.Get<ShipInfo>(ItemType.Ships.ToObjectReference(state.Code))); builder .Dependent(state.Pilot) .Build(Agent.Builder.Build) .Resolve((resolver, target, dependentObject) => target.Pilot = dependentObject); return builder; }
/// <summary>Load refined ore onto a ship</summary> /// <param name="ship"></param> /// <returns>True if the ship has picked up all the ore it can</returns> public bool LoadRefinedOre(Ship ship) { AssertShipInRange(ship, "load refined ore from this refinery"); if (RefinedOre != 0) { var refinedOre = new RefinedOre(); uint maxOreCanCarry = (refinedOre.SizePerUnit == 0d) ? RefinedOre : Math.Min((uint) Math.Floor(ship.CargoHoldRemaining/refinedOre.SizePerUnit), RefinedOre); RefinedOre -= maxOreCanCarry; refinedOre.Quantity = maxOreCanCarry; refinedOre.Owner = Owner; ship.AddCargo(refinedOre); Universe.EventPump.RaiseEvent(ship, EventType.ShipCargo, "Loaded {0:n0} refined ore from {1}", refinedOre.Quantity, Name); return (refinedOre.SizePerUnit == 0d) || (ship.CargoHoldRemaining < refinedOre.SizePerUnit); } return false; }
/// <summary>Unload raw ore from a ship</summary> /// <param name="ship"></param> /// <returns>True if ore was unloaded</returns> public bool UnloadOre(Ship ship) { AssertShipInRange(ship, "unload raw ore to this refinery"); IItem ore = ship.RemoveCargo(Ore.OreID); if (ore != null) { UnrefinedOre += ore.Quantity; Universe.EventPump.RaiseEvent(ship, EventType.ShipCargo, "Unloaded {0:n0} raw ore to {1}", ore.Quantity, Name); return true; } return false; }
private void CheckWeaponState(Ship ship) { Assert.That(ship.HardPoints, Is.Not.Empty); var hp = ship.HardPoints.First(); }
private void CheckPosition(SolarSystem solarSystem, Ship ship) { Assert.That(ship.Position.LocalCoordinates, Is.EqualTo(Ship.LocalCoordinates)); Assert.That(ship.SolarSystem, Is.EqualTo(solarSystem)); Assert.That(ship.Position.GetSolarSystem(), Is.EqualTo(solarSystem)); }
public HardPoint(Ship ship, HardPointPosition position) : this(position) { Ship = ship; }
/// <summary>Unload refined ore from a ship</summary> /// <param name="ship"></param> /// <returns>True if ore was unloaded</returns> public bool UnloadRefinedOre(Ship ship) { AssertShipInRange(ship, "unload refined ore to this manufactory"); IItem ore = ship.RemoveCargo(RefinedOre.RefinedOreID); if (ore != null) { OreRemaining += ore.Quantity; Universe.EventPump.RaiseEvent(ship, EventType.ShipCargo, "Unloaded {0:n0} refined ore to {1}", ore.Quantity, Name); return true; } return false; }
public void SetUp() { _random = new Mock<IRandom>(MockBehavior.Strict); Func<ShipState, ObjectBuilder<Ship>> ship = state => Ship.Builder.Build(null, state); _target = new Ship {Statistics = new ShipStatistics(Stats())}; _weapon = new Weapon(); _combatFactory = (state, idResolver) => new AttackShipCombat(_random.Object) { Ship = ship(state).Build(idResolver), Target = _target }; _combat = _combatFactory(new ShipState(ItemCode.LightFrigate), new IdResolutionContext(new[] { new ShipInfo() { Code = ItemCode.LightFrigate } })); }
public void JumpShip() { var s = new Ship(); _a.EnterSystem(s, Vector.Zero); _a1.Jump(s); Assert.That(s.SolarSystem, Is.EqualTo(_b)); }
public void TestMovesToExtent() { var ship = new Ship(new Corporation()); var hardPoint = new HardPoint(ship, HardPointPosition.Right); var aimAt = new Location(0, 1, 0); // 90* forward Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved 45* Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4)); // assert we moved forward Assert.Greater(hardPoint.Orientation.Y, 0d); // now make sure the hard point knows this =) Assert.AreEqual(45d, hardPoint.Inclination); hardPoint.Reset(); aimAt = new Location(0, -1, 0); // 90* back Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination); // assert we moved 45* Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4)); // assert we moved back Assert.Less(hardPoint.Orientation.Y, 0d); // now make sure the hard point knows this =) Assert.AreEqual(-45d, hardPoint.Inclination); }