CharacterDamageController - jimdroberts/FishMMO GitHub Wiki
Controls damage, healing, and death logic for a character, including achievement tracking and resistance application. Manages health resource, immortality, and event-driven updates in the FishMMO system.
-
public AchievementTemplate DamageAchievementTemplate
Achievement template for dealing damage to another character.
-
public AchievementTemplate DamagedAchievementTemplate
Achievement template for receiving damage from another character.
-
public AchievementTemplate KillAchievementTemplate
Achievement template for killing another character.
-
public AchievementTemplate KilledAchievementTemplate
Achievement template for being killed by another character.
-
public AchievementTemplate HealAchievementTemplate
Achievement template for healing another character.
-
public AchievementTemplate HealedAchievementTemplate
Achievement template for being healed by another character.
-
public AchievementTemplate ResurrectAchievementTemplate
Achievement template for resurrecting another character.
-
public AchievementTemplate ResurrectedAchievementTemplate
Achievement template for being resurrected by another character.
-
private bool immortal
If true, this character cannot be damaged or killed.
-
private CharacterResourceAttribute resourceInstance
Cached reference to the character's health resource attribute.
-
public bool Immortal { get; set; }
Gets or sets whether the character is immortal (cannot be damaged or killed).
-
public bool IsAlive { get; }
Returns true if the character is alive (resource attribute's current value is above zero).
-
public CharacterResourceAttribute ResourceInstance { get; }
Gets the cached health resource attribute for this character. Throws an exception if the attribute controller or health attribute is missing.
-
public int ApplyModifiers(ICharacter target, int amount, DamageAttributeTemplate damageAttribute)
Applies resistance modifiers to the damage amount for the target character. Subtracts the target's resistance value from the incoming damage and clamps the result. target (ICharacter): The character receiving damage. amount (int): The base damage amount. damageAttribute (DamageAttributeTemplate): The damage type being applied. Returns the modified damage amount after resistance is applied (int).
-
public void Damage(ICharacter attacker, int amount, DamageAttributeTemplate damageAttribute, bool ignoreAchievements = false)
Applies damage to the character, updates achievements, and checks for death. attacker (ICharacter): The character dealing damage. amount (int): The amount of damage to apply. damageAttribute (DamageAttributeTemplate): The damage type being applied. ignoreAchievements (bool): If true, skips achievement updates.
-
public void Kill(ICharacter killer)
Kills the character, triggers achievements, removes buffs, and handles pet death. killer (ICharacter): The character responsible for the kill.
-
public void Heal(ICharacter healer, int amount, bool ignoreAchievements = false)
Heals the character, updates achievements, and triggers events. healer (ICharacter): The character performing the heal. amount (int): The amount to heal. ignoreAchievements (bool): If true, skips achievement updates.
-
public void CompleteHeal()
Fully heals the character to their maximum health value.
- Assign achievement templates for damage, healing, kills, and resurrection as needed.
- Use the Immortal property to control whether the character can be damaged or killed.
- Use Damage, Heal, and Kill methods to manage health and combat logic.
// Example 1: Applying damage to a character
characterDamageController.Damage(attacker, 50, fireDamageTemplate);
// Example 2: Healing a character
characterDamageController.Heal(healer, 30);
- Always check IsAlive before applying damage or healing.
- Use ApplyModifiers to account for resistances when calculating damage.
- Use achievement templates to track combat-related achievements.
- Handle pet and buff cleanup on death for robust gameplay logic.