Exemplo n.º 1
0
        public static ShopPackDefinition[] GetValidatedLoadout(bool outputValidationErrors)
        {
            var mymod = RewardsMod.Instance;
            var defs  = new List <ShopPackDefinition>();

            for (int i = 0; i < mymod.ShopConfig.ShopLoadout.Count; i++)
            {
                ShopPackDefinition def = mymod.ShopConfig.ShopLoadout[i];
                string             fail;

                if (!def.Validate(out fail))
                {
                    if (outputValidationErrors)
                    {
                        Main.NewText("Could not load shop item " + def.Name + " (" + fail + ")", Color.Red);
                    }
                    continue;
                }
                if (!def.RequirementsMet())
                {
                    continue;
                }

                defs.Add(def);
            }

            return(defs.ToArray());
        }
Exemplo n.º 2
0
        public bool IsSameAs(ShopPackDefinition def)
        {
            int count = this.Items.Count;

            if (!def.Name.Equals(this.Name))
            {
                return(false);
            }
            if (def.Price != this.Price)
            {
                return(false);
            }
            if (!def.NeededBossKill?.Equals(this.NeededBossKill) ?? this.NeededBossKill != null)
            {
                return(false);
            }
            if (def.Items.Count != count)
            {
                return(false);
            }

            for (int i = 0; i < count; i++)
            {
                if (!this.Items[i].IsSameAs(def.Items[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public static Item[] OpenPack(Player player, ShopPackDefinition packDef)
        {
            Item[] packItems = new Item[packDef.Items.Count];
            int    i         = 0;

            foreach (ShopPackItemDefinition itemInfo in packDef.Items)
            {
                if (!itemInfo.IsAvailable())
                {
                    continue;
                }

                int  itemType = itemInfo.ItemDef.Type;
                Item newItem  = new Item();
                newItem.SetDefaults(itemType);

                ItemHelpers.CreateItem(player.position, itemType, itemInfo.Stack, newItem.width, newItem.height);

                packItems[i++] = newItem;
            }

            Main.PlaySound(SoundID.Coins);

            return(packItems);
        }
Exemplo n.º 4
0
        public static Item CreateItem(ShopPackDefinition packInfo)
        {
            Item item = new Item();

            item.SetDefaults(ModContent.ItemType <ShopPackItem>());
            item.SetNameOverride(packInfo.Name);

            var myitem = (ShopPackItem)item.modItem;

            myitem.Info = packInfo;

            return(item);
        }
Exemplo n.º 5
0
        ////////////////

        public bool BuyAndOpenPack_Synced(Player player, out string output)
        {
            var mymod = RewardsMod.Instance;

            ItemHelpers.DestroyItem(this.item);

            if (this.Info == null)
            {
                output = "No pack info available.";
                return(false);
            }

            var info  = (ShopPackDefinition)this.Info;
            int price = info.Price;

            var      myworld = ModContent.GetInstance <RewardsWorld>();
            KillData data    = myworld.Logic.GetPlayerData(player);

            if (data == null)
            {
                output = "No player data for " + player.name;
                return(false);
            }

            if (!data.Spend(price, player))
            {
                Main.NewText("Not enough progress points.", Color.Red);
                output = "";
                return(true);
            }

            if (Main.netMode == 0)
            {
                Item[] items = ShopPackDefinition.OpenPack(player, info);

                foreach (var hook in RewardsMod.Instance.OnPointsSpentHooks)
                {
                    hook(player, info.Name, info.Price, items);
                }
            }
            else if (Main.netMode == 1)
            {
                PackPurchaseProtocol.SendSpendToServer(info);
            }

            output = player.name + " bought " + info.Name + " (" + info.Price + ")";

            return(true);
        }
Exemplo n.º 6
0
        internal ShopPackDefinition(ShopPackDefinition clone)
        {
            var itemList = new List <ShopPackItemDefinition>();

            if (clone.Items == null)
            {
                LogHelpers.WarnOnce("No pack item definitions present for pack " + clone.Name);
            }
            else
            {
                foreach (ShopPackItemDefinition packItemDef in clone.Items)
                {
                    itemList.Add(new ShopPackItemDefinition(packItemDef));
                }
            }

            this.NeededBossKill = clone.NeededBossKill != null ?
                                  new NPCDefinition(clone.NeededBossKill.mod, clone.NeededBossKill.name) :
                                  null;
            this.Name  = clone.Name;
            this.Price = clone.Price;
            this.Items = itemList;
        }
Exemplo n.º 7
0
 internal ShopPackItem(ShopPackItem clone)
 {
     this.Info = clone.Info != null ?
                 new ShopPackDefinition(clone.Info) :
                 null;
 }