first commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum AttackResult: string
|
||||
{
|
||||
case WIN = 'win';
|
||||
case LOSE = 'lose';
|
||||
case DRAW = 'draw';
|
||||
case ESCAPE = 'escape';
|
||||
|
||||
/**
|
||||
* Get all result values as an array
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name for a result
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::WIN => 'Victory',
|
||||
self::LOSE => 'Defeat',
|
||||
self::DRAW => 'Draw',
|
||||
self::ESCAPE => 'Escaped',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the attacker won
|
||||
*/
|
||||
public function attackerWon(): bool
|
||||
{
|
||||
return $this === self::WIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the defender won (attacker lost)
|
||||
*/
|
||||
public function defenderWon(): bool
|
||||
{
|
||||
return $this === self::LOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the experience reward for this result (for attacker)
|
||||
*/
|
||||
public function experienceReward(): int
|
||||
{
|
||||
return match($this) {
|
||||
self::WIN => 200,
|
||||
self::LOSE => 50,
|
||||
self::DRAW => 100,
|
||||
self::ESCAPE => 25,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the money reward for this result (for attacker)
|
||||
*/
|
||||
public function moneyReward(): int
|
||||
{
|
||||
return match($this) {
|
||||
self::WIN => 500,
|
||||
self::LOSE => 0,
|
||||
self::DRAW => 100,
|
||||
self::ESCAPE => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user