| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Enums\DISASTER_TYPE;
- class DisasterService
- {
- /**
- * 获取所有灾害 减产比例
- *
- * @return float[]
- */
- public static function getAllDisasters()
- {
- $disasterTypes = [
- DISASTER_TYPE::DROUGHT->valueInt() => 0.05, // 干旱
- DISASTER_TYPE::PEST->valueInt() => 0.05, // 虫害
- DISASTER_TYPE::WEED->valueInt() => 0.05, // 杂草
- ];
- return $disasterTypes;
- }
- /**
- * 获取灾害 产生比例
- *
- * @return float[]
- */
- public static function getRate()
- {
- $disasterTypes = [
- DISASTER_TYPE::DROUGHT->valueInt() => 0.9, // 干旱
- DISASTER_TYPE::PEST->valueInt() => 0.9, // 虫害
- DISASTER_TYPE::WEED->valueInt() => 0.9, // 杂草
- ];
- return $disasterTypes;
- }
- /**
- * 获取灾害类型对应的键名
- *
- * @param int $disasterType
- * @return string
- */
- public static function getDisasterKey(int $disasterType): string
- {
- $keys = [
- DISASTER_TYPE::DROUGHT->valueInt() => 'drought',
- DISASTER_TYPE::PEST->valueInt() => 'pest',
- DISASTER_TYPE::WEED->valueInt() => 'weed',
- ];
- return $keys[$disasterType] ?? '';
- }
- /**
- * 灾害检查间隔时间(分钟)
- *
- * @return int
- */
- public static function getCheckInterval(): int
- {
- return 5; // 每5分钟检查一次
- }
- }
|