本帖最后由 liuzhly 于 2010-01-22 21:40 编辑
其他参见:https://discuz.dismall.com/thread-1551194-1-1.html
这次是针对 牧场作物(地块)与农场动物 的数据表进行压缩!!
打开:newfarmjosn.php,红色为增加项!!
if ( $_REQUEST['mod'] == "user" && $_REQUEST['act'] == "reclaim" )
{
$query = $_SGLOBAL['db']->query( "SELECT farmlandstatus,reclaim,money,exp FROM ".tname( "plug_newfarm" )." where uid=".$_SGLOBAL['supe_uid'] );
while ( $value = $_SGLOBAL['db']->fetch_array( $query ) )
{
$list[] = $value;
}
if ( $list[0][money] < $tudiarr[$list[0][reclaim]][money] || $list[0][exp] < $tudiarr[$list[0][reclaim]][exp] )
{
exit( );
}
$farmarr = json_decode( $list[0][farmlandstatus] );
foreach($farmarr->farmlandstatus as $key => $value){
if( $key >= $list[0][reclaim] ){unset($farmarr->farmlandstatus[$key]);}
}
$farmarr->farmlandstatus[$list[0][reclaim]] = json_decode("{\"a\":0,\"b\":0,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":0,\"l\":0,\"m\":0,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":0,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0}");
$farmarr_str = json_encode( $farmarr );
$_SGLOBAL['db']->query( "UPDATE ".tname( "plug_newfarm" )." set farmlandstatus='".$farmarr_str."',reclaim=reclaim+1,money=money-".$tudiarr[$list[0][reclaim]][money]." where uid=".$_SGLOBAL['supe_uid'] );
echo "{\"code\":1,\"direction\":\"\",\"money\":-".$tudiarr[$list[0][reclaim]][money]."}";
}
说明:当用户开垦土地时候,自动压缩多余的地块选项,只保留有用的!!!
牧场的:
打开 newmc.php
if ( $_REQUEST['mod'] == "cgi_buy_animal" )
。。。。。。。。。。。。。。。
$anicount=0;
$item2count=0;
$item3count=0;
$item2=intval($animal[item2])*3;
$item3=intval($animal[item3])*3;
$mc_exp=$list[0][mc_exp];
$animalnum=0;
$level=getLevel($mc_exp);
if($level<3){
$animalnum=$level+2;
}else{
$animalnum=3+ceil($level/2);
}
$gradea = 0;
foreach ( $animal[animal] as $key => $value )
{
if ( $value->cId != 0 )
{
($value->cId>1500)?$item3count++:$item2count++;
}
if($key >= $animalnum){
unset($animal[animal][$key]);
}else{
$gradea++;
}
}
for($i = 0; $i < $animalnum-$gradea; $i++){
$gradea <= 20 && $animal[animal][] = json_decode("{\"buyTime\":0,\"cId\":0,\"postTime\":0,\"totalCome\":0,\"tou\":\"\",\"cycle\":0}");
}
( $anicount + $_REQUEST['number'] ) > $animalnum && exit("{\"errorContent\":\"\\u5BF9\\u4E0D\\u8D77\\uFF0C\\u60A8\\u5F53\\u524D\\u7684\\u7B49\\u7EA7\\u6700\\u591A\\u80FD\\u9972\\u517B" . $animalnum . "\\u53EA\\u52A8\\u7269\\u3002\\uFF08\\u5DF2\\u9972\\u517B" . $anicount . "\\u53EA\\uFF09\",\"errorType\":\"1011\"}");
当用户购买动物的时候,自动根据级别压缩字段,去掉无用的字段~~~~那个蓝色的,是农场最大动物量~~~
至此,数据表压缩基本完成!!
初始化文件变量可以修改成(也可以不改,系统自动压缩):
$farmlandstatus = "{\"farmlandstatus\":[{\"a\":2,\"b\":6,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":1251315720,\"r\":1251351720,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":1,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":1251337325,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":0,\"g\":0,\"h\":0,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":1251337325,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":0,\"g\":2,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":1251326525,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":7,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":0,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":7,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":\"2\",\"o\":0,\"p\":[],\"q\":0,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0}]}";
$farmlandstatus = ( array )json_decode( $farmlandstatus );
foreach ( $farmlandstatus[farmlandstatus] as $key => $value ){
if ( $key == 0 ){
$value->q = $_SGLOBAL['timestamp'] - 36000;
}
if ( $key == 1 ){
$value->q = $_SGLOBAL['timestamp'] - 14400;
}
if ( $key == 2 ){
$value->q = $_SGLOBAL['timestamp'] - 14400;
}
if ( $key == 3 ){
$value->q = $_SGLOBAL['timestamp'] - 25200;
}
}
$farmlandstatus = json_encode( $farmlandstatus );
//背包
$package = "{}";
//肥料
$fertilizer = "{}";
//装饰
$decorative = "{\"1\":{\"1\":{\"status\":1,\"validtime\":0}},\"2\":{\"2\":{\"status\":1,\"validtime\":0}},\"3\":{\"3\":{\"status\":1,\"validtime\":0}},\"4\":{\"4\":{\"status\":1,\"validtime\":0}}}";
//宠物
$dog = "{}";
//花束
$nosegay = "{}";
//消息
$message = "{\"a\":[],\"b\":[],\"c\":[],\"d\":[],\"e\":[]}";
//牧场动物
$animal = "{\"animalfood\":20,\"animalfeedtime\":".$_SGLOBAL['timestamp'].",\"item1\":10111,\"item2\":10221,\"item3\":10330,\"item4\":10441,\"animal\":[{\"buyTime\":1244817632,\"cId\":1002,\"postTime\":0,\"totalCome\":0,\"tou\":\"\"},{\"buyTime\":0,\"cId\":0,\"postTime\":0,\"totalCome\":0,\"tou\":\"\"}]}";
//牧场背包
$mc_package = "{}";
//牧场日志
$mc_log = "{}"; |