_switchIsOpen('bigEventBoxDrop')) { return 0; } $boxNum = 0; $mapModeMeta = null; $currPhase = 0; $startTime = 0; $endTime = 0; $minNum = 0; $maxNum = 0; $maxNumLimit = 5000; $completionDegree = 0; mt\MapMode::getCurrentBoxDropInfo($mapModeMeta, $currPhase, $startTime, $endTime); $maxLst0 = mt\Parameter::getListValue('battle_event_loot_daily_period_max_0'); $maxLst1 = mt\Parameter::getListValue('battle_event_loot_daily_period_max_1'); if (count($maxLst0) != 2 || count($maxLst1) != 2) { return 0; } if ($currPhase < 1 || $currPhase > 2) { return 0; } $minNum = $maxLst0[$currPhase - 1]; $maxNum = $maxLst1[$currPhase - 1]; error_log(json_encode(array( 'mapNodeMeta' => $mapModeMeta, 'currPhase' => $currPhase, 'startTime' => $startTime, 'endTime' => $endTime, 'maxLst0' => $maxLst0, 'maxLst1' => $maxLst1, ))); $allocableNum = self::getDailyPhaseAllocNum($currPhase, myself()->_getNowDaySeconds()); $alreadyAllocNum = self::getDailyPhaseAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds()); if ($allocableNum <= 0) { $yesterDayTime = myself()->_getNowDaySeconds() - 3600 * 24; $yesterDayDropLastTime = self::getDailyPhaseDropLastTime($currPhase, $yesterDayTime); $yesterDayDropTotal = self::getDailyPhaseDropTotalNum($currPhase, $yesterDayTime); $yesterDayAllocNum = self::getDailyPhaseAllocNum($currPhase, $yesterDayTime); error_log(json_encode(array( 'yesterDayDropLastTime' => $yesterDayDropLastTime, 'yesterDayDropTotal' => $yesterDayDropTotal, 'yesterDayAllocNum' => $yesterDayAllocNum, 'maxNum' => $maxNum, ))); if ($yesterDayAllocNum <= 0) { $allocableNum = $maxNum; } else { if ($yesterDayDropTotal >= $yesterDayAllocNum) { //掉完了 $costTime = myself()->_getDaySecondsOffset($yesterDayDropLastTime) - $startTime; if ($costTime <= 0) { $completionDegree = 1; } else { $completionDegree = ($endTime - $startTime) / $costTime; } error_log(json_encode(array( 'yesterDayDropLastTime' => $yesterDayDropLastTime, 'yesterDayDropLastTime2' => myself()->_getDaySecondsOffset($yesterDayDropLastTime), 'startTime' => $startTime, 'costTime' => $costTime, 'completionDegree' => $completionDegree, ))); } else { //没掉完 $completionDegree = $yesterDayDropTotal / $yesterDayAllocNum; } $allocableNum = min($maxNumLimit, $yesterDayAllocNum * $completionDegree); if ($allocableNum <= 0) { $allocableNum = $yesterDayAllocNum; } } if ($allocableNum > 0) { self::setDailyPhaseAllocNum($currPhase, myself()->_getNowDaySeconds(), $allocableNum); } } else { error_log(json_encode(array( 'allocableNum' => $allocableNum, 'alreadyAllocNum' => $alreadyAllocNum, ))); $allocableNum = max(0, $allocableNum - $alreadyAllocNum); } if ($allocableNum > 0) { $lstVal = mt\Parameter::getListValue('battle_event_loot_per_game'); if (!($allocableNum <= 0 || empty($lstVal) || count($lstVal) < 2)) { $rnd = rand($lstVal[0], $lstVal[1]); if ($rnd > 0) { $boxNum = min($rnd, $allocableNum); } } } if ($boxNum > 0) { if (getReqVal('c', '') != 'Tools') { SqlHelper::insert( myself()->_getSelfMysql(), 't_box_alloc', array( 'room_uuid' => $roomUuid, 'account_id' => myself()->_getAccountId(), 'phase' => $currPhase, 'box_num' => $boxNum, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); } self::incAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds(), $boxNum); } return $boxNum; } public static function dump($phase, $day) { $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; $data = array( 'phase' => $phase, 'drop_last_time' => self::getDailyPhaseDropLastTime($phase, $daySeconds), 'drop_total' => self::getDailyPhaseDropTotalNum($phase, $daySeconds), 'alloc_num' => self::getDailyPhaseAllocNum($phase, $daySeconds), 'already_alloced_num' => self::getDailyPhaseAlreadyAllocNum($phase, $daySeconds), ); myself()->_rspData($data); } public static function internalClear($phase, $day) { $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; self::getDailyPhaseDropLastTime($phase, $daySeconds, 0); self::setDailyPhaseDropTotalNum($phase, $daySeconds, 0); self::setDailyPhaseAllocNum($phase, $daySeconds, 0); self::setDailyPhaseAlreadyAllocNum($phase, $daySeconds, 0); } public static function clear($phase, $day) { self::internalClear($phase, $day); self::dump($phase, $day); } public static function set($phase, $day) { $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; self::setDailyPhaseDropLastTime($phase, $daySeconds, getReqVal('drop_last_time', 0)); self::setDailyPhaseDropTotalNum($phase, $daySeconds, getReqVal('drop_total', 0)); self::setDailyPhaseAllocNum($phase, $daySeconds, getReqVal('alloc_num', 0)); self::setDailyPhaseAlreadyAllocNum($phase, $daySeconds, getReqVal('already_alloced_num', 0)); self::dump($phase, $day); } private static function getDailyPhaseDropLastTime($phase, $time) { $key = self::DAILY_PHASE_DROP_LAST_TIME_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $lastTime = $r->get($key); return empty($lastTime) ? 0 : $lastTime; } private static function getDailyPhaseDropTotalNum($phase, $time) { $key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $num = $r->get($key); return empty($num) ? 0 : $num; } private static function getDailyPhaseAllocNum($phase, $time) { $key = self::DAILY_PHASE_ALLOC_NUM_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $num = $r->get($key); return empty($num) ? 0 : $num; } private static function setDailyPhaseDropLastTime($phase, $time, $val) { $key = self::DAILY_PHASE_DROP_LAST_TIME_KEY . $phase . ':' . myself()->_getDaySeconds($time); $r = myself()->_getRedis($key); $r->setPx($key, $val, 1000 * 3600 * 24 * 7); } private static function setDailyPhaseDropTotalNum($phase, $time, $val) { $key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $r->setPx($key, $val, 1000 * 3600 * 24 * 7); } private static function setDailyPhaseAllocNum($phase, $time, $val) { $key = self::DAILY_PHASE_ALLOC_NUM_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $r->setPx($key, $val, 1000 * 3600 * 24 * 7); } private static function setDailyPhaseAlreadyAllocNum($phase, $time, $val) { $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $r->set($key, $val); } private static function getDailyPhaseAlreadyAllocNum($phase, $time) { $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $num = $r->get($key); return empty($num) ? 0 : $num; } public static function incAlreadyAllocNum($phase, $time, $val) { $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; $r = myself()->_getRedis($key); $num = intval($r->get($key)); if (empty($num)) { $r->setPx($key, $val, 1000 * 3600 * 24 * 7); } else { $r->setPx($key, $num + $val, 1000 * 3600 * 24 * 7); } } public static function incDropTotalNum($phase, $time, $val) { $key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . myself()->_getDaySeconds($time); $r = myself()->_getRedis($key); $num = intval($r->get($key)); if (empty($num)) { $r->setPx($key, $val, 1000 * 3600 * 24 * 7); } else { $r->setPx($key, $num + $val, 1000 * 3600 * 24 * 7); } self::setDailyPhaseDropLastTime($phase, $time, $time); } }