private void fightsTemplatesCombo_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (fightsTemplatesCombo.SelectedItem != null)
     {
         SelectedTemplate = (FormationTemplate)fightsTemplatesCombo.SelectedItem;
     }
 }
 public FilteringFormationTemplate(
     FormationTemplate Template, UnitConstraints Constraints, IEnumerable <FormationFeature> Features)
 {
     this.Template    = Template;
     this.Constraints = Constraints;
     this.Features    = Features.ToList();
 }
Пример #3
0
        /// <summary>
        /// Creates a formation from the given template and returns a read-only copy of it.
        /// <para>Will return null if the template was invalid.</para>
        /// </summary>
        /// <param name="template">The template used to create the formation.</param>
        /// <returns></returns>
        public IReadOnlyFormation CreateFormation(FormationTemplate template)
        {
            var formation = _formationFactory.Create(template);
            var swap      = new List <Formation> {
                formation
            };
            var shouldSetWorldEntity = template.MakeActive;

            if (formation != null)
            {
                lock (_lock)
                {
                    if (_formations.ContainsKey(template.OwnerId))
                    {
                        _formations[template.OwnerId].Add(formation);
                    }
                    else
                    {
                        _formations.Add(template.OwnerId, swap);
                        shouldSetWorldEntity = true;
                    }
                }
            }

            if (shouldSetWorldEntity)
            {
                _worldEntityAssigner.AssignWorldEntity(template.OwnerId, formation);
            }

            return(formation);
        }
Пример #4
0
        public ParameterizingFormationTemplate(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Features = (List <FormationFeature>)attributes[(int)Attribute.FEATURES];
            Template = (FormationTemplate)attributes[(int)Attribute.TEMPLATE];
        }
        public FilteringFormationTemplate(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Template    = (FormationTemplate)attributes[(int)Attribute.TEMPLATE];
            Constraints = (UnitConstraints)(attributes[(int)Attribute.CONSTRAINTS] ?? new UnitConstraints());
            Features    = (List <FormationFeature>)(attributes[(int)Attribute.FEATURES] ?? new List <FormationFeature>());
        }
        public ReplicatingFormationTemplate(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Template   = (FormationTemplate)attributes[(int)Attribute.TEMPLATE];
            Count      = (int)(attributes[(int)Attribute.COUNT] ?? 1);
            Regenerate = (bool)(attributes[(int)Attribute.REGENERATE] ?? false);
        }
Пример #7
0
        public IActionResult Patch(FormationTemplate template)
        {
            template.OwnerId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var formation = _formationManager.UpdateFormation(template);

            if (formation == null)
            {
                return(new BadRequestResult());
            }
            else
            {
                return(new StatusCodeResult(StatusCodes.Status204NoContent));
            }
        }
Пример #8
0
        private FormationTemplate GetRandomFormationTemplateForLevel(int level)
        {
            FormationTemplate choosenFormationTemplate = null;
            var formationTemplates  = _formationTemplateRepository.GetAll().Where(x => x.Level == level);
            var possibleFormations  = formationTemplates.Where(x => x.Level == level);
            var amountOfTemplates   = possibleFormations.Count();
            var counter             = 1;
            var formationDictionary = possibleFormations.ToDictionary(x => counter++, x => x);

            if (amountOfTemplates > 0)
            {
                var choosen = _randomizer.GetRandomValueInRange(1, amountOfTemplates + 1, "ChoosingFormation");
                choosenFormationTemplate = formationDictionary[choosen];
            }
            return(choosenFormationTemplate);
        }
Пример #9
0
        public IActionResult Post(FormationTemplate template)
        {
            template.OwnerId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var formation = _formationManager.CreateFormation(template);

            if (formation == null)
            {
                return(new BadRequestResult());
            }

            if (_stateManager.GetPlayerState(template.OwnerId) != PlayerStateConstants.InCombat)
            {
                _stateManager.SetPlayerFree(template.OwnerId);
            }

            return(new CreatedAtActionResult("post", "formation", template, formation));
        }
Пример #10
0
        private Quest GenerateFightQuest(int level, int counter)
        {
            FormationTemplate choosenFormationTemplate = GetRandomFormationTemplateForLevel(level);
            RewardTemplate    rewardTemplate           = GetRandomRewardTemplateForLevel(level);

            if (choosenFormationTemplate != null)
            {
                return(new Quest
                {
                    ID = $"Q_{counter}",
                    Level = level.ToString(),
                    FormationID = choosenFormationTemplate.ID,
                    Name = $"Defeat - {choosenFormationTemplate.Name}",
                    RewardsID = rewardTemplate == null ? "" : rewardTemplate.ID,
                    WinRewards = rewardTemplate == null ? "" : rewardTemplate.Rewards
                });
            }
            return(null);
        }
Пример #11
0
        /// <summary>
        /// Creates a Formation from a given FormationTemplate.
        /// </summary>
        /// <param name="template">The template to use to create the Formation.</param>
        /// <returns></returns>
        public Formation Create(FormationTemplate template)
        {
            if (template.Positions == null)
            {
                return(null);
            }
            if (template.Positions.Length != GameplayConstants.MaxFormationRows)
            {
                return(null);
            }
            if (template.Positions.GetTotalSize() != GameplayConstants.MaxFormationSize)
            {
                return(null);
            }

            var ids = new List <int>();

            foreach (var row in template.Positions)
            {
                if (row.Length != GameplayConstants.MaxFormationColumns)
                {
                    return(null);
                }

                foreach (var id in row)
                {
                    if (id != null)
                    {
                        ids.Add(id.Value);
                    }
                }
            }

            var entities = _combatEntityManager.GetModifiableEntities()
                           .Where(entity => ids.Contains(entity.Id));

            var positions = new CombatEntity[GameplayConstants.MaxFormationRows][];

            for (int i = 0; i < GameplayConstants.MaxFormationRows; i++)
            {
                var rowPositions = new CombatEntity[GameplayConstants.MaxFormationColumns];
                for (int j = 0; j < GameplayConstants.MaxFormationColumns; j++)
                {
                    if (template.Positions[i][j] == null)
                    {
                        rowPositions[j] = null;
                    }
                    else
                    {
                        rowPositions[j] = entities.FirstOrDefault(e => e.Id == template.Positions[i][j]);
                    }
                }
                positions[i] = rowPositions;
            }

            return(new Formation
            {
                Id = _id++,
                OwnerId = template.OwnerId,
                Positions = positions,
                LeaderId = template.LeaderId,
                Name = template.Name
            });
        }
 public ReplicatingFormationTemplate(FormationTemplate Template, int Count, bool Regenerate)
 {
     this.Template   = Template;
     this.Count      = Count;
     this.Regenerate = Regenerate;
 }
Пример #13
0
        /// <summary>
        /// Updates the Formation of the id given in the provided template with one created from the template.
        /// </summary>
        /// <param name="template">The template to use to update.</param>
        /// <returns>A readonly reference to the updated Formation.</returns>
        public IReadOnlyFormation UpdateFormation(FormationTemplate template)
        {
            if (template.Id == null)
            {
                return(null);
            }
            Formation oldFormation         = null;
            bool      shouldSetWorldEntity = template.MakeActive;

            lock (_lock)
            {
                if (!_formations.ContainsKey(template.OwnerId))
                {
                    return(null);
                }
                oldFormation = _formations[template.OwnerId].FirstOrDefault(f => f.Id == template.Id);
            }

            if (oldFormation == null || oldFormation.OwnerId != template.OwnerId)
            {
                return(null);
            }

            var formation = _formationFactory.Create(template);

            if (formation == null)
            {
                return(null);
            }
            formation.Id = oldFormation.Id;
            var swap = new List <Formation> {
                formation
            };

            lock (_lock)
            {
                if (_formations.ContainsKey(template.OwnerId))
                {
                    if (_formations[template.OwnerId].Count >= 1)
                    {
                        _formations[template.OwnerId].Remove(oldFormation);
                        _formations[template.OwnerId].Add(formation);
                        if (_formations[template.OwnerId].Count == 1)
                        {
                            shouldSetWorldEntity = true;
                        }
                    }
                    else
                    {
                        _formations.Add(template.OwnerId, swap);
                        shouldSetWorldEntity = true;
                    }
                }
                else
                {
                    throw new Exception($"Tried to update the Formation of player {template.OwnerId} when none exists!");
                }
            }

            if (shouldSetWorldEntity)
            {
                _worldEntityAssigner.AssignWorldEntity(template.OwnerId, formation);
            }

            return(formation);
        }
Пример #14
0
 public ParameterizingFormationTemplate(IEnumerable <FormationFeature> Features, FormationTemplate Template)
 {
     this.Features = Features.ToList();
     this.Template = Template;
 }