public void OnLeftMouseCliked(Grid_N grid) { if (grid.ItemObj == null) { return; } if (grid.ItemObj.GetCount() == 0) { new PeTipMsg(PELocalization.GetString(82209007), PeTipMsg.EMsgLevel.Warning); return; } ActiveWnd(); if (mSellOpLayer.gameObject.activeSelf) { return; } SelectItem_N.Instance.SetItem(null); mSellOpLayer.gameObject.SetActive(true); mIsBuy = true; mOpGrid = grid; mOpItem.SetItem(grid.ItemObj); mCurrentNum = 1; if (mCurrentPickTab == 0) { if (m_TypeShopIDList.Count <= grid.ItemIndex) { return; } int shopID = m_TypeShopIDList[grid.ItemIndex]; ShopData shopData = ShopRespository.GetShopData(shopID); if (shopData == null) { mPrice = 0; } else { mPrice = grid.ItemObj.GetBuyPrice(); } } else { mPrice = grid.ItemObj.GetSellPrice(); } mOpNumLabel.text = mCurrentNum.ToString(); mPriceLabel.text = mPrice.ToString(); mTotalLabel.text = mPrice.ToString(); mOKBtn.text = PELocalization.GetString(8000556); }
void UpdateBuyItemList(ItemLabel.Root _type) { //lz-2016.01.03 crash bug 错误 #8074 if (mTypeOfBuyItemList == null || null == mBuyItemList || null == m_TypeShopIDList || null == m_ShopIDList) { return; } mTypeOfBuyItemList.Clear(); for (int i = 0; i < mBuyItemList.Count; i++) { if (_type == ItemLabel.Root.all) { mTypeOfBuyItemList.Add(mBuyItemList[i]); } else { //lz-2017.02.27 错误 #9323 crash bug if (null != mBuyItemList[i] && null != mBuyItemList[i].protoData && null != mBuyItemList[i].protoData) { ItemLabel.Root roottype = mBuyItemList[i].protoData.rootItemLabel; if (roottype == _type) { mTypeOfBuyItemList.Add(mBuyItemList[i]); } } } } m_TypeShopIDList.Clear(); for (int i = 0; i < m_ShopIDList.Count; i++) { if (_type == ItemLabel.Root.all) { m_TypeShopIDList.Add(m_ShopIDList[i]); } else { ShopData sd = ShopRespository.GetShopData(m_ShopIDList[i]); if (sd == null) { continue; } ItemProto data = ItemProto.GetItemData(sd.m_ItemID); if (null != data) { ItemLabel.Root roottype = data.rootItemLabel; if (roottype == _type) { m_TypeShopIDList.Add(m_ShopIDList[i]); } } } } }
public bool BuyItem(int id) { ShopData data = ShopRespository.GetShopData(id); if (data == null) { return(false); } return(true); }
void Buy(Grid_N grid, int num) { //lw:2017.4.6 crash bug :NullReferenceException if (null == m_TypeShopIDList || null == m_ShopIDList) { return; } bool repurchase; int shopID = 0; int cost = 0; if (mCurrentPickTab == 0) { repurchase = false; if (m_TypeShopIDList.Count <= grid.ItemIndex) { return; } shopID = m_TypeShopIDList[grid.ItemIndex]; ShopData data = ShopRespository.GetShopData(shopID); if (data != null) { cost = data.m_Price; } } else { repurchase = true; if (grid.ItemObj.protoData != null) { cost = grid.ItemObj.protoData.currency; mSellOpLayer.gameObject.SetActive(false); } } if (PeGameMgr.IsMulti) { mSellOpLayer.gameObject.SetActive(false); if (repurchase) { PlayerNetwork.mainPlayer.RequestRepurchase(npc.Id, grid.ItemObj.instanceId, num); } else { PlayerNetwork.mainPlayer.RequestBuy(npc.Id, grid.ItemObj.instanceId, num); } return; } else { //lz-2016.09.19 购买失败情况比较多,详细提示放在里面了 if (!StroyManager.Instance.BuyItem(grid.ItemObj, num, shopID, m_CurNpcID, !repurchase)) { //lz-2016.09.19 失败需要返回,避免后面删除Npc的东西和给npc加钱 return; } //if (!PlayerFactory.mMainPlayer.BuyItem(grid.ItemObj, num, shopID, m_CurNpcName, !repurchase)) //{ // MessageBox_N.ShowOkBox(PELocalization.GetString(8000076)); // return; //} } cost *= num; //GameGui_N.Instance.mChatGUI.AddChat(PromptData.PromptType.PromptType_13, grid.ItemObj.protoData.GetName(), num, cost); //if (grid.ItemObj.GetCount() > num) //{ // grid.ItemObj.IncreaseStackCount(num); //} //else //{ // m_CurrentPack[grid.ItemIndex] = null; // grid.SetItem(null); // mOpGrid = null; // if(mCurrentPickTab == 1) // mRepurchaseList.RemoveAt(grid.ItemIndex); //} if (npc != null) { NpcPackageCmpt npcpc = npc.GetCmpt <NpcPackageCmpt>(); if (npcpc == null) { return; } npcpc.money.current += cost; } //lz-2016.09.19 是回购就移除回购的,不是回购就移除正常的 if (repurchase) { RemoveRepurchase(grid.ItemIndex, num); } else { int index = -1; if (grid.ItemIndex < m_TypeShopIDList.Count) { for (int i = 0; i < m_ShopIDList.Count; i++) { if (m_ShopIDList[i] == m_TypeShopIDList[grid.ItemIndex]) { index = i; break; } } mSellOpLayer.gameObject.SetActive(false); if (index != -1) { RemoveBuyItem(index, num); } } } ResetItem(); }
public bool UpdataShop(StoreData npc) { if (!mInit) { InitWindow(); } PeEntity ainpc = GameUI.Instance.mNpcWnd.m_CurSelNpc; if (ainpc == null) { return(false); } GameUI.Instance.mNpcWnd.Hide(); mBuyItemList.Clear(); if (npc == null) { return(false); } int iSize = npc.itemList.Count; if (iSize < 1) { return(false); } m_ShopIDList.Clear(); m_CurNpcID = ainpc.Id; if (!StroyManager.Instance.m_BuyInfo.ContainsKey(m_CurNpcID)) { StroyManager.Instance.InitBuyInfo(npc, m_CurNpcID); } Dictionary <int, stShopData> shoplist = StroyManager.Instance.m_BuyInfo[m_CurNpcID].ShopList; bool bPass = true; foreach (int key in shoplist.Keys) { ShopData data = ShopRespository.GetShopData(key); if (data == null) { continue; } bPass = true; for (int i = 0; i < data.m_LimitMisIDList.Count; i++) { if (data.m_LimitType == 1) { if (MissionManager.Instance.HadCompleteMission(data.m_LimitMisIDList[i])) { break; } } else { if (!MissionManager.Instance.HadCompleteMission(data.m_LimitMisIDList[i])) { bPass = false; break; } } } if (!bPass) { continue; } if (GameTime.Timer.Second - shoplist[key].CreateTime > data.m_RefreshTime) { if (shoplist[key].ItemObjID != 0) { ItemMgr.Instance.DestroyItem(shoplist[key].ItemObjID); } ItemObject itemObj = ItemMgr.Instance.CreateItem(data.m_ItemID); // single itemObj.stackCount = data.m_LimitNum; shoplist[key].ItemObjID = itemObj.instanceId; //itemObj.SetProperty(ItemProperty.NewFlagTime, 0f); shoplist[key].CreateTime = GameTime.Timer.Second; mBuyItemList.Add(itemObj); m_ShopIDList.Add(data.m_ID); } else { if (shoplist[key].ItemObjID == 0) { continue; } else { ItemObject itemObj = ItemMgr.Instance.Get(shoplist[key].ItemObjID); if (null != itemObj) { //itemObj.stackCount = data.m_LimitNum; shoplist[key].ItemObjID = itemObj.instanceId; //itemObj.SetProperty(ItemProperty.NewFlagTime, 0f); shoplist[key].CreateTime = GameTime.Timer.Second; mBuyItemList.Add(itemObj); m_ShopIDList.Add(data.m_ID); } } } } mRepurchaseList.Clear(); List <ItemObject> selllist; if (StroyManager.Instance.m_SellInfo.ContainsKey(m_CurNpcID)) { selllist = StroyManager.Instance.m_SellInfo[m_CurNpcID]; for (int i = 0; i < selllist.Count; i++) { mRepurchaseList.Add(selllist[i]); } } else { StroyManager.Instance.m_SellInfo.Add(m_CurNpcID, new List <ItemObject>()); } CSMain.AddTradeNpc(m_CurNpcID, shoplist.Keys.ToList()); ResetItem(); return(true); }
public void BuyItem(int instanceId, int count) { int shopID = -1; int cost = 0; ItemObject itemObj = ItemAsset.ItemMgr.Instance.Get(instanceId); if (itemObj == null) { UpdateShop(); return; } if (PeGameMgr.IsMulti) { cost = count * Mathf.RoundToInt(ShopRespository.GetPriceBuyItemId(itemObj.protoId) * (1 + ColonyConst.TRADE_POST_CHARGE_RATE)); if (PlayerMoney.current < cost) { PeTipMsg.Register(PELocalization.GetString(Money.Digital? 8000092:8000073), PeTipMsg.EMsgLevel.Warning); return; } _ColonyObj._Network.RPCServer(EPacketType.PT_CL_TRD_BuyItem, instanceId, count); return; } else { foreach (KeyValuePair <int, stShopData> kvp in mShopList) { if (kvp.Value.ItemObjID == instanceId) { shopID = kvp.Key; break; } } if (shopID < 0) { UpdateShop(); return; } ShopData data = ShopRespository.GetShopData(shopID); if (data != null) { cost = Mathf.RoundToInt(data.m_Price * (1 + ColonyConst.TRADE_POST_CHARGE_RATE)) * count; } else { PeTipMsg.Register(PELocalization.GetString(8000496), PeTipMsg.EMsgLevel.Warning); return; } if (!Buy(itemObj, count, data, false)) { return; } } colonyMoney += cost; RemoveBuyItem(itemObj, count); //--to do: updateUi; UpdateBuyDataToUI(); }
public void UpdateShop() { if (PeGameMgr.IsMulti) { UpdateDataToUI(); _ColonyObj._Network.RPCServer(EPacketType.PT_CL_TRD_RequestShop); return; } mBuyItemList.Clear(); bool bPass = true; foreach (int key in mShopList.Keys) { ShopData data = ShopRespository.GetShopData(key); if (data == null) { continue; } bPass = true; if (PeGameMgr.IsStory) { for (int i = 0; i < data.m_LimitMisIDList.Count; i++) { if (data.m_LimitType == 1) { if (MissionManager.Instance.HadCompleteMission(data.m_LimitMisIDList[i])) { break; } } else { if (!MissionManager.Instance.HadCompleteMission(data.m_LimitMisIDList[i])) { bPass = false; break; } } } } if (!bPass) { continue; } if (mShopList[key].CreateTime < 0) { ItemObject itemObj = ItemAsset.ItemMgr.Instance.CreateItem(data.m_ItemID); // single itemObj.stackCount = data.m_LimitNum; mShopList[key].ItemObjID = itemObj.instanceId; mShopList[key].CreateTime = GameTime.Timer.Second; mBuyItemList.Add(itemObj); } else if (GameTime.Timer.Second - mShopList[key].CreateTime > data.m_RefreshTime) { ItemObject itemObj; if (mShopList[key].ItemObjID >= 0) { itemObj = ItemMgr.Instance.Get(mShopList[key].ItemObjID); if (itemObj == null) { itemObj = ItemMgr.Instance.CreateItem(data.m_ItemID); } itemObj.stackCount = data.m_LimitNum; } else { itemObj = ItemMgr.Instance.CreateItem(data.m_ItemID); // single itemObj.stackCount = data.m_LimitNum; } mShopList[key].ItemObjID = itemObj.instanceId; mShopList[key].CreateTime = GameTime.Timer.Second; mBuyItemList.Add(itemObj); } else { if (mShopList[key].ItemObjID < 0) { continue; } else { ItemObject itemObj = ItemMgr.Instance.Get(mShopList[key].ItemObjID); if (itemObj == null) { itemObj = ItemMgr.Instance.CreateItem(data.m_ItemID); } mShopList[key].ItemObjID = itemObj.instanceId; mBuyItemList.Add(itemObj); } } } UpdateDataToUI(); }