IDamageable - jimdroberts/FishMMO GitHub Wiki

Description

Interface for entities that can receive damage from attacks. Implement this to allow objects to be damaged by characters or other sources.


API Access

Methods

  • void Damage(ICharacter attacker, int amount, DamageAttributeTemplate damageAttribute, bool ignoreAchievements = false)

    Applies damage to the entity. attacker (ICharacter): The character dealing the damage. amount (int): The amount of damage to apply. damageAttribute (DamageAttributeTemplate): The type of damage being applied (e.g., fire, physical). ignoreAchievements (bool): If true, achievement progress is not affected by this damage event.


Basic Usage

Setup

  1. Implement IDamageable on your entity or object class.
  2. Provide logic in the Damage method to handle receiving and processing damage.
  3. Use the interface to allow characters or other sources to apply damage to the entity.

Example

// Example 1: Implementing IDamageable
public class Enemy : MonoBehaviour, IDamageable {
    public void Damage(ICharacter attacker, int amount, DamageAttributeTemplate damageAttribute, bool ignoreAchievements = false) {
        // Apply damage logic here
    }
}

// Example 2: Applying damage in gameplay
IDamageable target = enemy.GetComponent<IDamageable>();
target.Damage(player, 50, fireAttribute);

Best Practices

  • Always implement the Damage method to handle all relevant damage logic for your entity.
  • Use the ignoreAchievements parameter to control whether damage should affect achievement progress.
  • Use IDamageable for all objects that should be affected by attacks or damaging effects.
⚠️ **GitHub.com Fallback** ⚠️