public bool DoesMeetRankRequirement(UserDataModel userData) { if (userData.IsCurrencyRankExempt) { return(true); } CurrencyModel currency = this.GetCurrency(); if (currency == null) { return(false); } RankModel rank = this.RequiredRank; if (rank == null) { return(false); } if (!currency.HasAmount(userData, rank.Amount)) { return(false); } if (this.MustEqual && currency.GetRank(userData) != rank) { return(false); } return(true); }
public override Task <Result> Validate(CommandParametersModel parameters) { CurrencyModel rankSystem = this.RankSystem; if (rankSystem == null) { return(Task.FromResult(new Result(MixItUp.Base.Resources.RankSystemDoesNotExist))); } RankModel rank = this.RequiredRank; if (rank == null) { return(Task.FromResult(new Result(MixItUp.Base.Resources.RankDoesNotExist))); } if (!parameters.User.Data.IsCurrencyRankExempt) { RankModel currentRank = rankSystem.GetRank(parameters.User.Data); if (this.MatchType == RankRequirementMatchTypeEnum.GreaterThanOrEqualTo) { if (!rankSystem.HasAmount(parameters.User.Data, rank.Amount)) { return(Task.FromResult(new Result(string.Format(MixItUp.Base.Resources.RankRequirementNotGreaterThanOrEqual, rank.Name, rank.Amount, rankSystem.Name) + " " + string.Format(MixItUp.Base.Resources.RequirementCurrentAmount, currentRank)))); } } else if (this.MatchType == RankRequirementMatchTypeEnum.EqualTo) { if (rankSystem.GetRank(parameters.User.Data) != rank) { return(Task.FromResult(new Result(string.Format(MixItUp.Base.Resources.RankRequirementNotGreaterThanOrEqual, rank.Name, rank.Amount, rankSystem.Name) + " " + string.Format(MixItUp.Base.Resources.RequirementCurrentAmount, currentRank)))); } } else if (this.MatchType == RankRequirementMatchTypeEnum.LessThanOrEqualTo) { RankModel nextRank = rankSystem.GetNextRank(parameters.User.Data); if (nextRank != CurrencyModel.NoRank && rankSystem.HasAmount(parameters.User.Data, nextRank.Amount)) { return(Task.FromResult(new Result(string.Format(MixItUp.Base.Resources.RankRequirementNotLessThan, rank.Name, rank.Amount, rankSystem.Name) + " " + string.Format(MixItUp.Base.Resources.RequirementCurrentAmount, currentRank)))); } } } return(Task.FromResult(new Result())); }
public override async Task <bool> Validate(UserViewModel user) { CurrencyModel rankSystem = this.RankSystem; if (rankSystem == null) { return(false); } RankModel rank = this.RequiredRank; if (rank == null) { return(false); } if (!user.Data.IsCurrencyRankExempt) { if (this.MatchType == RankRequirementMatchTypeEnum.GreaterThanOrEqualTo) { if (!rankSystem.HasAmount(user.Data, rank.Amount)) { await this.SendChatMessage(string.Format("You do not have the required rank of {0} ({1} {2}) to do this", rank.Name, rank.Amount, rankSystem.Name)); return(false); } } else if (this.MatchType == RankRequirementMatchTypeEnum.EqualTo) { if (rankSystem.GetRank(user.Data) != rank) { await this.SendChatMessage(string.Format("You do not have the required rank of {0} to do this", rank.Name, rank.Amount, rankSystem.Name)); return(false); } } else if (this.MatchType == RankRequirementMatchTypeEnum.LessThanOrEqualTo) { RankModel nextRank = rankSystem.GetNextRank(user.Data); if (nextRank != CurrencyModel.NoRank && rankSystem.HasAmount(user.Data, nextRank.Amount)) { await this.SendChatMessage(string.Format("You are over the required rank of {0} ({1} {2}) to do this", rank.Name, rank.Amount, rankSystem.Name)); return(false); } } } return(true); }