首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用C#多个属性作为要求

使用C#多个属性作为要求
EN

Stack Overflow用户
提问于 2017-05-14 03:05:24
回答 1查看 401关注 0票数 0

因此,我一直在尝试创建一个mod,我遇到了一个问题,试图要求多个技能集,或者更确切地说,限制多个技能集。

我试图做的是将其锁定,这样玩家一次只能访问一个技能树。我的工作是下面的,但这并不能阻止他们在另一棵树上学习技能。

代码语言:javascript
复制
namespace Test.run.TechTree
{
    using System;
    using System.Runtime.Serialization;
    using Test.Gameplay.Components;
    using Test.Gameplay.DynamicValues;
    using Test.Gameplay.Items;
    using Test.Gameplay.Players;
    using Test.Gameplay.Property;
    using Test.Gameplay.Skills;
    using Test.Gameplay.Systems.TextLinks;
    using Test.Shared.Services;
    using Test.Shared.Utils;
    using Gameplay.Systems.Tooltip;

    [DataContract]

    [RequiresSkill(typeof(FireSkill), 0)]
    public partial class ShootingSkill : Skill
    {
        public override string FriendlyName { get { return "Shooting"; } }
        public override string Description { get { return "This is how you shoot"; } }

        public static int[] SkillPointCost = { 1, 2, 2, 3, 3 };
        public override int RequiredPoint { get { return this.Level < this.MaxLevel ? SkillPointCost[this.Level] : 0; } }
        public override int MaxLevel { get { return 4; } }
    }

}

这允许他们学习并将点数放入此技能树中,这很棒,但我想限制它,以便如果他们已经在另一个技能树中学习技能,则不能将技能放入此技能树中。最后,我想要说的是,如果你没有在另一个技能中投入点数,或者直到你在另一个技能中至少有50分,你就可以使用这项技能。

在这个例子中,玩家想要开始将点数放入射击技能树的Fireskill中,但我想说的是,如果他们在附件技能树的Gearskill部分中有1到49点,我不希望他们能够使用它,直到他们没有在Gearskill中投入任何东西或至少50点。我承认我是C#的新手,还在学习更多关于属性的知识,但是我如何才能将下面的概念应用到工作中呢?任何帮助都将不胜感激。

代码语言:javascript
复制
namespace Test.run.TechTree
{
    using System;
    using System.Runtime.Serialization;
    using Test.Gameplay.Components;
    using Test.Gameplay.DynamicValues;
    using Test.Gameplay.Items;
    using Test.Gameplay.Players;
    using Test.Gameplay.Property;
    using Test.Gameplay.Skills;
    using Test.Gameplay.Systems.TextLinks;
    using Test.Shared.Services;
    using Test.Shared.Utils;
    using Gameplay.Systems.Tooltip;

    [DataContract]

    [RequiresSkill(typeof(FireSkill), 0), RequiresSkill(typeof(GearSkill), >1 or  <50]
    public partial class ShootingSkill : Skill
    {
        public override string FriendlyName { get { return "Shooting"; } }
        public override string Description { get { return "This is how you shoot"; } }

        public static int[] SkillPointCost = { 1, 2, 2, 3, 3 };
        public override int RequiredPoint { get { return this.Level < this.MaxLevel ? SkillPointCost[this.Level] : 0; } }
        public override int MaxLevel { get { return 4; } }
    }

}
EN

回答 1

Stack Overflow用户

发布于 2017-05-14 03:58:06

您需要为RequiresSkill属性设置AllowMultiple = true

代码语言:javascript
复制
[AttributeUsage(AttributeTargets.{whatever}, AllowMultiple = true)]  
public class RequiresSkill : Attribute  
{  
} 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43956982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档