引入属性、伤害管线
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
public static class DamageTypeExtensions
|
||||
{
|
||||
public static StatType ToScalingStat(this DamageType damageType)
|
||||
{
|
||||
switch (damageType)
|
||||
{
|
||||
case DamageType.Melee:
|
||||
return StatType.MeleeDamage;
|
||||
case DamageType.Ranged:
|
||||
return StatType.RangedDamage;
|
||||
case DamageType.Element:
|
||||
return StatType.ElementalDamage;
|
||||
default:
|
||||
return StatType.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e6128fa910e4a778c187123490b4119
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性查询接口。
|
||||
/// 供战斗碰撞(ImpactData)与伤害管线解耦读取属性值。
|
||||
/// </summary>
|
||||
public interface IAttributeProvider
|
||||
{
|
||||
float GetValue(StatType statType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b483f12479014631bb5914285260aa31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,37 +1,45 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct ImpactData
|
||||
{
|
||||
public ImpactData(CampType camp /*, int health*/, int attackBase, StatProperty attackStat = null,
|
||||
StatProperty defenseStat = null, StatProperty dodgeStat = null)
|
||||
{
|
||||
Camp = camp;
|
||||
//Health = health;
|
||||
AttackBase = attackBase;
|
||||
AttackStat = attackStat;
|
||||
DefenseStat = defenseStat;
|
||||
DodgeStat = dodgeStat;
|
||||
}
|
||||
|
||||
public CampType Camp { get; }
|
||||
|
||||
public int AttackBase { get; }
|
||||
|
||||
public StatProperty AttackStat { get; }
|
||||
public DamageType DamageType { get; }
|
||||
|
||||
public StatProperty DefenseStat { get; }
|
||||
public float ScalingRatio { get; }
|
||||
|
||||
public StatProperty DodgeStat { get; }
|
||||
public float BaseCritChance { get; }
|
||||
|
||||
public float CritMultiplier { get; }
|
||||
|
||||
public IAttributeProvider AttributeProvider { get; }
|
||||
|
||||
public ImpactData(
|
||||
CampType camp,
|
||||
int attackBase,
|
||||
IAttributeProvider attributeProvider = null,
|
||||
DamageType damageType = DamageType.None,
|
||||
float scalingRatio = 1.0f,
|
||||
float baseCritChance = 0f,
|
||||
float critMultiplier = 0f)
|
||||
{
|
||||
Camp = camp;
|
||||
AttackBase = attackBase;
|
||||
AttributeProvider = attributeProvider;
|
||||
DamageType = damageType;
|
||||
ScalingRatio = scalingRatio;
|
||||
BaseCritChance = baseCritChance;
|
||||
CritMultiplier = critMultiplier;
|
||||
}
|
||||
|
||||
public ImpactData(CampType camp, int attackBase)
|
||||
: this(camp, attackBase, null, DamageType.None, 1.0f, 0f, 0f)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,24 @@ namespace SepCore.Definition
|
||||
{
|
||||
public class PropItem
|
||||
{
|
||||
private readonly List<modifier> _modifiers = new();
|
||||
private readonly List<StatModifierConfig> _modifiers = new();
|
||||
public string Title { get; private set; }
|
||||
public string IconAssetName { get; private set; }
|
||||
public Rarity Rarity { get; private set; }
|
||||
public IReadOnlyList<modifier> Modifiers => _modifiers;
|
||||
public IReadOnlyList<StatModifierConfig> Modifiers => _modifiers;
|
||||
|
||||
public PropItem(PropConfig prop)
|
||||
{
|
||||
if (prop.Modifiers != null)
|
||||
if (prop.StatModifierConfigs != null)
|
||||
{
|
||||
_modifiers.AddRange(prop.Modifiers);
|
||||
_modifiers.AddRange(prop.StatModifierConfigs);
|
||||
}
|
||||
Title = prop.Name;
|
||||
Rarity = prop.Rarity;
|
||||
IconAssetName = prop.Sprite;
|
||||
}
|
||||
|
||||
public PropItem(IEnumerable<modifier> modifiers)
|
||||
public PropItem(IEnumerable<StatModifierConfig> modifiers)
|
||||
{
|
||||
if (modifiers != null)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ namespace SepCore.Definition
|
||||
}
|
||||
}
|
||||
|
||||
public PropItem(IEnumerable<modifier> modifiers, Rarity rarity, string title, string iconAssetName)
|
||||
public PropItem(IEnumerable<StatModifierConfig> modifiers, Rarity rarity, string title, string iconAssetName)
|
||||
{
|
||||
if (modifiers != null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
public sealed partial class StatConfig
|
||||
{
|
||||
public StatConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public StatConfig(
|
||||
StatType statType,
|
||||
string name = "",
|
||||
float defaultBaseValue = 0f,
|
||||
bool hasMin = false,
|
||||
float minValue = 0f,
|
||||
bool hasMax = false,
|
||||
float maxValue = 0f,
|
||||
bool isPercentDisplay = false)
|
||||
{
|
||||
StatType = statType;
|
||||
Name = name;
|
||||
DefaultBaseValue = defaultBaseValue;
|
||||
HasMin = hasMin;
|
||||
MinValue = minValue;
|
||||
HasMax = hasMax;
|
||||
MaxValue = maxValue;
|
||||
IsPercentDisplay = isPercentDisplay;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b910e53a2454b5f903517865c36ad18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性修饰器。
|
||||
/// 包含修饰数值、修饰类型(固定值/百分比加算/独立乘区)以及来源对象(道具/武器/羁绊/特质/Buff)。
|
||||
/// </summary>
|
||||
public sealed class StatModifier
|
||||
{
|
||||
public float Value { get; }
|
||||
public ModifierType Type { get; }
|
||||
public object Source { get; }
|
||||
|
||||
public StatModifier(float value, ModifierType type, object source = null)
|
||||
{
|
||||
Value = value;
|
||||
Type = type;
|
||||
Source = source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 Luban 导出的 modifier 数据结构转换。
|
||||
/// </summary>
|
||||
/// <param name="mod">Luban modifier 数据实例</param>
|
||||
/// <param name="source">来源对象引用</param>
|
||||
public static StatModifier FromLuban(StatModifierConfig mod, object source = null)
|
||||
{
|
||||
if (mod == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mod));
|
||||
}
|
||||
|
||||
ModifierType type = mod.ModifierType;
|
||||
return new StatModifier(mod.Value, type, source);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[StatModifier Type={Type}, Value={Value}, Source={Source}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 887b4b22fce86cb43b95cfdf3c6b967c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
public sealed partial class StatModifierConfig
|
||||
{
|
||||
public StatModifierConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public StatModifierConfig(StatType statType, float value, ModifierType modifierType)
|
||||
{
|
||||
StatType = statType;
|
||||
Value = value;
|
||||
ModifierType = modifierType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
public class StatProperty
|
||||
{
|
||||
public float Value;
|
||||
public float Percent;
|
||||
|
||||
public StatProperty()
|
||||
{
|
||||
Value = 0f;
|
||||
Percent = 1f;
|
||||
}
|
||||
|
||||
public StatProperty(float value, float percent)
|
||||
{
|
||||
Value = value;
|
||||
Percent = percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18e7bc9587114ae4a91c70f829543de8
|
||||
timeCreated: 1770353735
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Definition
|
||||
{
|
||||
public sealed partial class modifier
|
||||
{
|
||||
public StatType StatType => Key;
|
||||
|
||||
/// <summary>
|
||||
/// 实际参与数值计算的浮点数值。
|
||||
/// 1. 百分比加成(IsPercent == true):表内千分比(如 200 代表 20%),转换为 0.2f。
|
||||
/// 2. 非百分比加成(IsPercent == false):移动速度原为 float 放大了 1000 倍(如 800 代表 0.8f),除以 1000f;其余(如生命+53、攻击+10)直接使用原值。
|
||||
/// </summary>
|
||||
public float RealValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsPercent)
|
||||
{
|
||||
return Value / 1000f;
|
||||
}
|
||||
|
||||
if (Key == StatType.MovementSpeed)
|
||||
{
|
||||
return Value / 1000f;
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
|
||||
public modifier()
|
||||
{
|
||||
}
|
||||
|
||||
public modifier(StatType key, int value, bool isPercent)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
IsPercent = isPercent;
|
||||
}
|
||||
|
||||
public modifier(StatType key, float value, bool isPercent)
|
||||
{
|
||||
Key = key;
|
||||
Value = (isPercent || key == StatType.MovementSpeed)
|
||||
? Mathf.RoundToInt(value * 1000f)
|
||||
: Mathf.RoundToInt(value);
|
||||
IsPercent = isPercent;
|
||||
}
|
||||
|
||||
public string ToDisplayString()
|
||||
{
|
||||
if (IsPercent)
|
||||
{
|
||||
float percent = Value / 10f;
|
||||
return $"{Key} +{percent:0.##}%";
|
||||
}
|
||||
|
||||
if (Key == StatType.MovementSpeed)
|
||||
{
|
||||
float speed = Value / 1000f;
|
||||
return $"{Key} +{speed:0.##}";
|
||||
}
|
||||
|
||||
return $"{Key} +{Value}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user