/// <summary> /// 获得所有上架的商品; /// </summary> /// <returns></returns> public static BetterList <ShopTableItem> GetEffectShopItemsWithoutSecret() { BetterList <ShopTableItem> items = new BetterList <ShopTableItem>(); IDictionaryEnumerator itr = DataManager.ShopTable.GetEnumerator(); while (itr.MoveNext()) { ShopTableItem item = itr.Value as ShopTableItem; if (item == null || item.subTable == (int)ShopSubTable.Sceret) { continue; } items.Add(item); } // foreach (DictionaryEntry de in DataManager.ShopTable) // { // ShopTableItem item = de.Value as ShopTableItem; // // if (item == null || item.subTable == (int)ShopSubTable.Sceret) // continue; // // items.Add(item); // } return(items); }
/// <summary> /// 获取商店表中货币类型索引idx对应的单价值; /// </summary> /// <param name="resId"></param> /// <param name="idx"></param> /// <returns></returns> public static int GetShopItemPerPrice(int resId, int idx) { if (!DataManager.ShopTable.ContainsKey(resId)) { return(-1); } ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem; return(GetShopItemPerPrice(item, idx)); }
public static int GetShopItemPerPrice(ShopTableItem item, int idx) { if (idx < 0 || idx > 2) { return(-1); } if (item == null) { return(-1); } return(item[idx + 3]); }
public static int GetShopItemProceedsType(ShopTableItem item, int idx) { if (idx < 0 || idx > 2) { return(-1); } if (item == null) { return(-1); } return(item[idx]); }
public static ShopSubTable GetShopSubTableById(int resId) { ShopSubTable result = ShopSubTable.None; if (!DataManager.ShopTable.ContainsKey(resId)) { return(result); } ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem; if (item == null) { return(result); } return((ShopSubTable)item.subTable); }
void onMallBuy(EventBase ev) { ShopUIEvent e = ev as ShopUIEvent; if (e == null) { return; } int resId = e.resId; if (!DataManager.ShopTable.ContainsKey(resId)) { GameDebug.LogError("不存在的商店表id"); return; } ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem; string content = StringHelper.GetString("egg_get_item") + ItemManager.getItemNameWithColor(item.itemId) + " X "; uint count = 0; if (mSecretItems.ContainsKey(resId)) { PlayerDataModule pdm = ModuleManager.Instance.FindModule <PlayerDataModule>(); ShopItemInfo info = pdm.GetShopSecretItemInfo(resId); if (info == null) { return; } count = (uint)info.count * item.multiple; } else { count = item.minCount * item.multiple; } PopTipManager.Instance.AddNewTip(content + count); updateMallUI(resId, false); }
/// <summary> /// 神秘商店数据是从服务器获取的;获得积分兑换、装备栏上架的商品; /// </summary> /// <returns></returns> public static BetterList <int> GetEffectShopIdsWithoutSecret() { BetterList <int> ids = new BetterList <int>(); foreach (DictionaryEntry de in DataManager.ShopTable) { int id = (int)de.Key; if (id <= 0) { continue; } ShopTableItem item = DataManager.ShopTable[id] as ShopTableItem; if (item == null || item.subTable == (int)ShopSubTable.Sceret) { continue; } ids.Add(id); } return(ids); }
public void SetData(ShopTableItem node) { if (node == null) { resId = -1; mitem = null; SetName(""); huiSp.gameObject.SetActive(true); nullLb.gameObject.SetActive(true); icon.gameObject.SetActive(false); moneyLb.gameObject.SetActive(false); moneySp.gameObject.SetActive(false); countLb.gameObject.SetActive(false); discountSp.gameObject.SetActive(false); discountLb.gameObject.SetActive(false); effectSp.gameObject.SetActive(false); orignalPriceLb.gameObject.SetActive(false); orignalPriceSp.gameObject.SetActive(false); limitTimesLb.gameObject.SetActive(false); limitTimesSp.gameObject.SetActive(false); return; } ItemTableItem itemItem = ItemManager.GetItemRes(node.itemId); if (itemItem == null) { Debug.LogError("找不到物品id" + node.itemId + "对应的物品"); return; } resId = node.resId; mitem = node; SetName(ItemManager.getItemNameWithColor(node.itemId)); SetIcon(itemItem.picname); if (node.subTable != (int)ShopSubTable.Sceret) { uint count = node.minCount * node.multiple; mPt = (ProceedsType)(node.proceedType0); mCost = (uint)node.perPrice0 * count; //UIAtlasHelper.SetSpriteByMoneyType(moneySp, mPt); SetMoneyType(mPt); SetCurPrice(mCost); countLb.text = "x" + count; mInfo = new ShopItemInfo(); mInfo.proceedsTypeIdx = 0; mInfo.isBuyDone = false; mInfo.count = (int)node.minCount; } nullLb.gameObject.SetActive(false); huiSp.gameObject.SetActive(false); discountSp.gameObject.SetActive(false); discountLb.gameObject.SetActive(false); effectSp.gameObject.SetActive(false); orignalPriceLb.gameObject.SetActive(false); orignalPriceSp.gameObject.SetActive(false); limitTimesLb.gameObject.SetActive(false); limitTimesSp.gameObject.SetActive(false); }
void CreateMallItem(ShopTableItem item, ShopSubTable table = ShopSubTable.None) { GameObject go = WindowManager.Instance.CloneGameObject(mMallItemPrefab); if (go == null) { return; } go.SetActive(true); go.name = item == null ? "504" : item.resId.ToString(); ShopItemUI shopItem = new ShopItemUI(go); switch (table) { case ShopSubTable.Sceret: go.transform.parent = sGrid.transform; go.transform.localScale = Vector3.one; if (item == null) { mSecretItems.Add(mSecretItems.Count, shopItem); } else { mSecretItems.Add(item.resId, shopItem); } break; case ShopSubTable.Credit: go.transform.parent = jGrid.transform; go.transform.localScale = Vector3.one; //mCreditItems.Add(shopItem); mCreditCount++; break; case ShopSubTable.Equip: go.transform.parent = zGrid.transform; go.transform.localScale = Vector3.one; //mEquipItems.Add(shopItem); mEquipCount++; break; default: GameDebug.LogError("商店商品所在分栏错误"); break; } if (item != null) { if (!mAllItemsLists.ContainsKey(item.resId)) { mAllItemsLists.Add(item.resId, shopItem); } } shopItem.SetData(item); UIEventListener.Get(go).onClick = onMallItemClick; }
void OpenBuyForm(int resId) { if (!DataManager.ShopTable.ContainsKey(resId)) { return; } if (!mAllItemsLists.ContainsKey(resId)) { return; } ShopItemUI itemUi = mAllItemsLists[resId]; if (itemUi == null || itemUi.IsScretItemBuyDone) { return; } ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem; ItemTableItem tableItem = ItemManager.GetItemRes(item.itemId); if (tableItem == null) { #if UNITY_EDITOR GameDebug.LogError("物品表中缺少ID为" + item.itemId + "的物品"); #endif return; } //gNameLb.text = tableItem.name; gNameLb.text = ItemManager.getItemNameWithColor(item.itemId); gItemDetailLb.text = tableItem.desc; gGetDetailLb.text = tableItem.desc0; UIAtlasHelper.SetSpriteImage(gIconSp, tableItem.picname, true); gItemTypeLb.text = ItemManager.GetItemTypeStr(item.itemId); ProceedsType pt = ProceedsType.Invalid; int cost = 0; if (!itemUi.GetProcTypeAndCost(ref pt, ref cost)) { return; } UIAtlasHelper.SetSpriteByMoneyType(gMoneySp, pt); gMoneySp.transform.localScale = new Vector3(0.5f, 0.5f, 1f); PlayerDataModule playerModule = ModuleManager.Instance.FindModule <PlayerDataModule>(); if (playerModule == null) { GameDebug.LogError("player data is null!"); return; } if (playerModule.GetProceeds(pt) < cost) { gMoneyLb.text = StringHelper.StringWithColor(FontColor.Red, cost.ToString()); } else { gMoneyLb.text = cost.ToString(); } gBuyObj.SetActive(true); }
void BuyMallItem(int resId) { ShopTableItem item = DataManager.ShopTable[resId] as ShopTableItem; if (item == null) { return; } PlayerDataModule pdm = ModuleManager.Instance.FindModule <PlayerDataModule>(); if (pdm == null || pdm.GetShopIsBuyDone(resId)) { return; } if (!mAllItemsLists.ContainsKey(resId)) { return; } ShopItemUI itemUi = mAllItemsLists[resId]; if (itemUi == null) { return; } // 已经买了吗; if (itemUi.IsScretItemBuyDone) { //PromptUIManager.Instance.AddNewPrompt(StringHelper.GetString("buy_done")); PopTipManager.Instance.AddNewTip(StringHelper.StringWithColor(FontColor.Red, StringHelper.GetString("buy_done"))); return; } /// 钱够了吗; ProceedsType pt = ProceedsType.Invalid; int cost = 0; if (!itemUi.GetProcTypeAndCost(ref pt, ref cost)) { return; } if (pdm.GetProceeds(pt) < cost) { //PromptUIManager.Instance.AddNewPrompt(ShopModule.GetBuyMoneyNotEnougthStr(pt)); PopTipManager.Instance.AddNewTip(StringHelper.StringWithColor(FontColor.Red, ShopModule.GetBuyMoneyNotEnougthStr(pt))); return; } // 成功逻辑; ShopBuyItemAction param = new ShopBuyItemAction(); param.OpType = (int)ShopOpType.BuyItem; param.ResId = resId; Net.Instance.DoAction((int)Message.MESSAGE_ID.ID_MSG_SHOP, param); //MallBuyItemAction param = new MallBuyItemAction(); //param.ResId = resId; //param.SubIdx = subId; ////有钱没; //MallItemInfo info = item.mallItems[subId]; //if (pdm.GetProceeds((ProceedsType)item.processType) < info.processNow) //{ // PromptUIManager.Instance.AddNewPrompt("钱不够"); // return; //} ////次数够了没; //switch (mModule.GetLimitTypeByID(resId)) //{ // case MallLimitType.ERROR: // GameDebug.LogError("数据错误"); // return; // case MallLimitType.NONE: // break; // case MallLimitType.DAY: // case MallLimitType.FOREVER: // if (mModule.GetPlayerBuyTimes(resId) >= item.limitTimes) // { // PromptUIManager.Instance.AddNewPrompt("购买次数够了"); // return; // } // break; //} //Net.Instance.DoAction((int)Message.MESSAGE_ID.ID_MSG_MALL_BUY, param); }
/// <summary> /// 每次打开界面的强制刷新,只需要刷新神秘商店的,因为其他商店都是填表固定不变的; /// </summary> void updateMallUI(int resid = -1, bool needDestroy = true) { PlayerDataModule playerModule = ModuleManager.Instance.FindModule <PlayerDataModule>(); if (playerModule == null) { GameDebug.LogError("player data is null!"); return; } // 其他商店刷新; UpdateShopItemsMoneyWithoutSecret(); // 神秘商店初始化; BetterList <int> resIds = Module.GetPlayerSecretShopItemIds(); if (needDestroy) { if (mSecretItems.Count > 0) { clearSecretItemInAllItemList(); ObjectCommon.DestoryChildren(sGrid.gameObject); mSecretItems.Clear(); } if (resIds != null) { foreach (int id in resIds) { ShopTableItem tmpitem = DataManager.ShopTable[id] as ShopTableItem; if (tmpitem == null) { continue; } CreateMallItem(tmpitem, (ShopSubTable)tmpitem.subTable); } sGrid.repositionNow = true; } } //刷新指定resid的商品; if (resIds.Contains(resid)) { ShopItemInfo info = playerModule.GetShopSecretItemInfo(resid); if (info == null) { return; } setSecretItemInfo(resid, info); //isbuy = playerModule.GetShopIsBuyDone(resid); //if (!isbuy) // return; //if (!setItemBuyDone(resid)) //{ // GameDebug.LogError("商城数据错了"); // return; //} } //刷新全部的神秘商品; else { foreach (int id in resIds) { ShopItemInfo info = playerModule.GetShopSecretItemInfo(id); if (info == null) { continue; } setSecretItemInfo(id, info); } } }