主题
GameCore.Leveling
UnitLeveling 双端
命名空间 GameCore.Leveling
csharp
public class UnitLeveling : TagComponent, IGameObject<GameDataUnitLeveling>, IGameObject单位的等级系统,管理经验值、等级计算和升降级时的属性/状态修改。 由 GameDataUnitLeveling 提供等级曲线和升级奖励配置。
构造函数
UnitLeveling 双端
csharp
public UnitLeveling(Unit unit, IGameLink<GameDataUnitLeveling> link)属性
UnitPropertyComplex 双端
csharp
public UnitPropertyComplex UnitPropertyComplex { get; }Gets the UnitPropertyComplex component used for property calculations.
Unit 双端
csharp
public Unit Unit { get; }Gets the unit associated with this leveling logic.
Level 双端
csharp
public int Level { get; }Gets the current level of the unit.
ExperienceToNextLevel 双端
csharp
public double? ExperienceToNextLevel { get; }Gets the experience required to reach the next level, or null if at max level.
Experience 双端
csharp
public double Experience { get; }Gets the current experience points of the unit. Setting this property will recalculate the level and update the experience property accordingly.
LevelMax 双端
csharp
public int? LevelMax { get; }Gets the maximum level the unit can reach, or null if not set, this is determined by the LevelMax property in the UnitPropertyComplex component.
IsMaxLevel 双端
csharp
public bool IsMaxLevel { get; }Gets a value indicating whether the unit is at the maximum level.
ExperienceKillerFraction 双端
csharp
public Fraction ExperienceKillerFraction { get; }Gets or sets the fraction of experience points awarded to the unit if the unit is the one that dealt the killing blow.
Link 双端
csharp
public IGameLink<GameDataUnitLeveling> Link { get; }Cache 双端
csharp
public GameDataUnitLeveling Cache { get; }ModificationManager 仅服务端
csharp
public ModificationManager ModificationManager { get; set; }Gets the ModificationManager responsible for applying property and state changes based on level.
ExperienceDistributionMultiplier 仅服务端
csharp
public double ExperienceDistributionMultiplier { get; }When the unit receives experience, the experience points will be multiplied by this value, this only affects the actual experience points add to the unit, it is not the fraction of the experience points that will be distributed to other units.
方法
DisposeManaged 双端
csharp
protected override void DisposeManaged()CalculateCurrentLevel 仅服务端
csharp
protected double CalculateCurrentLevel()Calculates the current level based on the experience and the experience required for the next level. Handles both leveling up and down, and clamps the level within valid bounds.
返回: Remaining experience points after leveling up or down, or the current experience if no level change is possible.
ForceSetLevel 仅服务端
csharp
public bool ForceSetLevel(int newLevel)Forces the unit's level to the specified value, resetting experience to 0 if changed, will be clamped to a minimum of 0 and a maximum of LevelMax if set.
newLevel— The new level to set.
返回: true if the level was set or already at the desired value; false if the value is invalid.
UpdateModifications 仅服务端
csharp
public void UpdateModifications(bool forced = false)Applies property and state modifications based on the current level.
forced— Iftrue, resets all modifications before applying changes.
ForceRefreshLevel 仅服务端
csharp
public void ForceRefreshLevel()Forces a refresh of the current level by recalculating it.
备注
This method triggers a recalculation of the current level, ensuring that any changes affecting the level are immediately reflected. It is typically used when an explicit update is required.
GrantExperience 仅服务端
csharp
public void GrantExperience(double experience, bool affectedByMultiplier = false)Grants experience points to the unit, with an option to apply the ExperienceDistributionMultiplier. Supports both positive and negative values. Negative values will reduce experience and may cause the unit to level down.
experience— The amount of experience to grant. Positive values add experience, negative values remove it.affectedByMultiplier— Iftrue, the experience will be multiplied byExperienceDistributionMultiplierbefore applying. Iffalse, the raw experience value is applied directly.
DistributeExperience 仅服务端
csharp
public bool DistributeExperience(double experience)UnitLevelingExtension 双端
命名空间 GameCore.Leveling
csharp
public static class UnitLevelingExtension方法
GetComponent 双端
csharp
public static UnitLeveling? GetComponent<TComponent>(this Entity entity) where TComponent : UnitLevelingHasLeveling 双端
csharp
public static bool HasLeveling(this Entity unit)GameDataRuleExperienceGrant 双端
命名空间 GameCore.Leveling.Data
csharp
public class GameDataRuleExperienceGrant : GameDataRule, IGameData<GameDataRuleExperienceGrant>, IGameDataDefines the rules and configuration for distributing experience points when a unit is killed. This includes how experience is granted, the radius for distribution, filtering and validation of candidates, and whether to fallback to global distribution if no valid candidates are found within the radius.
构造函数
GameDataRuleExperienceGrant 双端
csharp
public GameDataRuleExperienceGrant(GameLink<GameDataRule, GameDataRuleExperienceGrant> link)GameDataRuleExperienceGrant 双端
csharp
public GameDataRuleExperienceGrant(IGameLink<GameDataRuleExperienceGrant> link)属性
ExperienceGrant 双端
csharp
public UnitKilledExperience? ExperienceGrant { get; set; }Delegate that calculates the experience points awarded when a unit is killed.
ExperienceDistributionRadius 双端
csharp
public float ExperienceDistributionRadius { get; set; }The radius within which experience is distributed to eligible units.
ExperienceDistributionFilter 双端
csharp
public TargetFilterComplex ExperienceDistributionFilter { get; set; }The filter used to determine which units within the radius are eligible to receive experience, the compare source is the killed unit. Combined with the validator.
备注
Only units that have leveling enabled will be considered for experience distribution.
ExperienceDistributionValidator 双端
csharp
public ExperienceDistributionValidator? ExperienceDistributionValidator { get; set; }Delegate that validates whether a candidate unit is eligible to receive experience. Combined with the filter,
AllowGlobalExperienceDistributionFallback 双端
csharp
public bool AllowGlobalExperienceDistributionFallback { get; set; }Indicates whether to fall back to global experience distribution if no valid candidates are found within the radius and the killer is not a valid candidate.
Link 双端
csharp
public new IGameLink<GameDataRuleExperienceGrant> Link { get; }方法
IsValidDistributionCandidate 双端
csharp
public bool IsValidDistributionCandidate(Unit killedUnit, Unit candidate, IExecutionContext killingContext)Determines whether the specified candidate unit is eligible to receive experience distribution based on the given killed unit and execution context.
killedUnit— The unit that was killed, which serves as the source of experience distribution.candidate— The unit being evaluated for eligibility to receive experience distribution.killingContext— The execution context in which the killing occurred, providing additional information for validation.
返回: true if the candidate unit is eligible to receive experience distribution; otherwise, false.
备注
A candidate unit is considered valid for experience distribution if it passes the experience distribution filter, has leveling capabilities, and satisfies any additional validation logic provided by the ExperienceDistributionValidator, if defined.
MorphValidDistributionCandidate 双端
csharp
public UnitLeveling? MorphValidDistributionCandidate(Unit killedUnit, Entity candidate, IExecutionContext killingContext)GenericKillExperienceProcess 仅服务端
csharp
public void GenericKillExperienceProcess(Unit killedUnit, DeathType deathType, IExecutionContext? context = null)GameDataUnitLeveling 双端
命名空间 GameCore.Leveling.Data
csharp
public class GameDataUnitLeveling : GameDataCategory<GameDataUnitLeveling>, IUnitModificationData, IGameDataCategory<GameDataUnitLeveling>, IGameData<GameDataUnitLeveling>, IGameData单位升级配置,定义经验分配、升级所需经验及满级后行为。
构造函数
GameDataUnitLeveling 双端
csharp
public GameDataUnitLeveling(GameLink<GameDataUnitLeveling, GameDataUnitLeveling> link)GameDataUnitLeveling 双端
csharp
public GameDataUnitLeveling(IGameLink<GameDataUnitLeveling> link)属性
ExperienceKillerFraction 双端
csharp
public Fraction ExperienceKillerFraction { get; set; }击杀者获得的经验比例,其余经验分配给助攻者。
ExperienceRequiredForEachLevel 双端
csharp
public List<double> ExperienceRequiredForEachLevel { get; set; }每级所需经验列表,索引 n 表示从 n-1 级升到 n 级所需经验。 索引 0 无实际意义(仅为数组对齐占位),索引 1 应始终为 0(单位创建即为 1 级)。 超出列表范围的等级将由 ExtraLevelExperienceRequiredLevelFactor 和 ExtraLevelExperienceRequiredBonusPerLevel 公式计算。
ExtraLevelExperienceRequiredLevelFactor 双端
csharp
public double ExtraLevelExperienceRequiredLevelFactor { get; set; }超出列表的等级使用公式计算:所需经验 = 本值 × 等级 + ExtraLevelExperienceRequiredBonusPerLevel。
ExtraLevelExperienceRequiredBonusPerLevel 双端
csharp
public double ExtraLevelExperienceRequiredBonusPerLevel { get; set; }超出列表的等级公式中的常数项。
MaxLevelLeech 双端
csharp
public bool MaxLevelLeech { get; set; }满级单位是否仍参与经验分配(如用于其他用途)。为 false 时满级单位不再获得经验,其余单位分得更多。
Modifications 双端
csharp
public List<UnitPropertyModification> Modifications { get; set; }AddStates 双端
csharp
public List<UnitState> AddStates { get; set; }RemoveStates 双端
csharp
public List<UnitState> RemoveStates { get; set; }ImmuneStates 双端
csharp
public List<UnitState> ImmuneStates { get; set; }方法
ExperienceRequiredForLevel 双端
csharp
public virtual double ExperienceRequiredForLevel(uint level)从上一级升到指定等级所需经验。列表内有则取列表值,超出则用公式计算。
level— 目标等级。
返回: 升到该等级所需经验。
TotalExperienceRequiredForLevel 双端
csharp
public virtual double TotalExperienceRequiredForLevel(uint level)从 0 级升到指定等级所需的总累计经验。
level— 目标等级。
返回: 升到该等级所需的总经验。
CreateUnitLeveling 双端
csharp
public virtual UnitLeveling CreateUnitLeveling(Unit unit)ExperienceDistributionValidator 双端
命名空间 GameCore.Leveling.Data.Struct
csharp
public delegate ExperienceDistributionValidatorRepresents a method that validates whether a candidate unit is eligible to receive experience points.
KilledUnit— The unit that has been killed, triggering the experience distribution process.candidate— The unit being considered for experience distribution. This is typically a unit that may receive experience.killContext— The execution context providing additional information relevant to the validation, such as the killer and victim.
返回: A CmdResult indicating whether the candidate is eligible to receive experience. If returns Ok, the candidate can receive experience; otherwise, the candidate is excluded.
UnitKilledExperience 双端
命名空间 GameCore.Leveling.Data.Struct
csharp
public delegate UnitKilledExperienceRepresents a method that calculates the experience points awarded when a unit is killed.
killedUnit— The unit that was killed.deathType— The type of death that occurred, which may influence the experience calculation. Normally, onlyNormalwill grant experience points.context— The execution context providing additional information or state relevant to the calculation, such as the killer and victim.
返回: The amount of experience points awarded as a double. If the experience is not applicable or cannot be calculated, null is returned.