理想情况下,应根据网站设置的游戏内日期(目前为3014-11-16),网站应计算当前年龄的字符并返回该年龄。因此,如果我们将年份设置为忽略年份为10,将字符出生日期设置为2,那么我们的年龄将为8岁。
当前日期设置为:3014-11-16(yyyy-mm-dd) 木狼的出生日期是:2998-01-12(yyyy-mm-dd)
他的年龄应该显示为16,而不是显示为-55
如果我将他的DOB设置为:3013-11-16,他的年龄变为-71 如果我将他的DOB设置为:3012-11-16,他的年龄会回来-70 如果我将他的DOB设置为:3005-11-16,他的年龄将回复为-63而不是7 如果我将他的DOB设置为:2998-11-16,他的年龄将回复为-56而不是16岁
如果我将他的DOB设置为:2945-11-16,他的年龄将恢复为-3 如果我将他的DOB设置为:2944-11-16,他的年龄将恢复为-1 如果我将他的DOB设置为:2943-11-16,他的年龄将恢复为0
如果我将他的DOB设置为:2105-11-16,他的年龄会回来837而不是909
我试图通过删除许多与问题无关的关键数组和部分来最小化代码。如果我将最后一行的$age
设置为$age=15
,我会得到十五,所以我知道我正在尝试修改返回$age
变量的值,但是我经过多次尝试,m完全丧失了。
我正在寻找一种方法来获得角色的正确年龄。多数民众赞成我的目标,希望有人可以看到我做错了什么。
以下是相关代码:
require_once('../include/Application.php'); // The only class we need to include
$app = new Application(); // Create the initial application object
$app->connect(); // Connect to the mysql server
$sess = new Session(); // Start a new session
$current = new CurrentUser(FALSE);
if ($current->errors) {
$errors = $current->errors;
trigger_error(current($errors), E_USER_ERROR);
}
include ("../functions.php");
$id="";
$record=array();
approveVars(array("id"));
$PHP_SELF = $_SERVER["PHP_SELF"];
$errors = array();
// Get daytimes from db
$daytimes = new DaytimeList();
if ($daytimes->errors) {
$errors = $daytimes->errors;
trigger_error(current($errors), E_USER_ERROR);
}
// Get the current game from the db
require_once('../include/Game.php');
$cu_game = new Game();
$cu_game->selectCurrent();
if ($cu_game->errors) { // Query error
$errors = $cu_game->errors;
trigger_error(current($errors), E_USER_ERROR);
} elseif ($cu_game->id) { // We got the current game
list($gametime, $realtime, $daylength, $inittod) = array(htmlspecialchars($cu_game->gametime, ENT_QUOTES), htmlspecialchars($cu_game->realtime, ENT_QUOTES), $cu_game->daylength/604800, htmlspecialchars($daytimes->data[$cu_game->inittod], ENT_QUOTES));
}
/*
$gametimefile = "$basefile/gamedate/gamedate.txt";
$tempy = file($gametimefile);
$gametime = trim($tempy[0]);
$realtime = trim($tempy[1]);
*/
if ($id) {
// FORMULA FOR GAME TIME
// FROM_DAYS(TO_DAYS('$gametime') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realtime')) /14))
if (!is_numeric($id)) {
$characterSQL = "SELECT *, DATE_FORMAT(lastmodified,'%b %e @ %h:%i %p') AS modformat, TO_DAYS(NOW()) - TO_DAYS(lastmodified) as modage, IFNULL(FLOOR((TO_DAYS('$gametime') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realtime')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age, DATE_FORMAT(dateofbirth, '%b %e, %Y') AS dateofbirth, datecreated AS dateadded FROM cerebra where codename=\"". mysql_real_escape_string($id) . "\"";
} else {
$characterSQL = "SELECT *, DATE_FORMAT(lastmodified,'%b %e @ %h:%i %p') AS modformat, TO_DAYS(NOW()) - TO_DAYS(lastmodified) as modage, IFNULL(FLOOR((TO_DAYS('$gametime') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realtime')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age, DATE_FORMAT(dateofbirth, '%b %e, %Y') AS dateofbirth, datecreated AS dateadded FROM cerebra where id=\"" . mysql_real_escape_string($id) . "\"";
} // end if'
$result=mysql_query($characterSQL, $db);
if (!mysql_num_rows($result)) { errorpage("There is no Cerebra record with that id number. Please check the link you used to access this page and try again, or check the <a href='/cerebra.php'>Cerebra main page</a> for the record you're looking for."); die; }
$record = mysql_fetch_assoc($result);
$id = $record["id"];
} else {
header("location: /cerebra.php");
die; } // end if ID
// "modelname","song","song_link"
//"Model", "Song", "Song Link",
$fields = array(
"Age"=>"age",
"Apparentage Age"=>"apparentage",
"Base Of Operations"=>"baseofoperations",
"Birthdate"=>"dateofbirth"
);
$patterns = array ("/\"/","/[\n\r\f]+/");
$replace = array (""","</p>\n<p>");
FOREACH ($fields as $label => $field) {
${$field} = preg_replace($patterns, $replace, trim($record[$field]));
${$field . "Name"} = $label;
} // end FOREACH
if ($age > "2000") { $age =""; }
//if i set $age = 15 here, then character age will appear as 15...