[WOG4.5][外掛] 隱藏商店

版主: 涅魂, 簫哥


涅魂
 
文章: 4463
註冊時間: 2004-01-04 11:17 am
來自: Taiwan
性別: 男生

[WOG4.5][外掛] 隱藏商店

文章涅魂 » 2011-02-20 2:36 am

簡介 寫:作者:涅魂
功能:戰鬥時,有機會遇上商人,可以從商人手中買下一件隨機商品
預覽:圖檔


資料表說明 寫:wog_monster
m_npc: 值為2時,代表是商人NPC

wog_monster_shop: 商人NPC的貨物列表
ms_id: 流水號
m_id: 商人NPC在wog_monster內的m_id
d_id: 商品在wog_df內d_id
item_num: 商品販賣的數量
ms_rate: 商品的出現機率, 0 = 必出現, 100 = 1/100機會出現,但商品項目仍有其他條件限制
ms_money: 商品的價格

wog_monster_shop_log: 玩家遭遇到商人時,會在此表格內留下紀錄
p_id: 玩家在wog_player內的p_id
m_id: 商人NPC在wog_monster內的m_id
ms_list: 遭遇到商人時,自動建立的商品列表

程式說明 寫:重點在wog_fight_select.php內的取得商品列表處
查詢時的基本條件是列出7件商品,由於程式沒有針對無商品進行除錯,請確保所有商人至少有一件物品能賣


SQL代碼(UTF-8) 寫:在wog_monster內加入商人資料
代碼: 選擇全部
INSERT INTO `wog_monster` VALUES (NULL, 0, 0, 0, 0, 0, '平原旅行商人', 1, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, '0', '0', 1, 0, NULL, 0, 0, 2, '真巧啊,最近剛從外地進了些少見的東西,說不定會有你喜歡的呢。');

新增wog_monster_shop與wog_monster_shop_log兩個資料表
代碼: 選擇全部
CREATE TABLE `wog_monster_shop` (
  `ms_id` int(10) unsigned NOT NULL auto_increment,
  `m_id` int(10) unsigned default '0',
  `d_id` int(10) unsigned default '0',
  `item_num` tinyint(3) unsigned default '0',
  `ms_rate` smallint(4) unsigned default '0',
  `ms_money` int(10) unsigned default NULL,
  PRIMARY KEY  (`ms_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

CREATE TABLE `wog_monster_shop_log` (
  `p_id` int(10) unsigned NOT NULL default '0',
  `m_id` int(10) unsigned default '0',
  `ms_list` varchar(100) collate utf8_unicode_ci default NULL,
  PRIMARY KEY  (`p_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


程式修改 寫:開啟檔案:wog_act.php
尋找
代碼: 選擇全部
   case "shop":
      include_once("./class/wog_item_tool.php");
      $wog_item_tool = new wog_item_tool;
      include_once("./class/wog_act_shop.php");
      $wog_act_class = new wog_act_shop;
      switch ($_POST["act"])
      {
         case "view":
            $wog_act_class->shop($_COOKIE["wog_cookie"]);
         break;
         case "buy":
            $wog_act_class->buy($_COOKIE["wog_cookie"]);
         break;
         case "check_item":
            $wog_act_class->check_item($_COOKIE["wog_cookie"]);
         break;
      }
      unset($wog_item_tool);
   break;

改成
代碼: 選擇全部
   case "shop":
      include_once("./class/wog_item_tool.php");
      $wog_item_tool = new wog_item_tool;
      include_once("./class/wog_act_shop.php");
      $wog_act_class = new wog_act_shop;
      switch ($_POST["act"])
      {
         case "view":
            $wog_act_class->shop($_COOKIE["wog_cookie"]);
         break;
         case "buy":
            $wog_act_class->buy($_COOKIE["wog_cookie"]);
         break;
         case "check_item":
            $wog_act_class->check_item($_COOKIE["wog_cookie"]);
         break;
         case 'mshop_buy':
            $wog_act_class->mshop_buy($_COOKIE["wog_cookie"]);
            break;
      }
      unset($wog_item_tool);
   break;


開啟檔案 class/wog_act_shop.php

尋找
代碼: 選擇全部
}
?>

上方,加上
代碼: 選擇全部
   function mshop_buy($user_id)
   {
      global $DB_site,$a_id,$lang,$wog_arry,$wog_item_tool;
      $temp["money"]="d_money";
      $temp["table"]="wog_df";
      $ms_id = intval($_POST['ms_id'], 10);
      //$buy_num=$_POST["buy_num"];
      if(!isset($_POST["ms_id"]))
      {
         alertWindowMsg($lang['wog_act_buy_noitem']);
      }
      //檢查LOG是否存在
      $log = $DB_site->query_first('SELECT * FROM wog_monster_shop_log WHERE p_id='.$user_id);
      if(!$log) alertWindowMsg('錯誤的操作');
      //檢查MSID是否存在於list內
      $list = explode(',', $log['ms_list']);
      //alertWindowMsg($ms_id.' -> '.$log['ms_list']);
      if(!in_array($ms_id, $list)) alertWindowMsg('錯誤的操作');
      //檢查物品是否存在
      $item = $DB_site->query_first('
         SELECT a.d_id, a.d_type, b.item_num, b.ms_money
         FROM wog_df a, wog_monster_shop b
         WHERE b.ms_id='.$ms_id.' AND a.d_id=b.d_id
      ');
      if(!$item) alertWindowMsg('錯誤的操作');
      
      //if(empty($buy_num)){$buy_num=1;}
      if($item['d_type'] == 11) $item['d_type'] = 5;
      check_type($item['d_type'],1);
      $DB_site->query_first("set autocommit=0");
      $DB_site->query_first("BEGIN");
      
      $sql="select ".$a_id." from wog_item where p_id=".$user_id." for update";
      $pack=$DB_site->query_first($sql);
      $pack[0]=trim($pack[0]);
      $temp_pack=array();
      if(!empty($pack[0]))
      {
         $temp_pack=explode(",",$pack[0]);
      }
      $have_price=$DB_site->query_first("select p_money,p_bag from wog_player where p_id=".$user_id." for update");
      if($a_id=="d_item_id")
      {
         $temp_pack=$wog_item_tool->item_in($temp_pack,$item['d_id'],$item['item_num']);
         //$must_price[0]=$must_price[0]*$buy_num;
         $bag=$wog_arry["item_limit"]+$have_price["p_bag"];
      }else
      {
         $temp_pack=$wog_item_tool->item_in($temp_pack,$item['d_id']);
         $bag=$wog_arry["item_limit"];
      }
      if($item['ms_money']>$have_price[0]){
         alertWindowMsg($lang['wog_act_nomoney']);
      }
      if(count($temp_pack) > $bag)
      {
         alertWindowMsg(sprintf($lang['wog_act_buy_tenitem'],$bag));
         unset($temp_pack);
      }

      $DB_site->query("update wog_player set p_money=p_money-".$item['ms_money']." where p_id=".$user_id);
      if($pack)
      {
         $pack[0]=implode(',', $temp_pack);
         $DB_site->query("update wog_item set ".$a_id."='".$pack[0]."' where p_id=".$user_id);
      }else
      {
         $pack[0]=implode(',', $temp_pack);
         $DB_site->query("insert into wog_item(".$a_id.",p_id)values('".$pack[0]."',".$user_id.")");
      }
      //$DB_site->query('DELETE FROM wog_monster_shop_log WHERE p_id="'.$user_id.'"');
      $DB_site->query_first("COMMIT");
      showscript('parent.job_end(6)');
      unset($pack,$temp_add,$must_price,$have_price,$temp,$a_id);

   }


開啟檔案:class/wog_fight_select.php

IN fire() function

尋找
代碼: 選擇全部
               if($m["m_npc"]==1)
            {
            ...
            }else
            {

改成
代碼: 選擇全部
            if($m["m_npc"]==1)
            {
            ...
            }elseif($m['m_npc'] == 2) {
               $DB_site->query('DELETE FROM wog_monster_shop_log WHERE p_id='.$user_id);
               //取得商品列表
               $query = $DB_site->query('
                  SELECT a.ms_id, a.d_id, a.item_num, a.ms_money, b.d_name
                  FROM wog_monster_shop a
                     LEFT JOIN wog_df b ON b.d_id=a.d_id
                  WHERE a.m_id='.$m['m_id'].' AND a.ms_rate <= '.rand(1, 100).'
                  ORDER BY RAND()
                  LIMIT 7
               ');
               $list = array();
               $data = array();
               while($d = $DB_site->fetch_array($query)) {
                  $list[] = $d['ms_id'];
                  $data[] = $d['ms_id'].','.$d['d_name'].'*'.$d['item_num'].','.$d['ms_money'];
               }
               if(count($list) > 0) {
                  $list = implode(',', $list);
                  $data = implode(';', $data);
                  $DB_site->query('INSERT INTO wog_monster_shop_log(p_id, m_id, ms_list)VALUES('.$user_id.', '.$m['m_id'].', "'.$list.'")');
                  $m['m_npc_message']=str_replace("\r\n","&n",$m['m_npc_message']);
                  echo 'parent.mshop_view("'.$m['m_name'].'", "'.$m['m_img'].'", "'.$m['m_npc_message'].'", "'.$data.'");';
               }
            }else
            {



開啟檔案 js/wog_shop.js

最底,加上
代碼: 選擇全部
function mshop_view(name, img, message, mslist) {
   setup_mname(name);
   if(!img) {
      img = "no_img.jpg";
   }
   if(img.indexOf('http') == -1) {
      img = mimg+img;
   }
   w_c('<form action="wog_act.php" method="post" target="mission" name=f1 >');
   w_c(temp_table1);
   w_c('<tr class="head_td"><td colspan="2">商店</td></tr>');
   w_c('<tr><td>'+name+'<br/><img src="'+img+'"/></td><td>'+message+'</td></tr>');
   w_c(temp_table2);
   w_c(temp_table1);
   w_c('<thead><tr class="head_td"><td>選取</td><td>商品</td><td>價格</td></tr></thead>');
   w_c('<tfoot><tr class="head_td"><td colspan="3"><input type="submit" value="購買"/></td></tr></tfoot>');
   w_c('<tbody>');
   mslist = mslist.split(';');
   for(i = 0, len = mslist.length; i < len; ++i) {
      var str = mslist[i].split(',');
      w_c('<tr><td><input type="radio" name="ms_id" value="'+str[0]+'"></td><td>'+str[1]+'</td><td>'+str[2]+'</td></tr>');
   }
   w_c('</tbody>');
   w_c(temp_table2);
   w_c('<input type="hidden" name="f" value="shop"/>');
   w_c('<input type="hidden" name="act" value="mshop_buy"/>');
   w_c('</form>');
   p_c();
}


儲存、關閉所有檔案


有任何問題請回覆,感謝~


圖檔


ETERNAL
 
文章: 2937
註冊時間: 2003-12-03 11:08 pm
性別: 男生

Re: [WOG4.5][外掛] 隱藏商店

文章ETERNAL » 2011-02-20 10:38 am

這東西很不錯耶 蠻好玩的


水色論壇 http://www.et99.net
簡恩峻分享

s960501
 
文章: 94
註冊時間: 2010-07-03 2:12 pm

Re: [WOG4.5][外掛] 隱藏商店

文章s960501 » 2011-02-20 7:14 pm

ET大
你也裝這個吧
看起來可以讓WOG更有趣




涅魂
 
文章: 4463
註冊時間: 2004-01-04 11:17 am
來自: Taiwan
性別: 男生

Re: [WOG4.5][外掛] 隱藏商店

文章涅魂 » 2011-02-20 10:05 pm

ETERNAL 寫:這東西很不錯耶 蠻好玩的

當時在做時還有想到其他延伸功能,像是魔石專賣店,或接任務時才出現的稀有商人,或是定期改變出現地點的商人等等

或許還能幫玩家另闢財路? :lol:


圖檔


回到 外掛區

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 3 位訪客

cron