public override int GetItemIndex(IDeckItem item)
        {
            if (!items.Any(c => c.Value == item))
            {
                return(-1);
            }
            var key = items.First(c => c.Value == item);

            return(key.Key);
        }
Beispiel #2
0
        public static void Initialize()
        {
            if (!Active)
            {
                return;
            }

            m_patchPath = Path.Combine(Path.GetDirectoryName(Plugin.CurrentPlugin.Context.AssemblyPath), PatchName);
            if (File.Exists(m_patchPath))
            {
                File.Delete(m_patchPath);
            }

            var orbSellerAction = new KeyValueListBase("npcs_actions");

            orbSellerAction.AddPair("Type", "Shop");
            orbSellerAction.AddPair("NpcId", OrbSeller);
            orbSellerAction.AddPair("Parameter0", OrbItemTemplate);

            AppendQuery("SET @orbshop=(SELECT Id FROM `npcs_actions` WHERE " +
                        string.Format("`NpcId`={0} AND `Type`='Shop')", OrbSeller));
            AppendQuery(SqlBuilder.BuildDelete("npcs_actions", "Id=@orbshop"));
            AppendQuery(SqlBuilder.BuildDelete("npcs_items", "NpcShopId=@orbshop"));

            AppendQuery(SqlBuilder.BuildInsert(orbSellerAction));
            AppendQuery("SET @orbshop=(SELECT LAST_INSERT_ID())");

            foreach (var seller in Sellers)
            {
                var npcAction = new KeyValueListBase("npcs_actions");
                npcAction.AddPair("Type", "Shop");
                npcAction.AddPair("NpcId", seller.Key);

                AppendQuery("SET @shopid=(SELECT Id FROM `npcs_actions` WHERE " +
                            string.Format("`NpcId`={0} AND `Type`='Shop')", seller.Key));
                AppendQuery(SqlBuilder.BuildDelete("npcs_actions", "Id=@shopid"));
                AppendQuery(SqlBuilder.BuildDelete("npcs_items", "NpcShopId=@shopid"));

                AppendQuery(SqlBuilder.BuildInsert(npcAction));
                AppendQuery("SET @shopid=(SELECT LAST_INSERT_ID())");

                var selector = (from entry in ItemManager.Instance.GetTemplates()
                                where
                                Array.IndexOf(seller.Value, (ItemTypeEnum)entry.TypeId) !=
                                -1 && entry.Level >= MinItemLevel &&
                                entry.Effects.Count > 0 && !entry.Etheral
                                orderby entry.Level ascending
                                select entry);

                foreach (var template in selector)
                {
                    if (IgnoredItems.Contains(template.Id))
                    {
                        continue;
                    }

                    var price = Prices.First(entry => template.Level <= entry.Key).Value;

                    if (template.TypeId == (int)ItemTypeEnum.PAIN)
                    {
                        var restoreEffect =
                            template.Effects.SingleOrDefault(entry => entry.EffectId == EffectsEnum.Effect_AddHealth) as
                            EffectDice;

                        if (restoreEffect == null)
                        {
                            continue;
                        }

                        price = (int)(Math.Max(restoreEffect.DiceFace, restoreEffect.DiceNum) * BreadHpPerKama);
                    }

                    var itemQuery = new KeyValueListBase("npcs_items");
                    itemQuery.AddPair("ItemId", template.Id);
                    itemQuery.AddPair("NpcShopId", new RawData("@shopid"));
                    itemQuery.AddPair("CustomPrice", price);
                    itemQuery.AddPair("BuyCriterion", string.Empty);
                    AppendQuery(SqlBuilder.BuildInsert(itemQuery));

                    if (price > 0)
                    {
                        var orbPrice = OrbsPrices.First(entry => template.Level <= entry.Key).Value;

                        var perfectItemQuery = new KeyValueListBase("npcs_items");
                        perfectItemQuery.AddPair("ItemId", template.Id);
                        perfectItemQuery.AddPair("NpcShopId", new RawData("@orbshop"));
                        perfectItemQuery.AddPair("CustomPrice", orbPrice);
                        perfectItemQuery.AddPair("MaxStats", "1");
                        perfectItemQuery.AddPair("BuyCriterion", string.Empty);
                        AppendQuery(SqlBuilder.BuildInsert(perfectItemQuery));
                    }

                    if (price != 0)
                    {
                        continue;
                    }

                    var updatePrice = new UpdateKeyValueList("items_templates");
                    updatePrice.AddPair("Price", 0);
                    updatePrice.AddWherePair("Id", template.Id);
                    AppendQuery(SqlBuilder.BuildUpdate(updatePrice));
                }
            }
        }