Example #1
0
        protected virtual bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            var totalCooldown = Cooldown * (1 - user.CooldownReduction());

            if (!user.HasWeaponType(RequiredWeapon) && RequiredWeapon != null)
            {
                response = new DougResponse(string.Format(DougMessages.WrongWeaponForSkill, RequiredWeapon.Name));
                return(false);
            }

            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.FireSkill(user.Id, TimeSpan.FromSeconds(totalCooldown), user.Energy);
            response = new DougResponse();
            return(true);
        }
Example #2
0
        protected override bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            var totalCooldown = Cooldown * (1 - user.CooldownReduction());

            if (target is User targetUser)
            {
                var usersInChannel = _slack.GetUsersInChannel(channel).Result;
                if (usersInChannel.All(usr => usr != targetUser.Id))
                {
                    response = new DougResponse(DougMessages.UserNotInChannel);
                    return(false);
                }
            }

            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.FireSkill(user.Id, TimeSpan.FromSeconds(totalCooldown), user.Energy);
            response = new DougResponse();
            return(true);
        }
Example #3
0
        protected bool CanActivateSkill(User user, out DougResponse response)
        {
            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.UpdateEnergy(user.Id, user.Energy);
            StatsRepository.SetSkillCooldown(user.Id, TimeSpan.FromSeconds(Cooldown));
            response = new DougResponse();
            return(true);
        }
Example #4
0
        private async Task <DougResponse> StealFromUser(User user, User target, string channel)
        {
            _statsRepository.SetSkillCooldown(user.Id, TimeSpan.FromSeconds(Cooldown));

            var userChance   = _eventDispatcher.OnStealingChance(user, user.BaseStealSuccessRate());
            var targetChance = _eventDispatcher.OnGettingStolenChance(target, target.BaseOpponentStealSuccessRate());

            var rollSuccessful = _randomService.RollAgainstOpponent(userChance, targetChance);
            var detected       = !_randomService.RollAgainstOpponent(user.BaseDetectionAvoidance(), target.BaseDetectionChance());

            var amount = _eventDispatcher.OnStealingAmount(user, user.BaseStealAmount());

            if (target.Credits - amount < 0)
            {
                amount = target.Credits;
            }

            string       message;
            DougResponse sneakResponse;

            if (rollSuccessful)
            {
                _creditsRepository.RemoveCredits(target.Id, amount);
                _creditsRepository.AddCredits(user.Id, amount);

                message       = string.Format(DougMessages.StealCreditsCaught, _userService.Mention(user), amount, _userService.Mention(target));
                sneakResponse = new DougResponse(string.Format(DougMessages.StealCredits, amount, _userService.Mention(target)));
            }
            else
            {
                message       = string.Format(DougMessages.StealFailCaught, _userService.Mention(user), _userService.Mention(target));
                sneakResponse = new DougResponse(string.Format(DougMessages.StealFail, _userService.Mention(target)));
            }

            if (detected)
            {
                await _slack.BroadcastMessage(message, channel);
            }

            return(sneakResponse);
        }
Example #5
0
        protected override bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            if (target is User targetUser)
            {
                _eventDispatcher.OnAttacking(user, target, 0);

                var channelType = _channelRepository.GetChannelType(channel);
                if (channelType != ChannelType.Pvp)
                {
                    response = new DougResponse(DougMessages.NotInRightChannel);
                    return(false);
                }

                var usersInChannel = _slack.GetUsersInChannel(channel).Result;
                if (usersInChannel.All(usr => usr != targetUser.Id))
                {
                    response = new DougResponse(DougMessages.UserIsNotInPvp);
                    return(false);
                }
            }

            return(base.CanActivateSkill(user, target, channel, out response));
        }