public int ConsumeStoreItem(BlackStoreManager _this, int storeId, int consumeCount)
        {
            var tbStore = Table.GetStore(storeId);

            if (null == tbStore)
            {
                return((int)ErrorCodes.Error_StoreID);
            }
            var storeData = _this.mDbData.BlackStoreInfo;

            if (null == storeData)
            {
                return((int)ErrorCodes.Unknow);
            }
            for (int i = 0; i < storeData.Count; i++)
            {
                var data = storeData[i];
                if (data.StoreItemId == storeId)
                {
                    if (_this.mDbData.BlackStoreInfo[i].StoreItemCount < consumeCount)
                    {
                        return((int)ErrorCodes.Error_TreasureStoreItemCountNotEnough);
                    }
                    else
                    {
                        _this.mDbData.BlackStoreInfo[i].StoreItemCount -= consumeCount;
                        return((int)ErrorCodes.OK);
                    }
                }
            }
            return((int)ErrorCodes.Error_TreasureStoreBuyFailed);
        }
        private void ReloadTable(IEvent ievent)
        {
            var v = ievent as ReloadTableEvent;

            if (v == null)
            {
                return;
            }
            if (v.tableName == "ServerName")
            {
                Table.ForeachServerName(record =>
                {
                    if (record.Id == record.LogicID && record.IsClientDisplay == 1 && ServerBlackStoreManager.Servers.ContainsKey(record.LogicID) == false)
                    {
                        BlackStoreManager temp = new BlackStoreManager();
                        temp.Init(record.LogicID);
                        ServerBlackStoreManager.Servers.Add(record.LogicID, temp);
                    }
                    return(true);
                });
            }
            if (v.tableName == "Store")
            {
                ResetStore();
            }
        }
        public IEnumerator FlushAll(Coroutine coroutine, BlackStoreManager _this)
        {
            var co = CoroutineFactory.NewSubroutine(SaveDb, coroutine, _this);

            if (co.MoveNext())
            {
                yield return(co);
            }
        }
        public BlackStoreManager GetBlackStoreManager(int serverId)
        {
            BlackStoreManager BlackStoreMgr = null;

            if (ServerBlackStoreManager.Servers.TryGetValue(serverId, out BlackStoreMgr) == false)
            {
                BlackStoreMgr = new BlackStoreManager();
                ServerBlackStoreManager.Servers.Add(serverId, BlackStoreMgr);
            }
            return(BlackStoreMgr);
        }
 private IEnumerator SaveDb(Coroutine coroutine, BlackStoreManager _this)
 {
     if (_this.mDbData != null)
     {
         PlayerLog.WriteLog((int)LogType.BlackStoreSave,
                            "--------------------SaveBlackStoreData--------------------{0}"
                            , _this.mDbData);
         var ret = ActivityServer.Instance.DB.Set(coroutine, DataCategory.BlackStore, GetDbName(_this.ServerId), _this.mDbData);
         yield return(ret);
     }
 }
        public void InitByBase(BlackStoreManager _this)
        {
            List <StoreRecord> tempList = new List <StoreRecord>();

            Table.ForeachStore(record =>
            {
                if (record.Type == 1100)//黑市商店
                {
                    tempList.Add(record);
                }
                return(true);
            });
            //Debug.Assert(false);
            GetBlackStoreItems(_this, tempList);
        }
 public void Init()
 {
     Table.ForeachServerName(record =>
     {
         if (record.Id == record.LogicID && record.IsClientDisplay == 1 && ServerBlackStoreManager.Servers.ContainsKey(record.LogicID) == false)
         {
             BlackStoreManager temp = new BlackStoreManager();
             temp.Init(record.LogicID);
             ServerBlackStoreManager.Servers.Add(record.LogicID, temp);
         }
         return(true);
     });
     SetTrigger();
     EventDispatcher.Instance.AddEventListener(ReloadTableEvent.EVENT_TYPE, ReloadTable);
 }
        private IEnumerator ReadDb(Coroutine coroutine, BlackStoreManager _this, int serverId)
        {
            var storeData = ActivityServer.Instance.DB.Get <DBBlackStore>(coroutine, DataCategory.BlackStore, GetDbName(serverId));

            yield return(storeData);

            _this.ServerId = serverId;
            if (storeData.Data == null)
            {
                _this.InitByBase();
                yield break;
            }
            _this.mDbData = storeData.Data;
            yield break;
        }
        public int ApplyStoreInfo(BlackStoreManager _this, ref List <StoneItem> info)
        {
            var storeData = _this.mDbData.BlackStoreInfo;

            if (null == storeData || storeData.Count == 0)
            {
                return((int)ErrorCodes.Unknow);
            }
            foreach (var data in storeData)
            {
                var item = new StoneItem();
                item.itemid    = data.StoreItemId;
                item.itemcount = data.StoreItemCount;
                info.Add(item);
            }
            return((int)ErrorCodes.OK);
        }
        private void GetBlackStoreItems(BlackStoreManager _this, List <StoreRecord> tempList)
        {
            _this.mDbData.BlackStoreInfo.Clear();
            var BlackStoreItems = new List <StoreRecord>();

            for (int i = 0; i < tempList.Count; i++)
            {
                BlackStoreItems.Add(tempList[i]);
            }
            var limitCount = Table.GetServerConfig(1204).ToInt();

            for (int i = 0; i < limitCount; i++)
            {
                var item = GetItemByWeight(BlackStoreItems);
                if (null != item)
                {
                    var tempItem = new BlackStoreItem();
                    tempItem.StoreItemId    = item.Id;
                    tempItem.StoreItemCount = item.FuBenCount;//策划指定使用黑市限购数量
                    BlackStoreItems.Remove(item);
                    _this.mDbData.BlackStoreInfo.Add(tempItem);
                }
            }
        }
        public int GetStoreItemCount(BlackStoreManager _this, int storeId, ref int itemCount)
        {
            var tbStore = Table.GetStore(storeId);

            if (null == tbStore)
            {
                return((int)ErrorCodes.Error_StoreID);
            }
            var storeData = _this.mDbData.BlackStoreInfo;

            if (null == storeData)
            {
                return((int)ErrorCodes.Unknow);
            }
            foreach (var data in storeData)
            {
                if (data.StoreItemId == storeId)
                {
                    itemCount = data.StoreItemCount;
                    return((int)ErrorCodes.OK);
                }
            }
            return((int)ErrorCodes.OK);
        }
 public void Init(BlackStoreManager _this, int serverId)
 {
     CoroutineFactory.NewCoroutine(ReadDb, _this, serverId).MoveNext();
 }