148 lines
4.9 KiB
PHP
148 lines
4.9 KiB
PHP
<?php
|
||
|
||
namespace services;
|
||
|
||
require_once('mt/Parameter.php');
|
||
|
||
/*
|
||
1、周期还害没结束,箱子就掉完了
|
||
完成度=T max/T cost time(last time-start time)
|
||
|
||
2、周期结束,箱子也还没掉完
|
||
完成度=N real num/N max
|
||
|
||
下一天的投放数量(下一天max)
|
||
下一天max=min(today max*today 完成度,qlobal max)
|
||
*/
|
||
class BattleBoxService {
|
||
|
||
const DAILY_PHASE_DROP_LAST_TIME_KEY = ':';
|
||
const DAILY_PHASE_DROP_TOTAL_KEY = ':';
|
||
const DAILY_PHASE_ALLOC_NUM_KEY = ':';
|
||
const DAILY_PHASE_ALREADY_ALLOC_NUM_KEY = ':';
|
||
|
||
public static function allocBox($roomUuid)
|
||
{
|
||
if (!myself()->_switchIsOpen('bigEventBoxDrop')) {
|
||
return 0;
|
||
}
|
||
$boxNum = 0;
|
||
$currPhase = self::getCurrentPhase();
|
||
$startTime = 0;
|
||
$endTime = 0;
|
||
$maxNum = 0;
|
||
|
||
$allocableNum = self::getDailyPhaseAllocNum($currPhase, myself()->_getNowDaySeconds());
|
||
$alreadyAllocNum = self::getDailyPhaseAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds());
|
||
if ($allocableNum <= 0) {
|
||
$yesterDayTime = myself()->_getNowDaySeconds() - 3600 * 24;
|
||
$yesterDayLastDropTime = self::getDailyPhaseDropLastTime($currPhase, $yesterDayTime);
|
||
$yesterDayDropTotal = self::getDailyPhaseDropTotalNum($currPhase, $yesterDayTime);
|
||
$yesterDayAllocNum = self::getDailyPhaseAllocNum($currPhase, $yesterDayTime);
|
||
if ($yesterDayAllocNum <= 0) {
|
||
$allocableNum = $maxNum;
|
||
} else {
|
||
|
||
}
|
||
if ($allocableNum) {
|
||
self::setDailyPhaseAllocNum($currPhase, $allocableNum);
|
||
}
|
||
}
|
||
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) {
|
||
SqlHelper::insert(
|
||
$this->_getSelfMysql(),
|
||
't_box_alloc',
|
||
array(
|
||
'room_uuid' => $roomUuid,
|
||
'account_id' => myself()->_getAccountId(),
|
||
'box_num' => $boxNum,
|
||
'createtime' => myself()->_getNowTime(),
|
||
'modifytime' => myself()->_getNowTime(),
|
||
)
|
||
);
|
||
self::incAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds(), $boxNum);
|
||
}
|
||
return $boxNum;
|
||
}
|
||
|
||
public static function getCurrentPhase()
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
private static function getDailyPhaseDropLastTime($phase, $time)
|
||
{
|
||
$key = self::DAILY_PHASE_DROP_LAST_TIME_KEY . $phase . ':' . $time;
|
||
$r = $this->_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 = $this->_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 = $this->_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 . ':' . $time;
|
||
$r = $this->_getRedis($key);
|
||
$r->setPx($key, $val, 1000 * 3600 * 24 * 7);
|
||
}
|
||
|
||
private static function setDailyPhaseDropTotalNum($phase, $time)
|
||
{
|
||
$key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . $time;
|
||
$r = $this->_getRedis($key);
|
||
$r->setPx($key, $val, 1000 * 3600 * 24 * 7);
|
||
}
|
||
|
||
private static function setDailyPhaseAllocNum($phase, $time)
|
||
{
|
||
$key = self::DAILY_PHASE_ALLOC_NUM_KEY . $phase . ':' . $time;
|
||
$r = $this->_getRedis($key);
|
||
$r->setPx($key, $val, 1000 * 3600 * 24 * 7);
|
||
}
|
||
|
||
private static function getDailyPhaseAlreadyAllocNum($phase, $time)
|
||
{
|
||
$key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time;
|
||
$r = $this->_getRedis($key);
|
||
$num = $r->get($key);
|
||
return empty($num) ? 0 : $num;
|
||
}
|
||
|
||
private static function incAlreadyAllocNum($phase, $time, $val)
|
||
{
|
||
$key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time;
|
||
$r = $this->_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);
|
||
}
|
||
}
|
||
|
||
}
|