47 lines
1.7 KiB
PHP
47 lines
1.7 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use Illuminate\Database\Migrations\Migration;
|
||
|
|
use Illuminate\Database\Schema\Blueprint;
|
||
|
|
use Illuminate\Support\Facades\Schema;
|
||
|
|
|
||
|
|
return new class extends Migration
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Run the migrations.
|
||
|
|
*/
|
||
|
|
public function up(): void
|
||
|
|
{
|
||
|
|
Schema::create('attacks', function (Blueprint $table) {
|
||
|
|
$table->id();
|
||
|
|
$table->foreignId('attacker_id')->constrained('characters')->onDelete('cascade');
|
||
|
|
$table->foreignId('defender_id')->constrained('characters')->onDelete('cascade');
|
||
|
|
$table->integer('attacker_damage')->default(0);
|
||
|
|
$table->integer('defender_damage')->default(0);
|
||
|
|
$table->integer('attacker_health_after')->default(0);
|
||
|
|
$table->integer('defender_health_after')->default(0);
|
||
|
|
$table->string('result')->default('draw'); // win, lose, draw, escape
|
||
|
|
$table->integer('money_stolen')->default(0);
|
||
|
|
$table->integer('experience_gained')->default(0);
|
||
|
|
$table->boolean('was_critical')->default(false);
|
||
|
|
$table->boolean('was_mugging')->default(false);
|
||
|
|
$table->foreignId('attacker_weapon_id')->nullable()->constrained('items')->onDelete('set null');
|
||
|
|
$table->foreignId('defender_armor_id')->nullable()->constrained('items')->onDelete('set null');
|
||
|
|
$table->timestamp('attacked_at')->useCurrent();
|
||
|
|
$table->timestamps();
|
||
|
|
|
||
|
|
$table->index('attacker_id');
|
||
|
|
$table->index('defender_id');
|
||
|
|
$table->index('attacked_at');
|
||
|
|
$table->index('result');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reverse the migrations.
|
||
|
|
*/
|
||
|
|
public function down(): void
|
||
|
|
{
|
||
|
|
Schema::dropIfExists('attacks');
|
||
|
|
}
|
||
|
|
};
|