使用Jscript[ASP,ASP.NET]开发本地QQ农场牧场的可行性【转帖】

zy91000 2010-08-09 01:57:22
目前,网上流行的QQ本地农场,本地开心农场,全部是PHP开发,有个PWSNS是.net开发,但是不开源,对于其他平台的程序来说,只能看着PHP程序使用,自己就没有办法吗?

那么多ASP,网站,没有办法?? 当然不是. 请看我对于php农场和其他语言的调研. 以下展示代码全部是Jscript [ASP]代码,部分方法基于SMART ASP 库

PHP本地农场的代码,大量使用了 键值对 的array 例如:



# 道具类型参数$Toolstype = array( "30001" => array("tId" => 1,"tName" => "普通化肥","price" => 400,"FBPrice" => 0,"YFBPrice" => 0,"timeLimit" => 0,"type" => 3,"effect" => 3600,"depict" => "每个阶段只能使用一次,减少该阶段成长时间1小时。","saleOut" => false), "30002" => array("tId" => 2,"tName" => "高速化肥","price" => 0,"FBPrice" => 4,"YFBPrice" => 3,"timeLimit" => 0,"type" => 3,"effect" => 9000,"depict" => "每个阶段只能使用一次,减少该阶段成长时间2.5小时。","saleOut" => false), "30003" => array("tId" => 3,"tName" => "极速化肥","price" => 0,"FBPrice" => 10,"YFBPrice" => 8,"timeLimit" => 0,"type" => 3,"effect" => 19800,"depict" => "每个阶段只能使用一次,减少该阶段成长时间5.5小时。","saleOut" => false), "40001" => array("tId" => 1,"tName" => "狗","price" => "1000","FBPrice" => "0","YFBPrice" => "0","timeLimit" => 0,"type" => 4,"effect" => "","depict" => "可能抓住摘取果实的好友,罚的金币归主人所有。没有狗粮,狗不会抓人","saleOut" => false), "40003" => array("tId" => 3,"tName" => "苏格兰牧羊犬","price" => "5000","FBPrice" => "0","YFBPrice" => "0","timeLimit" => 0,"type" => 4,"effect" => "","depict" => "可能抓住摘取果实的好友。牧羊犬比普通狗提高50%抓坏人的概率","saleOut" => false), "9001" => array("tId" => 9001,"tName" => "普通狗粮","price" => 0,"FBPrice" => 4,"YFBPrice" => 3,"timeLimit" => 0,"type" => 909090,"effect" => "","depict" => "每购买1天普通狗粮,1天内狗会在一定几率下抓住摘取果实的好友","saleOut" => false), "9002" => array("tId" => 9002,"tName" => "狗粮5送2礼包","price" => 0,"FBPrice" => 20,"YFBPrice" => 15,"timeLimit" => 0,"type" => 909090,"effect" => "","depict" => "一次性购买5天狗粮,可额外获赠2天狗粮,让狗狗为你看守农场一周","saleOut" => false));



那么翻译成JScript [或者叫 JSON 的形式] 是什么呢? 是对象:
代码
// 道具类型参数$Toolstype = { "30001" : {"tId" : 1,"tName" : "普通化肥","price" : 400,"FBPrice" : 0,"YFBPrice" : 0,"timeLimit" : 0,"type" : 3,"effect" : 3600,"depict" : "每个阶段只能使用一次,减少该阶段成长时间1小时。","saleOut" : false}, "30002" : {"tId" : 2,"tName" : "高速化肥","price" : 0,"FBPrice" : 4,"YFBPrice" : 3,"timeLimit" : 0,"type" : 3,"effect" : 9000,"depict" : "每个阶段只能使用一次,减少该阶段成长时间2.5小时。","saleOut" : false}, "30003" : {"tId" : 3,"tName" : "极速化肥","price" : 0,"FBPrice" : 10,"YFBPrice" : 8,"timeLimit" : 0,"type" : 3,"effect" : 19800,"depict" : "每个阶段只能使用一次,减少该阶段成长时间5.5小时。","saleOut" : false}, "40001" : {"tId" : 1,"tName" : "狗","price" : "1000","FBPrice" : "0","YFBPrice" : "0","timeLimit" : 0,"type" : 4,"effect" : "","depict" : "可能抓住摘取果实的好友,罚的金币归主人所有。没有狗粮,狗不会抓人","saleOut" : false}, "40003" : {"tId" : 3,"tName" : "苏格兰牧羊犬","price" : "5000","FBPrice" : "0","YFBPrice" : "0","timeLimit" : 0,"type" : 4,"effect" : "","depict" : "可能抓住摘取果实的好友。牧羊犬比普通狗提高50%抓坏人的概率","saleOut" : false}, "9001" : {"tId" : 9001,"tName" : "普通狗粮","price" : 0,"FBPrice" : 4,"YFBPrice" : 3,"timeLimit" : 0,"type" : 909090,"effect" : "","depict" : "每购买1天普通狗粮,1天内狗会在一定几率下抓住摘取果实的好友","saleOut" : false}, "9002" : {"tId" : 9002,"tName" : "狗粮5送2礼包","price" : 0,"FBPrice" : 20,"YFBPrice" : 15,"timeLimit" : 0,"type" : 909090,"effect" : "","depict" : "一次性购买5天狗粮,可额外获赠2天狗粮,让狗狗为你看守农场一周","saleOut" : false}}; 熟悉js的人,看出来了,对象就是键值对的组合.

...全文
64 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
semisage 2010-11-25
膜拜楼主啊,这么好的帖子没人顶.
同时也帮我解答了心中的疑问,现在好多大型网站都是PHP ASP做的,难道ASP.NET比他们差些?
回复
zy91000 2010-08-09
来看一个具体的数据库转换成对象[php中数组,jscript中的json对象]


while($value = $_QFG['db']->fetch_array($query)) { $list[] = $value;}




我使用了Smart ASP 后的代码:


代码
/* 获取某人信息 @uid 用户id @tofriend 好友信息 == 查看别人的农场 @return */ getAll:function(uid,tofriend){ var sql = "SELECT C.money,C.username,C.uid,C.yb,C.vip,C.pf,C.tianqi,N.Status,N.reclaim,N.nc_e,N.exp,N.taskid,N.badnum,N.dog,N.decorative,N.activeItem,N.healthMode FROM uchome_qqfarm_config C Left JOIN uchome_qqfarm_nc N ON N.uid=C.uid where C.uid=?"; if(tofriend){ sql = "SELECT C.uid,C.username,C.money,C.pf,C.yb,N.Status,N.reclaim,N.exp,N.taskid,N.badnum,N.dog,N.decorative,N.activeItem,N.healthMode FROM uchome_qqfarm_config C Left JOIN uchome_qqfarm_nc N ON N.uid=C.uid where C.uid=?"; } var db=getconn(); var params = [ db.createParam("uid", "int",uid, 11) ]; db.connect(); var rs = db.executeReader(sql,params); var list = new Array(); list= db.rsToJson(rs); db.close(); return list; }
回复
zy91000 2010-08-09
php代码: 提示信息,他是组装字符串


代码
//提示信息if((int)$vip1['valid'] > $_QFG['timestamp']) { $vipquantity = 2; $levelup_arr = '{"title":"升级奖励","direction":"这么快就升级到' . $levelups[$levelup_exp]['level'] . '级了啊?真是神速,奖励你' . $levelups[$levelup_exp]['eDesc'] . ',快到背包里看看吧。","item":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"level":' . $levelups[$levelup_exp]['level'] . ',"vipItem":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"vipText":"你是VIP用户,还可额外再获赠以下奖励:"}'; } else{ $vipquantity = 1; $levelup_arr = '{"title":"升级奖励","direction":"这么快就升级到' . $levelups[$levelup_exp]['level'] . '级了啊?真是神速,奖励你' . $levelups[$levelup_exp]['eDesc'] . ',快到背包里看看吧。","item":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"level":' . $levelups[$levelup_exp]['level'] . '}';}



使用JScript翻译过来,可以直接使用json形式


代码
//提示信息if(parseInt($vip1["valid"]) > timestamp ) { $vipquantity = 2; $levelup_arr = {"title":"升级奖励","direction":"这么快就升级到" + $levelups[$levelup_exp]["level"] + "级了啊?真是神速,奖励你" + $levelups[$levelup_exp]["eDesc"]+ ",快到背包里看看吧。","item":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"level": $levelups[$levelup_exp]["level"] ,"vipItem":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"vipText":"你是VIP用户,还可额外再获赠以下奖励:"}; } else{ $vipquantity = 1; $levelup_arr = {"title":"升级奖励","direction":"这么快就升级到" + $levelups[$levelup_exp]["level"] + "级了啊?真是神速,奖励你"+ $levelups[$levelup_exp]["eDesc"] +",快到背包里看看吧。","item":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"level": $levelups[$levelup_exp]["level"] };}

回复
zy91000 2010-08-09
熟悉js的人,看出来了,对象就是键值对的组合.



里面还使用了大量的遍历对象的操作 foreach:


//装饰参数$decorative = qf_decode($list[0]['decorative']);foreach($decorative as $itemtype => $value) { foreach($value as $key => $value1) { if($value1['status'] == 1) { if($_QFG['timestamp'] < $value1['validtime'] || $value1['validtime'] == 1) { $decorative_echo[$itemtype]['itemId'] = $key; } else { unset($decorative[$itemtype][$key]); $isUpdate = 1; $decorative[$itemtype][$itemtype]['status'] = 1; $decorative_echo[$itemtype]['itemId'] = $itemtype; } } else { if($value1['validtime'] != 1 && $_QFG['timestamp'] >= $value1['validtime']) { unset($decorative[$itemtype][$key]); $isUpdate = 1; } } }}



这样的操作对于JScript来说,也很好应对 for .. in :


代码
//装饰参数$decorative = qf_decode($list[0]["decorative"]);var $decorative_echo={};for(var $itemtype in $decorative ) { var $value=$decorative[$itemtype]; $itemtype = parseInt($itemtype); for( $key in $value) { $value1 = $value[$key]; $key = parseInt($key); if($value1["status"] == 1) { if( timestamp < $value1["validtime"] || $value1["validtime"] == 1) { $decorative_echo[$itemtype ] = {"itemId" :$key}; } else { $decorative.splice($decorative[$itemtype][$key]); $isUpdate = 1; $decorative[$itemtype][$itemtype]["status"] = 1; $decorative_echo[$itemtype ] = {"itemId" :$itemtype}; } } else { if($value1["validtime"] != 1 && $_QFG["timestamp"] >= $value1["validtime"]) { $decorative.splice($decorative[$itemtype][$key]); $isUpdate = 1; } } }}
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告