53 lines
2.0 KiB
PHP
53 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use Illuminate\Database\Migrations\Migration;
|
||
|
|
use Illuminate\Database\Schema\Blueprint;
|
||
|
|
use Illuminate\Support\Facades\Schema;
|
||
|
|
|
||
|
|
return new class extends Migration
|
||
|
|
{
|
||
|
|
public function up(): void
|
||
|
|
{
|
||
|
|
// Quests a player has claimed. Progress is never stored: it follows from the
|
||
|
|
// player's buildings and counters on every read.
|
||
|
|
Schema::create('player_quests', function (Blueprint $table) {
|
||
|
|
$table->id();
|
||
|
|
$table->foreignId('player_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->string('quest', 48);
|
||
|
|
$table->dateTime('claimed_at', 3);
|
||
|
|
$table->unique(['player_id', 'quest']);
|
||
|
|
});
|
||
|
|
|
||
|
|
// How often a player has done something a quest asks for (Counters::bump).
|
||
|
|
Schema::create('player_counters', function (Blueprint $table) {
|
||
|
|
$table->id();
|
||
|
|
$table->foreignId('player_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->string('key', 48);
|
||
|
|
$table->unsignedInteger('value')->default(0);
|
||
|
|
$table->unique(['player_id', 'key']);
|
||
|
|
});
|
||
|
|
|
||
|
|
// A building level reached for the first time pays back part of its cost, once
|
||
|
|
// per player, type and level, into the village it was reached in.
|
||
|
|
Schema::create('level_rewards', function (Blueprint $table) {
|
||
|
|
$table->id();
|
||
|
|
$table->foreignId('player_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->foreignId('village_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->string('type', 32);
|
||
|
|
$table->unsignedSmallInteger('level');
|
||
|
|
$table->json('reward');
|
||
|
|
$table->dateTime('reached_at', 3);
|
||
|
|
$table->dateTime('claimed_at', 3)->nullable();
|
||
|
|
$table->unique(['player_id', 'type', 'level']);
|
||
|
|
$table->index(['player_id', 'claimed_at']);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function down(): void
|
||
|
|
{
|
||
|
|
Schema::dropIfExists('level_rewards');
|
||
|
|
Schema::dropIfExists('player_counters');
|
||
|
|
Schema::dropIfExists('player_quests');
|
||
|
|
}
|
||
|
|
};
|