Commit 5157ddc4 authored by Nemo Ma's avatar Nemo Ma

Assorted BUGFIXes

Fix PHP Notice in game init
Fix background display
parent ffa2b33d
......@@ -996,6 +996,8 @@ if(isset($opendialog)){$log.="<span style=\"display:none\" id=\"open-dialog\">{$
if(isset($url)){$gamedata['url'] = $url;}
$gamedata['innerHTML']['pls'] = (!isset($plsinfo[$pls]) && isset($hplsinfo[$pgroup])) ? $hplsinfo[$pgroup][$pls] : $plsinfo[$pls];
$gamedata['innerHTML']['anum'] = $alivenum;
// 传递位置ID给JavaScript,用于更新背景图片
$gamedata['locationId'] = $pls;
ob_clean();
$main ? include template($main) : include template('profile');
......
# 修复背景图像显示和PHP Notice错误
## 问题描述
在游戏中,当玩家在不同位置切换时,模板会读取img\location下和位置pls编号相同的图像文件显示为背景。但有时,该功能显示的背景会出现错位,且输出以下notice:
```
Notice (8): Undefined variable: sdata in /volume1/web/gamedata/templates/1_header.tpl.php on line 36
Notice (8): Trying to access array offset on value of type null in /volume1/web/gamedata/templates/1_header.tpl.php on line 36
```
## 问题分析
1. 错误发生在header模板中,当尝试访问`$sdata['pls']`时,但在某些上下文中`$sdata`变量未定义。
2. 模板试图根据玩家当前位置设置背景图像。
3. 在某些页面加载时,`$sdata`变量可能不存在,导致PHP Notice错误。
## 修复方案
在templates/default/header.htm文件中,修改了背景图像设置的条件判断,添加了对`$sdata`变量和`$sdata['pls']`是否存在的检查:
```php
<!--{if (CURSCRIPT == 'game' && isset($sdata) && isset($sdata['pls']) && $sdata['pls']==$places)}-->
```
这样,只有当`$sdata`变量存在且`$sdata['pls']`也存在时,才会尝试设置背景图像,避免了在变量不存在时产生的PHP Notice错误。
## 修复效果
1. 消除了在页面加载时出现的PHP Notice错误
2. 保持了背景图像功能的正常工作
3. 提高了代码的健壮性,避免了在变量不存在时的错误
## 技术说明
在PHP中,访问未定义的变量或未定义变量的数组键会产生Notice级别的错误。通过使用`isset()`函数进行检查,可以避免这些错误。这是一种防御性编程的实践,确保代码在各种情况下都能正常工作。
# 修复背景图像更新问题
## 问题描述
在游戏中,当玩家移动到新位置时,背景图像不会自动更新,除非玩家进入战斗或重新加载页面。这是因为移动操作是通过AJAX请求完成的,而背景图像的更新逻辑没有包含在AJAX响应处理中。
## 问题分析
1. 玩家移动是通过AJAX请求处理的,不会重新加载整个页面
2. 背景图像是在页面初始加载时设置的,但在AJAX更新时没有更新
3. 需要在AJAX响应处理中添加更新背景图像的逻辑
## 修复方案
1. 在game20130526.js中添加了updateBackgroundImage函数,用于更新背景图像
2. 修改showData函数,在处理AJAX响应时检查位置是否更新,如果更新则调用updateBackgroundImage函数
3. 修改command.php,将当前位置ID传递给JavaScript
4. 在game.htm中定义CURSCRIPT变量,确保只在游戏页面更新背景图像
### 具体修改
1. 在game20130526.js中添加了updateBackgroundImage函数:
```javascript
function updateBackgroundImage(locationId) {
if (!locationId) return;
var bgUrl = "img/location/" + locationId + ".jpg";
document.body.style.backgroundImage = "url('" + bgUrl + "')";
document.body.style.backgroundPosition = "center";
}
```
2. 修改showData函数,在处理AJAX响应时检查位置是否更新:
```javascript
// 检查位置是否更新,如果更新则更新背景图片
if(sDi['pls'] && CURSCRIPT === 'game') {
// 从位置文本中提取位置ID
var plsText = sDi['pls'];
var locationId = null;
// 尝试从command.php中获取位置ID
if(shwData['locationId']) {
locationId = shwData['locationId'];
} else {
// 如果没有直接提供位置ID,尝试从URL参数中获取
var urlParams = new URLSearchParams(window.location.search);
var moveto = urlParams.get('moveto');
if(moveto) {
locationId = moveto;
}
}
// 如果有位置ID,更新背景图片
if(locationId) {
updateBackgroundImage(locationId);
}
}
```
3. 修改command.php,将当前位置ID传递给JavaScript:
```php
// 传递位置ID给JavaScript,用于更新背景图片
$gamedata['locationId'] = $pls;
```
4. 在game.htm中定义CURSCRIPT变量:
```javascript
<script type="text/javascript">
var CURSCRIPT = 'game';
</script>
```
## 修复效果
1. 玩家移动到新位置时,背景图像会自动更新,无需重新加载页面或进入战斗
2. 保持了原有的背景图像功能,只是增加了动态更新的能力
3. 提高了游戏体验,使背景图像变化更加流畅
## 技术说明
这个修复利用了JavaScript的DOM操作能力,在AJAX响应处理中动态更新背景图像。通过在服务器端传递位置ID,客户端可以准确地知道当前位置,并加载相应的背景图像。这种方法避免了重新加载整个页面,提高了用户体验。
# PHP Notice 错误修复
## 问题描述
在游戏初始化时,系统产生了大量的PHP Notice错误,主要集中在以下几个方面:
1. `Undefined offset` 错误在 system.func.php 的第286行和第328行
2. `Undefined variable: bwlist` 错误在 system.func.php 的第1137行
## 修复方案
### 1. 修复数组访问越界问题
在 system.func.php 中,当处理商店物品和地图物品时,代码尝试访问数组中可能不存在的索引,导致了 `Undefined offset` 错误。
修复方法:使用 `array_pad()` 函数确保数组有足够的元素,避免访问不存在的索引。
修改位置:
- 第177-190行:处理地图物品时,确保 `$item_parts` 数组至少有9个元素
- 第307-320行:处理商店物品时,确保 `$lst` 数组至少有10个元素
### 2. 修复未定义变量问题
在 get_gambling_result 函数中,变量 `$bwlist` 在某些代码路径中可能未被初始化就被使用,导致了 `Undefined variable: bwlist` 错误。
修复方法:在函数开始处初始化 `$bwlist` 变量为空数组。
修改位置:
- 第1026-1034行:在 get_gambling_result 函数开始处添加 `$bwlist = array();`
## 修复效果
这些修改应该能够消除游戏初始化过程中出现的PHP Notice错误,提高代码的健壮性和可靠性。
## 注意事项
虽然IDE报告了许多未使用的变量警告,但这些警告不会导致运行时错误,可以在后续优化中处理。
/*function hotkey(evt)
{
/*function hotkey(evt)
{
if(document.activeElement.tagName != 'INPUT'){
evt = (evt) ? evt : ((window.event) ? window.event : '');
var ky = evt.keyCode ? evt.keyCode : evt.which;
......@@ -8,21 +8,21 @@
$('submit').click();
}
}
}
}
}*/
var ms;
hotkey_ok = true;
refchat_ok = true;
function hotkey(evt)
{
function hotkey(evt)
{
if(hotkey_ok && document.activeElement.tagName != 'INPUT'){
evt = (evt) ? evt : ((window.event) ? window.event : '');
var ky = evt.keyCode ? evt.keyCode : evt.which;
flag=1;//是否完成冷却
if (ms!=undefined) {
if (ms>0) flag=0;
}
}
//双字母id=冷却时间内不可执行的操作 单字母可以执行
if(!evt.ctrlKey && !evt.altKey && !evt.shiftKey){
if(ky==90){
......@@ -66,7 +66,7 @@ function hotkey(evt)
flag==1 ? hotkey_click(kc+kc) : hotkey_click(kc);
}
}
}
}
}
function hotkey_click(hkid){
......@@ -97,7 +97,7 @@ function updateTime(timing,mode)
setTimeout("updateTime(t,tm)",1000);
}
else{
window.location.reload();
window.location.reload();
}
}
......@@ -203,7 +203,7 @@ function sl(id) {
// } else{
// $(id).innerHTML = '';
// }
//
//
// }
// if(gamedata['timer'] && typeof(timerid)=='undefined'){
// demiSecTimerStarter(gamedata['timer']);
......@@ -240,7 +240,7 @@ function sl(id) {
// $(id).innerHTML = regdata[id];
// } else{
// $(id).innerHTML = '';
// }
// }
// }
//}
......@@ -277,9 +277,9 @@ function sl(id) {
//function showAlive(mode){
// //window.location.href = 'alive.php?alivemode=' + mode;
//
//
// var oXmlHttp = zXmlHttp.createRequest();
//
//
// oXmlHttp.open("post", "alive.php", true);
// oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// oXmlHttp.onreadystatechange = function () {
......@@ -325,6 +325,14 @@ function postCmd(formName,sendto){
oXmlHttp.send(sBody);
}
// 更新背景图片函数
function updateBackgroundImage(locationId) {
if (!locationId) return;
var bgUrl = "img/location/" + locationId + ".jpg";
document.body.style.backgroundImage = "url('" + bgUrl + "')";
document.body.style.backgroundPosition = "center";
}
function showData(sdata){
shwData = sdata.parseJSON();
if(shwData['url']) {
......@@ -352,10 +360,34 @@ function showData(sdata){
sDd = shwData['display'];
for(var id in sDd){
if($(id)!=null){
$(id).style.display = sDd[id];
}
}
// 检查位置是否更新,如果更新则更新背景图片
if(sDi['pls'] && CURSCRIPT === 'game') {
// 从位置文本中提取位置ID
var plsText = sDi['pls'];
var locationId = null;
// 尝试从command.php中获取位置ID
if(shwData['locationId']) {
locationId = shwData['locationId'];
} else {
// 如果没有直接提供位置ID,尝试从URL参数中获取
var urlParams = new URLSearchParams(window.location.search);
var moveto = urlParams.get('moveto');
if(moveto) {
locationId = moveto;
}
}
// 如果有位置ID,更新背景图片
if(locationId) {
updateBackgroundImage(locationId);
}
}
}
if(shwData['timer'] && typeof(timerid)=='undefined'){
demiSecTimerStarter(shwData['timer']);
......@@ -422,12 +454,12 @@ function openShutManager(oSourceObj,oTargetObj,shutAble,oOpenTip,oShutTip){
if(shutAble) return;
targetObj.style.display="none";
if(openTip && shutTip){
sourceObj.innerHTML = shutTip;
sourceObj.innerHTML = shutTip;
}
} else {
targetObj.style.display="block";
if(openTip && shutTip){
sourceObj.innerHTML = openTip;
sourceObj.innerHTML = openTip;
}
}
}
......@@ -435,7 +467,7 @@ function openShutManager(oSourceObj,oTargetObj,shutAble,oOpenTip,oShutTip){
//元素合成界面的ajax效果 仅作美化使用
function getEmitmeR(type=0) {
if(type == 1)
{
{
var r = document.getElementById("emitme_max_r").value;
var e = document.getElementById("emax").value;
$('s_emitme_max').innerHTML = Math.round(e*(r/100));
......@@ -495,10 +527,10 @@ function AddMixElements(emix_arr) {
var numsarr = [];
var descarr = [];
const esum = [];
for (let i = 0; i < emix_arr.length; i++) {
esum[emix_arr[i][0]] = (esum[emix_arr[i][0]] || 0) + emix_arr[i][1];
}
}
for (let i = 0; i < emix_arr.length; i++) {
if($('maxe' + emix_arr[i][0] + 'num') === null || ($('maxe' + emix_arr[i][0] + 'num').value - esum[emix_arr[i][0]]) < 0) {
window.alert("合成所需的元素数量不足。");
......@@ -518,7 +550,7 @@ function AddMixElements(emix_arr) {
$('emixinfotop').style.display = 'block';
}
function changeVolume(cv){
function changeVolume(cv){
var v = $('gamebgm').volume;
v = v+cv;
v = Math.min(1,v); v = Math.max(0,v); v = v.toFixed(2);
......@@ -577,14 +609,14 @@ function changePages(mode,cPages)
function skill_unacquired_mouseover(e)
{
var children = this.childNodes;
for (var i = 0; i < children.length; i++)
for (var i = 0; i < children.length; i++)
{
var child = children[i];
if (child.className == 'skill_unacquired')
if (child.className == 'skill_unacquired')
{
child.className = 'skill_unacquired_transparent';
}
if (child.className == 'skill_unacquired_hint')
if (child.className == 'skill_unacquired_hint')
{
child.className = 'skill_unacquired_hint_transparent';
}
......@@ -594,14 +626,14 @@ function skill_unacquired_mouseover(e)
function skill_unacquired_mouseout(e)
{
var children = this.childNodes;
for (var i = 0; i < children.length; i++)
for (var i = 0; i < children.length; i++)
{
var child = children[i];
if (child.className == 'skill_unacquired_transparent')
if (child.className == 'skill_unacquired_transparent')
{
child.className = 'skill_unacquired';
child.className = 'skill_unacquired';
}
if (child.className == 'skill_unacquired_hint_transparent')
if (child.className == 'skill_unacquired_hint_transparent')
{
child.className = 'skill_unacquired_hint';
}
......@@ -611,13 +643,13 @@ function skill_unacquired_mouseout(e)
function selectRecordedFile() {
var input = document.createElement("input");
input.type = "file";
input.accept = ".gz";
input.accept = ".gz";
input.click();
// 处理选择的文件
input.onchange = function (event) {
var file = event.target.files[0];
var file = event.target.files[0];
console.log("选择的文件:", file);
displayRecordedData(file);
......@@ -665,7 +697,7 @@ function showPage(pageContent, currentPageIndex) {
var progressBar = document.createElement('div');
progressBar.className = 'progress-bar';
progressBar.style.width = ((currentPageIndex + 1) / pageContent.length) * 100 + '%';
var progressBar = document.createElement('input');
progressBar.type = 'range';
progressBar.min = 0;
......@@ -675,7 +707,7 @@ function showPage(pageContent, currentPageIndex) {
currentPageIndex = parseInt(progressBar.value);
showPage(pageContent, currentPageIndex);
};
recordedDataDiv.insertBefore(progressBar, recordedDataDiv.firstChild);
recordedDataDiv.insertBefore(nextPageButton, recordedDataDiv.firstChild);
recordedDataDiv.insertBefore(previousPageButton, recordedDataDiv.firstChild);
......@@ -712,7 +744,7 @@ function displayRecordedData(file) {
showPage(pageContent, 0);
};
reader.readAsArrayBuffer(file);
} else { // 如果没有选择文件,则显示选择文件的提示消息
} else { // 如果没有选择文件,则显示选择文件的提示消息
var noticeDiv = document.getElementById('notice'); noticeDiv.textContent = '请先选择一个录像文件';
}
}
......@@ -723,5 +755,4 @@ function displayRecordedData(file) {
downloadRecordedData();
}
};*/
\ No newline at end of file
......@@ -193,6 +193,9 @@ function rs_game($mode = 0) {
// 分割字符串
$item_parts = explode(',', $line);
// 确保数组有足够的元素
$item_parts = array_pad($item_parts, 9, '');
// 检查是否有itmpara字段
$itmpara = '';
if(count($item_parts) >= 9) {
......@@ -307,6 +310,9 @@ function rs_game($mode = 0) {
// 分割字符串
$lst = explode(',', $line);
// 确保数组有足够的元素
$lst = array_pad($lst, 10, '');
// 检查是否有itmpara字段
$itmpara = '';
if(count($lst) >= 10) {
......@@ -316,7 +322,6 @@ function rs_game($mode = 0) {
$itmpara = $json_content;
}
}
if(empty($lst[8])) $lst[8] = '';
list($kind,$num,$price,$area,$item,$itmk,$itme,$itms,$itmsk)=$lst;
if($kind != 0){
$qry .= "('$kind','$num','$price','$area','$item','$itmk','$itme','$itms','$itmsk','$itmpara'),";
......@@ -1026,6 +1031,7 @@ function get_credit_up($data,$winner = '',$winmode = 0){
function get_gambling_result($clist, $winner='',$winmode=''){
global $db,$tablepre,$gtablepre,$hdamage,$validnum,$now,$areanum,$areaadd,$gamevars;
$gblog = '';
$bwlist = array(); // Initialize $bwlist to avoid undefined variable
//$gbfile = GAME_ROOT.TPLDIR.'/lastgb.htm';
if(!in_array($winmode,Array(2,3,5,7))){//无人获胜,全部赌注被冴冴吃掉
$gblog .= '无人获胜,全部切糕被冴冴吃掉!';
......
......@@ -4,6 +4,9 @@
<!--{eval $bgm = init_bgm(1)}-->
$bgm
</div>
<script type="text/javascript">
var CURSCRIPT = 'game';
</script>
<!--{eval $bgurl = "img/location/".$pls.".jpg";}-->
<!--{if $horizon}-->
<style>
......
......@@ -27,7 +27,7 @@ jQuery.noConflict();
<script type="text/javascript" src="include/record.js"></script>
<!--{/if}-->
<!--{loop $plsinfo $places $info}-->
<!--{if (CURSCRIPT == 'game' && $sdata['pls']==$places)}-->
<!--{if (CURSCRIPT == 'game' && isset($sdata) && isset($sdata['pls']) && $sdata['pls']==$places)}-->
<!--{eval $bgurl = "img/location/".$places.".jpg"}-->
<style>
body {background-image: url("$bgurl");background-position: center;}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment