研究了涅魂大的這篇,看不懂是怎麼把裝備從陣列取出來..
所以只能把迴圈改進,這樣差不多能快個2,30%
0.00012 與 0.00015 的差別..
測試過沒有問題,不過不保證一定沒bug
發現bug請回報,謝謝~
----2011/04/24----
修改item_out一個bug
修改item_in,使同類道具以剩餘數量小到大排列
----2011/04/30----
修改item_in道具bug
----2011/05/05----
修改item_in道具bug
支援多個裝備out&in
修改步驟:覆蓋兩function,不能只覆蓋其一function,不然item裝備欄會出問題。
- 代碼: 選擇全部
function item_out($user_id,$item_id,$item_num=1,$item_now=null)
{
global $lang,$a_id;
if($item_num < 0 || $item_num > $this->itemMax){
alertWindowMsg($lang['wog_act_errdate']);
}
$temp_pack=$this->dataCheck($item_now,$user_id);
if($a_id == 'd_item_id'){
foreach($temp_pack as $key => $value){
$temp_packs=explode("*",$value);
if($item_id == $temp_packs[0]){
unset($temp_pack[$key]);
$remain_num=$temp_packs[1]-$item_num;
if($remain_num < 1){
$item_num-=$temp_packs[1];
}else{
$temp_pack[]=$temp_packs[0].'*'.$remain_num;
$item_num=0;
}
}
if($item_num == 0) break;
}
if($item_num > 0){
alertWindowMsg($lang['wog_act_errnum']."--".$item_num);
}
}else{
if(in_array($item_id,$temp_pack)){
foreach($temp_pack as $key => $value){
if($item_id == $value){
unset($temp_pack[$key]);
$item_num-=1;
}
if($item_num == 0) break;
}
if($item_num > 0){
alertWindowMsg($lang['wog_act_errnum']);
}
}else{
alertWindowMsg($lang['wog_act_errnum']);
}
}
return $temp_pack;
}
- 代碼: 選擇全部
function item_in($temp_pack,$adds,$buy_num=0)
{
global $a_id;
if($a_id == 'd_item_id'){
foreach($temp_pack as $key => $value){
$temp_packs=explode("*",$value);
if($adds == $temp_packs[0]){
unset($temp_pack[$key]);
$temp_packs[1]+=$buy_num;
if($temp_packs[1] > $this->itemMax){
$buy_num=$temp_packs[1]-$this->itemMax;
$temp_packs[1]=$this->itemMax;
$temp_pack[]=$adds.'*'.$buy_num;
}
$buy_num=0;
$temp_pack[]=$adds.'*'.$temp_packs[1];
break;
}
}
if($buy_num != 0){
$temp_pack[]=$adds.'*'.$buy_num;
}
}else{
if($buy_num > 1){
for($i=0;$i<$buy_num;$i++){
$temp_pack[]=$adds;
}
}else{
$temp_pack[]=$adds;
}
}
return $temp_pack;
}