// 自动买药 public bool OnAutoBuyDrug(int nId) { bool IsBuy = false; int ShopId = 3; int itemIdex = -1; Tab_SystemShop curShop = TableManager.GetSystemShopByID(ShopId, 0); if (curShop != null) { for (int i = 0; i < curShop.Pnum; i++) { if (nId == curShop.GetPidbyIndex(i)) { IsBuy = true; itemIdex = i; break; } } if (IsBuy) //可以买 { CG_SYSTEMSHOP_BUY buyPacket = (CG_SYSTEMSHOP_BUY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_BUY); buyPacket.SetBuyNum(1); buyPacket.SetShopId(ShopId); buyPacket.SetMercIndex(itemIdex); buyPacket.SendPacket(); } } return(true); }
public uint Execute(PacketDistributed ipacket) { CG_SYSTEMSHOP_BUY packet = (CG_SYSTEMSHOP_BUY )ipacket; if (null == packet) { return((uint)PACKET_EXE.PACKET_EXE_ERROR); } //enter your logic return((uint)PACKET_EXE.PACKET_EXE_CONTINUE); }
// 购买物品 public static void BuyItem(string strItemIndex, int count) { int curItemIndex; bool bCanGetID = int.TryParse(strItemIndex, out curItemIndex); if (!bCanGetID) { LogModule.ErrorLog("cur item id set error!"); return; } Tab_SystemShop sysShopTable = TableManager.GetSystemShopByID(m_curShopID, 0); if (null == sysShopTable) { LogModule.ErrorLog("cur sysshop id isn't exist! : id " + m_curShopID.ToString()); return; } int pid = sysShopTable.GetPricebyIndex(curItemIndex); if (pid < 0) { LogModule.ErrorLog("can not find cur item pid : itemID" + pid.ToString()); return; } if (count < ITEMCOUNT_MIN || count > ITEMCOUNT_MAX) { LogModule.ErrorLog("item count is out range : count " + count.ToString()); return; } CG_SYSTEMSHOP_BUY buyPacket = (CG_SYSTEMSHOP_BUY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_BUY); buyPacket.SetBuyNum(count); buyPacket.SetShopId(m_curShopID); buyPacket.SetMercIndex(curItemIndex); buyPacket.SendPacket(); }