예제 #1
0
        private void AddPlaysound(string name, uint price, string fileName, string source, Action <string> messageCallback)
        {
            if (Settings.PlaysoundsSavedSounds.FirstOrDefault(ps => ps.Name == name) != null)
            {
                messageCallback.Invoke(ColorCoder.Error($"A playsound with the name {ColorCoder.Bold($"'{name}'")} already exists!"));
                return;
            }

            string filePath = Utils.GetProjectFilePath($"{SoundsFolder}\\{fileName}");

            if (!File.Exists(filePath))
            {
                messageCallback.Invoke(ColorCoder.Error($"No file with the name {ColorCoder.Bold($"'{fileName}'")} was found in the playsounds folder!"));
                return;
            }

            Settings.PlaysoundsSavedSounds.Add(new Playsound()
            {
                Name      = name,
                FileName  = fileName,
                BasePrice = (int)price,
                Source    = source,
            });
            Settings.DelayedSave();

            messageCallback.Invoke(ColorCoder.Success($"Added playsound {ColorCoder.Bold($"'{name}'")}!"));
        }
예제 #2
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            string action     = parameters[0];
            string targetUser = parameters[1];
            Client target     = Parent.Client.GetClientByNamePart(targetUser);
            Group  group      = null;

            if (action == "add" || action == "remove")
            {
                group = AccessManager.GetGroupByName(parameters[2]);
                if (group == null)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"The group named '{ColorCoder.Bold(parameters[2])}' was not found"));
                    return;
                }
            }

            if (action == "add")
            {
                bool success = AccessManager.AddUserGroup(target.UniqueId, group);
                if (success)
                {
                    messageCallback.Invoke(ColorCoder.Success($"{ColorCoder.Username(target.Nickname)} was added to the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
                else
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"{ColorCoder.Username(target.Nickname)} is already in the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
            }
            else if (action == "remove")
            {
                bool success = AccessManager.RemoveUserGroup(target.UniqueId, group);
                if (success)
                {
                    messageCallback.Invoke(ColorCoder.Success($"{ColorCoder.Username(target.Nickname)} was removed from the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
                else
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"{ColorCoder.Username(target.Nickname)} was not in the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
            }
            else if (action == "list")
            {
                List <Group> groups  = AccessManager.GetUserGroups(target.UniqueId);
                string       toPrint = $"{ColorCoder.Username(target.Nickname)} has the following groups:";
                foreach (Group printGroup in groups)
                {
                    toPrint += $"\n\t- {printGroup.DisplayName}";
                }
                messageCallback.Invoke(toPrint);
            }
        }
예제 #3
0
        private void RemovePlaysound(string name, Action <string> messageCallback)
        {
            if (Settings.PlaysoundsSavedSounds.FirstOrDefault(ps => ps.Name == name) == null)
            {
                messageCallback.Invoke(ColorCoder.Error($"A playsound with the name {ColorCoder.Bold($"'{name}'")} wasn't found!"));
                return;
            }

            Playsound sound = Settings.PlaysoundsSavedSounds.First(ps => ps.Name == name);

            Settings.PlaysoundsSavedSounds.Remove(sound);
            Settings.DelayedSave();

            messageCallback.Invoke(ColorCoder.Success($"Removed playsound {ColorCoder.Bold($"'{name}'")}!"));
        }
예제 #4
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            string targetUid  = evt.InvokerUniqueId;
            string targetName = evt.InvokerName;

            if (TargetNamePart != null)
            {
                Client target = Parent.Client.GetClientByNamePart(TargetNamePart);
                targetUid  = target.UniqueId;
                targetName = target.Nickname;
            }

            CooldownManager.ResetCooldowns(targetUid);
            messageCallback.Invoke(ColorCoder.Success($"Reset all cooldowns for {ColorCoder.Username(targetName)}"));
        }
예제 #5
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            Client target = null;

            if (TargetName != null)
            {
                target = Parent.Client.GetClientByNamePart(TargetName);
            }

            if (target == null)
            {
                target = Parent.Client.GetClientById(evt.InvokerId);
            }

            if (IsSendingBalance)
            {
                if (SendParam == "all")
                {
                    SendAmount = (uint)Math.Max(0, EconomyManager.GetBalanceForUser(evt.InvokerUniqueId));
                }
                else if (SendParam == "excess")
                {
                    int tempB = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId);
                    if (tempB > Settings.EcoSoftBalanceLimit)
                    {
                        SendAmount = (uint)(tempB - Settings.EcoSoftBalanceLimit);
                    }
                    else
                    {
                        SendAmount = 0;
                    }
                }

                if (SendAmount == 0)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"Why would you want to send {ColorCoder.Currency(0)}? What are you, stupid {ColorCoder.Username(evt.InvokerName)}"));
                    return;
                }
                else if (EconomyManager.GetUserBalanceAfterPaying(evt.InvokerUniqueId, (int)SendAmount) < 0)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"You can't afford to send that much cash, {ColorCoder.Username(evt.InvokerName)}"));
                    return;
                }
                else if (EconomyManager.GetUserBalanceAfterPaying(target.UniqueId, -1 * (int)SendAmount) > Settings.EcoSoftBalanceLimit)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"You can't send that much cash because {ColorCoder.Username(target.Nickname)} would have more than '{ColorCoder.Currency(Settings.EcoSoftBalanceLimit)}'"));
                    return;
                }

                EconomyManager.ChangeBalanceForUser(evt.InvokerUniqueId, (-1) * (int)SendAmount);
                EconomyManager.ChangeBalanceForUser(target.UniqueId, (int)SendAmount);

                messageCallback.Invoke(ColorCoder.SuccessDim($"Sent '{ColorCoder.Currency(SendAmount)}' to {ColorCoder.Username(target.Nickname)}"));
            }
            else if (command == "setbalance")
            {
                int setAmount = SetAmount;
                if (SetAmountIsRelative)
                {
                    setAmount += EconomyManager.GetBalanceForUser(target.UniqueId);
                }

                EconomyManager.SetBalanceForUser(target.UniqueId, setAmount);
                int setTo = EconomyManager.GetBalanceForUser(target.UniqueId);
                messageCallback.Invoke(ColorCoder.Success($"Set balance for {ColorCoder.Username(target.Nickname)} to {ColorCoder.Bold($"{setTo} {Settings.EcoPointUnitName}")}"));
            }
            else
            {
                int max     = Settings.EcoSoftBalanceLimit;
                int balance = EconomyManager.GetBalanceForUser(target.UniqueId);
                messageCallback.Invoke($"Balance of {ColorCoder.Username(target.Nickname)}: {ColorCoder.Bold(balance.ToString())} / {ColorCoder.Bold($"{max} {Settings.EcoPointUnitName}")}");
            }
        }
예제 #6
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            if (command != CommandPrefix)
            {
                if (!Settings.DynamicCommands.ContainsKey(command.ToLower()))
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"The command {command} was not found in the dynamic commands list (should never happen)"));
                }

                string parametersJoined = string.Join(" ", parameters);
                string toPrint          = Settings.DynamicCommands[command.ToLower()];
                toPrint = toPrint.Replace("{params}", parametersJoined);
                messageCallback.Invoke(toPrint);
                return;
            }

            string action      = parameters[0];
            string commandName = "";
            string commandText = "";

            if (action == "add")
            {
                commandName = parameters[1];
                commandText = string.Join(" ", parameters.Skip(2));
            }
            else if (action == "remove")
            {
                commandName = parameters[1];
            }

            commandName = commandName.ToLower();


            if (action == "add")
            {
                if (Settings.DynamicCommands.ContainsKey(commandName))
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"The command {ColorCoder.Bold($"'{commandName}'")} already exists."));
                    return;
                }

                Settings.DynamicCommands.Add(commandName, commandText);
                messageCallback.Invoke(ColorCoder.Success($"Added command {ColorCoder.Bold($"'{commandName}'")}."));
                Settings.DelayedSave();
            }
            else if (action == "remove")
            {
                if (!Settings.DynamicCommands.ContainsKey(commandName))
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"The command {ColorCoder.Bold($"'{commandName}'")} does not exists."));
                    return;
                }

                Settings.DynamicCommands.Remove(commandName);
                messageCallback.Invoke(ColorCoder.Success($"Removed command {ColorCoder.Bold($"'{commandName}'")}."));
                Settings.DelayedSave();
            }
            else if (action == "list")
            {
                if (Settings.DynamicCommands.Count == 0)
                {
                    messageCallback.Invoke($"The dynamic commands list is currently empty.");
                    return;
                }


                string toPrint = $"These are all registered commands ({Settings.DynamicCommands.Count}):";
                foreach (string dynCommand in Settings.DynamicCommands.Keys.OrderBy(s => s))
                {
                    string dynCommandText = Settings.DynamicCommands[dynCommand];
                    toPrint += $"\n\t{ColorCoder.Bold($"'{dynCommand}'")}: {dynCommandText}";
                }

                messageCallback.Invoke(toPrint);
            }
        }
예제 #7
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            int amountToGamble      = 0;
            StatisticSettings stats = Parent.StatSettings;

            if (RequestedStats)
            {
                RouletteStatistics displayStats;
                string             toPrint;

                if (RequestedStatsName != null && RequestedStatsName == "all")
                {
                    displayStats = stats.Roulette;
                    toPrint      = "Global roulette stats:";
                }
                else
                {
                    string userUid  = evt.InvokerUniqueId;
                    string userName = evt.InvokerName;

                    if (RequestedStatsName != null)
                    {
                        Client user = Parent.Client.GetClientByNamePart(RequestedStatsName);
                        userUid  = user.UniqueId;
                        userName = user.Nickname;
                    }

                    CheckHasStatisticsEntry(userUid);
                    displayStats = stats.RouletteIndividual[userUid];
                    toPrint      = $"Roulette stats for {ColorCoder.Username(userName)}:";
                }

                int    won          = displayStats.GamesWon;
                int    lost         = displayStats.GamesLost;
                double ratioPercent = (double)won * 100 / (lost + won);
                string ratioPercentStr;
                if (double.IsNaN(ratioPercent))
                {
                    ratioPercentStr = "-%";
                }
                else
                {
                    ratioPercentStr = ColorCoder.ColorPivotPercent(ratioPercent, 50);
                }
                toPrint += $"\n\tGames: {won + lost} ({ColorCoder.SuccessDim($"{won}W")}, {ColorCoder.ErrorBright($"{lost}L")} | {ratioPercentStr})";

                int    balanceWon     = displayStats.PointsWon;
                int    balanceLost    = displayStats.PointsLost;
                int    balanceDiff    = balanceWon - balanceLost;
                string balanceDiffStr = ColorCoder.ColorPivot(balanceDiff, 0);
                toPrint += $"\n\tPoints: {balanceDiffStr} ({ColorCoder.SuccessDim($"+{balanceWon} won")}, {ColorCoder.ErrorBright($"-{balanceLost} lost")})";

                int jackpots      = displayStats.Jackpots;
                int jackpotPoints = displayStats.JackpotsPointsWon;
                toPrint += $"\n\tJackpots: {jackpots} ({ColorCoder.SuccessDim($"+{jackpotPoints} bonus")})";

                double rolls    = displayStats.Rolls;
                string rollsStr = (won + lost) == 0 ? "-" : $"{rolls / (won + lost):0.####}";
                toPrint += $"\n\tAvg. Roll: {rollsStr}";

                messageCallback.Invoke(toPrint);
                return;
            }


            if (!Settings.RouletteEnabled)
            {
                messageCallback.Invoke(ColorCoder.ErrorBright($"The casino is currently closed, sorry {ColorCoder.Username(evt.InvokerName)}!"));
                return;
            }

            CooldownManager.ThrowIfCooldown(evt.InvokerUniqueId, "command:roulette");

            int currentBalance = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId);

            if (currentBalance > Settings.EcoSoftBalanceLimit)
            {
                messageCallback.Invoke(ColorCoder.ErrorBright($"You can't gamble while being over {ColorCoder.Bold($"{Settings.EcoSoftBalanceLimit} {Settings.EcoPointUnitName}")}, {ColorCoder.Username(evt.InvokerName)}"));
                return;
            }

            if (IsAll)
            {
                amountToGamble = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId);
            }
            else if (IsPercent)
            {
                if (Amount > 100)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"You can't gamble away more than you own, {ColorCoder.Username(evt.InvokerName)}"));
                    return;
                }

                amountToGamble = EconomyManager.GetBalanceForUser(evt.InvokerUniqueId);
                amountToGamble = (int)Math.Ceiling(amountToGamble * ((double)Amount / 100));
            }
            else
            {
                int balanceAfterPay = EconomyManager.GetUserBalanceAfterPaying(evt.InvokerUniqueId, (int)Amount);
                if (balanceAfterPay < 0)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"You don't have enough to gamble away '{ColorCoder.Bold($"{Amount} {Settings.EcoPointUnitName}")}', {ColorCoder.Username(evt.InvokerName)}"));
                    return;
                }

                amountToGamble = (int)Amount;
            }

            if (amountToGamble <= 0)
            {
                messageCallback.Invoke(ColorCoder.ErrorBright($"You don't have any cash on you, get out of my casino!"));
                return;
            }

            CooldownManager.SetCooldown(evt.InvokerUniqueId, "command:roulette", Settings.RouletteCooldown);


            double winChancePercent     = Settings.RouletteWinChancePercent;
            double jackpotChancePercent = Settings.RouletteJackpotChancePercent;

            if (amountToGamble == Settings.EcoSoftBalanceLimit)
            {
                winChancePercent += 1;
            }

            winChancePercent     /= 100;
            jackpotChancePercent /= 100;

            Random r           = new Random();
            double chosenValue = r.NextDouble();

            string resultLogMsg = $"({chosenValue:0.#####} | win {winChancePercent:0.#####} | jackpot {jackpotChancePercent:0.#####})";

            Parent.LastRouletteResult = resultLogMsg;
            Parent.LogMessage($"Roulette result: {resultLogMsg}");

            int    changeBalanceAmount;
            string message;
            string ptsUnit = Settings.EcoPointUnitName;

            CheckHasStatisticsEntry(evt.InvokerUniqueId);
            RouletteStatistics indivStats = stats.RouletteIndividual[evt.InvokerUniqueId];
            RouletteStatistics allStats   = stats.Roulette;

            allStats.Rolls   += chosenValue;
            indivStats.Rolls += chosenValue;

            if (chosenValue < winChancePercent)   //User won the roulette

            {
                double yield = Settings.RouletteWinYieldMultiplier;
                changeBalanceAmount = (int)Math.Floor(amountToGamble * (yield - 1));

                if (chosenValue < jackpotChancePercent)
                {
                    allStats.Jackpots++;
                    int jackpotPoints = (int)(changeBalanceAmount * Settings.RouletteJackpotMultiplier);

                    allStats.JackpotsPointsWon   += jackpotPoints - changeBalanceAmount;
                    indivStats.JackpotsPointsWon += jackpotPoints - changeBalanceAmount;

                    changeBalanceAmount = jackpotPoints;
                    messageCallback.Invoke(ColorCoder.Success($"\t-\t JACKPOT! Your reward has just been tripled!\t-\t"));
                }

                allStats.GamesWon++;
                indivStats.GamesWon++;
                allStats.PointsWon   += changeBalanceAmount;
                indivStats.PointsWon += changeBalanceAmount;
                message = ColorCoder.ColorText(Color.DarkGreen, ColorCoder.Username(evt.InvokerName) + $" won {ColorCoder.Bold(changeBalanceAmount.ToString())} {ptsUnit} in roulette and now has {ColorCoder.Bold((currentBalance + changeBalanceAmount).ToString())} {ptsUnit} forsenPls ({chosenValue:0.####})");
            }
            else
            {
                changeBalanceAmount = -amountToGamble;
                allStats.GamesLost++;
                indivStats.GamesLost++;
                allStats.PointsLost   += amountToGamble;
                indivStats.PointsLost += amountToGamble;
                message = ColorCoder.ErrorBright(ColorCoder.Username(evt.InvokerName) + $" lost {ColorCoder.Bold(amountToGamble.ToString())} {ptsUnit} in roulette and now has {ColorCoder.Bold((currentBalance + changeBalanceAmount).ToString())} {ptsUnit} FeelsBadMan ({chosenValue:0.####})");
            }

            stats.DelayedSave();

            EconomyManager.ChangeBalanceForUser(evt.InvokerUniqueId, changeBalanceAmount);
            messageCallback.Invoke(message);
        }