Skip to content

Item

物品/装备基类,位于 FunGame.Core.Entity

Skill 一样,需要继承此类来构造自定义物品。物品通过 SkillsSkillGroup)关联主动/被动技能,装备后自动生效。

构造函数

csharp
// 指定物品类型(isInGame = 是否游戏内物品,默认 true)
public Item(ItemType type, bool isInGame = true)

// 默认构造(JSON 反序列化用)
public Item()

属性

基础信息

属性类型说明
Idlong唯一标识符
Namestring物品名称(可重写)
Descriptionstring物品描述
GeneralDescriptionstring通用描述(不随等级变化)
BackgroundStorystring背景故事
Categorystring分类
TagsList<string>标签

类型与品质

属性类型说明
ItemTypeItemType物品类型(武器/防具/消耗品等)
EquipSlotTypeEquipSlotType装备栏位
WeaponTypeWeaponType武器类型
QualityTypeQualityType品质等级
RarityTypeRarityType稀有度
RankTypeItemRankType物品等级
IsEquipmentbool是否为装备(只读)

使用与交易

属性类型说明
IsLockbool是否锁定
Equipable / Unequipablebool可装备/可卸下
Enablebool是否启用
IsInGameItembool是否游戏内物品
IsPurchasablebool是否可购买
Pricedouble价格
IsSellable / NextSellableTimebool / DateTime可出售 / 下次可出售时间
IsTradable / NextTradableTimebool / DateTime可交易 / 下次可交易时间
RemainUseTimesint剩余使用次数
IsReduceTimesAfterUsebool使用后是否减少次数
IsRemoveAfterUsebool使用后是否移除
Stackable / StackCountbool / int可堆叠 / 堆叠数量
Keyint快捷键

内容与归属

属性类型说明
SkillsSkillGroup物品技能组(Active 主动技 + Passives 被动技)
IsActivebool是否有主动技能(只读)
CharacterCharacter?所属角色
UserUser?所属用户
OthersDictionary<string, object>动态扩展数据

主要方法

方法说明
OnItemEquip(Character, EquipSlotType)装备时调用(触发被动技能等)
OnItemUnEquip(EquipSlotType)卸下时调用
UseItem(IGamingQueue, Character, DecisionPoints, ...)战斗内使用物品
UseItem(User, int times, Dictionary<string, object> args)对局外使用物品
ReduceTimesAndRemove(int times = 1)减少使用次数并在用尽时移除
SetGamingQueue(IGamingQueue)绑定队列(传递技能/特效上下文)
InquiryBeforeTargetSelection(Character, DecisionPoints)使用物品选择目标前询问
ResolveInquiryBeforeTargetSelection(...)解析询问结果
Copy(bool copyLevel, bool copyGuid, bool copyProperty, bool copyOthers, ...)复制物品(含关联技能)
SetLevel(int) / SetMagicsLevel(int)设置物品/魔法技能等级
SetPropertyToItemModuleNew(Item)同步新物品属性(物品模组用)
ToString() / ToString(bool, bool) / ToStringInventory(bool)文本输出(描述/背包)

可重写虚方法

方法说明
OnItemEquipped(Character, EquipSlotType)装备完成后回调(预制实体在此应用特性)
OnItemUnEquipped(Character, EquipSlotType)卸下完成后回调(恢复特性)
OnItemUsed(...)物品使用后回调
AfterCopy(...)复制完成后回调
InquiryBeforeTargetSelection(...) / ResolveInquiryBeforeTargetSelection(...)目标选择询问

继承示例

csharp
public class ExampleItem : Item
{
    public override long Id => 1;
    public override string Name => "ExampleItem";

    public ExampleItem(Character? character = null) : base(ItemType.Weapon)
    {
        Price = 0;
        IsSellable = false;
        IsTradable = false;

        // 技能一定要设置等级大于 0,否则不会生效
        Skills.Passives.Add(new ExampleItemSkill(character, this) { Level = 1 });
        Skills.Active = new ExampleNonDirectionalSkill2(character) { Level = 4 };
    }
}

关联

基于 LGPL-3.0 许可证发布