72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Village extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
// resources_at keeps milliseconds, so ordering with events is exact.
|
|
protected $dateFormat = 'Y-m-d H:i:s.v';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'wood' => 'float',
|
|
'clay' => 'float',
|
|
'iron' => 'float',
|
|
'food' => 'float',
|
|
'resources_at' => 'immutable_datetime',
|
|
'militia' => 'integer',
|
|
'levy_until' => 'immutable_datetime',
|
|
'starving_since' => 'immutable_datetime',
|
|
'loyalty' => 'float',
|
|
'loyalty_at' => 'immutable_datetime',
|
|
'crown' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function world(): BelongsTo
|
|
{
|
|
return $this->belongsTo(World::class);
|
|
}
|
|
|
|
public function player(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Player::class);
|
|
}
|
|
|
|
public function buildings(): HasMany
|
|
{
|
|
return $this->hasMany(Building::class)->orderBy('id');
|
|
}
|
|
|
|
/** In queue order. */
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->hasMany(BuildOrder::class)->orderBy('id');
|
|
}
|
|
|
|
/** Troops standing here: own (home_village_id is this village) and support from elsewhere. */
|
|
public function troops(): HasMany
|
|
{
|
|
return $this->hasMany(UnitStack::class)->orderBy('id');
|
|
}
|
|
|
|
/** Recruiting queues of all military buildings, in queue order. */
|
|
public function recruits(): HasMany
|
|
{
|
|
return $this->hasMany(RecruitOrder::class)->orderBy('id');
|
|
}
|
|
|
|
/** @return array{wood: float, clay: float, iron: float, food: float} */
|
|
public function resources(): array
|
|
{
|
|
return ['wood' => $this->wood, 'clay' => $this->clay, 'iron' => $this->iron, 'food' => $this->food];
|
|
}
|
|
}
|