本帖最后由 liuzhly 于 2009-12-24 09:29 编辑
由于不知flash有无点击锁定某物品功能,目前只能做到在程序上锁定,防止误操作~~~~
就是在清理仓库,全部卖出的时候,系统不卖出牧草~~~~
打开:newfarmjson.php
找到:
if ( $_REQUEST['mod'] == "repertory" && $_REQUEST['act'] == "saleAll" )
foreach ( $fruitarr as $key => $value ){
if ( ( 0 < $value ) && ( $crops[$key][cType] == 1 ) ){
$money = $money + $crops[$key][sale] * $value;
$fruitarr->$key = 0;
}
}
修改成如下:红色部分为添加的:
foreach ( $fruitarr as $key => $value ){
if ( ( 0 < $value ) && ( $crops[$key][cType] == 1 ) && $key !=40 ){
$money = $money + $crops[$key][sale] * $value;
$fruitarr->$key = 0;
}
}
这样就OK了,但是如果想优化代码,请继续操作:
代码里判断 $_REQUEST['type'] == "1" 和 $_REQUEST['type'] == "2" ,程序有重复,其实无需两个if 判断,使用一个,本人精简代码如下:
将整个:
if ( $_REQUEST['mod'] == "repertory" && $_REQUEST['act'] == "saleAll" )
{
if ( $_REQUEST['type'] == "1" )
{
$fruit = $_SGLOBAL['db']->result( $_SGLOBAL['db']->query( "SELECT fruit FROM ".tname( "plug_newfarm" )." where uid=".$_SGLOBAL['supe_uid'] ), 0 );
$fruitarr = json_decode( $fruit );
$money = 0;
foreach ( $fruitarr as $key => $value )
{
if ( ( 0 < $value ) && ( $crops[$key][cType] == 1 ) )
{
$money = $money + $crops[$key][sale] * $value;
$fruitarr->$key = 0;
}
}
$fruitarr = json_encode( $fruitarr );
$_SGLOBAL['db']->query( "UPDATE ".tname( "plug_newfarm" )." set money=money+".$money.",fruit='".$fruitarr."' where uid=".$_SGLOBAL['supe_uid'] );
echo "{\"code\":1,\"direction\":\"\",\"money\":".$money."}";
include_once( S_ROOT."./source/function_cp.php" );
$icon = "farm";
$title_template = "{actor} 去自己的 <a href=\"newfarm.php\">农场</a> 辛勤工作了一番,清理一下仓库";
$body_general = "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦!";
feed_add( $icon, $title_template );
exit( );
}
else
if ( $_REQUEST['type'] == "2" )
{
$fruit = $_SGLOBAL['db']->result( $_SGLOBAL['db']->query( "SELECT fruit FROM ".tname( "plug_newfarm" )." where uid=".$_SGLOBAL['supe_uid'] ), 0 );
$fruitarr = json_decode( $fruit );
$money = 0;
foreach ( $fruitarr as $key => $value )
{
if ( ( 0 < $value ) && ( $crops[$key][cType] == 2 ) )
{
$money = $money + $crops[$key][sale] * $value;
$fruitarr->$key = 0;
}
}
$fruitarr = json_encode( $fruitarr );
$_SGLOBAL['db']->query( "UPDATE ".tname( "plug_newfarm" )." set money=money+".$money.",fruit='".$fruitarr."' where uid=".$_SGLOBAL['supe_uid'] );
echo "{\"code\":1,\"direction\":\"\",\"money\":".$money."}";
include_once( S_ROOT."./source/function_cp.php" );
$icon = "farm";
$title_template = "{actor} 去自己的 <a href=\"newfarm.php\">农场</a> 辛勤工作了一番,清理一下仓库";
$body_general = "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦!";
feed_add( $icon, $title_template );
exit( );
}
}
精简为如下红色:
if ( $_REQUEST['mod'] == "repertory" && $_REQUEST['act'] == "saleAll" ){ //[=17=]
$Rtype =$_REQUEST['type'];
if ( $Rtype == "1" || $Rtype == "2"){
$fruit = $_SGLOBAL['db']->result( $_SGLOBAL['db']->query( "SELECT fruit FROM ".tname( "plug_newfarm" )." where uid=".$_SGLOBAL['supe_uid'] ), 0 );
$fruitarr = json_decode( $fruit );
$money = 0;
foreach ( $fruitarr as $key => $value ){
if ( ( 0 < $value ) && ( $crops[$key][cType] == $Rtype ) && $key != 40){
$money = $money + $crops[$key][sale] * $value;
$fruitarr->$key = 0;
}
}
$money == 0 && exit("{\"code\":1,\"direction\":\"\",\"money\":0}");
$fruitarr = json_encode( $fruitarr );
$_SGLOBAL['db']->query( "UPDATE ".tname( "plug_newfarm" )." set money=money+".$money.",fruit='".$fruitarr."' where uid=".$_SGLOBAL['supe_uid'] );
echo "{\"code\":1,\"direction\":\"\",\"money\":".$money."}";
include_once( S_ROOT."./source/function_cp.php" );
$icon = "farm";
$title_template = "{actor} 去自己的 <a href=\"newfarm.php\">农场</a> 辛勤工作了一番,清理一下仓库";
$body_general = "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦!";
feed_add( $icon, $title_template );
exit( );
}
} //[=17=]清理仓库,卖出果实
如此开心农场清理仓库牧草已经锁定!!想卖点击牧草,点对勾才能卖出~~,清理仓库不卖牧草~~~ |