我首先要说的不是程序员。像很多人一样,我可以通过PHP,JS,PowerShell等中的示例一起破解一些东西,但我在这里丢了一个空白。
我正在尝试创建一个页面,显示当前每日任务在Everquest 2中的内容。这些任务每18小时更改一次,并在每周的同一天/时间重复。
以下作品但是......太糟糕了。
<!DOCTYPE html>
<html>
<body>
<?php
$h = date('G'); //set variable $h to the server hour of the day, "G" is the date key for hours in 24 format (not 12), with no leading 0s, like 02. Adjust hourly offset in the event of daylight savings problems.. i.e $h = $h-2;
$h = $h+7;
$d = date('w'); //set variable $d to the server day of the week, 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
// Monday before 1400
if ($d == 1 && $h < 14) $text = 'Ossuary: Sanguine Fountains [Heroic]';
// Monday after 1400
if ($d == 1 && $h >= 14) $text = 'Ossuary: Resonance of Malice [Heroic]';
// Tuesday before 0800
if ($d == 2 && $h < 8) $text = 'Ossuary: Resonance of Malice [Heroic]';
// Tuesday after 0800
if ($d == 2 && $h >= 8) $text = 'Ssraeshza Temple [Heroic]';
// Wednesday before 0200
if ($d == 3 && $h < 2) $text = 'Ssraeshza Temple [Heroic]';
// Wednesday after 0200 but before 2000
if ($d == 3 && $h >= 2 && $H < 20) $text = 'Ssraeshza Temple: Inner Sanctum [Heroic]';
// Wednesday after 2000
if ($d == 3 && $h >= 20) $text = 'Brokenskull Bay: Bilgewater Falls [Heroic]';
// Thursday before 1400
if ($d == 4 && $h < 14) $text = 'Brokenskull Bay: Bilgewater Falls [Heroic]';
// Thursday after 1400
if ($d == 4 && $h >= 14) $text = 'Brokenskull Bay: Hoist the Yellow Jack [Heroic]';
// Friday before 0800
if ($d == 5 && $h < 8) $text = 'Brokenskull Bay: Hoist the Yellow Jack [Heroic]';
// Friday after 0800
if ($d == 5 && $h >= 8) $text = 'Zavithloa: The Lost Caverns [Heroic]';
// Saturday before 0200
if ($d == 6 && $h < 2) $text = 'Zavithloa: The Lost Caverns [Heroic]';
// Saturday after 0200 but before 2000
if ($d == 6 && $h >= 2 && $H < 20) $text = 'Zavithloa: The Hidden Caldera [Heroic]';
// Saturday after 2000
if ($d == 6 && $h >= 20) $text = 'Castle Highhold [Heroic]';
// Sunday before 0200
if ($d == 0 && $h < 2) $text = 'Castle Highhold [Heroic]';
// Sunday after 0200 but before 2000
if ($d == 0 && $h >= 2 && $H < 20) $text = 'Castle Highhold: Thresinets Den [Heroic]';
// Sunday after 2000
if ($d == 0 && $h >= 20) $text = 'Ossuary: Sanguine Fountains [Heroic]';
echo "Current Daily Mission: $text <BR>";
?>
</body>
</html>
如果是约会,我可能会把它放在一个SQL表中,然后循环执行一个约会,但我不知道如何使用当前格式使用它...我也更喜欢把它放在一个数组并循环通过,但再次,不知道最好的方式使用它..我应该使用任务名称作为键,然后找到一种方法来分开开始和结束时间?但由于我存储信息的任意方式,我不确定如何比较一天/时间?
$MissionTimes = array(
0 => "Mission1:1-14-00:2-8-00",
1 => "Mission2:2-8-00:3-2-00",
2 => "Mission3:3-2-00:3-20-00",
3 => "Mission4:3-20-00:4-14-00",
4 => "Mission5:4-14-00:5-8-00",
5 => "Mission6:5-8-00:6-2-00",
6 => "Mission7:6-2-00:6-18-00",
7 => "Mission8:6-18-00:0-2-00",
8 => "Mission9:0-2-00:0-18-00",
9 => "Mission10:0-18-00:1-14-00",
);
任何帮助指针/建议都会非常感激。
EDIT .... 有了Everts的帮助,我现在有一个数组和一个循环函数可以工作,任何人都可以帮助我如何获得“下一个”结果以及最终结果?我能想到的唯一方法是添加结束时间,然后使用for循环检查当前日期/时间是否在当前的foreach日期/时间之间,但是当任务落在星期六之间时,这将会分崩离析(第6天)和周日(第0天)。
<!DOCTYPE html>
<html>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Daily "start" time listed below in GMT, each daily lasts 18 hours.
// Sunday (0) 2AM = Castle Highhold: Thresinet’s Den [Heroic]
// Sunday (0) 8PM = Ossuary: Sanguine Fountains [Heroic]
// Monday (1) 2PM = Ossuary: Resonance of Malice [Heroic]
// Tuesday (2) 8AM = Ssraeshza Temple [Heroic]
// Wednesday (3) 2AM = Ssraeshza Temple: Inner Sanctum [Heroic]
// Wednesday (3) 8PM = Brokenskull Bay: Bilgewater Falls [Heroic]
// Thursday (4) 2PM = Brokenskull Bay: Hoist the Yellow Jack [Heroic]
// Friday (5) 8AM = Zavith’loa: The Lost Caverns [Heroic]
// Saturday (6) 2AM = Zavith’loa: The Hidden Caldera [Heroic]
// Saturday (6) 8PM = Castle Highhold [Heroic]
$MissionTimes = array(
array(
'missionid' => "Castle Highhold: Thresinet’s Den [Heroic]",
'startdow' => 0,
'starthour' => 0
),
array(
'missionid' => "Castle Highhold: Thresinet’s Den [Heroic]",
'startdow' => 0,
'starthour' => 2
),
array(
'missionid' => "Ossuary: Sanguine Fountains [Heroic]",
'startdow' => 0,
'starthour' => 20
),
array(
'missionid' => "Ossuary: Resonance of Malice [Heroic]",
'startdow' => 1,
'starthour' => 14
),
array(
'missionid' => "Ssraeshza Temple [Heroic]",
'startdow' => 2,
'starthour' => 8
),
array(
'missionid' => "Ssraeshza Temple: Inner Sanctum [Heroic]",
'startdow' => 3,
'starthour' => 2
),
array(
'missionid' => "Brokenskull Bay: Bilgewater Falls [Heroic]",
'startdow' => 3,
'starthour' => 20
),
array(
'missionid' => "Brokenskull Bay: Hoist the Yellow Jack [Heroic]",
'startdow' => 4,
'starthour' => 14
),
array(
'missionid' => "Zavith’loa: The Lost Caverns [Heroic]",
'startdow' => 5,
'starthour' => 8
),
array(
'missionid' => "Zavith’loa: The Hidden Caldera [Heroic]",
'startdow' => 6,
'starthour' => 2
),
array(
'missionid' => "Castle Highhold [Heroic]",
'startdow' => 6,
'starthour' => 20
)
);
$hour = date('G');
$dow = date('w');
$hour = $hour+7;
foreach($MissionTimes as $mission)
{
if ($mission['startdow'] > $dow)
{
// If the current date of the week is higher than the start dow of
// of this mission, we skip to the next item.
continue;
}
if ($mission['starthour'] > $hour)
{
// If the current hour of the day is higher than the start hour of
// of this mission, we skip to the next item.
continue;
}
$missionstring = $mission['missionid'];
// break;
}
echo "The current mission is: $missionstring";
?>
</body>
</html>
答案 0 :(得分:0)
我认为你非常接近,但我会稍微改变一下结构,不要将所有东西打包成一个字符串。
示例:
$MissionTimes = [
[
'missionid' => 1,
'startdow' => 1,
'starthour' => 14
],
[
'missionid' => 1,
'startdow' => 1,
'starthour' => 14
],
[
'missionid' => 2,
'startdow' => 2,
'starthour' => 8
],
/*** etc ***/
];
所以注意几点:
[ and ]
与array( and )
相同。那你怎么找到当前的使命?
$hour = date('G');
$dow = date('w');
$missionId = 0;
foreach($MissionTimes as $mission) {
if ($mission['startdow']) > $dow) {
// If the current date of the week is higher than the start dow of
// of this mission, we skip to the next item.
continue;
}
if ($mission['starthour'] > $hour) {
// If the current hour of the day is higher than the start hour of
// of this mission, we skip to the next item.
continue;
}
// If we got here, stop the loop.
$missionId = $mission['missionid'];
break;
}
另外2个笔记:
$MissionTimes
数组是有序的,并从星期日午夜(第0小时,第0天)开始的条目开始。最后,你没有提到任何关于时区的事情,但你加上7小时的小时值......这很奇怪。我的假设是,everquest任务时间是UTC,你在太平洋时间。要获取UTC的值,请使用gmdate()
代替date()
函数。