XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Collections.Generic;
using System;
using Terraria;

namespace SoulHarvest.Common;

public readonly record struct DeathAltarItemReference(DeathAltarItemStorage Storage, byte Slot, int ExpectedItemType)
{
    public bool TryGetSlotItem(Player player, out Item item)
    {
        item = new Item();
        if (Storage == DeathAltarItemStorage.CharacterDeathDomain)
        {
            item.SetDefaults(ExpectedItemType);
            return item.type == ExpectedItemType;
        }

        Item[] container = Storage == DeathAltarItemStorage.Inventory ? player.inventory : player.armor;
        int accessibleSlots = Storage == DeathAltarItemStorage.Inventory ? Math.Min(58, container.Length) : container.Length;
        if (Slot >= accessibleSlots)
            return false;

        item = container[Slot];
        return true;
    }

    public bool TryResolve(Player player, out Item item)
    {
        return TryGetSlotItem(player, out item)
            && item.type == ExpectedItemType
            && item.ModItem is IDeathAltarUpgradeable;
    }
}