コード例 #1
0
    void UpdateMapObjectives(MapObject objective)
    {
        GameObject   mapObjective          = this.MapObjectivesQueue.Dequeue();
        MapObjective mapObjectiveComponent = mapObjective.GetComponent <MapObjective>();

        mapObjectiveComponent.SetIcon(new Icons(objective));
        mapObjectiveComponent.UpdateLocation(new MapPosition(objective));
        this.MapObjectivesQueue.Enqueue(mapObjective);
    }
コード例 #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            SaveRule();
            SaveScenario();

            if (!Id.HasValue)
            {
                map = new Map();
                _context.Maps.Add(map);
            }

            map.Name          = txtName.Text;
            map.ColourMapName = txtColourMap.Text;
            map.Description   = txtDescription.Text;

            for (int y = 0; y < GRID_SIZE; y++)
            {
                for (int x = 0; x < GRID_SIZE; x++)
                {
                    var cell = _context.TerrainMaps.SingleOrDefault(cell => cell.Map == map && cell.RowId == y && cell.ColumnId == x);
                    if (cell == null)
                    {
                        cell = new MapTerrain()
                        {
                            RowId    = y,
                            ColumnId = x,
                            Map      = map,
                        };
                        _context.TerrainMaps.Add(cell);
                    }
                    cell.TerrainId = terrainMap[y][x];
                }
            }

            foreach (var scenarioData in scenarioList)
            {
                var scenario = _context.Scenarios.SingleOrDefault(x => x.Id == scenarioData.Id);
                if (scenario == null)
                {
                    scenario = new Scenario()
                    {
                        Map = map,
                    };
                    _context.Scenarios.Add(scenario);
                }
                scenario.Name        = scenarioData.Name;
                scenario.Description = scenarioData.Description;
                scenario.IsDefault   = scenarioData.IsDefault;
                scenario.EnemyDeckId = scenarioData.EnemyDeckId;

                _context.SaveChanges();

                if (scenarioData.Id == null)
                {
                    scenarioList.Single(x => x == scenarioData).Id = scenario.Id;
                }

                foreach (var ruleData in scenarioData.ScenarioRules)
                {
                    var rule = _context.ScenarioRules.SingleOrDefault(x => x.Id == ruleData.Id);
                    if (rule == null)
                    {
                        rule = new ScenarioRule();
                        _context.ScenarioRules.Add(rule);
                    }
                    rule.Name        = ruleData.Name;
                    rule.Description = ruleData.Description;

                    var scenarioRuleSet = _context.ScenarioRuleSets.SingleOrDefault(x => x.Scenario == scenario && x.Rule == rule);
                    if (scenarioRuleSet == null)
                    {
                        scenarioRuleSet = new ScenarioRuleSet();

                        rule.ScenarioRules.Add(scenarioRuleSet);
                        scenario.ScenarioRuleSet.Add(scenarioRuleSet);
                        _context.ScenarioRuleSets.Add(scenarioRuleSet);
                    }
                }

                var objectiveList = new List <Objective>();
                foreach (var objectiveData in scenarioData.Objectives)
                {
                    var objective = _context.Objectives.SingleOrDefault(x => x.Id == objectiveData.Id);
                    if (objective == null)
                    {
                        objective = new Objective();
                        _context.Objectives.Add(objective);
                    }
                    objective.Name  = objectiveData.Name;
                    objective.Red   = objectiveData.Color.R;
                    objective.Green = objectiveData.Color.G;
                    objective.Blue  = objectiveData.Color.B;

                    objectiveList.Add(objective);
                }

                for (int y = 0; y < GRID_SIZE; y++)
                {
                    for (int x = 0; x < GRID_SIZE; x++)
                    {
                        var deploymentCell = _context.DeploymentMaps.SingleOrDefault(cell => cell.Scenario == scenario && cell.RowId == y && cell.ColumnId == x);
                        if (deploymentCell == null)
                        {
                            deploymentCell = new MapDeployment()
                            {
                                RowId    = y,
                                ColumnId = x,
                                Scenario = scenario,
                            };
                            _context.DeploymentMaps.Add(deploymentCell);
                        }
                        deploymentCell.PlayerId = scenarioData.DeploymentMap[y][x];

                        var objectiveCell = _context.ObjectiveMaps.SingleOrDefault(cell => cell.Scenario == scenario && cell.RowId == y && cell.ColumnId == x);
                        if (objectiveCell == null)
                        {
                            objectiveCell = new MapObjective()
                            {
                                RowId    = y,
                                ColumnId = x,
                                Scenario = scenario,
                            };
                            _context.ObjectiveMaps.Add(objectiveCell);
                        }
                        var objectiveIndex = scenarioData.ObjectiveMap[y][x];
                        if (!objectiveIndex.HasValue)
                        {
                            objectiveCell.ObjectiveId = null;
                        }
                        else
                        {
                            objectiveCell.Objective = objectiveList[objectiveIndex.Value];
                        }
                    }
                }
            }

            if (Id.HasValue)
            {
                var removeScenarios = map.Scenarios.Where(x => !scenarioList.Select(y => y.Id).Contains(x.Id));
                foreach (var removeScenario in removeScenarios)
                {
                    removeScenario.DeploymentMap.Clear();
                    removeScenario.ScenarioRuleSet.Clear();
                    var removeObjectives = removeScenario.ObjectiveMap.Where(x => x.ObjectiveId.HasValue).Select(x => x.Objective);
                    _context.Objectives.RemoveRange(removeObjectives);
                    removeScenario.ObjectiveMap.Clear();
                }
                _context.Scenarios.RemoveRange(removeScenarios);

                foreach (var scenario in map.Scenarios)
                {
                    var scenarioData = scenarioList.Single(x => x.Id == scenario.Id);

                    var removeRuleSets = scenario.ScenarioRuleSet.Where(x => !scenarioData.ScenarioRules.Any(y => y.Id == x.RuleId));
                    _context.ScenarioRuleSets.RemoveRange(removeRuleSets);

                    var removeObjectives = _context.Objectives.Where(x => !x.MapObjectives.Any());
                    _context.Objectives.RemoveRange(removeObjectives);
                }
            }

            _context.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }