Пример #1
0
        public ItemSacrificeResult SacrificeItem(out int amountWeSacrificed)
        {
            int amountNeeded = 0;

            amountWeSacrificed = 0;
            Item item = _itemSlotsForUI[0];

            if (!CreativeItemSacrificesCatalog.Instance.TryGetSacrificeCountCapToUnlockInfiniteItems(item.type, out amountNeeded))
            {
                return(ItemSacrificeResult.CannotSacrifice);
            }
            int value = 0;

            Main.LocalPlayerCreativeTracker.ItemSacrifices.SacrificesCountByItemIdCache.TryGetValue(item.type, out value);
            int num = Utils.Clamp(amountNeeded - value, 0, amountNeeded);

            if (num == 0)
            {
                return(ItemSacrificeResult.CannotSacrifice);
            }
            int num2 = Math.Min(num, item.stack);

            if (!Main.ServerSideCharacter)
            {
                Main.LocalPlayerCreativeTracker.ItemSacrifices.RegisterItemSacrifice(item.type, num2);
            }
            else
            {
                NetPacket packet = NetCreativeUnlocksPlayerReportModule.SerializeSacrificeRequest(item.type, num2);
                NetManager.Instance.SendToServerOrLoopback(packet);
            }
            bool num3 = num2 == num;

            item.stack -= num2;
            if (item.stack <= 0)
            {
                item.TurnToAir();
            }
            amountWeSacrificed = num2;
            RefreshAvailableInfiniteItemsList();
            if (item.stack > 0)
            {
                item.position.X    = Main.player[Main.myPlayer].Center.X - (float)(item.width / 2);
                item.position.Y    = Main.player[Main.myPlayer].Center.Y - (float)(item.height / 2);
                _itemSlotsForUI[0] = Main.LocalPlayer.GetItem(Main.myPlayer, item, GetItemSettings.InventoryUIToInventorySettings);
            }
            if (!num3)
            {
                return(ItemSacrificeResult.SacrificedButNotDone);
            }
            return(ItemSacrificeResult.SacrificedAndDone);
        }
Пример #2
0
        public CreativeUI.ItemSacrificeResult SacrificeItem(out int amountWeSacrificed)
        {
            int amountNeeded = 0;

            amountWeSacrificed = 0;
            Item newItem = this._itemSlotsForUI[0];

            if (!CreativeItemSacrificesCatalog.Instance.TryGetSacrificeCountCapToUnlockInfiniteItems(newItem.type, out amountNeeded))
            {
                return(CreativeUI.ItemSacrificeResult.CannotSacrifice);
            }
            int num1 = 0;

            Main.LocalPlayerCreativeTracker.ItemSacrifices.SacrificesCountByItemIdCache.TryGetValue(newItem.type, out num1);
            int val1 = Utils.Clamp <int>(amountNeeded - num1, 0, amountNeeded);

            if (val1 == 0)
            {
                return(CreativeUI.ItemSacrificeResult.CannotSacrifice);
            }
            int amount = Math.Min(val1, newItem.stack);

            if (!Main.ServerSideCharacter)
            {
                Main.LocalPlayerCreativeTracker.ItemSacrifices.RegisterItemSacrifice(newItem.type, amount);
            }
            else
            {
                NetPacket packet = NetCreativeUnlocksPlayerReportModule.SerializeSacrificeRequest(newItem.type, amount);
                NetManager.Instance.SendToServerOrLoopback(packet);
            }
            int num2 = amount == val1 ? 1 : 0;

            newItem.stack -= amount;
            if (newItem.stack <= 0)
            {
                newItem.TurnToAir();
            }
            amountWeSacrificed = amount;
            this.RefreshAvailableInfiniteItemsList();
            if (newItem.stack > 0)
            {
                newItem.position.X      = Main.player[Main.myPlayer].Center.X - (float)(newItem.width / 2);
                newItem.position.Y      = Main.player[Main.myPlayer].Center.Y - (float)(newItem.height / 2);
                this._itemSlotsForUI[0] = Main.LocalPlayer.GetItem(Main.myPlayer, newItem, GetItemSettings.InventoryUIToInventorySettings);
            }
            return(num2 == 0 ? CreativeUI.ItemSacrificeResult.SacrificedButNotDone : CreativeUI.ItemSacrificeResult.SacrificedAndDone);
        }