修复星海小博士随机事件金币/经验不记日志:改走UserCurrencyService.change(),新增CurrencySource::AUTO_EVENT枚举
This commit is contained in:
@@ -469,14 +469,32 @@ class ChatController extends Controller
|
||||
if ($eventChance > 0 && rand(1, 100) <= $eventChance) {
|
||||
$autoEvent = Autoact::randomEvent();
|
||||
if ($autoEvent) {
|
||||
// 应用经验/金币变化(不低于 0)
|
||||
// 经验变化:通过 UserCurrencyService 写日志
|
||||
if ($autoEvent->exp_change !== 0) {
|
||||
$user->exp_num = max(0, $user->exp_num + $autoEvent->exp_change);
|
||||
$this->currencyService->change(
|
||||
$user,
|
||||
'exp',
|
||||
$autoEvent->exp_change,
|
||||
CurrencySource::AUTO_EVENT,
|
||||
"随机事件:{$autoEvent->text_body}",
|
||||
$id,
|
||||
);
|
||||
}
|
||||
|
||||
// 金币变化:通过 UserCurrencyService 写日志
|
||||
if ($autoEvent->jjb_change !== 0) {
|
||||
$user->jjb = max(0, ($user->jjb ?? 0) + $autoEvent->jjb_change);
|
||||
$this->currencyService->change(
|
||||
$user,
|
||||
'gold',
|
||||
$autoEvent->jjb_change,
|
||||
CurrencySource::AUTO_EVENT,
|
||||
"随机事件:{$autoEvent->text_body}",
|
||||
$id,
|
||||
);
|
||||
}
|
||||
$user->save();
|
||||
|
||||
// 重新从数据库读取最新属性(service 已原子更新,需刷新本地对象)
|
||||
$user->refresh();
|
||||
|
||||
// 重新计算等级(经验可能因事件而变化,但管理员不参与自动升降级)
|
||||
if ($user->user_level < $superLevel) {
|
||||
@@ -497,8 +515,8 @@ class ChatController extends Controller
|
||||
'is_secret' => false,
|
||||
'font_color' => match ($autoEvent->event_type) {
|
||||
'good' => '#16a34a', // 绿色(好运)
|
||||
'bad' => '#dc2626', // 红色(坏运)
|
||||
default => '#7c3aed', // 紫色(中性)
|
||||
'bad' => '#dc2626', // 红色(坏运)
|
||||
default => '#7c3aed', // 紫色(中性)
|
||||
},
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
|
||||
Reference in New Issue
Block a user