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

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
UTF-8
using SoulHarvest.Common;
using SoulHarvest.Items;
using SoulHarvest.Tiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.GameContent.UI.Elements;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.UI;

namespace SoulHarvest.UI;

internal readonly record struct AltarEquipmentEntry(
    AltarEquipmentEntryKind Kind,
    DeathAltarItemReference? ItemReference,
    int ItemType)
{
    public bool IsCharacterSickle => Kind == AltarEquipmentEntryKind.CharacterSickle;
    public bool IsCharacterDeathDomain => Kind == AltarEquipmentEntryKind.CharacterDeathDomain;
    public bool IsCharacterProgression => IsCharacterSickle || IsCharacterDeathDomain;

    public static AltarEquipmentEntry CreateCharacterSickle()
    {
        return new AltarEquipmentEntry(
            AltarEquipmentEntryKind.CharacterSickle,
            null,
            ModContent.ItemType<NormalSickle>());
    }

    public static AltarEquipmentEntry CreateCharacterDeathDomain()
    {
        int itemType = ModContent.ItemType<DeathDomain>();
        return new AltarEquipmentEntry(
            AltarEquipmentEntryKind.CharacterDeathDomain,
            new DeathAltarItemReference(DeathAltarItemStorage.CharacterDeathDomain, 0, itemType),
            itemType);
    }

    public static AltarEquipmentEntry CreateItem(DeathAltarItemReference reference)
    {
        return new AltarEquipmentEntry(
            AltarEquipmentEntryKind.UpgradeableItem,
            reference,
            reference.ExpectedItemType);
    }

    public bool TryGetDisplayItem(Player player, out Item item)
    {
        if (IsCharacterProgression)
        {
            item = new Item();
            item.SetDefaults(ItemType);
            return true;
        }

        if (ItemReference is DeathAltarItemReference reference)
            return reference.TryResolve(player, out item);

        item = new Item();
        return false;
    }
}