checkCanReceiveDamage method

bool checkCanReceiveDamage(
  1. AttackFromEnum attacker,
  2. double damage,
  3. dynamic from
)

This method is used to check if this component can receive damage from any attacker.

Implementation

bool checkCanReceiveDamage(
  AttackFromEnum attacker,
  double damage,
  dynamic from,
) {
  switch (receivesAttackFrom) {
    case ReceivesAttackFromEnum.ALL:
      return true;
    case ReceivesAttackFromEnum.ENEMY:
      if (attacker == AttackFromEnum.ENEMY) {
        return true;
      }
      break;
    case ReceivesAttackFromEnum.PLAYER_AND_ALLY:
      if (attacker == AttackFromEnum.PLAYER_OR_ALLY) {
        return true;
      }
      break;
    case ReceivesAttackFromEnum.NONE:
      return false;
  }

  return false;
}