서버의 분턴 변경시 '정확히' 현재 턴에 비례해서 변경되도록 변경

This commit is contained in:
2018-09-16 04:38:06 +09:00
parent ae4a349d79
commit 029a6f03b7
2 changed files with 25 additions and 37 deletions
+17 -34
View File
@@ -43,10 +43,6 @@ switch ($btn) {
$gameStor->msg = $msg;
break;
case "로그쓰기":
$lognum = $admin['historyindex'] + 1;
if ($lognum >= 29) {
$lognum = 0;
}
pushWorldHistory(["<R>★</><S>{$log}</>"]);
break;
case "변경1":
@@ -69,6 +65,7 @@ switch ($btn) {
case "30분턴":
case "60분턴":
case "120분턴":
$admin = $gameStor->getDBValues(['turntime', 'turnterm', 'year', 'startyear', 'month']);
switch ($btn) {
case "1분턴": $turnterm = 1; break;
case "2분턴": $turnterm = 2; break;
@@ -79,41 +76,27 @@ switch ($btn) {
case "60분턴": $turnterm = 60; break;
case "120분턴": $turnterm = 120; break;
}
$oldunit = $admin['turnterm'] * 60;
$unit = $turnterm * 60;
$unitDiff = $unit / $oldunit;
$servTurnTime = new \DateTimeImmutable($admin['turntime']);
foreach ($db->query('SELECT no,turntime FROM general') as $gen) {
$genTurnTime = new \DateTimeImmutable($gen['turntime']);
$timeDiff = TimeUtil::DateIntervalToSeconds($genTurnTime->diff($servTurnTime));
$timeDiff *= $unitDiff;
$newGenTurnTime = $servTurnTime->add(TimeUtil::secondsToDateInterval($timeDiff));
$db->update('general', [
'turntime'=>$newGenTurnTime->format('Y-m-d H:i:s.u')
], 'no=%i', $gen['no']);
}
$turn = ($admin['year'] - $admin['startyear']) * 12 + $admin['month'] - 1;
$starttime = date("Y-m-d H:i:s", strtotime($admin['turntime']) - $turn * $unit);
$starttime = $servTurnTime->sub(TimeUtil::secondsToDateInterval($turn * $unit))->format('Y-m-d H:i:s');
$starttime = cutTurn($starttime, $turnterm);
$gameStor->turnterm = $turnterm;
$gameStor->starttime = $starttime;
// 턴시간이 길어지는 경우 랜덤턴 배정
if ($turnterm < $admin['turnterm']) {
$query = "select no from general";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
$count = MYDB_num_rows($result);
for ($i=0; $i < $count; $i++) {
$gen = MYDB_fetch_array($result);
$turntime = getRandTurn($turnterm);
$db->update('general', [
'turntime'=>$turntime
], 'no=%i', $gen['no']);
}
// 턴시간이 너무 멀리 떨어진 선수 제대로 보정
} else {
$servTurnTime = new \DateTime($admin['turntime']);
$timeUnit = new \DateInterval("T{$unit}S");
foreach($db->query('SELECT no,turntime FROM general') as $gen){
$genTurnTime = new \DateTime($gen['turntime']);
$timeDiff = $genTurnTime->diff($servTurnTime);
$num = intdiv((strtotime($gen['turntime']) - strtotime($admin['turntime'])), $unit);
if ($num > 0) {
$gen['turntime'] = date("Y-m-d H:i:s", strtotime($gen['turntime']) - $unit * $num);
$query = "update general set turntime='{$gen['turntime']}' where no='{$gen['no']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
}
}
}
pushWorldHistory(["<R>★</>턴시간이 <C>$btn</>으로 변경됩니다."]);
break;
}
+8 -3
View File
@@ -58,7 +58,7 @@ class TimeUtil
return $obj->format('Y-m-d H:i:s.u');
}
public static function secondsToDateTime(float $fullSeconds): \DateTime{
public static function secondsToDateTime(float $fullSeconds, bool $isDateTimeImmutable=false): \DateTime{
$seconds = floor($fullSeconds);
$fraction = $fullSeconds - $seconds;
@@ -66,6 +66,11 @@ class TimeUtil
$interval->s = $seconds;
$interval->f = $fraction;
if($isDateTimeImmutable){
$dateTime = new \DateTimeImmutable("@0");
return $dateTime->add($interval);
}
$dateTime = new \DateTime("@0");
$dateTime->add($interval);
return $dateTime;
@@ -77,8 +82,8 @@ class TimeUtil
return static::secondsToDateTime($fullSeconds)->diff($d0);
}
public static function DateTimeToSeconds(\DateTime $dateTime): float{
$dateBase = new \DateTime("@0");
public static function DateTimeToSeconds(\DateTimeInterface $dateTime): float{
$dateBase = new \DateTimeImmutable("@0");
return static::DateIntervalToSeconds($dateTime->diff($dateBase));
}