void LearnSkill(string service, string username, string skill) { Player player = context.GetModule <PlayerModule>().GetExistingPlayer(service, username); User user = context.GetModule <UserModule>().GetUser(player.UserID); SkillType skilltype = (SkillType)Enum.Parse(typeof(SkillType), skill, true); int skillevel = GetSkillLevel(player.UserID, skilltype); if (skillevel >= 3) { throw new StreamCommandException($"You know everything there is to know about {skilltype}."); } int skillconsumption = GetUsedSkillPoints(player.UserID); int skillpointsleft = player.Level - skillconsumption; int nextlevel = skillevel + 1; if (skillpointsleft < GetSkillpointRequirement(nextlevel)) { context.GetModule <RPGMessageModule>().Create().User(user).Text(" doesn't have enough skillpoints to learn ").Skill(skilltype).Send(); return; } if (context.Database.Update <PlayerSkill>().Set(s => s.Level == s.Level + 1).Where(s => s.PlayerID == player.UserID && s.Skill == skilltype).Execute() == 0) { context.Database.Insert <PlayerSkill>().Columns(s => s.PlayerID, s => s.Skill, s => s.Level).Values(player.UserID, skilltype, nextlevel).Execute(); } context.GetModule <RPGMessageModule>().Create().User(user).Text(" learned ").Skill(skilltype).Text($" level {nextlevel}.").Send(); SkillChanged?.Invoke(player.UserID, skilltype, nextlevel); }
void ForgetSkill(string service, string username, string skill) { Player player = context.GetModule <PlayerModule>().GetExistingPlayer(service, username); SkillType skilltype = (SkillType)Enum.Parse(typeof(SkillType), skill, true); int level = GetSkillLevel(player.UserID, skilltype); if (level <= 0) { throw new StreamCommandException($"You don't know anything of {skilltype}"); } context.Database.Update <PlayerSkill>().Set(s => s.Level == s.Level - 1).Where(s => s.PlayerID == player.UserID && s.Skill == skilltype).Execute(); context.Database.Delete <PlayerSkill>().Where(s => s.Level <= 0).Execute(); User user = context.GetModule <UserModule>().GetExistingUser(service, username); context.GetModule <RPGMessageModule>().Create().User(user).Text(" forgets something about ").Skill(skilltype).Text(".").Send(); SkillChanged?.Invoke(player.UserID, skilltype, level - 1); }
public void ChangeSkill(Skill skill) { Skill = skill; SkillChanged?.Invoke(this); }