|
|
@@ -89,6 +89,194 @@ trait GridHelperTrait
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加产出详情列
|
|
|
+ *
|
|
|
+ * 展示该土地类型的作物种类概率和产量
|
|
|
+ *
|
|
|
+ * @param string $field 字段名
|
|
|
+ * @param string $label 标签名
|
|
|
+ * @return Column
|
|
|
+ */
|
|
|
+ public function columnOutputDetails(string $field = 'output_details', string $label = '产出详情'): Column
|
|
|
+ {
|
|
|
+ return $this->grid->column($field, $label)->display(function () {
|
|
|
+ // 获取当前土地类型
|
|
|
+ $landType = $this;
|
|
|
+
|
|
|
+ $html = '<div class="output-details">';
|
|
|
+ $html .= '<div class="mb-2"><strong>' . htmlspecialchars($landType->name) . ' (产量加成:' . ($landType->output_bonus * 100) . '%)</strong></div>';
|
|
|
+
|
|
|
+ // 1. 显示神秘种子的产出概率和产量
|
|
|
+ $html .= self::renderMysterySeeLOutputs($landType);
|
|
|
+
|
|
|
+ // 2. 显示普通种子的产出
|
|
|
+ $html .= self::renderNormalSeeLOutputs($landType);
|
|
|
+
|
|
|
+ $html .= '</div>';
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ })->width(500);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渲染神秘种子的产出详情
|
|
|
+ *
|
|
|
+ * @param \App\Module\Farm\Models\FarmLandType $landType
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private static function renderMysterySeeLOutputs($landType): string
|
|
|
+ {
|
|
|
+ // 获取神秘种子
|
|
|
+ $mysterySeeds = \App\Module\Farm\Models\FarmSeed::where('type', \App\Module\Farm\Enums\SEED_TYPE::MYSTERIOUS->value)->get();
|
|
|
+
|
|
|
+ if ($mysterySeeds->isEmpty()) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html = '<div class="mb-3">';
|
|
|
+ $html .= '<h6 class="text-info">神秘种子产出概率</h6>';
|
|
|
+
|
|
|
+ foreach ($mysterySeeds as $seed) {
|
|
|
+ try {
|
|
|
+ // 使用神秘种子逻辑计算概率
|
|
|
+ $mysteryLogic = new \App\Module\Farm\Logics\MysterySeeLLogic();
|
|
|
+ $adjustedOutputs = $mysteryLogic->calculateAdjustedProbabilities($seed->id, $landType->id);
|
|
|
+
|
|
|
+ $html .= '<div class="mb-2">';
|
|
|
+ $html .= '<strong>' . htmlspecialchars($seed->name) . ':</strong>';
|
|
|
+ $html .= '<div class="table-responsive">';
|
|
|
+ $html .= '<table class="table table-sm table-bordered">';
|
|
|
+ $html .= '<thead><tr><th>产出物品</th><th>概率</th><th>正常产量</th><th>灾害产量</th><th>应用土地加成后(正常)</th><th>应用土地加成后(灾害)</th></tr></thead>';
|
|
|
+ $html .= '<tbody>';
|
|
|
+
|
|
|
+ foreach ($adjustedOutputs as $output) {
|
|
|
+ // 跳过概率为0的产出
|
|
|
+ if ($output['adjusted_probability'] <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $itemName = self::getItemName($output['item_id']);
|
|
|
+ $probability = number_format($output['adjusted_probability'], 2) . '%';
|
|
|
+
|
|
|
+ // 正常产量范围
|
|
|
+ $normalMin = $output['min_amount'];
|
|
|
+ $normalMax = $output['max_amount'];
|
|
|
+
|
|
|
+ // 灾害产量范围
|
|
|
+ $disasterMin = $output['disaster_min_amount'] ?? $output['min_amount'];
|
|
|
+ $disasterMax = $output['disaster_max_amount'] ?? $output['max_amount'];
|
|
|
+
|
|
|
+ // 应用土地加成后的产量
|
|
|
+ $normalBonusMin = (int)($normalMin * (1 + $landType->output_bonus));
|
|
|
+ $normalBonusMax = (int)($normalMax * (1 + $landType->output_bonus));
|
|
|
+ $disasterBonusMin = (int)($disasterMin * (1 + $landType->output_bonus));
|
|
|
+ $disasterBonusMax = (int)($disasterMax * (1 + $landType->output_bonus));
|
|
|
+
|
|
|
+ $html .= '<tr>';
|
|
|
+ $html .= '<td>' . htmlspecialchars($itemName) . '</td>';
|
|
|
+ $html .= '<td><span class="badge badge-info">' . $probability . '</span></td>';
|
|
|
+ $html .= '<td>' . $normalMin . '-' . $normalMax . '</td>';
|
|
|
+ $html .= '<td class="text-warning">' . $disasterMin . '-' . $disasterMax . '</td>';
|
|
|
+ $html .= '<td class="text-success"><strong>' . $normalBonusMin . '-' . $normalBonusMax . '</strong></td>';
|
|
|
+ $html .= '<td class="text-danger"><strong>' . $disasterBonusMin . '-' . $disasterBonusMax . '</strong></td>';
|
|
|
+ $html .= '</tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '</tbody></table>';
|
|
|
+ $html .= '</div>';
|
|
|
+ $html .= '</div>';
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $html .= '<div class="text-danger">计算神秘种子概率失败:' . htmlspecialchars($e->getMessage()) . '</div>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '</div>';
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渲染普通种子的产出详情
|
|
|
+ *
|
|
|
+ * @param \App\Module\Farm\Models\FarmLandType $landType
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private static function renderNormalSeeLOutputs($landType): string
|
|
|
+ {
|
|
|
+ // 获取普通种子的产出配置
|
|
|
+ $normalOutputs = \App\Module\Farm\Models\FarmSeedOutput::with(['seed', 'item'])
|
|
|
+ ->whereHas('seed', function($query) {
|
|
|
+ $query->where('type', '!=', \App\Module\Farm\Enums\SEED_TYPE::MYSTERIOUS->value);
|
|
|
+ })
|
|
|
+ ->where('is_default', true)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if ($normalOutputs->isEmpty()) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html = '<div class="mb-3">';
|
|
|
+ $html .= '<h6 class="text-success">普通种子产出</h6>';
|
|
|
+ $html .= '<div class="table-responsive">';
|
|
|
+ $html .= '<table class="table table-sm table-bordered">';
|
|
|
+ $html .= '<thead><tr><th>种子</th><th>产出物品</th><th>正常产量</th><th>灾害产量</th><th>应用土地加成后(正常)</th><th>应用土地加成后(灾害)</th></tr></thead>';
|
|
|
+ $html .= '<tbody>';
|
|
|
+
|
|
|
+ foreach ($normalOutputs as $output) {
|
|
|
+ $seedName = $output->seed->name ?? "种子{$output->seed_id}";
|
|
|
+ $itemName = $output->item->name ?? "物品{$output->item_id}";
|
|
|
+
|
|
|
+ // 正常产量范围
|
|
|
+ $normalMin = $output->min_amount;
|
|
|
+ $normalMax = $output->max_amount;
|
|
|
+
|
|
|
+ // 灾害产量范围
|
|
|
+ $disasterMin = $output->disaster_min_amount ?? $output->min_amount;
|
|
|
+ $disasterMax = $output->disaster_max_amount ?? $output->max_amount;
|
|
|
+
|
|
|
+ // 应用土地加成后的产量
|
|
|
+ $normalBonusMin = (int)($normalMin * (1 + $landType->output_bonus));
|
|
|
+ $normalBonusMax = (int)($normalMax * (1 + $landType->output_bonus));
|
|
|
+ $disasterBonusMin = (int)($disasterMin * (1 + $landType->output_bonus));
|
|
|
+ $disasterBonusMax = (int)($disasterMax * (1 + $landType->output_bonus));
|
|
|
+
|
|
|
+ $html .= '<tr>';
|
|
|
+ $html .= '<td>' . htmlspecialchars($seedName) . '</td>';
|
|
|
+ $html .= '<td>' . htmlspecialchars($itemName) . '</td>';
|
|
|
+ $html .= '<td>' . $normalMin . '-' . $normalMax . '</td>';
|
|
|
+ $html .= '<td class="text-warning">' . $disasterMin . '-' . $disasterMax . '</td>';
|
|
|
+ $html .= '<td class="text-success"><strong>' . $normalBonusMin . '-' . $normalBonusMax . '</strong></td>';
|
|
|
+ $html .= '<td class="text-danger"><strong>' . $disasterBonusMin . '-' . $disasterBonusMax . '</strong></td>';
|
|
|
+ $html .= '</tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '</tbody></table>';
|
|
|
+ $html .= '</div>';
|
|
|
+ $html .= '</div>';
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取物品名称
|
|
|
+ *
|
|
|
+ * @param int $itemId
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private static function getItemName(int $itemId): string
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $item = \App\Module\GameItems\Models\Item::find($itemId);
|
|
|
+ return $item ? $item->name : "物品{$itemId}";
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return "物品{$itemId}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加种子类型列
|
|
|
*
|