From 0a764a3a8654c096e0d4676ac3bf5293404b39f3 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 11 Apr 2026 17:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=9A=E5=91=98=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 34 +++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 35b3a3f..9b08147 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -496,12 +496,22 @@ class ChatController extends Controller if ($eventChance > 0 && rand(1, 100) <= $eventChance) { $autoEvent = Autoact::randomEvent(); if ($autoEvent) { + // 计算会员倍率加成(仅正向奖励有效) + $expMul = $this->vipService->getExpMultiplier($user); + $jjbMul = $this->vipService->getJjbMultiplier($user); + + $finalExp = $autoEvent->exp_change > 0 ? (int) round($autoEvent->exp_change * $expMul) : $autoEvent->exp_change; + $finalJjb = $autoEvent->jjb_change > 0 ? (int) round($autoEvent->jjb_change * $jjbMul) : $autoEvent->jjb_change; + + $bonusExp = ($autoEvent->exp_change > 0 && $finalExp > $autoEvent->exp_change) ? $finalExp - $autoEvent->exp_change : 0; + $bonusJjb = ($autoEvent->jjb_change > 0 && $finalJjb > $autoEvent->jjb_change) ? $finalJjb - $autoEvent->jjb_change : 0; + // 经验变化:通过 UserCurrencyService 写日志 - if ($autoEvent->exp_change !== 0) { + if ($finalExp !== 0) { $this->currencyService->change( $user, 'exp', - $autoEvent->exp_change, + $finalExp, CurrencySource::AUTO_EVENT, "随机事件:{$autoEvent->text_body}", $id, @@ -509,11 +519,11 @@ class ChatController extends Controller } // 金币变化:通过 UserCurrencyService 写日志 - if ($autoEvent->jjb_change !== 0) { + if ($finalJjb !== 0) { $this->currencyService->change( $user, 'gold', - $autoEvent->jjb_change, + $finalJjb, CurrencySource::AUTO_EVENT, "随机事件:{$autoEvent->text_body}", $id, @@ -529,13 +539,27 @@ class ChatController extends Controller $user->save(); } + // 构建会员额外加成文案(参考钓鱼系统,确保不弄错) + $bonusParts = []; + if ($bonusExp > 0) { + $bonusParts[] = "+经验{$bonusExp}"; + } + if ($bonusJjb > 0) { + $bonusParts[] = "+金币{$bonusJjb}"; + } + + $eventContent = $autoEvent->renderText($user->username); + if (! empty($bonusParts)) { + $eventContent .= '('.$user->vipName().'追加:'.implode(',', $bonusParts).')'; + } + // 广播随机事件消息到聊天室 $eventMsg = [ 'id' => $this->chatState->nextMessageId($id), 'room_id' => $id, 'from_user' => '星海小博士', 'to_user' => '大家', - 'content' => $autoEvent->renderText($user->username), + 'content' => $eventContent, 'is_secret' => false, 'font_color' => match ($autoEvent->event_type) { 'good' => '#16a34a', // 绿色(好运)