Exemplo n.º 1
0
            public static ObjectBuilder<SolarSystem> Build(StarCluster starCluster, SolarSystemState state)
            {
                var solarSystem = new SolarSystem
                {
                    Id = state.ObjectId,
                    Name = state.Name,
                    Position = new Position(starCluster, state.LocalCoordinates),
                };

                var builder = new ObjectBuilder<SolarSystem>(solarSystem)
                    .Resolve((target, resolver) => BuildOrbits(state, target));

                builder
                    .Dependents(state.Ships)
                    .Build(Echo.Ships.Ship.Builder.Build)
                    .Resolve((resolver, target, dependent) => target.Ships.Add(dependent));

                builder
                    .Dependents(state.JumpGates)
                    .Build(Echo.JumpGates.JumpGate.Builder.Build)
                    .Resolve((resolver, target, dependent) => target.JumpGates.Add(dependent));

                builder
                    .Dependents(state.Satellites)
                    .Build((target, dependent) => CelestialObject.Builder.For(dependent).Build(solarSystem))
                    .Resolve((resolver, target, dependent) => target.Satellites.Add(dependent));

                builder
                    .Dependents(state.Structures)
                    .Build((target, dependent) => Structure.Builder.For(dependent).Build(solarSystem))
                    .Resolve((resolver, target, dependent) => target.Structures.Add(dependent));

                return builder;
            }
Exemplo n.º 2
0
            private static void BuildSatelliteOrbits(SolarSystemState state, IIdResolver resolver)
            {
                Ensure.That(resolver).IsNotNull();

                var query =
                    (
                        from s in state.Satellites
                        let satellite = resolver.GetById<CelestialObject>(s.ObjectId)
                        where s.Orbits.HasValue
                        select new
                        {
                            s.ObjectId,
                            s.Orbits,
                            s.LocalCoordinates,
                            Instance = satellite,
                        }
                    );

                foreach (var satellite in query)
                {
                    var parent = GetParent(resolver, satellite.Instance, satellite.Orbits);

                    parent.Satellites.Add(satellite.Instance);
                    satellite.Instance.Position = new Position(parent, satellite.LocalCoordinates);

                    var orbitDistance = satellite.LocalCoordinates.Magnitude - satellite.Instance.Size;
                    CheckOrbitDistance(satellite.Instance, parent, orbitDistance);
                }
            }
Exemplo n.º 3
0
        public MockUniverse(IIdGenerator idGenerator = null)
        {
            _idGenerator = idGenerator ?? new IdGenerator();
            var universeId = Id();

            SpaceshipCommand = TestSkills.For(SkillCode.SpaceshipCommand);
            BluePrint = TestItems.BluePrint(ItemCode.MissileLauncher);
            ShipBluePrint = TestItems.BluePrint(ItemCode.LightFrigate);
            Weapon = TestItems.Weapon(ItemCode.MissileLauncher);
            Item = TestItems.Item(ItemCode.Veldnium);

            John = new AgentState
            {
                ObjectId = Id(),
                Name = "John",
                Statistics = Enum.GetValues(typeof(AgentStatistic)).Cast<AgentStatistic>().Select(x => new AgentStatisticState { Statistic = x, CurrentValue = 50, Value = 50 }),
                Implants = new[] { AgentStatistic.Intelligence, AgentStatistic.Willpower, }.Select(x => new Implant { Stat = x, Rank = 3, Value = 15 }),
                Skills = new[] { new SkillLevel(SkillCode.SpaceshipCommand, level: 5) }
            };

            MSCorp = new CorporationState
            {
                ObjectId = Id(),
                Name = "MS",
                Employees = new[] { John }
            };

            AppleCorp = new CorporationState
            {
                ObjectId = Id(),
                Name = "Apple",
            };

            BuyOrder = new AuctionState
            {
                ObjectId = Id(),
                PricePerUnit = 5,
                Trader = John.ToObjectReference(),
                Item = new ItemState { Code = ItemCode.Veldnium, Quantity = 50 },
                Owner = MSCorp.ToObjectReference(),
            };

            SellOrder = new AuctionState
            {
                ObjectId = Id(),
                PricePerUnit = 10,
                Trader = John.ToObjectReference(),
                Item = new ItemState { Code = ItemCode.Veldnium, Quantity = 100 },
                Owner = MSCorp.ToObjectReference(),
            };

            Earth = new CelestialObjectState
            {
                ObjectId = Id(),
                CelestialObjectType = CelestialObjectType.Planet,
                Name = "Earth",
                LocalCoordinates = new Vector(Units.FromAU(1), 0),
                Mass = Units.SolarMass*1E-6,
                Size = 5d,
            };
            AsteroidBelt = new CelestialObjectState
            {
                ObjectId = Id(),
                CelestialObjectType = CelestialObjectType.AsteriodBelt,
                Name = "Asteroid Belt",
                Orbits = Earth.ToObjectReference(),
                LocalCoordinates = new Vector(-5.5, 0, 0),
                AsteroidBelt = new AsteroidBeltState
                {
                    Richness = 500000,
                    AmountRemaining = 250000,
                },
            };
            Moon = new CelestialObjectState
            {
                ObjectId = Id(),
                CelestialObjectType = CelestialObjectType.Moon,
                Name = "Moon",
                Orbits = Earth.ToObjectReference(),
                Mass = 0.5d,
                Size = 0.5d,
                LocalCoordinates = new Vector(7.5, 0, 0)
            };
            Manufactory = new StructureState()
            {
                ObjectId = Id(),
                Name = "MFC",
                Orbits = Moon.ToObjectReference(),
                LocalCoordinates = new Vector(0.5001, 0, 0),
                Owner = MSCorp.ToObjectReference(),
                Manufactory = new ManufactoryState() { Efficiency = 0.5d },
            };
            TradingStation = new StructureState()
            {
                ObjectId = Id(),
                Name = "TS",
                Orbits = Moon.ToObjectReference(),
                LocalCoordinates = new Vector(-0.5001, 0, 0),
                Owner = MSCorp.ToObjectReference(),
                HangerItems = new[] { new HangarItemState { Owner = MSCorp.ToObjectReference(), Items = new[] { ItemCode.MissileLauncher.ToItemState(quantity:10) }  }, },
                BuyOrders = new[] { BuyOrder },
                SellOrders = new[] { SellOrder },
                TradingStation = new TradingStationState()
            };

            Ship = new ShipState()
            {
                ObjectId = Id(),
                Name = "Ship",
                LocalCoordinates = new Vector(8.5, 0, 0),
                Code = ItemCode.LightFrigate,
                HardPoints = new[]
                {
                    new HardPointState
                    {
                        Position = HardPointPosition.Front,
                        Orientation = HardPoint.CalculateOrientation(HardPointPosition.Front),
                        Speed = 0.5d,
                        Weapon = new WeaponState
                        {
                            ObjectId = Id(),
                            Name = "Blaster",
                            Code = Weapon.Code,
                        }
                    },
                },
                Pilot = John,
                Statistics = Enum.GetValues(typeof(ShipStatistic)).Cast<ShipStatistic>().Select(x => new ShipStatisticState { Statistic = x, CurrentValue = 50, Value = 50 }),
            };
            SolarSystem = new SolarSystemState
            {
                ObjectId = Id(),
                Name = "Sol",
                Satellites = new[] { Earth, Moon, AsteroidBelt, },
                Structures = new[] { Manufactory, TradingStation },
                Ships = new[] { Ship }
            };
            StarCluster = new StarClusterState
            {
                ObjectId = Id(),
                Name = "Revvon",
                SolarSystems = new[] { SolarSystem },
                MarketPlace = new MarketPlaceState
                {
                    AuctionLength = 10,
                    SettlementDelay = 5,
                    Settlements = new[]
                    {
                        new SettlementState
                        {
                            ObjectId = Id(),
                            Item = new ItemState { Code = ItemCode.Veldnium, Quantity = 50 },
                            Owner = MSCorp.ToObjectReference(),
                            Location = TradingStation.ToObjectReference(),
                            TimeToSettlement = 100,
                            SpendByOwner = new Dictionary<ObjectReference, long> { { AppleCorp.ToObjectReference(), 1000 } },
                        }
                    },
                    Auctions = new[] { BuyOrder.ToObjectReference(), SellOrder.ToObjectReference() },
                }
            };

            Universe = new UniverseState
            {
                ObjectId = universeId,
                StarClusters = new[] {StarCluster},
                Weapons = new[] { Weapon },
                Skills = TestSkills.Skills,
                Corporations = new[] { MSCorp, AppleCorp },
                Items = TestItems.Items,
                BluePrints = TestItems.BluePrints,
                Ships = new[]
                {
                    new ShipInfo
                    {
                        Code = ItemCode.LightFrigate,
                        ShipClass = ShipClass.LightFrigate,
                        PilotRequirements = new[]
                        {
                            new State.SkillLevel(SkillCode.SpaceshipCommand, level:1),
                        }
                    }
                }
            };
        }
Exemplo n.º 4
0
 private static void BuildOrbits(SolarSystemState arg1, IIdResolver arg2)
 {
     BuildSatelliteOrbits(arg1, arg2);
     BuildStructureOrbits(arg1, arg2);
 }
Exemplo n.º 5
0
            private static void BuildStructureOrbits(SolarSystemState state, IIdResolver resolver)
            {
                Ensure.That(resolver).IsNotNull();

                var query =
                    (
                        from s in state.Structures
                        let structure = resolver.GetById<Structure>(s.ObjectId)
                        select new
                        {
                            s.ObjectId,
                            s.Orbits,
                            s.LocalCoordinates,
                            Instance = structure,
                        }
                    );

                foreach ( var structure in query )
                {
                    var parent = GetParent(resolver, structure.Instance, structure.Orbits);

                    parent.Structures.Add(structure.Instance);
                    structure.Instance.Position = new Position(parent, structure.LocalCoordinates);

                    var orbitDistance = structure.LocalCoordinates.Magnitude;
                    CheckOrbitDistance(structure.Instance, parent, orbitDistance);
                }
            }
Exemplo n.º 6
0
 public void EmptySolarSystemSize0()
 {
     var x = new SolarSystemState();
     Assert.That(x.Size().Magnitude, Is.EqualTo(0.0));
 }
Exemplo n.º 7
0
 public WrappedObjectState(SolarSystemState value)
 {
     Value = value;
 }
Exemplo n.º 8
0
        private void Check(SolarSystemState state)
        {
            var builder = Echo.Celestial.SolarSystem.Builder.Build(null, state);
            builder.Dependent(new ShipInfo { Code = ItemCode.LightFrigate }).Build(x => new ObjectBuilder<ShipInfo>(x));
            builder.Dependent(Universe.Weapon).Build(x => new ObjectBuilder<WeaponInfo>(x));
            builder.Dependent(Universe.MSCorp).Build(Corporation.Builder.Build);

            var solarSystem = builder.Materialise();
            Check(solarSystem);
        }
Exemplo n.º 9
0
 public SolarSystemBuilder()
 {
     _solarSystem = new SolarSystemState();
     _satellites = new List<CelestialObjectState>();
 }
Exemplo n.º 10
0
        public StarClusterBuilder SolarSystem(Vector localCoordinates = default(Vector))
        {
            var solarSystem = new SolarSystemState
            {
                LocalCoordinates = localCoordinates
            };

            _solarSystems.Add(solarSystem);

            return this;
        }