Пример #1
0
        public void Load(Player fromPlayer)
        {
            if (fromPlayer == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to load an ExtendedPlayerData with a null player!");
                return;
            }

            _player = fromPlayer;
            LoadValue(fromPlayer, "ExtendedPlayerData", out var init);
            EquipmentAndQuickSlots.LogWarning("Loaded ExtendedPlayerData");

            if (LoadValue(fromPlayer, nameof(QuickSlotInventory), out var quickSlotData))
            {
                var pkg = new ZPackage(quickSlotData);
                _isLoading = true;
                QuickSlotInventory.Load(pkg);
                _isLoading = false;
            }

            if (LoadValue(fromPlayer, nameof(EquipmentSlotInventory), out var equipSlotData))
            {
                var pkg = new ZPackage(equipSlotData);
                _isLoading = true;
                EquipmentSlotInventory.Load(pkg);
                _isLoading = false;
            }
        }
Пример #2
0
        public static void Prefix(Player __instance)
        {
            if (__instance.m_inventory.NrOfItems() == 0)
            {
                return;
            }

            EquipmentSlotHelper.AllowMove = false;
            __instance.UnequipAllItems();
            var allInventories = __instance.GetAllInventories();

            var gameObject = Object.Instantiate(__instance.m_tombstone, __instance.GetCenterPoint(), __instance.transform.rotation);
            var container  = gameObject.GetComponent <Container>();

            // Modify tombstone prefab
            var totalPossibleSlots = allInventories.Sum(x => x.m_width * x.m_height);
            var width  = __instance.m_inventory.m_width;
            var height = (totalPossibleSlots / width) + 1;

            container.m_width              = width;
            container.m_height             = height;
            container.m_inventory.m_width  = width;
            container.m_inventory.m_height = height;

            var containerInventory = container.GetInventory();

            foreach (var inventory in allInventories)
            {
                foreach (var item in inventory.m_inventory)
                {
                    if (!item.m_shared.m_questItem && !item.m_equiped)
                    {
                        if (containerInventory.GetItemAt(item.m_gridPos.x, item.m_gridPos.y) != null)
                        {
                            containerInventory.AddItem(item);
                        }
                        else
                        {
                            containerInventory.m_inventory.Add(item);
                        }
                    }
                }

                inventory.m_inventory.RemoveAll(item => !item.m_shared.m_questItem && !item.m_equiped);
                inventory.Changed();
            }
            containerInventory.Changed();

            var tombStone     = gameObject.GetComponent <TombStone>();
            var playerProfile = Game.instance.GetPlayerProfile();
            var name          = playerProfile.GetName();
            var playerId      = playerProfile.GetPlayerID();

            tombStone.Setup(name, playerId);

            EquipmentAndQuickSlots.LogWarning($"Creating tombstone for ({name}) with w:{width} h:{height} (total:{totalPossibleSlots})");

            EquipmentSlotHelper.AllowMove = true;
        }
Пример #3
0
        public static void Postfix()
        {
            var player = Player.m_localPlayer;

            if (player == null)
            {
                return;
            }

            EquipmentAndQuickSlots.LogWarning("Recovered Tombstone Items, verifying inventory...");
            var droppedItems = new List <ItemDrop.ItemData>();

            foreach (var inventory in player.GetAllInventories())
            {
                foreach (var itemData in inventory.m_inventory)
                {
                    var isOutsideInventoryGrid = itemData.m_gridPos.x < 0 ||
                                                 itemData.m_gridPos.x >= inventory.m_width ||
                                                 itemData.m_gridPos.y < 0 ||
                                                 itemData.m_gridPos.y >= inventory.m_height;
                    if (isOutsideInventoryGrid)
                    {
                        var itemText = Localization.instance.Localize(itemData.m_shared.m_name) + (itemData.m_stack > 1 ? $" x{itemData.m_stack}" : "");
                        EquipmentAndQuickSlots.LogWarning($"> Item Outside Inventory Grid! ({itemText}, <{itemData.m_gridPos.x},{itemData.m_gridPos.y}>)");
                        inventory.RemoveItem(itemData);
                        var addSuccess = inventory.AddItem(itemData);
                        if (!addSuccess)
                        {
                            EquipmentAndQuickSlots.LogError($"> Could not add item to inventory, item dropped! ({itemText})");
                            droppedItems.Add(itemData);
                            ItemDrop.DropItem(itemData, itemData.m_stack, player.transform.position + player.transform.forward * 2 + Vector3.up, Quaternion.identity);
                        }
                    }
                }
            }

            if (droppedItems.Count > 0)
            {
                var droppedItemTexts    = droppedItems.Select(x => Localization.instance.Localize(x.m_shared.m_name) + (x.m_stack > 1 ? $" x{x.m_stack}" : ""));
                var droppedItemsMessage = ">>>> ERROR IN TOMBSTONE RECOVERY - ITEMS DROPPED: " + string.Join(", ", droppedItemTexts);
                player.Message(MessageHud.MessageType.Center, droppedItemsMessage);
                Debug.LogError(droppedItemsMessage);
                EquipmentAndQuickSlots.LogError(droppedItemsMessage);
            }
            else
            {
                EquipmentAndQuickSlots.LogWarning("> No issues!");
            }
        }
Пример #4
0
        public void Load(Player fromPlayer)
        {
            if (fromPlayer == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to load an ExtendedPlayerData with a null player!");
                return;
            }

            _player = fromPlayer;
            LoadValue(fromPlayer, "ExtendedPlayerData", out var init);
            EquipmentAndQuickSlots.LogWarning("Loaded ExtendedPlayerData");

            if (LoadValue(fromPlayer, nameof(QuickSlotInventory), out var quickSlotData))
            {
                var pkg = new ZPackage(quickSlotData);
                _isLoading = true;
                QuickSlotInventory.Load(pkg);

                if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
                {
                    _player.m_inventory.MoveAll(QuickSlotInventory);

                    pkg = new ZPackage(quickSlotData);
                    QuickSlotInventory.Save(pkg);
                    SaveValue(_player, nameof(QuickSlotInventory), pkg.GetBase64());
                }

                _isLoading = false;
            }

            if (LoadValue(fromPlayer, nameof(EquipmentSlotInventory), out var equipSlotData))
            {
                var pkg = new ZPackage(equipSlotData);
                _isLoading = true;
                EquipmentSlotInventory.Load(pkg);

                if (!EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
                {
                    _player.m_inventory.MoveAll(EquipmentSlotInventory);

                    pkg = new ZPackage(quickSlotData);
                    EquipmentSlotInventory.Save(pkg);
                    SaveValue(_player, nameof(EquipmentSlotInventory), pkg.GetBase64());
                }

                _isLoading = false;
            }
        }
Пример #5
0
        public void Save()
        {
            if (_player == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to save an ExtendedPlayerData without a player!");
                return;
            }

            EquipmentAndQuickSlots.LogWarning("Saving ExtendedPlayerData");
            SaveValue(_player, "ExtendedPlayerData", "This player is using ExtendedPlayerData!");

            var pkg = new ZPackage();

            QuickSlotInventory.Save(pkg);
            SaveValue(_player, nameof(QuickSlotInventory), pkg.GetBase64());

            pkg = new ZPackage();
            EquipmentSlotInventory.Save(pkg);
            SaveValue(_player, nameof(EquipmentSlotInventory), pkg.GetBase64());
        }
Пример #6
0
        public bool OverrideAddItem(ItemDrop.ItemData item)
        {
            CallBase = true;
            var result = false;

            foreach (var inventory in _inventories)
            {
                if (!inventory.CountAsEmptySlots(_player))
                {
                    continue;
                }

                if (inventory.AddItem(item))
                {
                    EquipmentAndQuickSlots.LogWarning($"Added item ({item.m_shared.m_name}) to ({inventory.m_name}) at ({item.m_gridPos})");
                    result = true;
                    break;
                }
            }

            CallBase = false;
            return(result);
        }
Пример #7
0
 public ExtendedInventory(Player player, string name, Sprite bkg, int w, int h) : base(name, bkg, w, h)
 {
     EquipmentAndQuickSlots.LogWarning("New Extended Inventory for Player");
     _player = player;
 }
Пример #8
0
        public static void RefreshEquipmentInSlots(Player player)
        {
            var inventories        = player.GetAllInventories();
            var equipSlotInventory = player.GetEquipmentSlotInventory();
            var swaps = new List <SwapData>();
            var drops = new List <SwapData>();

            // Swap in newly equipped items
            foreach (var inventory in inventories)
            {
                if (inventory != equipSlotInventory)
                {
                    foreach (var item in inventory.m_inventory)
                    {
                        if (item.m_equiped && EquipmentAndQuickSlots.IsSlotEquippable(item))
                        {
                            var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                            if (equipSlot.x < 0 || equipSlot.y < 0)
                            {
                                continue;
                            }
                            swaps.Add(new SwapData(inventory, item, equipSlotInventory, equipSlot));
                            EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to equip slot");
                        }
                    }
                }
            }

            foreach (var swap in swaps)
            {
                Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB);
            }
            swaps.Clear();

            // Swap out unequipped items and incorrectly added
            foreach (var item in equipSlotInventory.m_inventory)
            {
                if (!item.m_equiped || !EquipmentAndQuickSlots.IsSlotEquippable(item))
                {
                    var  destInventories = player.GetAllInventories();
                    bool moved           = false;
                    foreach (var destInventory in destInventories)
                    {
                        if (!destInventory.CountAsEmptySlots(player))
                        {
                            continue;
                        }

                        var emptySlot = destInventory.FindEmptySlot(false);
                        if (emptySlot.x >= 0 && emptySlot.y >= 0)
                        {
                            moved = true;
                            swaps.Add(new SwapData(equipSlotInventory, item, destInventory, emptySlot));
                            break;
                        }
                    }

                    EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to main inventory");
                    if (!moved)
                    {
                        if (!CanEquip(item, player))
                        {
                            player.Message(MessageHud.MessageType.Center, "Item force unequipped, inventory full, dropped item");
                            drops.Add(new SwapData(equipSlotInventory, item, null, new Vector2i()));
                        }
                        else
                        {
                            item.m_equiped = true;
                            player.Message(MessageHud.MessageType.Center, "Could not unequip, inventory full");
                        }
                    }
                }
                else
                {
                    var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                    if ((equipSlot.x >= 0 && equipSlot.y >= 0) && item.m_gridPos != equipSlot)
                    {
                        item.m_gridPos = equipSlot;
                        EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to correct slot ({equipSlot})");
                    }
                }
            }

            foreach (var drop in drops)
            {
                ItemDrop.DropItem(drop.Item, drop.Item.m_stack, player.transform.position, Quaternion.identity);
                drop.InventoryA.RemoveItem(drop.Item);
            }
            drops.Clear();

            foreach (var swap in swaps)
            {
                Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB);
            }
            swaps.Clear();
        }
Пример #9
0
        public static void Prefix(Player __instance)
        {
            if (__instance.m_inventory.NrOfItems() == 0)
            {
                return;
            }

            EquipmentSlotHelper.AllowMove = false;
            __instance.UnequipAllItems();

            var allInventories = __instance.GetAllInventories();

            // Modify tombstone prefab
            var totalPossibleSlots = allInventories.Sum(x => x.m_width * x.m_height);
            var width  = __instance.m_inventory.m_width;
            var height = (totalPossibleSlots / width) + 1;

            __instance.m_tombstone.GetComponent <Container>().m_width  = width;
            __instance.m_tombstone.GetComponent <Container>().m_height = height;

            var gameObject    = Object.Instantiate(__instance.m_tombstone, __instance.GetCenterPoint(), __instance.transform.rotation);
            var tombStone     = gameObject.GetComponent <TombStone>();
            var playerProfile = Game.instance.GetPlayerProfile();
            var name          = playerProfile.GetName();
            var playerId      = playerProfile.GetPlayerID();

            tombStone.Setup(name, playerId);

            var container = gameObject.GetComponent <Container>();

            EquipmentAndQuickSlots.LogWarning("== PLAYER DIED ==");
            var containerInventory = container.GetInventory();

            foreach (var inventory in allInventories)
            {
                foreach (var item in inventory.m_inventory)
                {
                    if (containerInventory.GetItemAt(item.m_gridPos.x, item.m_gridPos.y) != null)
                    {
                        var newSlot = containerInventory.FindEmptySlot(true);
                        item.m_gridPos = newSlot;
                        EquipmentAndQuickSlots.LogWarning($"Adding item to tombstone [newslot]: {item.m_shared.m_name} ({newSlot})");
                        containerInventory.m_inventory.Add(item);
                    }
                    else
                    {
                        containerInventory.m_inventory.Add(item);
                        EquipmentAndQuickSlots.LogWarning($"Adding item to tombstone [manual ]: {item.m_shared.m_name}");
                    }
                }

                inventory.m_inventory.RemoveAll(item => !item.m_shared.m_questItem && !item.m_equiped);
                inventory.Changed();
                containerInventory.Changed();
            }

            // I don't know why I need this here, vanilla doesn't have it
            container.Save();

            EquipmentAndQuickSlots.LogWarning($"Creating tombstone for ({name}) with w:{width} h:{height} (total:{totalPossibleSlots})");
            EquipmentAndQuickSlots.LogWarning($"== Container Inventory ({containerInventory.NrOfItems()}):");
            foreach (var item in containerInventory.m_inventory)
            {
                EquipmentAndQuickSlots.LogWarning($"  - {item.m_shared.m_name} {item.m_stack}");
            }

            EquipmentSlotHelper.AllowMove = true;
        }