132 lines
4.5 KiB
C#
132 lines
4.5 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Continentis.MainGame.Card;
|
||
|
||
namespace Continentis.MainGame
|
||
{
|
||
/// <summary>
|
||
/// 攻击上下文,携带来源卡牌和标签信息。
|
||
/// 替代 Attack() 方法中零散的 boolean 参数,提供可扩展的伤害标记体系。
|
||
/// </summary>
|
||
public class AttackContext
|
||
{
|
||
/// <summary>触发此次攻击的来源卡牌(可为 null)。</summary>
|
||
public CardInstance sourceCard;
|
||
|
||
/// <summary>攻击标签集合,用于控制伤害计算与事件触发行为。</summary>
|
||
public HashSet<string> tags;
|
||
|
||
/// <summary>
|
||
/// 伤害属性关键词(如 "Physics"、"Fire"),驱动 offset 和元素乘区计算。
|
||
/// 为 null 时回退到卡牌元素关键词(向后兼容)。
|
||
/// </summary>
|
||
public List<string> damageKeywords;
|
||
|
||
/// <summary>
|
||
/// 基础伤害读取的属性名(如 "Damage_Physics")。
|
||
/// 为 null 或空时默认读取 "Damage"。
|
||
/// </summary>
|
||
public string baseDamageAttributeName;
|
||
|
||
public AttackContext()
|
||
{
|
||
tags = new HashSet<string>();
|
||
}
|
||
|
||
public AttackContext(CardInstance sourceCard) : this()
|
||
{
|
||
this.sourceCard = sourceCard;
|
||
}
|
||
|
||
/// <summary>检查是否包含指定标签。</summary>
|
||
public bool HasTag(string tag)
|
||
{
|
||
return tags != null && tags.Contains(tag);
|
||
}
|
||
|
||
/// <summary>检查是否包含任意一个指定标签。</summary>
|
||
public bool HasAnyTag(params string[] checkTags)
|
||
{
|
||
if (tags == null || tags.Count == 0) return false;
|
||
return checkTags.Any(t => tags.Contains(t));
|
||
}
|
||
|
||
/// <summary>链式添加标签。</summary>
|
||
public AttackContext WithTag(string tag)
|
||
{
|
||
tags ??= new HashSet<string>();
|
||
tags.Add(tag);
|
||
return this;
|
||
}
|
||
|
||
/// <summary>链式添加多个标签。</summary>
|
||
public AttackContext WithTags(params string[] newTags)
|
||
{
|
||
tags ??= new HashSet<string>();
|
||
foreach (string tag in newTags)
|
||
{
|
||
tags.Add(tag);
|
||
}
|
||
return this;
|
||
}
|
||
|
||
/// <summary>链式设置伤害属性关键词。</summary>
|
||
public AttackContext WithDamageKeywords(params string[] keywords)
|
||
{
|
||
damageKeywords = new List<string>(keywords);
|
||
return this;
|
||
}
|
||
|
||
/// <summary>链式设置基础伤害属性名。</summary>
|
||
public AttackContext WithBaseDamageAttribute(string attributeName)
|
||
{
|
||
baseDamageAttributeName = attributeName;
|
||
return this;
|
||
}
|
||
|
||
/// <summary>创建一个携带来源卡牌的默认上下文。</summary>
|
||
public static AttackContext Default(CardInstance card = null)
|
||
{
|
||
return new AttackContext(card);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 预定义的攻击标签常量。
|
||
/// Mod 开发者可以使用自定义字符串扩展标签体系,无需修改此类。
|
||
/// </summary>
|
||
public static class AttackTags
|
||
{
|
||
/// <summary>
|
||
/// 完全静默攻击:不触发任何攻击事件(角色 EventSubmodule + Buff 层均跳过)。
|
||
/// 等价于旧 API 的 triggerAttackEvent = false。
|
||
/// </summary>
|
||
public const string Silent = "Silent";
|
||
|
||
/// <summary>
|
||
/// 响应式攻击:由 Buff 被动效果产生的附带攻击。
|
||
/// 触发角色 EventSubmodule 事件,但跳过 Buff 层的 onDealAttack/onGetAttacked,
|
||
/// 从机制上杜绝 Buff 触发链的无限递归。
|
||
/// </summary>
|
||
public const string Reactive = "Reactive";
|
||
|
||
/// <summary>
|
||
/// 生命移除:无视闪避、格挡、护盾,不触发任何事件。
|
||
/// 直接对目标造成生命值扣减,类似 Dota 2 的 HP Removal。
|
||
/// </summary>
|
||
public const string HpRemoval = "HpRemoval";
|
||
|
||
/// <summary>
|
||
/// 反弹伤害:由反弹/反伤机制产生的伤害。
|
||
/// Buff 可检查此标签以避免"反弹的反弹"导致无限循环。
|
||
/// </summary>
|
||
public const string Reflected = "Reflected";
|
||
|
||
/// <summary>必中,无视闪避。</summary>
|
||
public const string GuaranteedHit = "GuaranteedHit";
|
||
|
||
/// <summary>穿透,无视格挡。</summary>
|
||
public const string Penetrating = "Penetrating";
|
||
}
|
||
}
|