$expGained, 'min_exp' => $minExp ]); return false; } // 检查宠物ID过滤(0表示任意宠物) if ($petId > 0 && $eventPetId != $petId) { Log::info('宠物ID不匹配', [ 'event_pet_id' => $eventPetId, 'condition_pet_id' => $petId ]); return false; } // 检查来源类型过滤(空表示任意来源) if (!empty($sourceType) && $eventSourceType != $sourceType) { Log::info('经验来源类型不匹配', [ 'event_source_type' => $eventSourceType, 'condition_source_type' => $sourceType ]); return false; } return true; } catch (\Exception $e) { Log::error('宠物经验累计条件匹配检查失败', [ 'event_params' => $eventParams, 'condition_params' => $conditionParams, 'error' => $e->getMessage() ]); return false; } } /** * 计算事件对条件进度的贡献值 * * @param array $eventParams 事件参数 * @param array $conditionParams 条件参数 * @return int 进度增量 */ public function calculateProgress(array $eventParams, array $conditionParams): int { try { // 先检查是否匹配 if (!$this->isMatch($eventParams, $conditionParams)) { return 0; } // 返回实际获得的经验值作为进度增量 return $eventParams['exp_gained'] ?? 0; } catch (\Exception $e) { Log::error('宠物经验累计进度计算失败', [ 'event_params' => $eventParams, 'condition_params' => $conditionParams, 'error' => $e->getMessage() ]); return 0; } } /** * 检查条件是否已完成 * * @param int $currentValue 当前值 * @param int $targetValue 目标值 * @param string $operator 运算符 * @return bool 是否已完成 */ public function isCompleted(int $currentValue, int $targetValue, string $operator = '>='): bool { switch ($operator) { case '=': return $currentValue == $targetValue; case '>=': return $currentValue >= $targetValue; case '>': return $currentValue > $targetValue; case '<=': return $currentValue <= $targetValue; case '<': return $currentValue < $targetValue; default: return false; } } }