private void enchantToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.lstRunes.SelectedItems.Count <= 0)
            {
                return;
            }

            int EnchantLevel = Utils.CInt(Utils.Input_Text("To What Level?", "Enchant this Rune to what level (1 - 4):"));

            if ((EnchantLevel < 1) || (EnchantLevel > 4))
            {
                return;
            }

            try
            {
                GameObjs.Rune Rune = (GameObjs.Rune) this.lstRunes.SelectedItems[0].Tag;

                Utils.StartMethodMultithreaded(() =>
                {
                    GameClient.Current.EnchantRune(Rune.Name, EnchantLevel, Rune.ID_User);
                });
            }
            catch { }
        }
            public int CompareLVIs(ListViewItem lvi1, ListViewItem lvi2)
            {
                if (this._SortOrder == System.Windows.Forms.SortOrder.None)
                {
                    return(0);
                }

                int sort_result = -1;

                GameObjs.Rune Rune1 = (GameObjs.Rune)lvi1.Tag;
                GameObjs.Rune Rune2 = (GameObjs.Rune)lvi2.Tag;

                if (this._ComparerType == ComparerTypes.EK_Rune_Level)
                {
                    sort_result = Rune1.Level.CompareTo(Rune2.Level);
                }
                else if (this._ComparerType == ComparerTypes.Standard_Numeric)
                {
                    sort_result = Utils.CInt(lvi1.SubItems[_SortedColumn].Text).CompareTo(Utils.CInt(lvi2.SubItems[_SortedColumn].Text));
                }
                else
                {
                    sort_result = string.Compare(lvi1.SubItems[_SortedColumn].Text, lvi2.SubItems[_SortedColumn].Text);
                }

                return((this._SortOrder == System.Windows.Forms.SortOrder.Ascending) ? sort_result : -sort_result);
            }
        private void previewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.lstRunes.SelectedItems.Count <= 0)
            {
                return;
            }

            try
            {
                GameObjs.Rune Rune = (GameObjs.Rune) this.lstRunes.SelectedItems[0].Tag;

                frmMain.ext().PopupRunePreviewWindow(Rune.ID_Generic, Rune.Level, Cursor.Position);
            }
            catch { }
        }
        private void sellToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <ListViewItem> items = this.AllSelectedItems;

            if (items.Count <= 0)
            {
                return;
            }

            if (MessageBox.Show("Do you really want to sell " + items.Count.ToString("#,##0") + " " + Utils.PluralWord(items.Count, "rune", "runes") + "?", "Confirm Rune Sale", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            string runes_to_sell   = "";
            int    gold_amount     = 0;
            int    gold_runes_sold = items.Count;

            foreach (ListViewItem lvi in items)
            {
                GameObjs.Rune rune = (GameObjs.Rune)lvi.Tag;

                runes_to_sell += rune.ID_User.ToString() + "_";
                gold_amount   += rune.SellWorth;
            }

            runes_to_sell = runes_to_sell.Trim(new char[] { '_' });

            Cursor cur = this.Cursor;

            this.Cursor = Cursors.WaitCursor;
            Utils.StartMethodMultithreadedAndWait(() =>
            {
                GameClient.Current.GetGameData("card", "SaleCardRunes", "Runes=" + runes_to_sell);
                GameClient.Current.GameVitalsUpdate(GameClient.Current.GetGameData("user", "GetUserInfo"));
                GameClient.Current.UserRunes_CachedData = null;
                Utils.LoggerNotifications("<color=#ffa000>Sold " + gold_runes_sold.ToString("#,##0") + " " + Utils.PluralWord(gold_runes_sold, "rune", "runes") + " for " + gold_amount.ToString("#,##0") + " gold.</color>");
            });
            this.Cursor = cur;
            this.InitRunes();
        }
        private int FindBestUserRuneByName_IndexID(string name, JObject users_runes = null)
        {
            if (!Utils.ValidText(name))
                return -1;

            string required_rune_name = name.Trim();
            int rune_required_level = -1;

            if (required_rune_name.Contains(":"))
            {
                try
                {
                    string[] rune_search_parts = Utils.SubStringsDups(required_rune_name, ":");

                    required_rune_name = rune_search_parts[0].Trim();

                    if (rune_search_parts.Length >= 2)
                    {
                        if (Utils.ValidNumber(rune_search_parts[1]))
                        {
                            // name and level
                            rune_required_level = Utils.CInt(rune_search_parts[1]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.DebugLogger("Couldn't parse: " + name);
                    Utils.DebugLogger(Errors.GetShortErrorDetails(ex));
                }
            }

            required_rune_name = GameClient.DropLevelFromName(required_rune_name);

            if (rune_required_level == -1)
                Utils.DebugLogger("FILLING DECK: looking for rune <b>" + required_rune_name + "</b> at <b>best</b> level");
            else
                Utils.DebugLogger("FILLING DECK: looking for rune <b>" + required_rune_name + "</b> only at level <b>" + rune_required_level.ToString() + "</b>");

            try
            {
                if (users_runes == null)
                    users_runes = this.GetUsersRunes();

                int rune_required_GID = Utils.CInt(this.GetRuneByName(required_rune_name)["RuneId"]);
                int MatchingRuneIndex = -1;

                for (int Level = 10; Level > -1; Level--)
                {
                    int RunesInDeck = 0;

                    if (rune_required_level != -1)
                        if (Level != rune_required_level)
                            continue;

                    if (MatchingRuneIndex == -1)
                    {
                        foreach (var rune in users_runes["data"]["Runes"])
                        {
                            if (Utils.CInt(rune["RuneId"]) == rune_required_GID)
                            {
                                if (Utils.CInt(rune["Level"]) == Level)
                                {
                                    GameObjs.Rune this_rune = new GameObjs.Rune(rune);

                                    Utils.DebugLogger("FILLING DECK: found rune <b>" + this_rune.Name + "</b> at level <b>" + this_rune.Level.ToString() + "</b>");

                                    MatchingRuneIndex = RunesInDeck;
                                    break;
                                }
                            }

                            RunesInDeck++;
                        }
                    }
                }

                return MatchingRuneIndex;
            }
            catch { }

            return -1;
        }
        public void EnchantRune(string rune_name, int rune_level, int unique_rune_id_to_enchant = 0)
        {
            JObject EnchantThisRune = this.GetRuneByName(rune_name);

            if (EnchantThisRune == null)
            {
                Utils.LoggerNotifications("<color=#ffa000>Couldn't find a matching rune to enchant.</color>");
                return;
            }

            JObject user_data = JObject.Parse(this.GetGameData("user", "GetUserInfo", false));
            int UserGold = Utils.CInt(user_data["data"]["Coins"]);

            this.UserRunes_CachedData = null;
            this.GetUsersRunes();

            GameObjs.Rune RuneToEnchant = null;
            List<GameObjs.Rune> RunesToEat = new List<GameObjs.Rune>();

            if (unique_rune_id_to_enchant == 0)
            {
                for (int iLevelCap = rune_level - 1; iLevelCap >= 0; iLevelCap--)
                {
                    foreach (var jRune in this.UserRunes_CachedData["data"]["Runes"])
                    {
                        GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                        if ((TempRune.Level == iLevelCap) && (TempRune.ID_Generic == Utils.CInt(EnchantThisRune["RuneId"])))
                        {
                            if (TempRune.MaxLevel >= rune_level)
                            {
                                Utils.LoggerNotifications("<color=#ffa000>Found a level " + TempRune.Level.ToString() + " " + TempRune.Name + " to enchant to level " + rune_level.ToString() + "!</color>");
                                Utils.LoggerNotifications("<color=#ffa000>... it will cost " + TempRune.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP to enchant</color>");
                                Utils.LoggerNotifications("<color=#ffa000>... it will cost " + TempRune.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold to enchant</color>");

                                RuneToEnchant = TempRune;
                                break;
                            }
                        }
                    }

                    if (RuneToEnchant != null)
                        break;
                }
            }
            else
            {
                foreach (var jRune in this.UserRunes_CachedData["data"]["Runes"])
                {
                    GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                    if (TempRune.Level < TempRune.MaxLevel)
                    {
                        if (TempRune.MaxLevel >= rune_level)
                        {
                            if (TempRune.ID_User == unique_rune_id_to_enchant)
                            {
                                Utils.LoggerNotifications("<color=#ffa000>Enchanting your level " + TempRune.Level.ToString() + " " + TempRune.Name + " to level " + rune_level.ToString() + "!</color>");
                                Utils.LoggerNotifications("<color=#ffa000>... it will cost " + TempRune.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP to enchant</color>");
                                Utils.LoggerNotifications("<color=#ffa000>... it will cost " + TempRune.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold to enchant</color>");

                                RuneToEnchant = TempRune;
                                break;
                            }
                        }
                    }
                }
            }

            if (RuneToEnchant == null)
            {
                Utils.LoggerNotifications("<color=#ffa000>You don't have an eligible " + EnchantThisRune["RuneName"].ToString().Trim() + " to enchant.</color>");
            }
            else if (((double)UserGold) < (((double)RuneToEnchant.EnchantToLevelCostGold(rune_level)) * 1.05))
            {
                Utils.LoggerNotifications("<color=#ffa000>You need more gold to enchant this rune.</color>");
            }
            else
            {
                GameObjs.Rune.StarsAllowedToEnchantWith = Utils.SubStrings(Utils.GetAppSetting("Enchant_Runes_WithStars").Replace(" ", ""), ",");
                GameObjs.Rune.RunesExcludedFromEnchantingWith = Utils.SubStrings(Utils.GetAppSetting("Enchant_Runes_Excluded").Replace(" ", ""), ",");
                List<string> temp = new List<string>();
                foreach (string s in GameObjs.Rune.RunesExcludedFromEnchantingWith)
                {
                    JObject rune = this.GetRuneByName(s);
                    if (rune != null)
                        temp.Add(Utils.CInt(rune["RuneId"]).ToString());
                }
                GameObjs.Rune.RunesExcludedFromEnchantingWith = temp.ToArray();

                int XPRunningTotal = 0;

                Dictionary<int,int> runeCount = new Dictionary<int,int>();

                foreach (var jRune in this.UserRunes_CachedData["data"]["Runes"])
                {
                    GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                    if (!runeCount.ContainsKey(TempRune.ID_Generic))
                        runeCount.Add(TempRune.ID_Generic, 1);
                    else
                        runeCount[TempRune.ID_Generic]++;
                }

                Dictionary<int,int> runeUsed = new Dictionary<int,int>();
                int iDontUseMoreThanThreshold = Utils.GetAppValue("Enchant_Runes_ReserveThreshold", 1);

                List<int> runesInDecks = new List<int>();
                string json = this.GetGameData(ref GameClient.Current.opts, "card", "GetCardGroup", false);
                JObject decks = JObject.Parse(json);
                foreach (JObject deck in decks["data"]["Groups"])
                    foreach (JObject rune in deck["UserRuneInfo"])
                        if (Utils.CInt(rune["UserRuneId"]) > 0)
                            if (!runesInDecks.Contains(Utils.CInt(rune["UserRuneId"])))
                                runesInDecks.Add(Utils.CInt(rune["UserRuneId"]));

                foreach (var jRune in this.UserRunes_CachedData["data"]["Runes"])
                {
                    GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                    if (TempRune.OkayToConsume && !runesInDecks.Contains(TempRune.ID_User))
                    {
                        int iUsedSoFar = 0;
                        if (runeUsed.ContainsKey(TempRune.ID_Generic))
                            iUsedSoFar = runeUsed[TempRune.ID_Generic];

                        if (runeCount[TempRune.ID_Generic] - iUsedSoFar <= iDontUseMoreThanThreshold)
                            continue;

                        //Utils.LoggerNotifications("Found a level " + TempRune.Level.ToString() + " " + TempRune.Name + " to enchant with for " + TempRune.EnchantingWorth.ToString("#,##0") + " XP");

                        XPRunningTotal += TempRune.EnchantingWorth;
                        RunesToEat.Add(TempRune);

                        if (!runeUsed.ContainsKey(TempRune.ID_Generic))
                            runeUsed.Add(TempRune.ID_Generic, 1);
                        else
                            runeUsed[TempRune.ID_Generic]++;

                        if (XPRunningTotal >= RuneToEnchant.EnchantToLevelCostXP(rune_level))
                            break;
                    }
                }

                bool bEnchantAnyway = false;

                if ((RunesToEat.Count > 0) && (XPRunningTotal < RuneToEnchant.EnchantToLevelCostXP(rune_level)))
                    if (MessageBox.Show("Enchanting needs consume at least " + RuneToEnchant.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP and " + RuneToEnchant.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold in costs.  The " + RunesToEat.Count.ToString("#,##0") + " runes available to enchant with only add up to " + XPRunningTotal.ToString("#,##0") + " XP.\r\n\r\nWould you like to enchant as much as you can with the available runes?", "Partially Enchant?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                        bEnchantAnyway = true;

                if ((bEnchantAnyway) || ((XPRunningTotal >= RuneToEnchant.EnchantToLevelCostXP(rune_level)) && (RunesToEat.Count > 0)))
                {
                    Utils.LoggerNotifications("<color=#ffa000>Enchanting will consume " + RunesToEat.Count.ToString("#,##0") + " runes, totalling at least " + RuneToEnchant.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP and " + RuneToEnchant.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold in costs.</color>");

                    string runes_to_eat_list = "";
                    foreach (GameObjs.Rune TempRune in RunesToEat)
                        runes_to_eat_list += "_" + TempRune.ID_User.ToString();

                    if (runes_to_eat_list.Length > 0)
                    {
                        runes_to_eat_list = runes_to_eat_list.Substring(1);

                        string upgrade_preview_json = this.GetGameData("streng", "RunePreview", "UserRuneId1=" + RuneToEnchant.ID_User.ToString() + "&UserRuneId2=" + runes_to_eat_list, false);

                        Utils.Logger(upgrade_preview_json);

                        JObject upgrade_preview = JObject.Parse(upgrade_preview_json);

                        string message = "";
                        try
                        {
                            if (Utils.CInt(upgrade_preview["status"]) == 0)
                                message = upgrade_preview["message"].ToString();
                        }
                        catch { }

                        if (Utils.ValidText(message))
                        {
                            Utils.LoggerNotifications("<color=#ffa000>Rune enchantment preview failure!</color>");
                            Utils.LoggerNotifications("<color=#ffa000>... " + message + "</color>");
                        }
                        else if ((Utils.CInt(upgrade_preview["data"]["RuneLevel"]) != rune_level) && (!bEnchantAnyway))
                        {
                            Utils.LoggerNotifications("<color=#ffa000>Rune enchantment preview failure!</color>");
                            Utils.LoggerNotifications("<color=#ffa000>... is one of the enchantment runes in use?</color>");
                        }
                        else
                        {
                            Utils.LoggerNotifications("<color=#ffa000>... actual preview cost is " + Utils.CInt(upgrade_preview["data"]["Exp"]).ToString("#,##0") + " XP and " + Utils.CInt(upgrade_preview["data"]["Coins"]).ToString("#,##0") + " gold in costs.</color>");

                            if (Utils.CInt(upgrade_preview["data"]["Coins"]) > UserGold)
                            {
                                Utils.LoggerNotifications("<color=#ffa000>You need more gold to enchant this rune.</color>");
                            }
                            else
                            {
                                //todo: remove (if enabled/debugging)
                                //Utils.LoggerNotifications("--- disabled --- debug mode --- disabled ---");
                                //Utils.LoggerNotifications(upgrade_preview_json);

                                string enchant_result_json = this.GetGameData("streng", "Rune", "UserRuneId1=" + RuneToEnchant.ID_User.ToString() + "&UserRuneId2=" + runes_to_eat_list, false);

                                Utils.Logger(enchant_result_json);

                                JObject enchant_result = JObject.Parse(enchant_result_json);

                                Utils.LoggerNotifications("<color=#ffa000>Rune has been enchanted to level " + upgrade_preview["data"]["RuneLevel"].ToString() + "!</color>");
                            }
                        }
                    }
                    else
                    {
                        // logic error: shouldn't be able to get here

                        Utils.LoggerNotifications("<color=#ffa000>Enchanting needs consume at least " + RuneToEnchant.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP and " + RuneToEnchant.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold in costs.  The " + RunesToEat.Count.ToString("#,##0") + " runes available to enchant with only add up to " + XPRunningTotal.ToString("#,##0") + " XP.</color>");
                    }
                }
                else if (RunesToEat.Count > 0)
                {
                    Utils.LoggerNotifications("<color=#ffa000>Enchanting needs consume at least " + RuneToEnchant.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP and " + RuneToEnchant.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold in costs.  The " + RunesToEat.Count.ToString("#,##0") + " runes available to enchant with only add up to " + XPRunningTotal.ToString("#,##0") + " XP.</color>");
                }
                else
                {
                    Utils.LoggerNotifications("<color=#ffa000>Enchanting needs consume at least " + RuneToEnchant.EnchantToLevelCostXP(rune_level).ToString("#,##0") + " XP and " + RuneToEnchant.EnchantToLevelCostGold(rune_level).ToString("#,##0") + " gold in costs.  There are not enough available runes to enchant with in your collection.  Check your collection and/or your settings to make sure EK Unleashed is allowed to enchant with 1* and 2* runes, for example.</color>");
                }
            }

            Utils.LoggerNotifications("<color=#ffa000>Auto-enchant finished.</color>");
        }
Example #7
0
        private void InitRunes()
        {
            Cursor cur = this.Cursor;
            this.Cursor = Cursors.WaitCursor;

            Utils.DontDrawControl(this.lstRunes);

            Utils.StartMethodMultithreadedAndWait(() =>
            {
                JObject Runes = GameClient.Current.GetUsersRunes();

                this.ClearList();

                List<GameObjs.Rune> runeobjs = new List<GameObjs.Rune>();

                foreach (var jRune in Runes["data"]["Runes"])
                {
                    try
                    {
                        GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                        if (!TempRune.Valid) continue;
                        if (!Utils.ValidText(TempRune.Name)) continue;

                        if ((TempRune.Stars == 1) && (!this.chk1Star.Checked)) continue;
                        if ((TempRune.Stars == 2) && (!this.chk2Star.Checked)) continue;
                        if ((TempRune.Stars == 3) && (!this.chk3Star.Checked)) continue;
                        if ((TempRune.Stars == 4) && (!this.chk4Star.Checked)) continue;
                        if ((TempRune.Stars == 5) && (!this.chk5Star.Checked)) continue;

                        runeobjs.Add(TempRune);
                    }
                    catch (Exception ex)
                    {
                        Utils.Chatter(Errors.GetShortErrorDetails(ex));
                    }
                }

                this.AddRunes(runeobjs);
            });

            this.lstRunes.Sort();

            Utils.DrawControl(this.lstRunes);

            this.Cursor = cur;
        }
        private void InitRunes()
        {
            Cursor cur = this.Cursor;

            this.Cursor = Cursors.WaitCursor;

            Utils.DontDrawControl(this.lstRunes);

            Utils.StartMethodMultithreadedAndWait(() =>
            {
                JObject Runes = GameClient.Current.GetUsersRunes();

                this.ClearList();

                List <GameObjs.Rune> runeobjs = new List <GameObjs.Rune>();

                foreach (var jRune in Runes["data"]["Runes"])
                {
                    try
                    {
                        GameObjs.Rune TempRune = new GameObjs.Rune(jRune);

                        if (!TempRune.Valid)
                        {
                            continue;
                        }
                        if (!Utils.ValidText(TempRune.Name))
                        {
                            continue;
                        }

                        if ((TempRune.Stars == 1) && (!this.chk1Star.Checked))
                        {
                            continue;
                        }
                        if ((TempRune.Stars == 2) && (!this.chk2Star.Checked))
                        {
                            continue;
                        }
                        if ((TempRune.Stars == 3) && (!this.chk3Star.Checked))
                        {
                            continue;
                        }
                        if ((TempRune.Stars == 4) && (!this.chk4Star.Checked))
                        {
                            continue;
                        }
                        if ((TempRune.Stars == 5) && (!this.chk5Star.Checked))
                        {
                            continue;
                        }

                        runeobjs.Add(TempRune);
                    }
                    catch (Exception ex)
                    {
                        Utils.Chatter(Errors.GetShortErrorDetails(ex));
                    }
                }

                this.AddRunes(runeobjs);
            });

            this.lstRunes.Sort();

            Utils.DrawControl(this.lstRunes);

            this.Cursor = cur;
        }