public static bool OpenRoulette(string id)
        {
            List <Roulette> OpenRoulette = Roulettes.Where(x => x.id == Guid.Parse(id)).ToList();

            OpenRoulette.ForEach(x => x.isOpen = true);
            return(OpenRoulette.Count > 0);
        }
Example #2
0
        public void CloseRoullete(Roulettes roulettes)
        {
            var roulette = _context.Roulettes.Where(r => r.RouletteId == roulettes.RouletteId).SingleOrDefault();

            _context.Roulettes.Update(roulette);
            _context.SaveChanges();
        }
        public static bool BetInRoulette(Bet _bet)
        {
            if (Roulettes.Any(roullete => roullete.id == _bet.id_roullete && roullete.isOpen))
            {
                Bets.Add(_bet);
                if (!Clients.Any(client => client.id_client == _bet.id_client))
                {
                    Clients.Add(new Client {
                        id_client = _bet.id_client
                    });
                }

                Clients.Where(client => client.id_client == _bet.id_client)
                .ToList()
                .ForEach(client =>
                {
                    client.balance -= _bet.amount;
                    client.earnings = 0;
                    client.isWinner = false;
                });

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static string AddRoullete()
        {
            Guid _id = Guid.NewGuid();

            Roulettes.Add(new Roulette {
                id = _id
            });
            return(_id.ToString());
        }
Example #5
0
        public List <dynamic> Get()
        {
            var list = new List <dynamic>();

            list.AddRange(Roulettes.Select(x => (dynamic)GetRoulette(x)));
            list.AddRange(RouletteResults.Select(x => (dynamic)GetRouletteResult(x)));

            return(list);
        }
Example #6
0
        public ActionResult OpenRoulette(Roulettes roulette)
        {
            if (!_rouletteService.OpenRoulette(roulette))
            {
                return(NotFound());
            }

            return(Ok());
        }
Example #7
0
        public Guid Create()
        {
            var      key      = Guid.NewGuid();
            Roulette roulette = new() { Id = key };

            Roulettes = Roulettes.Append(key).ToList();
            _cache.JsonSet(key.ToString(), roulette);

            return(key);
        }
Example #8
0
        public int CreateRoulette()
        {
            var roulette = new Roulettes()
            {
                Open = false
            };

            _context.Roulettes.Add(roulette);
            _context.SaveChanges();
            _logger.LogInformation("Created Roulette");
            return(roulette.RouletteId);
        }
        public static ICollection <Client> CloseRoulette(string id)
        {
            if (Roulettes.Any(roullete => roullete.id.ToString() == id && roullete.isOpen))
            {
                Roulettes.Where(roullete => roullete.id.ToString() == id)
                .ToList()
                .ForEach(roulette => roulette.isOpen = false);

                return(GetClientsWinners());
            }
            else
            {
                return(new List <Client>());
            }
        }
Example #10
0
        public bool OpenRoulette(Roulettes roulette)
        {
            var result = _context.Roulettes.Where(r => r.RouletteId == roulette.RouletteId && !r.Open).SingleOrDefault();

            if (result == null)
            {
                _logger.LogInformation("RouletteId doesn't exist");
                return(false);
            }

            result.Open = true;
            _context.SaveChanges();
            _logger.LogInformation("Opened Roulette");
            return(true);
        }
Example #11
0
        internal static Roulette GetRoulette(int code)
        {
            if (Roulettes.TryGetValue(code, out var roulette))
            {
                return(roulette);
            }

            if (code != 0)
            {
                // "Missing Roulette code"
            }

            return(new Roulette {
                Name = Localization.GetText("unknown-roulette", code)
            });
        }
Example #12
0
        internal static Roulette GetRoulette(int code)
        {
            if (Roulettes.TryGetValue(code, out var roulette))
            {
                return(roulette);
            }

            if (code != 0)
            {
                var @event = new SentryEvent("Missing Roulette code");
                @event.Level        = ErrorLevel.Warning;
                @event.Tags["code"] = code.ToString();
                Sentry.ReportAsync(@event);
            }

            return(new Roulette {
                Name = Localization.GetText("unknown-roulette", code)
            });
        }
Example #13
0
        public RouletteResult CloseBets(Guid id)
        {
            var roulette = GetRoulette(id);

            var(number, color) = SpinRoulette();
            var rouletteResult = new RouletteResult()
            {
                Id     = roulette.Id,
                Number = number,
                Color  = color,
                Bets   = roulette.Bets
            };

            rouletteResult = ProcessBets(rouletteResult, number, color);
            _cache.JsonSet(id.ToString(), rouletteResult);
            Roulettes       = Roulettes.Where(x => x != id).ToList();
            RouletteResults = RouletteResults.Append(id).ToList();

            return(rouletteResult);
        }
Example #14
0
        internal static Roulette GetRoulette(int code)
        {
            if (Roulettes.TryGetValue(code, out var roulette))
            {
                Log.Debug($"Debug:随机任务[ID.{code}:{roulette.Name}]");
                return(roulette);
            }

            if (code != 0)
            {
                Log.Debug($"Debug:未知的随机任务[ID.{code}]");
                //var @event = new SentryEvent("Missing Roulette code");
                //@event.Level = ErrorLevel.Warning;
                //@event.Tags["code"] = code.ToString();
                //Sentry.ReportAsync(@event);
            }

            return(new Roulette {
                Name = Localization.GetText("unknown-roulette", code)
            });
        }
Example #15
0
 public List <Bets> ClosedBet(Roulettes roulettes)
 {
     _betService.ClosedBet(roulettes);
     return(_betService.GetBetsByRoulette(roulettes));
 }
Example #16
0
 public dynamic GetById(Guid id) => Roulettes.Contains(id) ? GetRoulette(id) : GetRouletteResult(id);
Example #17
0
        public bool DrawConfigUI()
        {
            var drawConfig = true;

            var scale = ImGui.GetIO().FontGlobalScale;

            var modified = false;

            ImGui.SetNextWindowSize(new Vector2(360 * scale, 350), ImGuiCond.FirstUseEver);
            ImGui.SetNextWindowSizeConstraints(new Vector2(360 * scale, 350), new Vector2(560 * scale, 650));
            ImGui.Begin($"{plugin.Name} Config", ref drawConfig, ImGuiWindowFlags.NoCollapse);

#if DEBUG
            var alwaysShowAlert = AlwaysShowAlert;
            if (ImGui.Checkbox("Debug: Always Alert", ref alwaysShowAlert))
            {
                AlwaysShowAlert = alwaysShowAlert;
                Save();
            }

            if (ImGui.Button("Debug: Print All Alerts"))
            {
                foreach (var r in plugin.RouletteList)
                {
                    if (r.ContentRouletteRoleBonus.Row > 0)
                    {
                        try {
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.Tank);
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.Healer);
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.DPS);
                        } catch (Exception ex) {
                            PluginLog.LogError(ex.ToString());
                        }
                    }
                }
            }
#endif

            var inGameAlerts = InGameAlert;
            if (ImGui.Checkbox("Send alerts in game chat.", ref inGameAlerts))
            {
                InGameAlert = inGameAlerts;
                Save();
            }

            ImGui.SameLine();
            ImGui.SetNextItemWidth(150);

            var selectedDetails = ChatType.GetDetails();

            if (ImGui.BeginCombo("###chatType", ChatType == XivChatType.None ? "Any" : (selectedDetails == null ? ChatType.ToString() : selectedDetails.FancyName)))
            {
                foreach (var chatType in ((XivChatType[])Enum.GetValues(typeof(XivChatType))))
                {
                    var details = chatType.GetDetails();

                    if (ImGui.Selectable(chatType == XivChatType.None ? "Any" : (details == null ? chatType.ToString() : details.FancyName), chatType == ChatType))
                    {
                        ChatType = chatType;
                        Save();
                    }

                    if (chatType == ChatType)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            var webhookAlerts = WebhookAlert;
            if (ImGui.Checkbox("Send alerts to webhook.", ref webhookAlerts))
            {
                WebhookAlert = webhookAlerts;
                Save();
            }

            ImGui.SameLine();
            if (ImGui.SmallButton("Setup Webhooks"))
            {
                showWebhookWindow = true;
            }

            ImGui.Separator();
            ImGui.Columns(6, "###cols", false);
            ImGui.SetColumnWidth(0, 40f * scale);
            ImGui.SetColumnWidth(1, ImGui.GetWindowWidth() - 240f * scale);
            ImGui.SetColumnWidth(2, 40f * scale);
            ImGui.SetColumnWidth(3, 40f * scale);
            ImGui.SetColumnWidth(4, 40f * scale);
            ImGui.SetColumnWidth(5, 80f * scale);

            ImGui.NextColumn();
            ImGui.Text("Roulette");
            ImGui.NextColumn();
            ImGui.Text("T");
            ImGui.NextColumn();
            ImGui.Text("H");
            ImGui.NextColumn();
            ImGui.Text("D");
            ImGui.NextColumn();
            ImGui.Text("Current");
            ImGui.NextColumn();

            ImGui.Separator();

            if (plugin.RouletteList != null)
            {
                foreach (var r in plugin.RouletteList.Where(r => r != null && r.ContentRouletteRoleBonus != null && r.ContentRouletteRoleBonus.Row > 0))
                {
                    var rCfg = Roulettes.ContainsKey(r.RowId) ? Roulettes[r.RowId] : new RouletteConfig();
                    modified = ImGui.Checkbox($"###rouletteEnabled{r.RowId}", ref rCfg.Enabled) || modified;
                    ImGui.NextColumn();

                    ImGui.Text(r.Name);
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteTankEnabled{r.RowId}", ref rCfg.Tank) || modified;
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteHealerEnabled{r.RowId}", ref rCfg.Healer) || modified;
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteDPSEnabled{r.RowId}", ref rCfg.DPS) || modified;
                    ImGui.NextColumn();

                    if (plugin.LastPreferredRoleList != null)
                    {
                        var currentRole = plugin.LastPreferredRoleList.Get(r.ContentRouletteRoleBonus.Row);
                        ImGui.Text(currentRole.ToString());
                    }

                    ImGui.NextColumn();

                    Roulettes[r.RowId] = rCfg;
                }
            }

            ImGui.Columns(1);

            ImGui.End();

            if (modified)
            {
                Save();
            }


            if (showWebhookWindow)
            {
                ImGui.Begin($"{plugin.Name}: Webhooks", ref showWebhookWindow);

                ImGui.TextWrapped($"Add webhook urls here to have {plugin.Name} send alerts somewhere else, like discord.");

                ImGui.TextColored(new Vector4(0.5f, 0.5f, 1f, 1f), "Discord Webhook Guide");
                if (ImGui.IsItemHovered())
                {
                    ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
                }

                if (ImGui.IsItemClicked(0))
                {
                    Process.Start("https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks");
                }

                for (var i = 0; i < Webhooks.Count; i++)
                {
                    var url = Webhooks[i];
                    ImGui.SetNextItemWidth(-1);
                    if (ImGui.InputText($"###webhook{i}", ref url, 1024))
                    {
                        Webhooks[i] = url;
                        Save();
                    }
                }

                if (ImGui.SmallButton("Add Webhook"))
                {
                    Webhooks.Add("");
                }

                ImGui.End();
            }


            return(drawConfig);
        }
Example #18
0
 //
 public static Roulette TryRoulette(int code)
 {
     return(Roulettes.TryGetValue(code, out Roulette roulette) ? roulette : null);
 }
Example #19
0
 public List <Bets> GetBetsByRoulette(Roulettes roulettes)
 {
     return(_context.Bets.Where(b => b.Roulettes.RouletteId == roulettes.RouletteId).ToList());
 }
Example #20
0
 //
 public static Roulette GetRoulette(int code)
 {
     return(Roulettes.TryGetValue(code, out var roulette) ? roulette : new Roulette {
         Name = Localization.GetText("l-unknown-roulette", code)
     });
 }
Example #21
0
 //
 public static Roulette GetRoulette(int code)
 {
     return(Roulettes.TryGetValue(code, out Roulette roulette) ? roulette : new Roulette {
         Name = Mesg.GetText("l-unknown-roulette", code)
     });
 }
Example #22
0
 public void ClosedBet(Roulettes roulettes)
 {
     _rouletteService.CloseRoullete(roulettes);
 }