AttackResult::class, 'was_critical' => 'boolean', 'was_mugging' => 'boolean', 'attacked_at' => 'datetime', ]; /** * Get the attacker character. */ public function attacker(): BelongsTo { return $this->belongsTo(Character::class, 'attacker_id'); } /** * Get the defender character. */ public function defender(): BelongsTo { return $this->belongsTo(Character::class, 'defender_id'); } /** * Get the weapon used by attacker. */ public function attackerWeapon(): BelongsTo { return $this->belongsTo(Item::class, 'attacker_weapon_id'); } /** * Get the armor used by defender. */ public function defenderArmor(): BelongsTo { return $this->belongsTo(Item::class, 'defender_armor_id'); } /** * Check if this was a successful attack (attacker won) */ public function isWin(): bool { return $this->result === AttackResult::WIN; } /** * Check if this was a loss (attacker lost) */ public function isLose(): bool { return $this->result === AttackResult::LOSE; } /** * Check if this was a draw */ public function isDraw(): bool { return $this->result === AttackResult::DRAW; } /** * Check if attacker escaped */ public function isEscape(): bool { return $this->result === AttackResult::ESCAPE; } /** * Check if this attack resulted in defender's death */ public function defenderDied(): bool { return $this->defender_health_after <= 0; } /** * Check if this attack resulted in attacker's death */ public function attackerDied(): bool { return $this->attacker_health_after <= 0; } }