因為我是用utf-8,請使用big5的站長自行更改成big5編碼,不便之處請見諒
可能因為疏忽忘了貼上其他修改,有任何錯誤請回報回覆
簡介
外掛名稱:以物易物
外掛作者:stu6707
版本:1.0ss_mm
功能:支持單數量單物品換取多數量多物品
-------2011/2/16-------
修復bug - 買家裝備取出裝備後為空時將不會更新背包
更新程式碼 - 減少對資料庫查詢次數,程式運作速度略為增加,如果換取物品為同一類裝備速度增加幅度較大
在資料庫中輸入下列語法
CREATE TABLE `wog_barter` (
`s_id` int(10) unsigned NOT NULL auto_increment,
`p_id` int(11) NOT NULL default '0',
`d_id` int(11) NOT NULL,
`b_id` varchar(40) collate utf8_unicode_ci NOT NULL,
`b_no` varchar(20) collate utf8_unicode_ci NOT NULL,
`b_name` text collate utf8_unicode_ci NOT NULL,
`dateline` int(11) NOT NULL default '0',
PRIMARY KEY (`s_id`)
)
開啟wog.js,找function sale_item(s),f.write('</form>');後面加上
- 代碼: 選擇全部
f.write(hr);
f.write('<form action="wog_act.php" method="post" target="mission">');
f.write(temp_table1);
f.write('<tr><td colspan="3">以物易物</td></tr>');
f.write('<tr><td width=25%>交易物品</td><td width=10%>交易時間</td><td width=65%>換取物品</td></tr>');
f.write('<tr><td>'+s1[1]+'</td><td><input type="text" name="barter_day" size="2" maxlength="2"> 天</td>');
f.write('<td><input type="text" name="want_item" size="65"></td></tr>');
f.write('<tr><td colspan="3"><input type="submit" class="Button" value="開始交易"></td></tr>');
f.write(temp_table2);
f.write('<input type="hidden" name="f" value="barter">');
f.write('<input type="hidden" name="act" value="place">');
f.write('<input type="hidden" name="bitem_id" value="'+s1[0]+'">');
f.write('</form>');
找空位放儲存關閉
- 代碼: 選擇全部
function barter_view(saletotal,page,s,type)
{
message_cls();
var f=parent.wog_view.document;
f.write('<form action="wog_etc.php" method="get" name="pageform" target="mission">');
pagesplit(saletotal,page);
f.write('<input type="hidden" name="page" value="1">');
f.write('<input type="hidden" name="type" value="'+type+'">');
f.write('<input type="hidden" name="f" value="barter">');
f.write('<input type="hidden" name="act" value="view">');
f.write('</form>');
f.write('<form action="wog_act.php" method="post" target="mission" name=f1>');
f.write(temp_table1);
f.write('<tr><td colspan="13"><a href=javascript:parent.sel_type("0");>武器</a> <a href=javascript:parent.sel_type("1");>頭部</a> <a href=javascript:parent.sel_type("2");>身體</a> <a href=javascript:parent.sel_type("3");>手套</a> <a href=javascript:parent.sel_type("4");>鞋子</a> <a href=javascript:parent.sel_type("5");>道具</a></td></tr>');
f.write('<tr><td colspan="13">拍賣商品</td></tr>');
f.write('<tr><td>選擇</td><td>拍賣者</td><td>商品</td><td>物攻</td><td>魔攻</td><td>物防</td><td>魔防</td><td>速度</td><td>能力限制</td><td>交換物品</td><td>原價</td><td>剩餘日</td></tr>');
if(s!="")
{
var s1=s.split(";");
for(var i=0;i<s1.length;i++)
{
var s2=s1[i].split(",");
var now_date=new Date();
var sale_day=Math.ceil((s2[2]-(now_date.getTime()/1000))/(60*60*24));
f.write('<tr><td><input type="radio" name="s_id" value="'+s2[0]+'"></td><td>'+s2[3]+'</td><td>'+s2[11]+'</td><td>'+s2[12]+'</td><td>'+s2[13]+'</td><td>'+s2[4]+'</td><td>'+s2[5]+'</td><td>'+s2[6]+'</td><td>力:'+s2[7]+' 速:s'+2[8]+' 智:'+s2[9]+'</td><td>');
f.write(s2[1].replace(/#/g," "))
f.write('</td><td>'+s2[10]+'</td><td>'+sale_day+'</td></tr>');
}
}
f.write('<input type="hidden" name="stype" value="0">');
f.write('<tr><td><br></td></tr><tr><td colspan="13"><input type="submit" class="Button" value="交易"></td></tr>');
f.write(temp_table2);
f.write('<input type="hidden" name="f" value="barter">');
f.write('<input type="hidden" name="act" value="trade">');
f.write('</form>');
}
開啟wog_act.php,找後面加上
- 代碼: 選擇全部
case "pk":
...
break;儲存關閉
- 代碼: 選擇全部
case "barter":
include_once("./class/wog_item_tool.php");
$wog_item_tool = new wog_item_tool;
include("./class/wog_act_barter.php");
$wog_act_class = new wog_act_barter;
switch ($_POST["act"])
{
case "place":
$wog_act_class->barter_place($HTTP_COOKIE_VARS["wog_cookie"]);
break;
case "trade":
$wog_act_class->barter_trade($HTTP_COOKIE_VARS["wog_cookie"]);
break;
}
unset($wog_item_tool);
break;
新增class/wog_act_barter.php
- 代碼: 選擇全部
<?
/***************************************************************************
外掛名稱: 以物易物
外掛作者: stu6707 <http://azurestars.twbbs.org/wog/>
外掛版本: 1.0ss_mm
功能:支持單數量單物品換取多數量多物品
***************************************************************************/
class wog_act_barter{
function barter_place($user_id)
{
global $DB_site,$_POST,$a_id,$temp_ss,$wog_arry,$lang,$wog_item_tool;
$day=$_POST["barter_day"];
$temp_b_item="";
if(empty($day) || empty($_POST["want_item"]))
{
alertWindowMsg($lang['wog_act_bid_nodate']);
}
if(empty($_POST["bitem_id"]))
{
alertWindowMsg($lang['wog_act_arm_noselect']);
}
if($day<0 || !is_numeric($_POST["barter_day"]) )
{
alertWindowMsg($lang['wog_act_bid_nodate']);
}
if($day>$wog_arry["sale_day"])
{
alertWindowMsg(sprintf($lang['wog_act_bid_limitday'],$wog_arry["sale_day"]));
}
$total=$DB_site->query_first("select count(s_id) as s_id from wog_barter where p_id=".$user_id." ");
if($total[0]>=5)
{
alertWindowMsg("交易的商品不能超過5樣");
}
$sql="select d_send from wog_df where d_id=".$_POST["bitem_id"]." ";
$pay=$DB_site->query_first($sql);
if($pay[0]==1)
{
alertWindowMsg($lang['wog_act_arm_nosend']);
}
//檢驗交換物品 begin
$_POST["want_item"]=trim($_POST["want_item"]);
$want_item=explode(",",$_POST["want_item"]);
if(count($want_item) > 5){alertWindowNsg("欲交換物品不能超過5樣");}
$item_1=array();
$item_2=array();
for($i=0;$i<count($want_item);$i++)
{
$w_item{$i}=explode("*",$want_item[$i]);
$item_1[]=$w_item{$i}[0];
$item_2[]=$w_item{$i}[1];
$item_iden{$i}=$DB_site->query_first("select d_id,d_type,d_send from wog_df where d_name='".$w_item{$i}[0]."'");
if($w_item{$i}[1] < 1)
{
alertWindowMsg($lang['wog_act_bid_nodate']);
}
if(!$item_iden{$i})
{
alertWindowMsg($lang['wog_act_bid_nodate']);
}
if($item_iden{$i}[2]==1)
{
alertWindowMsg("欲交換物品為綁定物品");
}
$temp_w_item.=",".$item_iden{$i}[0];
$temp_w_no.=",".$w_item{$i}[1];
$temp_name.="#".$w_item{$i}[0]."*".$w_item{$i}[1];
}
$temp_w_item=substr($temp_w_item,1,strlen($temp_w_item));
$temp_w_no=substr($temp_w_no,1,strlen($temp_w_no));
$temp_name=substr($temp_name,1,strlen($temp_name));
//檢驗交換物品 end
check_type($_POST["bitem_id"]);
$temp_ss=$wog_item_tool->item_out($user_id,$_POST["bitem_id"]);
$cost=$wog_arry["barter_cost"];
$have_price=$DB_site->query_first("select p_money from wog_player where p_id=".$user_id." and p_lock=0");
if($have_price)
{
if($have_price["p_money"]<$cost)
{
alertWindowMsg("您必須支付 $cost 手續費才能交易");
}
$DB_site->query("update wog_player set p_money=p_money-".$cost." where p_id=".$user_id." ");
}else
{
alertWindowMsg($lang['wog_act_nologin']);
}
$DB_site->query("update wog_item set ".$a_id."='".implode(',',$temp_ss)."' where p_id=".$user_id." ");
$DB_site->query("insert wog_barter(p_id,d_id,b_id,b_no,b_name,dateline)values(".$user_id.",".$_POST["bitem_id"].",'".$temp_w_item."','".$temp_w_no."','".$temp_name."',".(time()+($day*24*60*60)).")");
showscript("parent.job_end(9)");
unset($pay,$a_id);
}
function barter_trade($user_id)
{
global $DB_site,$_POST,$a_id,$lang,$wog_arry,$wog_item_tool;
if(!isset($_POST["s_id"]))
{
alertWindowMsg($lang['wog_act_arm_noselect']);
}
$pack=$DB_site->query_first("select a.p_id,a.b_id,a.b_no,a.b_name,b.d_id,b.d_name,b.d_type,c.p_name from wog_barter a,wog_df b,wog_player c where a.s_id=".$_POST["s_id"]." and b.d_id=a.d_id and c.p_id=a.p_id");
if(!$pack)
{
alertWindowMsg($lang['wog_act_bid_buyed']);
}
if(empty($pack[4]))
{
alertWindowMsg($lang['wog_act_arm_noselect']);
}
$have_price=$DB_site->query_first("select p_name,p_lv,p_bag from wog_player where p_id=".$user_id);
if($have_price[1] < 15)
{
alertWindowMsg(sprintf($lang['wog_act_cant_bid'],15));
}
$item_name=str_replace("#"," ",$pack[3]);
// 從買家身上取出b_id and 將b_id放入賣家 begin
$b_item=explode(",",$pack[1]);
$b_no=explode(",",$pack[2]);
$item_no=count($b_item);
$seller=$DB_site->query_first("select p_bag from wog_player where p_id=".$pack[0]);
for($i=0;$i<$item_no;$i++)
{
${b_type.$i}=check_type($b_item[$i]);
if($i==0)
{
$bag1=$this->first_item_out(${b_type.$i},$user_id,$b_item[0],$b_no[0]);
$bag2=$this->first_item_in(${b_type.$i},$pack[0]);
${itemout.$i}=$this->b_item_out($user_id,$b_item[0],$b_no[0],$bag1,${b_type.$i});
${itemin.$i}=$this->b_item_in($bag2,$b_item[0],$b_no[0],${b_type.$i});
unset($bag1,$bag2);
}else
{
${chk.$i}=false;
for($z=0;$z<$i;$z++)
{
if(${b_type.$i}==${b_type.$z})
{
${itemout.$i}=$this->b_item_out($user_id,$b_item[$i],$b_no[$i],${itemout.$z},${b_type.$i});
${itemin.$i}=$this->b_item_in(${itemin.$z},$b_item[$i],$b_no[$i],${b_type.$i});
${chk.$i}=true;
unset(${itemout.$z},${itemin.$z});
}
else if($z==($i-1) && ${chk.$i}==false)
{
$bag3=$this->first_item_out(${b_type.$i},$user_id,$b_item[$i],$b_no[$i]);
$bag4=$this->first_item_in(${b_type.$i},$pack[0]);
${itemout.$i}=$this->b_item_out($user_id,$b_item[$i],$b_no[$i],$bag3,${b_type.$i});
${itemin.$i}=$this->b_item_in($bag4,$b_item[$i],$b_no[$i],${b_type.$i});
unset($bag3,$bag4);
}
}
}
if(count(${itemin.$i})>($wog_arry["item_limit"]+$seller[0]))
{
$DB_site->query("insert into wog_message(p_id,title,dateline)values(".$pack[0].",'【以物易物】您的裝備欄滿了,無法完成交易 以 ".$pack[5]." 換取 ".$item_name."',".time().")");
alertWindowMsg("賣家裝備欄滿了");
}
}
// 從買家身上取出b_id and 將b_id放入賣家 end
// 將d_id放入買家 begin
check_type($pack['d_type'],1);
$d_chk=false;
for($d=0;$d<$item_no;$d++)
{
if($a_id==${b_type.$d} && is_array(${itemout.$d}))
{
$b_itemout=$this->b_item_in(${itemout.$d},$pack[4],1,$a_id);
$d_chk=true;
unset(${itemout.$d});
}
else if($d==($item_no-1) && $d_chk==false)
{
$d_bag=$DB_site->query_first("select ".$a_id." from wog_item where p_id=".$user_id);
$d_bag2=array();
if(!empty($d_bag[0]))
{
$d_bag2=explode(",",$d_bag[0]);
unset($d_bag);
}
$b_itemout=$this->b_item_in($d_bag2,$pack[4],1,$a_id);
unset($d_bag2);
}
}
if(count($b_itemout)>($wog_arry["item_limit"]+$have_price[2]))
{
alertWindowMsg($lang['wog_act_bid_full']);
}
// 將d_id放入買家 end
$DB_site->query("insert into wog_message(p_id,title,dateline)values(".$pack[0].",'【以物易物】".$have_price[0]." 以 ".$item_name." 成功換取您的 ".$pack[5]."',".time().")");
$DB_site->query("insert into wog_message(p_id,title,dateline)values(".$user_id.",'【以物易物】您以 ".$item_name." 成功換取 ".$pack[7]." 的 ".$pack[5]."',".time().")");
for($y=0;$y<$item_no;$y++)
{
if(is_array(${itemout.$y}))
{
$DB_site->query("update wog_item set ".${b_type.$y}."='".implode(',',${itemout.$y})."' where p_id=".$user_id);
}
if(is_array(${itemin.$y}))
{
$DB_site->query("update wog_item set ".${b_type.$y}."='".implode(',',${itemin.$y})."' where p_id=".$pack[0]);
}
unset(${b_type.$y},${itemout.$y},${itemin.$y});
}
$DB_site->query("update wog_item set ".$a_id."='".implode(',',$b_itemout)."' where p_id=".$user_id);
$DB_site->query("delete from wog_barter where s_id=".$_POST["s_id"]);
unset($pack,$have_price,$a_id,$seller,$b_itemout);
showscript("parent.job_end(6)");
}
function barter_view()
{
global $DB_site,$_GET,$a_id,$wog_arry,$wog_item_tool;
$ttime=time();
$pack=$DB_site->query("select b.d_type,b.d_id,a.p_id from wog_barter a,wog_df b where a.dateline < ".$ttime." and a.d_id=b.d_id ");
while($packs=$DB_site->fetch_array($pack))
{
check_type($packs[0],1);
$sql="select ".$a_id." from wog_item where p_id=".$packs[2]."";
$pack2=$DB_site->query_first($sql);
$temp_pack=array();
if(!empty($pack2[0]))
{
$temp_pack=explode(",",$pack2[0]);
}
$bag=$DB_site->query_first("select p_bag from wog_player where p_id=".$packs[2]);
$bbag=$wog_arry["item_limit"]+$bag[0];
if($a_id=="d_item_id")
{
$temp_pack=$wog_item_tool->item_in($temp_pack,$packs["d_id"],1);
}else
{
$temp_pack=$wog_item_tool->item_in($temp_pack,$packs["d_id"]);
}
if(count($temp_pack) < $bbag)
{
$DB_site->query("update wog_item set ".$a_id."='".implode(',',$temp_pack)."' where p_id=".$packs[2]."");
}
}
$DB_site->free_result($pack);
unset($temp_pack,$pack,$packs,$pack2);
$DB_site->query("delete from wog_barter where dateline < ".$ttime." ");
if(empty($_GET["type"]) || !is_numeric($_GET["type"]))
{
$_GET["type"]="0";
}
$d_type=$_GET["type"];
if($d_type=="5"){$d_type="5,6";}
$sale_total=$DB_site->query_first("select count(a.s_id) as s_id from wog_barter a,wog_player b,wog_df c where a.p_id=b.p_id and a.d_id=c.d_id and c.d_type in (".$d_type.")");
if(empty($_GET["page"]) || !is_numeric($_GET["page"]))
{
$_GET["page"]="1";
}
$spage=((int)$_GET["page"]*8)-8;
$temp_s="";
$sale=$DB_site->query("select a.s_id,a.b_name,a.dateline,b.p_name,c.d_df,c.d_mdf,c.d_agl,c.d_mstr,c.d_magl,c.d_msmart,c.d_money,c.d_name,c.d_at,c.d_mat from wog_barter a,wog_player b,wog_df c where b.p_id=a.p_id and c.d_id=a.d_id and c.d_type in (".$d_type.") ORDER BY a.dateline LIMIT ".$spage.",8 ");
while($sales=$DB_site->fetch_array($sale))
{
$temp_s.=";".$sales[0].",".$sales[1].",".$sales[2].",".$sales[3].",".$sales[4].",".$sales[5].",".$sales[6].",".$sales[7].",".$sales[8].",".$sales[9].",".$sales[10].",".$sales[11].",".$sales[12].",".$sales[13];
}
$DB_site->free_result($sale);
unset($sales);
$temp_s=substr($temp_s,1,strlen($temp_s));
showscript("parent.barter_view($sale_total[0],".$_GET["page"].",'$temp_s',".$_GET["type"].")");
unset($temp_s,$sale_total);
}
function first_item_out($type,$id,$item,$no)
{
global $DB_site;
$bag=$DB_site->query_first("select ".$type." from wog_item where p_id=".$id." and ".$type." LIKE '%".$item."%'");
if(!$bag || empty($bag[0]) || is_null($bag[0]))
{
alertWindowMsg("錯誤物品數量");
}
$count=explode(",",$bag[0]);
if($type!='d_item_id' && count($count) < $no)
{
alertWindowMsg("錯誤物品數量");
}
return $bag[0];
unset($bag);
}
function first_item_in($type,$id)
{
global $DB_site;
$bag=$DB_site->query_first("select ".$type." from wog_item where p_id=".$id);
$b_bag=array();
if(!empty($bag[0]))
{
$b_bag=explode(",",$bag[0]);
unset($ch2);
}
return $b_bag;
}
function b_item_out($user_id,$item,$no,$bag,$type)
{
global $wog_item_tool;
switch ($type)
{
default:
for($a=0;$a<$no;$a++){
if($a==0){
${temp_item.$a}=$wog_item_tool->item_out($user_id,$item,1,$bag);
}else{
$b=$a-1;
${temp_item.$a}=$wog_item_tool->item_out($user_id,$item,1,${temp_item.$b});
}
if($a==($no-1)){
$temp_item=${temp_item.$a};
}
}
break;
case "d_item_id":
$temp_item=$wog_item_tool->item_out($user_id,$item,$no,$bag);
break;
}
return $temp_item;
}
function b_item_in($bag,$item,$no,$type)
{
global $wog_item_tool;
switch ($type)
{
default:
for($a=0;$a<$no;$a++){
if($a==0){
${temp_item.$a}=$wog_item_tool->item_in($bag,$item,1);
}else{
$b=$a-1;
${temp_item.$a}=$wog_item_tool->item_in(${temp_item.$b},$item,1);
}
if($a==($no-1)){
$temp_item=${temp_item.$a};
}
}
break;
case "d_item_id":
$temp_item=$wog_item_tool->item_in($bag,$item,$no);
break;
}
return $temp_item;
}
}
?>
物品輸入格式
(1) 木刀*2,捕捉器*5
(2) 布衣*1
(3) 物品1*數量1,物品2*數量2,物品3*數量3