コード例 #1
0
 private static void FunSmallExamples(PublicStash publicStash)
 {
     //var KnifeList = GetAllUsersWithEtherealKnivesGemsIntheirStashIfAny(publicStash);
     //var BeltList = GetAllWhoHasPricedTheirStygianVise(publicStash);
     //var CurrencyDict = GetAllCurrencyAndAddThemUp(publicStash);
     //var MapList = GetInterestingMapsListedForLessOrEqualToFifteenChaos(publicStash);
 }
コード例 #2
0
        public static void Run(List <Action <PublicStash> > actions, int delay = 10000)
        {
            var         init           = true;
            PublicStash publicStash    = null;
            var         nextChangeId   = "";
            var         cachedChangeId = "";

            while (true)
            {
                try
                {
                    if (init)
                    {
                        publicStash    = GetAsync().Result;
                        nextChangeId   = publicStash.next_change_id;
                        cachedChangeId = "";
                        init           = false;
                    }

                    var Start = DateTime.UtcNow;
                    if (cachedChangeId != nextChangeId)
                    {
                        cachedChangeId = nextChangeId;
                        foreach (var action in actions)
                        {
                            action(publicStash);
                        }
                    }
                    else
                    {
                        publicStash  = GetAsync(nextChangeId).Result;
                        nextChangeId = publicStash.next_change_id;
                        new ManualResetEvent(false).WaitOne(Math.Max(0,
                                                                     delay - (int)(DateTime.UtcNow - Start).TotalMilliseconds));
                    }
                }
                catch
                {
                    if (String.IsNullOrEmpty(nextChangeId))
                    {
                        nextChangeId = GetLatestStashIdAsync().Result;
                    }
                }
            }
        }
コード例 #3
0
        public static Dictionary<String, int> GetAllCurrencyAndAddThemUp(PublicStash ps)
        {
            var dict = new Dictionary<String, int>();

            foreach (var stash in ps.stashes)
            {
                foreach (var item in stash.items)
                {
                    switch (item)
                    {
                        case Currency currency when item.GetType() == typeof(Currency):
                            dict.TryGetValue(currency.typeLine, out var current);
                            current += currency.stackSize;
                            dict[currency.typeLine] = current;

                            break;
                    }
                }
            }

            return dict;
        }
コード例 #4
0
        private static List<(String, Belt)> GetAllWhoHasPricedTheirStygianVise(PublicStash ps)
        {
            var list = new List<(String, Belt)>();

            foreach (var stash in ps.stashes)
            {
                foreach (var item in stash.items)
                {
                    switch (item)
                    {
                        case Belt belt when item.GetType() == typeof(Belt):
                            if (belt.typeLine == "Stygian Vise" &&
                                belt.note?.IndexOf("~") >= 0)
                            {
                                list.Add((stash.accountName, belt));
                            }
                            break;
                    }
                }
            }

            return list;
        }
コード例 #5
0
        private static List<(String, Map)> GetInterestingMapsListedForLessOrEqualToFifteenChaos(PublicStash ps)
        {
            var maps = new List<String>
            {
                "Scriptorium Map",
                "Shaped Scriptorium Map",
                "Vault Map",
                "Shaped Vault Map",
                "Shaped Spider Forest Map",
                "Shaped Arachnid Tomb Map",
            };

            bool LessThenFiveC(String cond)
            {
                if (String.IsNullOrEmpty(cond)) return false;

                for (var i = 0; i < 15; i++)
                {
                    if (cond.IndexOf($"~price {i} chaos", StringComparison.Ordinal) >= 0 ||
                        cond.IndexOf($"~b/o {i} chaos", StringComparison.Ordinal) >= 0)
                    {
                        return true;
                    }
                }

                return false;
            }

            var list = new List<(String, Map)>();

            foreach (var stash in ps.stashes)
            {
                foreach (var item in stash.items)
                {
                    switch (item)
                    {
                        case Map map when item.GetType() == typeof(Map):
                            if (maps.Any(m => map.typeLine.IndexOf(m, StringComparison.Ordinal) >= 0 &&
                                              LessThenFiveC(map.note)))
                            {
                                list.Add((stash.accountName, map));
                            }
                            break;
                    }
                }
            }

            return list;
        }
コード例 #6
0
        private static List<(String, Gem)> GetAllUsersWithEtherealKnivesGemsIntheirStashIfAny(PublicStash ps)
        {
            var list = new List<(String, Gem)>();

            foreach (var stash in ps.stashes)
            {
                foreach (var item in stash.items)
                {
                    switch (item)
                    {
                        case Gem gem when item.GetType() == typeof(Gem):
                            if (gem.typeLine == "Ethereal Knives")
                            {
                                list.Add((stash.accountName, gem));
                            }
                            break;
                    }
                }
            }

            return list;
        }
コード例 #7
0
        public IEnumerable <Price> GetCurrencyListings(PublicStash ps)
        {
            var prices = new List <Price>();

            foreach (var stash in ps.stashes)
            {
                foreach (var item in stash.items)
                {
                    switch (item)
                    {
                    case PoECurrency curr when item.note != null &&
                        item.GetType() ==
                        typeof(PoECurrency):

                        foreach (var query in matches)
                        {
                            if (curr.note?.IndexOf(query) >= 0)
                            {
                                var matchedText = Regex.Matches(curr.note, $@"^{query}[0-9//]+ [\w-]+")
                                                  .Cast <Match>()
                                                  .Select(m => m.Value)
                                                  .ToArray();

                                if (matchedText.Length == 1)
                                {
                                    var parsedCurrency = ParseCurrency(query, matchedText[0]);

                                    if (parsedCurrency[0].Contains("/"))
                                    {
                                        var decimalPrice = parsedCurrency[0].Split('/');

                                        // Missing value "/X" or "X/"
                                        if (String.IsNullOrEmpty(decimalPrice[0]) ||
                                            String.IsNullOrEmpty(decimalPrice[1]))
                                        {
                                            break;
                                        }

                                        // Missing value "/X" or "X/"
                                        if (int.Parse(decimalPrice[0]) == 0 ||
                                            int.Parse(decimalPrice[1]) == 0)
                                        {
                                            break;
                                        }


                                        var price = new Price(
                                            new Seller(stash.accountName, stash.lastCharacterName, curr.league),
                                            decimal.Divide(
                                                decimal.Parse(decimalPrice[1]),
                                                decimal.Parse(decimalPrice[0])),
                                            $"Selling {decimalPrice[1]} {curr.typeLine} for {decimalPrice[0]} {parsedCurrency[1]}",
                                            matchedText[0],
                                            new Sell(curr.typeLine, int.Parse(decimalPrice[1])),
                                            new Buy(parsedCurrency[1], int.Parse(decimalPrice[0])));
                                        prices.Add(price);
                                    }
                                    else
                                    {
                                        var price = new Price(
                                            new Seller(stash.accountName, stash.lastCharacterName, curr.league),
                                            decimal.Parse(parsedCurrency[0]),
                                            $"Selling {curr.stackSize} {curr.typeLine} for {int.Parse(parsedCurrency[0]) * curr.stackSize} {parsedCurrency[1]}",
                                            matchedText[0],
                                            new Sell(curr.typeLine, curr.stackSize),
                                            new Buy(parsedCurrency[1],
                                                    curr.stackSize * int.Parse(parsedCurrency[0])));
                                        prices.Add(price);
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }

            return(prices);
        }