public IActionResult Post([FromRoute] string id) { var simulationScenario = new SimulationScenario(new IRSTaxFileBuilder(), this.mediator); var result = simulationScenario.Run(); var yearResults = result.Results. Select(i => new YearResultModel { Movements = Adapt(i.Movements), Year = i.Year, SharesProfit = i.SharesProfit, TaxResult = i.TaxResult }); var shares = new ShareModel { TotalCount = result.Shares.Count() }; var model = new SimulationResultsModel { SimulationId = id, YearResults = yearResults, Shares = shares, TotalGains = result.TotalProfit, SharesIncome = result.Results.Sum(i => i.SharesProfit), TotalTaxes = result.Results.Sum(i => i.TaxResult.TaxSettling) }; return(this.Ok(model)); }
public SimulationRunModel Post([FromRoute] string id) { var simulationScenario = new SimulationScenario(new IRSTaxFileBuilder(), this.mediator); var result = simulationScenario.Run(); var yearResults = result.Results. Select(i => new YearResultModel { Movements = i.Movements.Select(mvt => new MovementsModel { ExerciseCost = mvt.ExerciseCost, ShareCost = mvt.ShareCost, ShareValue = mvt.ShareValue, Type = mvt.MovementType == Shares.ShareMovementType.Acquisition ? MovementType.Vesting : MovementType.Selling }), Year = i.Year, SharesProfit = i.SharesProfit, TaxResult = i.TaxResult }); var shares = new ShareModel { TotalCount = result.Shares.Count() }; var model = new SimulationRunModel { SimulationId = id, FamilyAggregate = result.Aggregate, YearResults = yearResults, Shares = shares, TotalGains = result.TotalProfit }; return(model); }
/// <summary> /// Simulates a given scenario and calculates profit / loss that would be made if scenario happened on each second in history of captured market order books. /// Profit/losses are output to a file given in scenario description. /// </summary> /// <param name="scenario">Scenario to simulate.</param> /// <param name="historyLoader">Loader to be used to access history of market order books.</param> public ProfitSimulator(SimulationScenario scenario, BitstampHistoryLoader historyLoader) { _historyEnumerator = new HistoryEnumerator(historyLoader); var firstEntry = _historyEnumerator.PeekNext(); if (firstEntry == null) { return; } _engine = new SimulationEngine(firstEntry.AcqTime); _engine.AfterEventSimulation += LoadOrderBookHistoryEventsIntoEngine; _dependencyFactory = new SimulationDependencyFactory(_engine); _scenario = scenario; _dependencyFactory.HedgingEngine.WhenStrategy.Delay = _scenario.HedgingDelay * 1000; _dependencyFactory.PricingEngine.PricingStrategy.SellSpread = _scenario.SellSpread / 100; _dependencyFactory.PricingEngine.PricingStrategy.BuySpread = _scenario.BuySpread / 100; _dependencyFactory.SolarisBank.InfiniteBalance = true; _dependencyFactory.SolarisBank.TransferDelay = 10; _resultWriter = new CsvProfitSimulationWriter(_scenario.OutputFilename); _resultWriter.Initialize(); _isSimulationDone = false; _liquidityEngine = new SimulationLiquidityEngineMoq(_dependencyFactory); }
public SimulationRoot(Simulation ecs, SimulationConfiguration configuration, EntityStateSerializer entityStateSerializer, SimulationScenario scenario) : base(ecs, configuration, entityStateSerializer) { Scenario = scenario; }
private int ShowOptions(ShowOptions opts) { var baseScenario = new SimulationScenario(new IRSTaxFileBuilder(), this.mediator); var baseResult = baseScenario.Run(); baseResult.Display(); return(1); }
public static ScenarioInfo ToScenarioInfo(this SimulationScenario scenario) { return(new ScenarioInfo() { Key = scenario.Key, Name = scenario.Name, Description = scenario.Description, MaxPlayerCount = scenario.MaxPlayers, MinPlayerCount = scenario.MinPlayers, LocalizationDictionary = scenario.LocalizationDictionary, }); }
public void SetupScenario(string name, out SimulationLifecycleManager lifecycleManager, NodeConfig[] nodeConfigs) { ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var edgeConfigs = ConfigurationHelper.GenerateFullyConnectedConfiguration(nodeConfigs, 1); var archetypes = new List <Archetype> { SubsystemNode.Archetype, ConnectionNode.Archetype, Player.Archetype, TutorialScanner.Archetype, AntivirusWorkstation.Archetype, AnalyserActivator.Archetype, AntivirusTool.Archetype, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); var scenarioInfo = new ScenarioInfo { Description = name, Key = name, LocalizationDictionary = null, MaxPlayerCount = 1, MinPlayerCount = 1, Name = name }; var scenario = new SimulationScenario(scenarioInfo) { Configuration = configuration, Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), }; lifecycleManager = SimulationLifecycleManager.Initialize(scenario); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration #region graph var node00 = new NodeConfig(0, 0, AntivirusWorkstation.Archetype, "Antivirus"); var node10 = new NodeConfig(1, 0, SubsystemNode.Archetype); var node20 = new NodeConfig(2, 0, SubsystemNode.Archetype); var node01 = new NodeConfig(0, 1, SubsystemNode.Archetype); var node11 = new NodeConfig(1, 1, SubsystemNode.Archetype); var node21 = new NodeConfig(2, 1, SubsystemNode.Archetype); var nodeConfigs = new NodeConfig[] { node00, node10, node20, node01, node11, node21, }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var connection0010 = new EdgeConfig(node00.Id, EdgeDirection.East, node10.Id, ConnectionNode.Archetype); var connection1000 = connection0010.Reciprocate(); var connection1020 = new EdgeConfig(node10.Id, EdgeDirection.East, node20.Id, ConnectionNode.Archetype); var connection2010 = connection1020.Reciprocate(); var connection0001 = new EdgeConfig(node00.Id, EdgeDirection.South, node01.Id, ConnectionNode.Archetype); var connection0100 = connection0001.Reciprocate(); var connection0111 = new EdgeConfig(node01.Id, EdgeDirection.East, node11.Id, ConnectionNode.Archetype); var connection1101 = connection0111.Reciprocate(); var connection1121 = new EdgeConfig(node11.Id, EdgeDirection.East, node21.Id, ConnectionNode.Archetype); var connection2111 = connection1121.Reciprocate(); var connection2021 = new EdgeConfig(node20.Id, EdgeDirection.South, node21.Id, ConnectionNode.Archetype); var connection2120 = connection2021.Reciprocate(); var edgeConfigs = new EdgeConfig[] { connection0010, connection1000, connection1020, connection2010, connection0001, connection0100, connection0111, connection1101, connection1121, connection2111, connection2021, connection2120, }; #endregion var archetypes = new List <Archetype> { SubsystemNode.Archetype, ConnectionNode.Archetype, Player.Archetype, ScannerTool.Archetype, AntivirusWorkstation.Archetype, AnalyserActivator.Archetype, CaptureTool.Archetype, AntivirusTool.Archetype, RedVirus80, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 561122999; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { node00.Id, node20.Id, node01.Id, node21.Id }), Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), Scoring = SimulationScenario.ScoringMode.Full, }; var spawnSequence = new NodeSequence(new[] { // offset by one vs config node00, node20, node10, node00, node20, node01, node10, node01, }); #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetTimer <Simulation, SimulationConfiguration>(scenario.TimeLimitSeconds.Value), new CreateItem(ScannerTool.Archetype, node10), new CreateItem(ScannerTool.Archetype, node20), new CreateItem(CaptureTool.Archetype, node10), new CreateItem(CaptureTool.Archetype, node10), }, ExitCondition = new WaitForTicks(1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(RedVirus80, node01) }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, OnTickActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ConditionalAction <Simulation, SimulationConfiguration>(new NodeSequenceAction(spawnSequence, ec => new CreateMalware(RedVirus80, ec)), new OnEvent <AntivirusActivationEvent>(aae => aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.SoloExtermination || aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.CoopExtermination)), }, ExitCondition = new WaitForTimer(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Neutral), }, } ); #endregion return(scenario); }
public DatabaseEventLogger(SimulationScenario scenario, EventSystem eventSystem) { _scenario = scenario; _eventSystem = eventSystem; _eventQueue = new Queue <IEvent>(100); }
public void TestMemoryResourceTransmission() { var nodeConfigs = new List <NodeConfig> { new NodeConfig() { X = 0, Y = 0, Name = "Node 0", Archetype = SubsystemNode.Archetype, } }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var systems = new List <SystemConfiguration>() { new SystemConfiguration <ItemStorageSystem>(), new SystemConfiguration <ResourcesSystem>() { ExtensionConfiguration = new SystemExtensionConfiguration[] { new SystemExtensionConfiguration <ISubsystemResourceEffect>() { Implementations = new SystemExtensionImplementation[] { new SystemExtensionConfiguration <ISubsystemResourceEffect> .SystemExtensionImplementation <ResetMemoryEachTick>(), new SystemExtensionConfiguration <ISubsystemResourceEffect> .SystemExtensionImplementation <ItemStorageConsumesMemoryEffect>(), } } } }, }; var archetypes = new List <Archetype>() { SubsystemNode.Archetype, ScannerTool.Archetype, }; var lifecycleConfig = new LifeCycleConfiguration(); var configuration = new SimulationConfiguration(nodeConfigs, null, null, archetypes, systems, lifecycleConfig); var scenarioA = new SimulationScenario() { Configuration = configuration }; var rootA = SimulationInstaller.CreateSimulationRoot(scenarioA); var ecsA = rootA.ECS; MemoryResource memoryResourceA; TestEntityState(ecsA, SimulationConstants.SubsystemInitialMemory, out memoryResourceA); ecsA.Tick(); var scenarioB = new SimulationScenario() { Configuration = configuration }; var rootB = SimulationInstaller.CreateSimulationRoot(scenarioB); var ecsB = rootB.ECS; MemoryResource memoryResourceB; TestEntityState(ecsB, SimulationConstants.SubsystemInitialMemory, out memoryResourceB); Assert.That(memoryResourceB, Is.Not.EqualTo(memoryResourceA)); var json = rootA.GetEntityState(); rootB.UpdateEntityState(json); MemoryResource memoryResourceC; TestEntityState(ecsB, SimulationConstants.ItemMemoryConsumption, out memoryResourceC); Assert.That(memoryResourceC, Is.EqualTo(memoryResourceB), "Memory Resource was recreated"); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration #region graph var nodeLeft = new NodeConfig() { Name = "00", X = 0, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var nodeMiddle = new NodeConfig() { Name = "10", X = 1, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var nodeRight = new NodeConfig() { Name = "20", X = 2, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var nodeAntivirus = new NodeConfig() { Name = "11", X = 1, Y = 1, Archetype = TutorialAntivirusWorkstation.Archetype, }; var nodeConfigs = new NodeConfig[] { nodeLeft, nodeRight, nodeMiddle, nodeAntivirus }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var edgeConfigs = ConfigurationHelper.GenerateFullyConnectedConfiguration(nodeConfigs, 1); #endregion var archetypes = new List <Archetype> { TutorialSubsystem.Archetype, ConnectionNode.Archetype, Player.Archetype, ScannerTool.Archetype, TutorialScanner.Archetype, TutorialCapture.Archetype, TutorialAntivirusWorkstation.Archetype, AnalyserActivator.Archetype, AntivirusTool.Archetype, RedTutorialVirus.Archetype, VisibleGreenTutorialVirus.Archetype, TutorialText.Archetype, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 897891658; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new [] { nodeRight.Id }), // TODO: need a config driven specification for these Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), }; #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateItem(ScannerTool.Archetype, nodeRight), new ShowText(true, $"{scenario.Key}_Frame1"), new CreateMalware(RedTutorialVirus.Archetype, nodeLeft), }, ExitCondition = new WaitForTutorialContinue().Or(new GenomeRevealedAtLocation(nodeLeft, SimulationConstants.MalwareGeneRed)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetHighlight(nodeAntivirus), new ShowText(true, $"{scenario.Key}_Frame2"), }, ExitCondition = new WaitForTutorialContinue().Or(new GenomeRevealedAtLocation(nodeLeft, SimulationConstants.MalwareGeneRed)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 3 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetHighlight(nodeLeft), new ShowText(false, $"{scenario.Key}_Frame3"), }, ExitCondition = new GenomeRevealedAtLocation(nodeLeft, SimulationConstants.MalwareGeneRed), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 4 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateItem(TutorialCapture.Archetype, nodeAntivirus), new ShowText(true, $"{scenario.Key}_Frame4"), }, ExitCondition = new ItemTypeIsInInventory <Capture>().Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 5 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame5"), }, ExitCondition = new PlayerIsAtLocation(nodeAntivirus).Or(new ItemTypeIsInInventory <Capture>()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 6 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame6"), }, ExitCondition = EvaluatorExtensions.Not(new ItemTypeIsInInventory <Scanner>()).Or(new ItemTypeIsInInventory <Capture>()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 7 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame7"), }, ExitCondition = new ItemTypeIsInInventory <Capture>(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 8 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame8"), }, ExitCondition = new PlayerIsAtLocation(nodeLeft).Or(new GenomeIsCaptured(SimulationConstants.MalwareGeneRed)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 9 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame9"), }, ExitCondition = new GenomeIsCaptured(SimulationConstants.MalwareGeneRed), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 10 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame10"), }, ExitCondition = new PlayerIsAtLocation(nodeAntivirus).And(new ItemTypeIsInInventory <Capture>()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 11 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame11"), }, ExitCondition = new ItemTypeIsInStorageAtLocation <Antivirus>(nodeAntivirus), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 12 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame12"), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(nodeLeft)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 13 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(VisibleGreenTutorialVirus.Archetype, nodeLeft), new CreateMalware(VisibleGreenTutorialVirus.Archetype, nodeMiddle), new CreateMalware(VisibleGreenTutorialVirus.Archetype, nodeRight), new ShowText(true, $"{scenario.Key}_Frame13"), }, ExitCondition = new WaitForTutorialContinue().Or(EvaluatorExtensions.Not(new IsInfected())), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 14 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame14"), }, ExitCondition = new EntityDisposed <Malware>().Or(EvaluatorExtensions.Not(new IsInfected())), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 15 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame15"), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 16 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new WaitForTicks(5), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Success), }, } ); #endregion configuration.LifeCycleConfiguration.TickInterval = 100; return(scenario); }
public void TestItemOwnerTransmission() { var testSystem = new Archetype("TestSystem") .HasComponent(new ComponentBinding <Subsystem>()) .HasComponent(new ComponentBinding <Coordinate2DProperty>()) .HasComponent(new ComponentBinding <Name>()) .HasComponent(new ComponentBinding <ItemStorage>() { ComponentTemplate = new ItemStorage() { Items = new ItemContainer[1], } }); var testItem = new Archetype("TestItem") .HasComponent(new ComponentBinding <Scanner>()) .HasComponent(new ComponentBinding <Owner>()); var nodeConfigs = new List <NodeConfig> { new NodeConfig() { X = 0, Y = 0, Name = "Node 0", Archetype = testSystem.Name }, }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var systems = new List <SystemConfiguration>() { new SystemConfiguration <ItemStorageSystem>(), }; var archetypes = new List <Archetype>() { testSystem, testItem, }; var lifecycleConfig = new LifeCycleConfiguration(); var configuration = new SimulationConfiguration(nodeConfigs, null, null, archetypes, systems, lifecycleConfig); var scenario = new SimulationScenario() { Configuration = configuration }; var rootA = SimulationInstaller.CreateSimulationRoot(scenario); var ecsA = rootA.ECS; Owner ownerA; TestEntityState(ecsA, null, out ownerA); ecsA.Tick(); var rootB = SimulationInstaller.CreateSimulationRoot(scenario); var ecsB = rootB.ECS; Owner ownerB; TestEntityState(ecsB, null, out ownerB); Assert.That(ownerB, Is.Not.EqualTo(ownerA)); const int owner = 3; ownerA.Value = 3; var json = rootA.GetEntityState(); rootB.UpdateEntityState(json); Owner ownerC; TestEntityState(ecsB, owner, out ownerC); Assert.That(ownerC, Is.EqualTo(ownerB), "Owner was recreated"); ownerA.Value = null; json = rootA.GetEntityState(); rootB.UpdateEntityState(json); Owner ownerD; TestEntityState(ecsB, null, out ownerD); Assert.That(ownerD, Is.EqualTo(ownerB), "Owner was recreated"); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration var text = new Dictionary <string, Dictionary <string, string> >(); #region graph var node00 = new NodeConfig(0, 0, SubsystemNode.Archetype); var node10 = new NodeConfig(1, 0, SubsystemNode.Archetype); var node20 = new NodeConfig(2, 0, SubsystemNode.Archetype); var node30 = new NodeConfig(3, 0, SubsystemNode.Archetype); var node01 = new NodeConfig(0, 1, TransferWorkstation.Archetype); var node11 = new NodeConfig(1, 1, AntivirusWorkstation.Archetype); var node21 = new NodeConfig(2, 1, SubsystemNode.Archetype); var node31 = new NodeConfig(3, 1, TransferWorkstation.Archetype); var node02 = new NodeConfig(0, 2, SubsystemNode.Archetype); var node12 = new NodeConfig(1, 2, SubsystemNode.Archetype); var node22 = new NodeConfig(2, 2, SubsystemNode.Archetype); var node32 = new NodeConfig(3, 2, SubsystemNode.Archetype); var nodeConfigs = new NodeConfig[] { node00, node10, node20, node30, node01, node11, node21, node31, node02, node12, node22, node32, }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); // top row // horizontal var connection0010 = new EdgeConfig(node00, EdgeDirection.East, node10, ConnectionNode.Archetype); var connection1000 = connection0010.Reciprocate(); var connection1020 = new EdgeConfig(node10, EdgeDirection.East, node20, ConnectionNode.Archetype); var connection2010 = connection1020.Reciprocate(); var connection2030 = new EdgeConfig(node20, EdgeDirection.East, node30, ConnectionNode.Archetype); var connection3020 = connection2030.Reciprocate(); //vertical var connection0001 = new EdgeConfig(node00, EdgeDirection.South, node01, ConnectionNode.Archetype); var connection0100 = connection0001.Reciprocate(); var connection1011 = new EdgeConfig(node10, EdgeDirection.South, node11, ConnectionNode.Archetype); var connection1110 = connection1011.Reciprocate(); var connection3031 = new EdgeConfig(node30, EdgeDirection.South, node31, ConnectionNode.Archetype); var connection3130 = connection3031.Reciprocate(); // middle row //horizontal var connection0111 = new EdgeConfig(node01, EdgeDirection.East, node11, ConnectionNode.Archetype); var connection1101 = connection0111.Reciprocate(); var connection2131 = new EdgeConfig(node21, EdgeDirection.East, node31, ConnectionNode.Archetype); var connection3121 = connection2131.Reciprocate(); // vertical var connection0102 = new EdgeConfig(node01, EdgeDirection.South, node02, ConnectionNode.Archetype); var connection0201 = connection0102.Reciprocate(); var connection2122 = new EdgeConfig(node21, EdgeDirection.South, node22, ConnectionNode.Archetype); var connection2221 = connection2122.Reciprocate(); var connection3132 = new EdgeConfig(node31, EdgeDirection.South, node32, ConnectionNode.Archetype); var connection3231 = connection3132.Reciprocate(); // bottom row //horizontal var connection0212 = new EdgeConfig(node02, EdgeDirection.East, node12, ConnectionNode.Archetype); var connection1202 = connection0212.Reciprocate(); var connection1222 = new EdgeConfig(node12, EdgeDirection.East, node22, ConnectionNode.Archetype); var connection2212 = connection1222.Reciprocate(); var connection2232 = new EdgeConfig(node22, EdgeDirection.East, node32, ConnectionNode.Archetype); var connection3222 = connection2232.Reciprocate(); var edgeConfigs = new List <EdgeConfig>() { connection0010, connection1000, connection1020, connection2010, connection2030, connection3020, connection0001, connection0100, connection1011, connection1110, connection3031, connection3130, connection0111, connection1101, connection2131, connection3121, connection0102, connection0201, connection2122, connection2221, connection3132, connection3231, connection0212, connection1202, connection1222, connection2212, connection2232, connection3222, }; #endregion var archetypes = new List <Archetype> { SubsystemNode.Archetype, ConnectionNode.Archetype, Player.Archetype, AntivirusWorkstation.Archetype, AnalyserActivator.Archetype, CaptureTool.Archetype, AntivirusTool.Archetype, TransferWorkstation.Archetype, TransferActivator.Archetype, ScannerTool.Archetype, RedVirus.Archetype, GreenVirus.Archetype }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 889753438; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { node00.Id, node30.Id, node02.Id, node32.Id }), Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), Scoring = SimulationScenario.ScoringMode.Full, }; var redSpawnSequence = new NodeSequence(new[] { // offset by one vs config node10, node22, node02, node30, node21, node01, node31, node11, node12, node00, node32, node10, }); var greenSpawnSequence = new NodeSequence(new[] { // offset by one vs config node12, node00, node32, node20, node31, node22, node02, node30, node21, node01, node10, node11, node12, }); #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetTimer <Simulation, SimulationConfiguration>(scenario.TimeLimitSeconds.Value), new CreateItem(ScannerTool.Archetype, node00), new CreateItem(ScannerTool.Archetype, node32), new CreateItem(CaptureTool.Archetype, node10), new CreateItem(CaptureTool.Archetype, node22), }, ExitCondition = new WaitForTicks(1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(RedVirus.Archetype, node10), new CreateMalware(GreenVirus.Archetype, node21), }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, OnTickActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ConditionalAction <Simulation, SimulationConfiguration>(new NodeSequenceAction(redSpawnSequence, ec => new CreateMalware(RedVirus.Archetype, ec)), new OnEvent <AntivirusActivationEvent>(aae => (aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.SoloExtermination || aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.CoopExtermination) && aae.MalwareCount[SimulationConstants.MalwareGeneRed] == 0)), new ConditionalAction <Simulation, SimulationConfiguration>(new NodeSequenceAction(greenSpawnSequence, ec => new CreateMalware(GreenVirus.Archetype, ec)), new OnEvent <AntivirusActivationEvent>(aae => (aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.SoloExtermination || aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.CoopExtermination) && aae.MalwareCount[SimulationConstants.MalwareGeneGreen] == 0)), }, ExitCondition = new WaitForTimer(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Neutral), }, } ); #endregion return(scenario); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration #region graph var nodeT1 = new NodeConfig() { Name = "00", X = 0, Y = 0, Archetype = TransferWorkstation.Archetype, }; var node10 = new NodeConfig() { Name = "10", X = 1, Y = 0, Archetype = SubsystemNode.Archetype, }; var node01 = new NodeConfig() { Name = "01", X = 0, Y = 1, Archetype = SubsystemNode.Archetype, }; var node11 = new NodeConfig() { Name = "11", X = 1, Y = 1, Archetype = SubsystemNode.Archetype, }; var node21 = new NodeConfig() { Name = "21", X = 2, Y = 1, Archetype = SubsystemNode.Archetype, }; var node30 = new NodeConfig() { Name = "30", X = 3, Y = 0, Archetype = SubsystemNode.Archetype, }; var node31 = new NodeConfig() { Name = "31", X = 3, Y = 1, Archetype = SubsystemNode.Archetype, }; var node40 = new NodeConfig() { Name = "40", X = 4, Y = 0, Archetype = SubsystemNode.Archetype, }; var nodeT2 = new NodeConfig() { Name = "41", X = 4, Y = 1, Archetype = TransferWorkstation.Archetype, }; var nodeConfigs = new NodeConfig[] { nodeT1, node10, node01, node11, node21, node30, node31, node40, nodeT2, }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var edgeConfigs = ConfigurationHelper.GenerateFullyConnectedConfiguration(nodeConfigs, 1); edgeConfigs = edgeConfigs.Where(e => !(e.Source == nodeT1.Id && e.Destination == node10.Id) && !(e.Source == node10.Id && e.Destination == nodeT1.Id)).ToList(); #endregion var archetypes = new List <Archetype> { SubsystemNode.Archetype, ConnectionNode.Archetype, TransferWorkstation.Archetype, TransferActivator.Archetype, Player.Archetype, TutorialNPC.Archetype, ScannerTool.Archetype, RedTutorialAntivirus.Archetype, VisibleRedTutorialVirus.Archetype, GreenTutorialAntivirus.Archetype, VisibleGreenTutorialVirus.Archetype, TutorialText.Archetype, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 477359007; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { node40.Id }), Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), }; #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(VisibleRedTutorialVirus.Archetype, node10), new CreateMalware(VisibleRedTutorialVirus.Archetype, node01), new CreateMalware(VisibleRedTutorialVirus.Archetype, node11), new CreateMalware(VisibleGreenTutorialVirus.Archetype, node21), new CreateMalware(VisibleGreenTutorialVirus.Archetype, node30), new CreateMalware(VisibleGreenTutorialVirus.Archetype, node31), new ShowText(true, $"{scenario.Key}_Frame1") }, ExitCondition = new PlayerIsAtLocation(nodeT1).Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(true, $"{scenario.Key}_Frame2") }, ExitCondition = new PlayerIsAtLocation(nodeT1).Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 3 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateItem(GreenTutorialAntivirus.Archetype, nodeT1), new SetCommandEnabled <ActivateItemCommand>(false), new ShowText(false, $"{scenario.Key}_Frame3") }, ExitCondition = new PlayerIsAtLocation(nodeT1) .And(new ItemTypeIsInInventory <Antivirus>(filter: new AntivirusGenomeFilter(SimulationConstants.MalwareGeneGreen)).Or(new ItemTypeIsInStorageAtLocation <Antivirus, TransferItemContainer>(nodeT1))), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new SetCommandEnabled <SetActorDestinationCommand>(false), }, } ); // 4 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateItem(RedTutorialAntivirus.Archetype, nodeT2, typeof(TransferItemContainer)), new SetCommandEnabled <MoveItemCommand>(false), new ShowText(true, $"{scenario.Key}_Frame4"), }, ExitCondition = new ItemTypeIsInStorageAtLocation <Antivirus, TransferItemContainer>(nodeT1).Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 5 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(true), new ShowText(false, $"{scenario.Key}_Frame5"), }, ExitCondition = new ItemTypeIsInStorageAtLocation <Antivirus, TransferItemContainer>(nodeT1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <PickupItemCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), }, } ); // 6 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new ItemTypeIsInStorageAtLocation <Antivirus, TransferItemContainer>(nodeT2, new AntivirusGenomeFilter(SimulationConstants.MalwareGeneGreen)) .And(new ItemTypeIsInStorageAtLocation <Antivirus, TransferItemContainer>(nodeT1, new AntivirusGenomeFilter(SimulationConstants.MalwareGeneRed))), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new SetCommandEnabled <PickupItemCommand>(true), new SetCommandEnabled <MoveItemCommand>(true), new SetCommandEnabled <DropItemCommand>(false), }, } ); // 7 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame7"), }, ExitCondition = new WaitForTicks(1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreatePlayer(TutorialNPC.Archetype, nodeT2, "Colleague"), new SetCommandEnabled <ActivateItemCommand>(false), }, } ); #region NPC behaviour // 8 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), }, ExitCondition = new WaitForTicks(10), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new PickupItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetDestination(node30, 1), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new ItemTypeIsInInventory <Antivirus>().And(new PlayerIsAtLocation(node01)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new SetCommandEnabled <DropItemCommand>(true), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node01)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), new SetCommandEnabled <ActivateItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new SetCommandEnabled <DropItemCommand>(false), }, } ); // 9 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(true), }, ExitCondition = new PlayerIsAtLocation(node30, 1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new DropItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), }, } ); // 10 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new ActivateItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetCommandEnabled <SetActorDestinationCommand>(true), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node30)).And(new WaitForTicks(1)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <ActivateItemCommand>(false), new EnqueuePlayerCommand(new PickupItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetDestination(node31, 1), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new ItemTypeIsInInventory <Antivirus>().And(new PlayerIsAtLocation(node11)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new SetCommandEnabled <DropItemCommand>(true), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node11)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), new SetCommandEnabled <ActivateItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new SetCommandEnabled <DropItemCommand>(false), }, } ); // 11 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(true), }, ExitCondition = new PlayerIsAtLocation(node31, 1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new DropItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), }, } ); // 12 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new ActivateItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetCommandEnabled <SetActorDestinationCommand>(true), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node31)).And(new WaitForTicks(1)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <ActivateItemCommand>(false), new EnqueuePlayerCommand(new PickupItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetDestination(node21, 1), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new ItemTypeIsInInventory <Antivirus>().And(new PlayerIsAtLocation(node10)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new SetCommandEnabled <DropItemCommand>(true), }, } ); scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node10)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), new SetCommandEnabled <ActivateItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new SetCommandEnabled <DropItemCommand>(false), }, } ); // 13 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(true), }, ExitCondition = new PlayerIsAtLocation(node21, 1), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new DropItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <ActivateItemCommand>(true), }, } ); // 14 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new ActivateItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, // TODO: find the npc player id automatically }), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <ActivateItemCommand>(false), new HideText(), }, } ); #endregion // 15 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new WaitForTicks(5), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Success), }, } ); #endregion return(scenario); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration #region graph var nodeLeft = new NodeConfig() { Name = "00", X = 0, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var nodeRight = new NodeConfig() { Name = "10", X = 1, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var nodeConfigs = new NodeConfig[] { nodeLeft, nodeRight }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var edgeConfigs = ConfigurationHelper.GenerateFullyConnectedConfiguration(nodeConfigs, 1); #endregion var archetypes = new List <Archetype> { TutorialSubsystem.Archetype, ConnectionNode.Archetype, Player.Archetype, TutorialScanner.Archetype, RedTutorialAntivirus.Archetype, RedTutorialVirus.Archetype, TutorialText.Archetype, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 282581594; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { nodeRight.Id }), Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), }; #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(true, $"{scenario.Key}_Frame1") }, ExitCondition = new PlayerDestinarionIs(nodeLeft).Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new SetCommandEnabled <SetActorDestinationCommand>(true), }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame2") }, ExitCondition = new PlayerDestinarionIs(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 3 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame3"), }, ExitCondition = new PlayerIsAtLocation(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 4 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { // TODO: this should disable the cancapture flag of the inventory slot new SetCommandEnabled <PickupItemCommand>(false), new SetCommandEnabled <ActivateItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new CreateItem(TutorialScanner.Archetype, nodeRight), new ShowText(true, $"{scenario.Key}_Frame4"), }, ExitCondition = new PlayerIsAtLocation(nodeRight).Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 5 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame5"), }, ExitCondition = new PlayerIsAtLocation(nodeRight), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 6 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <ActivateItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new ShowText(false, $"{scenario.Key}_Frame6"), }, ExitCondition = new ItemTypeIsActivated <Scanner>(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 7 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(RedTutorialVirus.Archetype, nodeLeft), new ShowText(true, $"{scenario.Key}_Frame7"), new SetCommandEnabled <PickupItemCommand>(true), }, ExitCondition = new ItemTypeIsInInventory <Scanner>().Or(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 8 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <PickupItemCommand>(true), new ShowText(false, $"{scenario.Key}_Frame8") }, ExitCondition = new ItemTypeIsInInventory <Scanner>(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), }, } ); // 9 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame9"), }, ExitCondition = new PlayerIsAtLocation(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new HideText(), }, } ); // 10 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new ShowText(false, $"{scenario.Key}_Frame10"), }, ExitCondition = new ItemTypeIsInStorageAtLocation <Scanner>(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), new HideText(), }, } ); // 11 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame11"), new SetCommandEnabled <SetActorDestinationCommand>(false), }, ExitCondition = new GenomeRevealedAtLocation(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(true), new HideText(), }, } ); // 12 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame12"), new SetCommandEnabled <ActivateItemCommand>(false), new SetCommandEnabled <DropAndActivateItemCommand>(false), new CreateItem(RedTutorialAntivirus.Archetype, nodeRight), }, ExitCondition = new ItemTypeIsInInventory <Antivirus>(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <DropItemCommand>(false), new SetCommandEnabled <PickupItemCommand>(false), new SetCommandEnabled <SwapInventoryItemCommand>(false), new SetCommandEnabled <SwapInventoryItemAndActivateCommand>(false), new ClearHighlight(), }, } ); // 13 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new PlayerIsAtLocation(nodeLeft), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new SetCommandEnabled <DropItemCommand>(true), new SetCommandEnabled <DropAndActivateItemCommand>(true), new SetCommandEnabled <SwapInventoryItemCommand>(true), new SetCommandEnabled <SwapInventoryItemAndActivateCommand>(true), new SetCommandEnabled <ActivateItemCommand>(true), }, } ); // 13 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(nodeLeft)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 14 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new WaitForTicks(5), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Success), }, } ); #endregion return(scenario); }
// TODO: this should be parameterized further and read from config public override SimulationScenario GenerateScenario() { #region configuration #region graph var node00 = new NodeConfig() { Name = "00", X = 0, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var node10 = new NodeConfig() { Name = "10", X = 1, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var node20 = new NodeConfig() { Name = "20", X = 2, Y = 0, Archetype = TutorialSubsystem.Archetype, }; var node01 = new NodeConfig() { Name = "01", X = 0, Y = 1, Archetype = TutorialSubsystem.Archetype, }; var node11 = new NodeConfig() { Name = "11", X = 1, Y = 1, Archetype = AntivirusWorkstation.Archetype, }; var node21 = new NodeConfig() { Name = "21", X = 2, Y = 1, Archetype = TutorialSubsystem.Archetype, }; var nodeConfigs = new NodeConfig[] { node00, node10, node20, node01, node11, node21, }; ConfigurationHelper.ProcessNodeConfigs(nodeConfigs); var connection0010 = new EdgeConfig(node00.Id, EdgeDirection.East, node10.Id, ConnectionNode.Archetype); var connection1000 = connection0010.Reciprocate(); var connection1020 = new EdgeConfig(node10.Id, EdgeDirection.East, node20.Id, ConnectionNode.Archetype); var connection2010 = connection1020.Reciprocate(); var connection1011 = new EdgeConfig(node10.Id, EdgeDirection.South, node11.Id, ConnectionNode.Archetype); var connection1110 = connection1011.Reciprocate(); var connection0111 = new EdgeConfig(node01.Id, EdgeDirection.East, node11.Id, ConnectionNode.Archetype); var connection1101 = connection0111.Reciprocate(); var connection1121 = new EdgeConfig(node11.Id, EdgeDirection.East, node21.Id, ConnectionNode.Archetype); var connection2111 = connection1121.Reciprocate(); var edgeConfigs = new EdgeConfig[] { connection0010, connection1000, connection1020, connection2010, connection1011, connection1110, connection0111, connection1101, connection1121, connection2111, }; #endregion var archetypes = new List <Archetype> { TutorialSubsystem.Archetype, ConnectionNode.Archetype, AntivirusWorkstation.Archetype, TutorialCapture.Archetype, AnalyserActivator.Archetype, Player.Archetype, AntivirusTool.Archetype, VisibleRedTutorialVirus.Archetype, VisibleGreenTutorialVirus.Archetype, TutorialText.Archetype, TutorialNPC.Archetype, }; var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes); configuration.RNGSeed = 2007196112; #endregion var scenario = new SimulationScenario(ScenarioInfo) { Configuration = configuration, PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { node21.Id }), Sequence = new List <SequenceFrame <Simulation, SimulationConfiguration> >(), }; #region frames // 1 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(VisibleRedTutorialVirus.Archetype, node00), new ShowText(true, $"{scenario.Key}_Frame1") }, ExitCondition = new WaitForTutorialContinue(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 2 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetHighlight(node10), new CreateMalware(VisibleRedTutorialVirus.Archetype, connection0010), new ShowText(true, $"{scenario.Key}_Frame2") }, ExitCondition = new IsInfected(node10) .And(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 3 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(VisibleRedTutorialVirus.Archetype, connection0010), new ShowText(true, $"{scenario.Key}_Frame3") }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(connection0010)) .And(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 4 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateMalware(VisibleGreenTutorialVirus.Archetype, node20), new CreateMalware(VisibleGreenTutorialVirus.Archetype, connection2010), new ShowText(true, $"{scenario.Key}_Frame4") }, ExitCondition = new IsInfected(node10, new MalwareGenomeFilter(SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen)) .And(new WaitForTutorialContinue()), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ClearHighlight(), new HideText(), }, } ); // 5 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreateItem(TutorialCapture.Archetype, node11), new ShowText(false, $"{scenario.Key}_Frame5") }, ExitCondition = new PlayerIsAtLocation(node10).And(new ItemTypeIsActivated <Capture>(activationState: ActivationState.Deactivating)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new ClearHighlight(), }, } ); // 6 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetCommandEnabled <SetActorDestinationCommand>(false), new SetCommandEnabled <PickupItemCommand>(false), new ShowText(true, $"{scenario.Key}_Frame6") }, ExitCondition = new WaitForTutorialContinue(), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 7 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ShowText(false, $"{scenario.Key}_Frame7"), }, ExitCondition = new ItemTypeIsActivated <Capture>(activationState: ActivationState.Deactivating), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), new SetCommandEnabled <SetActorDestinationCommand>(true), new SetCommandEnabled <PickupItemCommand>(true), }, } ); // 8 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new SetHighlight(node10), new ShowText(false, $"{scenario.Key}_Frame8") }, ExitCondition = new ItemTypeIsInStorageAtLocation <Antivirus>(node10, new AntivirusGenomeFilter(SimulationConstants.MalwareGeneGreen)) .And(new ItemTypeIsInStorageAtLocation <Antivirus>(node10, new AntivirusGenomeFilter(SimulationConstants.MalwareGeneRed))), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 9 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new CreatePlayer(TutorialNPC.Archetype, node10, "Colleague"), new ShowText(false, $"{scenario.Key}_Frame9") }, ExitCondition = new ItemTypeIsActivated <Antivirus>(node10), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new ClearHighlight(), }, } ); // 10 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EnqueuePlayerCommand(new ActivateItemTypeCommand() { ItemType = typeof(Antivirus), PlayerId = 1, }), }, ExitCondition = EvaluatorExtensions.Not(new IsInfected(node10)), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new HideText(), }, } ); // 11 scenario.Sequence.Add( new SimulationFrame() { OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { }, ExitCondition = new WaitForTicks(5), OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >() { new EndGame(EndGameState.Success), }, } ); #endregion return(scenario); }