public void Initialize(IMap map, Transform target, EnemyStats stats, IPathFinder pathFinder, AttackResolver attackResolver) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (target == null) { throw new ArgumentNullException(nameof(target)); } if (stats == null) { throw new ArgumentNullException(nameof(stats)); } if (pathFinder == null) { throw new ArgumentNullException(nameof(pathFinder)); } if (attackResolver == null) { throw new ArgumentNullException(nameof(attackResolver)); } this.map = map; this.target = target; this.stats = stats; this.pathFinder = pathFinder; this.attackResolver = attackResolver; }
void Attack(Transform target) { IAttackable targetBody = target.GetComponent <IAttackable>(); if (targetBody == null) { throw new ArgumentException("Target cannot be attacked."); } Attack attack = BuildAttack(); Defense targetDefense = targetBody.GetDefense(); AttackResult result = AttackResolver.ResolvePhysicalAttack(attack, targetDefense); targetBody.Attack(result); }