Ejemplo n.º 1
0
        public IActionResult Update(int id, [FromBody] KnownSkill skill)
        {
            if (skill == null)
            {
                return(BadRequest(Json(new ErrorResponse("Bad request body"))));
            }
            if (String.IsNullOrEmpty(skill.Name))
            {
                return(Json(BadRequest(new ErrorResponse("Skill name is required."))));
            }
            if (_skillsProvider.Exists(skill.Name))
            {
                return(Json(BadRequest(new ErrorResponse(String.Format("Skill named {0} already exists.", skill.Name)))));
            }
            bool updateSuccessful = _skillsProvider.Update(id, skill);

            if (updateSuccessful)
            {
                KnownSkill knownSkill = _skillsProvider.Get(id);
                if (knownSkill != null)
                {
                    return(Json(new SkillResponse(knownSkill)));
                }
            }
            return(Json(BadRequest(new ErrorResponse("Update failed"))));
        }
Ejemplo n.º 2
0
        private void DoSkillStuff(MenuItem selectedItem, MenuAction selectedAction)
        {
            if (selectedItem.Text == "Cancel")
            {
                CloseActivity();
                return;
            }

            switch (selectedAction)
            {
            case MenuAction.Use:
                CloseActivity();

                KnownSkill knownSkill = (KnownSkill)selectedItem.Value;

                ActionEventData actionEventData = new ActionEventData
                {
                    Action     = ActionType.UseSkill,
                    Parameters = knownSkill.Skill
                };

                _systemContainer.EventSystem.Try(EventType.Action, _entity, actionEventData);

                break;

            default:
                throw new ApplicationException($"Unknown MenuAction in {nameof(SkillMenu)}");
            }
        }
Ejemplo n.º 3
0
        public IActionResult Create([FromBody] KnownSkill skill)
        {
            if (skill == null)
            {
                return(BadRequest(Json(new ErrorResponse("Bad request body"))));
            }
            if (String.IsNullOrEmpty(skill.Name))
            {
                return(Json(BadRequest(new ErrorResponse("Skill name is required."))));
            }
            if (_skillsProvider.Exists(skill.Name))
            {
                return(Json(BadRequest(new ErrorResponse(String.Format("Skill named {0} already exists.", skill.Name)))));
            }
            int skillId;

            try
            {
                skillId = _skillsProvider.Create(skill);
            }
            catch (ArgumentException e)
            {
                return(BadRequest(Json(new ErrorResponse(e.Message))));
            }

            return(Json(new SkillIdResponse(_skillsProvider.Create(skill))));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Update an existing skill
 /// </summary>
 /// <param name="skillId">The id of the existing skill</param>
 /// <param name="skill">The new skill to update to</param>
 /// <returns>Success status</returns>
 public bool Update(int skillId, KnownSkill skill)
 {
     using (var dbContext = new AllocationContext(_dbContextOptions))
     {
         Model.Skill dbSkill = dbContext.Skills.Find(skillId);
         if (dbSkill == null)
         {
             return(false);
         }
         dbSkill.Name = skill.Name;
         dbContext.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new skill
        /// </summary>
        /// <param name="skill">New skill to store in the database</param>
        /// <returns>The database identifier key of newly created skill</returns>
        public int Create(KnownSkill newSkill)
        {
            using (var dbContext = new AllocationContext(_dbContextOptions))
            {
                Model.Skill skill = dbContext.Skills.FirstOrDefault(
                    s => String.Equals(s.Name, newSkill.Name, StringComparison.OrdinalIgnoreCase));

                if (skill == null) // No existing skill was found
                {
                    skill = new Model.Skill()
                    {
                        Name = newSkill.Name
                    };
                    dbContext.Skills.Add(skill);
                    dbContext.SaveChanges();
                }
                return(skill.SkillId);
            }
        }
Ejemplo n.º 6
0
 public IEntity GetSkillFromKnown(KnownSkill knownSkill)
 {
     return(systemContainer.PrototypeSystem.Get(knownSkill.Skill));
 }
Ejemplo n.º 7
0
        private static MenuItem ConvertSkillToMenuItem(KnownSkill skill, ISystemContainer systemContainer, IEntity equippedEntity)
        {
            var skillEntity = systemContainer.SkillSystem.GetSkillFromKnown(skill);

            return(new MenuItem($"{skillEntity.DescriptionName}", skill));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs a Message with the supplied skill
 /// </summary>
 /// <param name="skill">Skill to initialize the class with</param>
 public SkillResponse(KnownSkill skill) : base(ResponseStatus.Success) => Skill = skill;