功能:钓鱼游戏后台管理系统
一、钓鱼全局开关
- 钓鱼纳入 GameConfig(game_key=fishing),游戏管理页可一键开关
- cast() 接口加开关校验,关闭时返回 403 友好提示
- GameConfigSeeder 新增 fishing 配置(含4个参数)
二、钓鱼事件数据库化
- 新建 fishing_events 表(emoji/name/message/exp/jjb/weight/is_active/sort)
- FishingEvent 模型含 rollOne() 加权随机方法
- FishingEventSeeder 填充7条初始事件(经验降低、金币提升)
- FishingController::randomFishResult() 改为读数据库事件
三、钓鱼参数迁移至 GameConfig
- fishing_cost/wait_min/wait_max/cooldown 改为 GameConfig::param() 读取
- 保留 Sysparam fallback 兼容旧数据
四、后台管理页面
- 新建 FishingEventController(CRUD + AJAX toggle)
- 新建 admin/fishing/index.blade.php(事件列表+概率显示+编辑弹窗)
- 侧边栏「游戏管理」下方新增「🎣 钓鱼事件」入口
- 游戏管理视图 gameParamLabels 新增钓鱼参数标签
This commit is contained in:
23
database/factories/FishingEventFactory.php
Normal file
23
database/factories/FishingEventFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\FishingEvent>
|
||||
*/
|
||||
class FishingEventFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建钓鱼事件表
|
||||
*
|
||||
* 将钓鱼随机事件从硬编码迁移到数据库,支持后台增删改。
|
||||
* weight 字段为权重(不是百分比),由所有激活事件的权重之和决定概率。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 fishing_events 表
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('fishing_events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('emoji', 10)->comment('事件表情符号');
|
||||
$table->string('name', 100)->comment('事件名称(后台展示用)');
|
||||
$table->string('message', 255)->comment('聊天室播报内容');
|
||||
$table->integer('exp')->default(0)->comment('经验变化(正为获得,负为扣除)');
|
||||
$table->integer('jjb')->default(0)->comment('金币变化(正为获得,负为扣除)');
|
||||
$table->unsignedSmallInteger('weight')->default(10)->comment('权重(权重越大概率越高)');
|
||||
$table->boolean('is_active')->default(true)->comment('是否启用');
|
||||
$table->unsignedTinyInteger('sort')->default(0)->comment('排序(越小越靠前)');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除 fishing_events 表
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('fishing_events');
|
||||
}
|
||||
};
|
||||
123
database/seeders/FishingEventSeeder.php
Normal file
123
database/seeders/FishingEventSeeder.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:钓鱼事件初始数据填充
|
||||
*
|
||||
* 将原硬编码的 7 个钓鱼事件迁移至数据库,
|
||||
* 调整奖励:经验减少,金币提升,游戏更加休闲娱乐。
|
||||
*
|
||||
* 执行方式:php artisan db:seed --class=FishingEventSeeder
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\FishingEvent;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class FishingEventSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* 填充钓鱼事件数据
|
||||
*
|
||||
* weight 权重说明(总权重 100):
|
||||
* 15 → 大鲨鱼(幸运)
|
||||
* 15 → 娃娃鱼(卖鱼)
|
||||
* 20 → 大草鱼(经验)
|
||||
* 20 → 小鲤鱼(双收)
|
||||
* 15 → 掉河(惩罚)
|
||||
* 10 → 被打(惩罚)
|
||||
* 5 → 超级大奖
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// 避免重复 Seed
|
||||
if (FishingEvent::count() > 0) {
|
||||
$this->command->info('钓鱼事件已存在,跳过填充。');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$events = [
|
||||
[
|
||||
'sort' => 1,
|
||||
'emoji' => '🦈',
|
||||
'name' => '大鲨鱼',
|
||||
'message' => '钓到一条大鲨鱼!获得经验30、金币50',
|
||||
'exp' => 30,
|
||||
'jjb' => 50,
|
||||
'weight' => 15,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 2,
|
||||
'emoji' => '🐟',
|
||||
'name' => '娃娃鱼',
|
||||
'message' => '钓到一条娃娃鱼,到集市卖得80个金币',
|
||||
'exp' => 0,
|
||||
'jjb' => 80,
|
||||
'weight' => 15,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 3,
|
||||
'emoji' => '🐠',
|
||||
'name' => '大草鱼',
|
||||
'message' => '钓到一只大草鱼,吃下增加经验20、金币30',
|
||||
'exp' => 20,
|
||||
'jjb' => 30,
|
||||
'weight' => 20,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 4,
|
||||
'emoji' => '🐡',
|
||||
'name' => '小鲤鱼',
|
||||
'message' => '钓到一条小鲤鱼,增加经验10、金币20',
|
||||
'exp' => 10,
|
||||
'jjb' => 20,
|
||||
'weight' => 20,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 5,
|
||||
'emoji' => '💧',
|
||||
'name' => '落水惨败',
|
||||
'message' => '鱼没钓到,摔到河里损失金币30',
|
||||
'exp' => 0,
|
||||
'jjb' => -30,
|
||||
'weight' => 15,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 6,
|
||||
'emoji' => '👊',
|
||||
'name' => '被抓殴打',
|
||||
'message' => '偷钓鱼塘被主人发现,一阵殴打!金币减少10',
|
||||
'exp' => 0,
|
||||
'jjb' => -10,
|
||||
'weight' => 10,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'sort' => 7,
|
||||
'emoji' => '🎉',
|
||||
'name' => '超级大奖',
|
||||
'message' => '运气爆棚!钓到大鲨鱼、大草鱼、小鲤鱼各一条!经验+50,金币+200!',
|
||||
'exp' => 50,
|
||||
'jjb' => 200,
|
||||
'weight' => 5,
|
||||
'is_active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
FishingEvent::create($event);
|
||||
}
|
||||
|
||||
$this->command->info('✅ 钓鱼事件已填充(7 条)');
|
||||
}
|
||||
}
|
||||
@@ -116,6 +116,21 @@ class GameConfigSeeder extends Seeder
|
||||
'curse_chance' => 5, // 大凶签概率(%)
|
||||
],
|
||||
],
|
||||
|
||||
// ─── 钓鱼小游戏 ──────────────────────────────────────────────
|
||||
[
|
||||
'game_key' => 'fishing',
|
||||
'name' => '钓鱼小游戏',
|
||||
'icon' => '🎣',
|
||||
'description' => '消耗金币抛竿,等待浮漂下沉后点击收竿,随机获得奖励或惩罚。持有自动钓鱼卡可自动循环。',
|
||||
'enabled' => false,
|
||||
'params' => [
|
||||
'fishing_cost' => 5, // 每次抛竿消耗金币
|
||||
'fishing_wait_min' => 8, // 浮漂等待最短秒数
|
||||
'fishing_wait_max' => 15, // 浮漂等待最长秒数
|
||||
'fishing_cooldown' => 300, // 收竿后冷却秒数
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($games as $game) {
|
||||
|
||||
Reference in New Issue
Block a user