Files
chatroom/database/migrations/2026_02_26_094113_create_autoact_table.php

74 lines
4.3 KiB
PHP
Raw Normal View History

<?php
/**
* 文件功能创建自动动作事件表autoact
* 复刻原版 ASP 聊天室的 autoact
* 存储系统随机事件(好运/坏运/经验/金币奖惩等)
* 管理员可在后台增删改这些事件
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 创建 autoact 表并插入默认随机事件
*/
public function up(): void
{
Schema::create('autoact', function (Blueprint $table) {
$table->id();
$table->string('text_body', 500)->comment('事件文本内容(支持变量替换)');
$table->string('event_type', 20)->default('neutral')->comment('事件类型good=好运, bad=坏运, neutral=中性');
$table->integer('exp_change')->default(0)->comment('经验变化值(正=奖励, 负=惩罚)');
$table->integer('jjb_change')->default(0)->comment('金币变化值(正=奖励, 负=惩罚)');
$table->boolean('enabled')->default(true)->comment('是否启用');
$table->timestamps();
});
// 插入默认随机事件
$events = [
// 好运事件(奖励经验/金币)
['text_body' => '🎉 恭喜【{username}】路遇仙人指点,获得 100 经验值!', 'event_type' => 'good', 'exp_change' => 100, 'jjb_change' => 0],
['text_body' => '💰 【{username}】在路边捡到一袋金币,获得 500 金币!', 'event_type' => 'good', 'exp_change' => 0, 'jjb_change' => 500],
['text_body' => '🌟 天降祥瑞!【{username}】获得 200 经验 + 200 金币!', 'event_type' => 'good', 'exp_change' => 200, 'jjb_change' => 200],
['text_body' => '🎊 【{username}】参加武林大会获胜,奖励 300 经验!', 'event_type' => 'good', 'exp_change' => 300, 'jjb_change' => 0],
['text_body' => '🏆 【{username}】完成了一个神秘任务,获得 150 金币!', 'event_type' => 'good', 'exp_change' => 0, 'jjb_change' => 150],
['text_body' => '✨ 【{username}】领悟了一招绝学,经验暴增 500', 'event_type' => 'good', 'exp_change' => 500, 'jjb_change' => 0],
['text_body' => '🎁 系统随机赠送【{username}】100 金币,请查收!', 'event_type' => 'good', 'exp_change' => 0, 'jjb_change' => 100],
// 坏运事件(扣除经验/金币)
['text_body' => '💀 【{username}】不小心踩到陷阱,损失 50 经验!', 'event_type' => 'bad', 'exp_change' => -50, 'jjb_change' => 0],
['text_body' => '😱 【{username}】遭遇山贼打劫,被抢走 100 金币!', 'event_type' => 'bad', 'exp_change' => 0, 'jjb_change' => -100],
['text_body' => '🌧️ 【{username}】在雨中迷路,消耗 80 经验值。', 'event_type' => 'bad', 'exp_change' => -80, 'jjb_change' => 0],
['text_body' => '🐍 【{username}】被毒蛇咬了一口,损失 30 经验和 50 金币!', 'event_type' => 'bad', 'exp_change' => -30, 'jjb_change' => -50],
// 中性事件(纯文字,不奖惩)
['text_body' => '🔮 星海小博士:【{username}】今天运势不错,继续加油!', 'event_type' => 'neutral', 'exp_change' => 0, 'jjb_change' => 0],
['text_body' => '📜 星海小博士:有人说"坚持就是胜利",【{username}】觉得呢?', 'event_type' => 'neutral', 'exp_change' => 0, 'jjb_change' => 0],
['text_body' => '🌈 星海小博士:【{username}】今天心情如何?记得多喝水哦!', 'event_type' => 'neutral', 'exp_change' => 0, 'jjb_change' => 0],
['text_body' => '🎵 星海小博士:送给【{username}】一首歌,祝你天天开心!', 'event_type' => 'neutral', 'exp_change' => 0, 'jjb_change' => 0],
];
$now = now();
foreach ($events as &$event) {
$event['enabled'] = true;
$event['created_at'] = $now;
$event['updated_at'] = $now;
}
DB::table('autoact')->insert($events);
}
/**
* 回滚:删除 autoact
*/
public function down(): void
{
Schema::dropIfExists('autoact');
}
};