mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 04:17:13 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Data;
|
||||
using Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
@@ -12,6 +12,28 @@ namespace Item
|
||||
/// </summary>
|
||||
public class ItemResource
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数:通过 ItemDef 对象初始化 ItemResource。
|
||||
/// </summary>
|
||||
/// <param name="def">物品的定义对象。</param>
|
||||
/// <exception cref="ArgumentNullException">如果传入的 ItemDef 为 null,则抛出此异常。</exception>
|
||||
public ItemResource(ItemDef def)
|
||||
{
|
||||
// 参数校验:在构造函数中进行参数非空检查至关重要,避免空引用异常。
|
||||
if (def == null) throw new ArgumentNullException(nameof(def), "创建 ItemResource 时,ItemDef 不能为 null。");
|
||||
|
||||
// 从 ItemDef 对象中直接赋值 ItemResource 的所有属性。
|
||||
// 这将创建 ItemResource 的逻辑完全封装在类内部,外部调用方无需关心具体属性的提取过程。
|
||||
DefName = def.defName;
|
||||
Name = def.label;
|
||||
Description = def.description;
|
||||
Rarity = def.rarity;
|
||||
MaxStack = def.maxStack;
|
||||
IsEquippable = def.ssEquippable;
|
||||
FPS = MathF.Max(0.0001f, def.FPS);
|
||||
Icon = PackagesImageManager.Instance.GetSprites(def.textures);
|
||||
SelfItemDef = def;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -55,6 +77,8 @@ namespace Item
|
||||
/// </summary>
|
||||
public float FPS { get; protected set; }
|
||||
|
||||
public ItemDef SelfItemDef { get; protected set; }
|
||||
|
||||
public static ItemResource GetDefault()
|
||||
{
|
||||
ItemDef defaultDef = new()
|
||||
@@ -68,26 +92,5 @@ namespace Item
|
||||
};
|
||||
return new ItemResource(defaultDef);
|
||||
}
|
||||
/// <summary>
|
||||
/// 构造函数:通过 ItemDef 对象初始化 ItemResource。
|
||||
/// </summary>
|
||||
/// <param name="def">物品的定义对象。</param>
|
||||
/// <exception cref="ArgumentNullException">如果传入的 ItemDef 为 null,则抛出此异常。</exception>
|
||||
public ItemResource(ItemDef def)
|
||||
{
|
||||
// 参数校验:在构造函数中进行参数非空检查至关重要,避免空引用异常。
|
||||
if (def == null) throw new ArgumentNullException(nameof(def), "创建 ItemResource 时,ItemDef 不能为 null。");
|
||||
|
||||
// 从 ItemDef 对象中直接赋值 ItemResource 的所有属性。
|
||||
// 这将创建 ItemResource 的逻辑完全封装在类内部,外部调用方无需关心具体属性的提取过程。
|
||||
DefName = def.defName;
|
||||
Name = def.label;
|
||||
Description = def.description;
|
||||
Rarity = def.rarity;
|
||||
MaxStack = def.maxStack;
|
||||
IsEquippable = def.ssEquippable;
|
||||
FPS = MathF.Max(0.0001f,def.FPS);
|
||||
Icon = PackagesImageManager.Instance.GetSprites(def.textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,60 @@
|
||||
using Base;
|
||||
using Data;
|
||||
using Entity;
|
||||
using Prefab;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using Entity;
|
||||
using Managers;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class WeaponResource : ItemResource
|
||||
{
|
||||
public Attributes Attributes { get; private set; }
|
||||
public BulletDef Bullet { get; private set; }
|
||||
public WeaponType Type { get; private set; }
|
||||
|
||||
public IReadOnlyList<Sprite> AttackAnimation { get; private set; }
|
||||
public float AttackAnimationTime { get; private set; }
|
||||
public float AttackCooldown => 1f / Attributes.attackSpeed;
|
||||
public float AttackDetectionTime { get; private set; }
|
||||
public bool UseEntityAttackAnimation { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
|
||||
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
|
||||
/// </summary>
|
||||
/// <param name="def">武器的定义对象。</param>
|
||||
/// <exception cref="ArgumentNullException">如果传入的 WeaponDef 为 null,则抛出此异常。</exception>
|
||||
public WeaponResource(WeaponDef def)
|
||||
: base(def) // 调用基类 ItemResource 的构造函数,直接传入 WeaponDef。
|
||||
: base(def)
|
||||
{
|
||||
// 参数校验:确保 WeaponDef 对象不为空,避免空引用异常。
|
||||
if (def == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(def), "创建 WeaponResource 时,WeaponDef 不能为 null。");
|
||||
}
|
||||
if (def == null) throw new ArgumentNullException(nameof(def), "创建 WeaponResource 时,WeaponDef 不能为 null。");
|
||||
|
||||
Bullet = def.bullet;
|
||||
// 初始化武器的属性。Attributes 对象通过 WeaponDef 中的属性数据进行构建。
|
||||
Attributes = new Attributes(def.attributes);
|
||||
// 初始化武器类型,直接从 WeaponDef 定义中获取。
|
||||
Type = def.type;
|
||||
|
||||
AttackAnimation = PackagesImageManager.Instance.GetSprites(def.attackAnimation);
|
||||
AttackAnimationTime = AttackAnimation.Count / FPS;
|
||||
AttackDetectionTime = def.attackDetectionTime;
|
||||
UseEntityAttackAnimation = def.useEntityAttackAnimation;
|
||||
|
||||
SelfWeaponDef = def;
|
||||
}
|
||||
|
||||
// 武器的属性
|
||||
public Attributes Attributes { get; }
|
||||
|
||||
// 武器发射的子弹定义
|
||||
public BulletDef Bullet { get; private set; }
|
||||
|
||||
// 武器类型
|
||||
public WeaponType Type { get; private set; }
|
||||
|
||||
// 攻击动画的精灵列表
|
||||
public IReadOnlyList<Sprite> AttackAnimation { get; }
|
||||
|
||||
// 攻击动画的时长
|
||||
public float AttackAnimationTime { get; private set; }
|
||||
|
||||
// 攻击冷却时间
|
||||
public float AttackCooldown => 1f / Attributes.attackSpeed;
|
||||
|
||||
// 攻击判定时间
|
||||
public float AttackDetectionTime { get; private set; }
|
||||
|
||||
// 是否使用实体自身的攻击动画
|
||||
public bool UseEntityAttackAnimation { get; private set; }
|
||||
|
||||
public WeaponDef SelfWeaponDef { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user