Exemplo n.º 1
0
        public override bool UseItem(Player player)
        {
            var            mymod = (LicensesMod)this.mod;
            int            savings;
            int            oldStack    = this.item.stack;
            ItemDefinition randItemDef = this.AttemptToLicenseRandomItem(player, out savings);

            if (randItemDef == null)
            {
                Main.NewText("No items of the given tier left to license.", Color.Red);
                return(false);
            }

            int   targetRarity = WildcardLicenseItem.ComputeTargetRarityOfLicenseStackSize(oldStack);
            Color color        = ItemRarityAttributeHelpers.RarityColor[targetRarity];

            string randItemName = ItemAttributeHelpers.GetQualifiedName(randItemDef.Type);
            string msg          = randItemName + " licensed";

            if (savings > 0)
            {
                msg += " - " + savings + " discounted";
            }

            PlayerMessages.AddPlayerLabel(player, msg, color, 2 * 60, true);
            Main.NewText(msg, color);

            if (LicensesMod.Config.DebugModeInfo)
            {
                LogHelpers.Alert(randItemName + " unlocked");
            }

            return(true);
        }
Exemplo n.º 2
0
        ////////////////

        public override bool CanUseItem(Player player)
        {
            var mymod         = (LicensesMod)this.mod;
            int maxRarityCost = WildcardLicenseItem.ComputeMaxCost();

            if (this.item.stack > maxRarityCost)
            {
                Main.NewText("Invalid stack size. Stack size must correspond to a valid item ranking value (rarity).", Color.Yellow);
            }

            return(this.item.stack <= maxRarityCost);
        }
Exemplo n.º 3
0
        public override void ModifyTooltips(List <TooltipLine> tooltips)
        {
            var         mymod        = (LicensesMod)this.mod;
            int         targetRarity = WildcardLicenseItem.ComputeTargetRarityOfLicenseStackSize(this.item.stack);
            TooltipLine tip;

            if (targetRarity >= 0)
            {
                if (targetRarity > ItemRarityAttributeHelpers.HighestVanillaRarity)
                {
                    tip = new TooltipLine(mymod, "WildcardLicense:Tier", "Stack size exceeds highest item tier.")
                    {
                        overrideColor = ItemRarityAttributeHelpers.RarityColor[ItemRarityAttributeHelpers.JunkRarity]
                    };
                }
                else
                {
                    string rareStr    = ItemRarityAttributeHelpers.RarityLabel[targetRarity];
                    string rareClrStr = ItemRarityAttributeHelpers.RarityColorText[targetRarity];

                    tip = new TooltipLine(mymod, "WildcardLicense:Tier", "Current item tier: " + rareStr + " (" + rareClrStr + ")")
                    {
                        overrideColor = ItemRarityAttributeHelpers.RarityColor[targetRarity]
                    };
                }
            }
            else
            {
                tip = new TooltipLine(mymod, "WildcardLicense:Tier", "No applicable item tier.")
                {
                    overrideColor = ItemRarityAttributeHelpers.RarityColor[ItemRarityAttributeHelpers.JunkRarity]
                };
            }

            tooltips.Add(tip);
        }
Exemplo n.º 4
0
        public ItemDefinition AttemptToLicenseRandomItem(Player player, out int savings)
        {
            var myplayer = player.GetModPlayer <LicensesPlayer>();

            int targetRarity = WildcardLicenseItem.ComputeTargetRarityOfLicenseStackSize(this.item.stack);

            string             grpName = "Any " + ItemRarityAttributeHelpers.RarityColorText[targetRarity] + " Tier";
            IReadOnlySet <int> tierItems, equipments;

            EntityGroups.TryGetItemGroup(grpName, out tierItems);
            EntityGroups.TryGetItemGroup("Any Equipment", out equipments);

            IList <int> tierEquips = new List <int>(tierItems.Intersect(equipments));

            int            randItemType;
            ItemDefinition randItemDef;

            IDictionary <int, string> idsToNames = ItemAttributeHelpers.DisplayNamesToIds
                                                   .ToLookup(kv => kv.Value)
                                                   .ToDictionary(g => g.Key, g => g.First().Key);

            do
            {
                int count = tierEquips.Count();
                if (count == 0)
                {
                    savings = 0;
                    return(null);
                }

                randItemType = tierEquips[Main.rand.Next(count)];
                randItemDef  = new ItemDefinition(randItemType);

                tierEquips.Remove(randItemType);
            } while(myplayer.LicensedItems.Contains(randItemDef));

            var dummyItem = new Item();

            dummyItem.SetDefaults(randItemType, true);

            int  cost              = WildcardLicenseItem.ComputeCost(dummyItem, out savings);
            Item selectedItem      = player.inventory[PlayerItemHelpers.VanillaInventorySelectedSlot];
            int  selectedItemStack = selectedItem?.stack ?? 0;

            myplayer.LicenseItemByDefinition(randItemDef, true);

            ItemHelpers.ReduceStack(this.item, cost);

            // Failsafes:
            if (selectedItem.type == this.item.type)
            {
                int newStackSize = (selectedItemStack >= cost) ? (selectedItemStack - cost) : 0;

                selectedItem.stack   = newStackSize;
                Main.mouseItem.stack = newStackSize;

                if (selectedItem.stack == 0)
                {
                    selectedItem.active = false;
                }
                if (Main.mouseItem.stack == 0)
                {
                    Main.mouseItem.active = false;
                }
            }

            return(randItemDef);
        }