Esempio n. 1
0
        /// <summary>
        ///     买满了,等待揭晓结果
        /// </summary>
        /// <returns></returns>
        private void WaitResult(GroupShopOne _this)
        {
            GroupShop.Dirty = true;
            _this.State     = (int)eGroupShopItemState.WaitResult;

            //流拍逻辑
            if (_this.NowCount < _this.tbGroupShop.LimitMinCount)
            {
                CoroutineFactory.NewCoroutine(PassIn, _this).MoveNext();
                return;
            }

            var t = DateTime.Now.AddMinutes(GroupShopOne.OverTimeMinutes);

            _this.OverTime = t;
            if (_this.overTrigger != null)
            {
                TeamServerControl.tm.DeleteTrigger(_this.overTrigger);
            }
            _this.overTrigger = TeamServerControl.tm.CreateTrigger(t, () => GiveItem(_this));

            var characterId = _this.BuyCharacterList.Range();
            var count       = _this.CharactersCount[characterId];

            _this.mDbData.LuckyId    = characterId;
            _this.mDbData.LuckyCount = count;
            CoroutineFactory.NewCoroutine(GetLogicSimpleDataCoroutine, _this).MoveNext();

            var item = _this.mDbData.ItemData;

            PlayerLog.WriteLog((ulong)LogType.GroupShopOldDatasKeySame,
                               "WaitResult, luckyId = {0}, luckyCount = {1}, item id = {2}, count = {3}", characterId, count,
                               item.ItemId, item.Count);
        }
Esempio n. 2
0
        public void OverCopy(GroupShopOne _this, GroupShopOne one)
        {
            if (_this.mDbData == null)
            {
                _this.mDbData = new DBGroupShopOne();
                if (_this.mDbData.ItemData == null)
                {
                    _this.mDbData.ItemData = new ItemBaseData();
                }
            }
            _this.Guid        = one.Guid;
            _this.tbGroupShop = one.tbGroupShop;
            _this.State       = (int)eGroupShopItemState.Sold;
            _this.CharactersCount.AddRange(one.CharactersCount);
            _this.mDbData.Characters.AddRange(one.mDbData.Characters);
            _this.mDbData.GroupShopId     = one.tbGroupShop.Id;
            _this.mDbData.OverTime        = one.mDbData.OverTime;
            _this.mDbData.ItemData.ItemId = one.mDbData.ItemData.ItemId;
            _this.mDbData.ItemData.Count  = one.mDbData.ItemData.Count;
            _this.mDbData.ItemData.Exdata.AddRange(one.mDbData.ItemData.Exdata);
            _this.mDbData.BuyCount      = one.NowCount;
            _this.mDbData.LuckyId       = one.mDbData.LuckyId;
            _this.mDbData.LuckyCount    = one.mDbData.LuckyCount;
            _this.mDbData.LuckyName     = one.mDbData.LuckyName;
            _this.mDbData.LuckyServerId = one.mDbData.LuckyServerId;

            if (_this.mDbData.LuckyId > 0)
            {
                CoroutineFactory.NewCoroutine(SendChatNotify, _this).MoveNext();
            }
        }
Esempio n. 3
0
        private void Reset(GroupShopOne _this)
        {
            if (_this.overTrigger != null)
            {
                TeamServerControl.tm.DeleteTrigger(_this.overTrigger);
                _this.overTrigger = null;
            }
            var guid = GroupShop.GetNextGuid();

            GroupShop.ResetShopItem(_this, guid);
            var items = new Dictionary <int, int>();

            ShareDrop.DropMother(_this.tbGroupShop.MotherID, items);
            var itemsCount = items.Count;

            if (itemsCount < 1)
            {
                ShareItemFactory.Create(22000, _this.mDbData.ItemData);
            }
            else
            {
                var itemT = items.First();
                var item  = ShareItemFactory.Create(itemT.Key, _this.mDbData.ItemData);
                item.SetCount(itemT.Value);
                if (itemsCount > 1)
                {
                    Logger.Warn("GroupShopOne InitByBase itemsCount ={0} GroupShopRecord={1}", itemsCount,
                                _this.tbGroupShop.Id);
                }
            }
            _this.OverTime    = DateTime.Now.AddHours(_this.tbGroupShop.ExistTime);
            _this.overTrigger = TeamServerControl.tm.CreateTrigger(_this.OverTime, () => TimeOver(_this));
        }
Esempio n. 4
0
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); //

        #endregion

        #region 初始化

        public void InitByBase(GroupShopOne _this, GroupShopRecord tbTable)
        {
            _this.mDbData = new DBGroupShopOne();
            if (_this.mDbData.ItemData == null)
            {
                _this.mDbData.ItemData = new ItemBaseData();
            }
            _this.tbGroupShop         = tbTable;
            _this.mDbData.GroupShopId = tbTable.Id;
            _this.OverTime            = DateTime.Now.AddHours(tbTable.ExistTime);
            var items = new Dictionary <int, int>();

            ShareDrop.DropMother(tbTable.MotherID, items);
            var itemsCount = items.Count;

            if (itemsCount < 1)
            {
                ShareItemFactory.Create(22000, _this.mDbData.ItemData);
            }
            else
            {
                var itemT = items.First();
                var item  = ShareItemFactory.Create(itemT.Key, _this.mDbData.ItemData);
                item.SetCount(itemT.Value);
                if (itemsCount > 1)
                {
                    Logger.Warn("GroupShopOne InitByBase itemsCount ={0} GroupShopRecord={1}", itemsCount, tbTable.Id);
                }
            }
            _this.overTrigger = TeamServerControl.tm.CreateTrigger(_this.OverTime, () => TimeOver(_this));
        }
Esempio n. 5
0
 /// <summary>
 ///     尚未买满,但团购时间结束了
 /// </summary>
 /// <returns></returns>
 private void TimeOver(GroupShopOne _this)
 {
     _this.overTrigger = null;
     if (_this.BuyCharacterList.Count == 0)
     {
         Reset(_this);
         return;
     }
     WaitResult(_this);
 }
Esempio n. 6
0
        /// <summary>
        ///     团购物品发出去后,给各个服务器发送通知
        ///     对于最高档的物品,通知会发给所有服务器的所有人,否则,就只发给中奖者所在的服务器的所有人
        /// </summary>
        /// <param name="co"></param>
        /// <param name="_this"></param>
        /// <returns></returns>
        private IEnumerator SendChatNotify(Coroutine co, GroupShopOne _this)
        {
            var strs = new List <string>
            {
                _this.mDbData.LuckyName,
                _this.mDbData.LuckyCount.ToString(),
                Utils.AddItemId(_this.mDbData.ItemData.ItemId)
            };
            var exData    = new List <int>(_this.mDbData.ItemData.Exdata);
            var content   = Utils.WrapDictionaryId(300409, strs, exData);
            var chatAgent = TeamServer.Instance.ChatAgent;

            if (GroupShop.TopItems.Contains(_this.mDbData.GroupShopId))
            {
//最高档的奖励,发所有服务器的所有人
                //缓存一下这条消息
                var notifys = GroupShop.DbData.Notifys.Items;
                if (notifys.Count > 20)
                {
                    notifys.RemoveAt(0);
                }
                notifys.Add(content);

                //发送给所有服务器的所有人
                var serverIds = new List <int>();
                Table.ForeachServerName(r =>
                {
                    var serverId = r.LogicID;
                    if (!serverIds.Contains(serverId))
                    {
                        serverIds.Add(serverId);
                    }
                    return(true);
                });
                foreach (var id in serverIds)
                {
                    chatAgent.BroadcastWorldMessage((uint)id, (int)eChatChannel.WishingGroup, 0, string.Empty,
                                                    new ChatMessageContent {
                        Content = content
                    });
                    yield return(TeamServerControl.Instance.Wait(co, TimeSpan.FromSeconds(3)));
                }
            }
            else
            {
//只发本服务器的人
                var serverId = SceneExtension.GetServerLogicId(_this.mDbData.LuckyServerId);
                chatAgent.BroadcastWorldMessage((uint)serverId, (int)eChatChannel.WishingGroup, 0, string.Empty,
                                                new ChatMessageContent {
                    Content = content
                });
            }
        }
Esempio n. 7
0
        private void AddItem(GroupShopRecord tbGroupShop)
        {
            var nextGuid = GetNextGuid();
            var temp     = new GroupShopOne();

            temp.InitByBase(tbGroupShop);
            temp.Guid = nextGuid;
            GroupShop.DbData.ItemList.Add(temp.mDbData);
            GroupShop.Datas.Add(nextGuid, temp);
            var tempList = GroupShop.StoreList[tbGroupShop.Id];

            tempList.Add(temp);
            GroupShop.Dirty = true;
        }
Esempio n. 8
0
        //某玩家买了一次
        public int CharacterBuy(GroupShopOne _this, ulong cId, int buyCount)
        {
            _this.CharactersCount.modifyValue(cId, buyCount);
            for (var i = 0; i < buyCount; i++)
            {
                _this.BuyCharacterList.Add(cId);
            }
            var count = _this.BuyCharacterList.Count;

            if (count >= _this.MaxCount)
            {
                //重置物品
                WaitResult(_this);
            }
            return(count);
        }
Esempio n. 9
0
 public bool CheckCountLimit(GroupShopOne _this, ulong cId, int buyCount)
 {
     if (_this.tbGroupShop.BuyLimit > 0)
     {
         int count;
         if (!_this.CharactersCount.TryGetValue(cId, out count))
         {
             count = 0;
         }
         if (count + buyCount > _this.tbGroupShop.BuyLimit)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        private void InitByDb(DBGroupShop dbData)
        {
            GroupShop.DbData = dbData;
            var delList = new List <DBGroupShopOne>();

            foreach (var item in GroupShop.DbData.ItemList)
            {
                List <GroupShopOne> list;
                if (GroupShop.StoreList.TryGetValue(item.GroupShopId, out list))
                {
                    var temp = new GroupShopOne();
                    temp.InitByDB(item);
                    GroupShop.Datas.Add(temp.Guid, temp);
                    list.Add(temp);
                }
                else
                {
                    delList.Add(item);
                }
            }
            if (delList.Count > 0)
            {
                GroupShop.DbData.ItemList.RemoveAll(i => delList.Contains(i));
            }
            //移除过期的历史
            var overTime = DateTime.Now.AddDays(-7).ToBinary();
            var count    = GroupShop.DbData.OldItems.RemoveAll(item => item.OverTime <= overTime);

            if (count > 0)
            {
                GroupShop.Dirty = true;
            }
            foreach (var item in GroupShop.DbData.OldItems)
            {
                var temp = new GroupShopOne();
                temp.InitByDB(item);
                if (GroupShop.OldDatas.ContainsKey(temp.Guid))
                {
                    PlayerLog.WriteLog((int)LogType.GroupShopOldDatasKeySame, "GroupShop.OldDatas has duplicate key!");
                    Logger.Fatal(
                        "----------------------------GroupShop.OldDatas has duplicate key!--------------------------------");
                    continue;
                }
                GroupShop.OldDatas.Add(temp.Guid, temp);
            }
            CheckTableChange();
        }
Esempio n. 11
0
 public void InitByDB(GroupShopOne _this, DBGroupShopOne dbData)
 {
     _this.mDbData     = dbData;
     _this.tbGroupShop = Table.GetGroupShop(dbData.GroupShopId);
     foreach (var character in dbData.Characters)
     {
         _this.CharactersCount.modifyValue(character, 1);
     }
     if (_this.State == (int)eGroupShopItemState.WaitResult)
     {
         _this.overTrigger = TeamServerControl.tm.CreateTrigger(_this.OverTime, () => GiveItem(_this));
     }
     else if (_this.State == (int)eGroupShopItemState.OnSell)
     {
         _this.overTrigger = TeamServerControl.tm.CreateTrigger(_this.OverTime, () => TimeOver(_this));
     }
 }
Esempio n. 12
0
        private IEnumerator GroupShopMailCoroutine(Coroutine co, GroupShopOne _this)
        {
            var data        = _this.mDbData;
            var item        = data.ItemData;
            var characterId = data.LuckyId;

            PlayerLog.WriteLog((ulong)LogType.GroupShopOldDatasKeySame,
                               "GroupShopMailCoroutine, luckyId = {0}, luckyCount = {1}, item id = {2}, count = {3}", characterId,
                               data.LuckyCount,
                               item.ItemId, item.Count);

            var args = new StringArray();

            args.Items.Add(data.LuckyCount.ToString());
            var msg = TeamServer.Instance.LogicAgent.SendMailToCharacterByItems(characterId, 52, item, args);

            yield return(msg.SendAndWaitUntilDone(co));
        }
Esempio n. 13
0
        //网络类型转换
        public GroupShopItemOne GetNetData(GroupShopOne _this, ulong cId)
        {
            var netData = new GroupShopItemOne
            {
                Guid        = _this.Guid,
                GroupShopId = _this.mDbData.GroupShopId,
                ItemData    = _this.mDbData.ItemData,
                OverTime    = _this.mDbData.OverTime,
                State       = _this.State
            };

            var tbServerName = Table.GetServerName(_this.mDbData.LuckyServerId);

            switch ((eGroupShopItemState)_this.State)
            {
            case eGroupShopItemState.OnSell:
                netData.CharacterCount = _this.BuyCharacterList.Count;
                break;

            case eGroupShopItemState.WaitResult:
                netData.CharacterCount = _this.BuyCharacterList.Count;
                netData.LuckyPlayer    = _this.mDbData.LuckyName;
                netData.LuckyCount     = _this.mDbData.LuckyCount;
                netData.LuckyServer    = tbServerName != null ? tbServerName.Name : "Nothing";
                break;

            case eGroupShopItemState.Sold:
                netData.CharacterCount = _this.mDbData.BuyCount;
                netData.LuckyPlayer    = _this.mDbData.LuckyName;
                netData.LuckyCount     = _this.mDbData.LuckyCount;
                netData.LuckyServer    = tbServerName != null ? tbServerName.Name : "Nothing";
                break;
            }

            int count;

            if (_this.CharactersCount.TryGetValue(cId, out count))
            {
                netData.SelfCount = count;
            }
            return(netData);
        }
Esempio n. 14
0
        private IEnumerator GetLogicSimpleDataCoroutine(Coroutine co, GroupShopOne _this)
        {
            var characterId = _this.mDbData.LuckyId;
            var loginMsg    = TeamServer.Instance.LoginAgent.GetLoginSimpleData(characterId, characterId);

            yield return(loginMsg.SendAndWaitUntilDone(co));

            if (loginMsg.State != MessageState.Reply)
            {
                yield break;
            }
            if (loginMsg.ErrorCode != (int)ErrorCodes.OK)
            {
                yield break;
            }
            var charData = loginMsg.Response;

            _this.mDbData.LuckyName     = charData.Name;
            _this.mDbData.LuckyServerId = charData.ServerId;
        }
Esempio n. 15
0
        private IEnumerator PassIn(Coroutine co, GroupShopOne _this)
        {
            var args = new StringArray();
            var item = new ItemBaseData();

            item.ItemId = (int)eResourcesType.DiamondRes;
            var tbItem = Table.GetItemBase(_this.mDbData.ItemData.ItemId);

            if (tbItem != null)
            {
                args.Items.Add(tbItem.Name);
            }
            foreach (var v in _this.CharactersCount)
            {
                item.Count = v.Value;
                var msg = TeamServer.Instance.LogicAgent.SendMailToCharacterByItems(v.Key, 5, item, args);
                msg.SendAndWaitUntilDone(co);
            }
            Reset(_this);
            yield break;
        }
Esempio n. 16
0
        //更换guid
        public void ResetShopItem(GroupShopOne one, long guid)
        {
            //老的
            if (one.NowCount > 0)
            {
                var temp = new GroupShopOne();
                temp.OverCopy(one);
                GroupShop.DbData.OldItems.Add(temp.mDbData);
                GroupShop.OldDatas.Add(temp.Guid, temp);
            }

            //新的
            GroupShop.Datas.Remove(one.Guid);
            one.Guid               = guid;
            one.mDbData.LuckyId    = 0;
            one.mDbData.LuckyCount = 0;
            one.mDbData.LuckyName  = string.Empty;
            one.mDbData.Characters.Clear();
            one.CharactersCount.Clear();
            one.State = (int)eGroupShopItemState.OnSell;
            GroupShop.Datas.Add(guid, one);
            GroupShop.Dirty = true;
        }
Esempio n. 17
0
        //获取一堆历史道具
        public List <GroupShopOne> GetHistorys(List <long> ids)
        {
            GroupShopOne one = null;

            return((from id in ids where GroupShop.OldDatas.TryGetValue(id, out one) select one).ToList());
        }
Esempio n. 18
0
 public void OverCopy(GroupShopOne one)
 {
     mImpl.OverCopy(this, one);
 }
Esempio n. 19
0
 //给某个玩家发奖
 private void GiveItem(GroupShopOne _this)
 {
     //给予物品
     CoroutineFactory.NewCoroutine(GroupShopMailCoroutine, _this).MoveNext();
     Reset(_this);
 }
Esempio n. 20
0
 //更换guid
 public static void ResetShopItem(GroupShopOne one, long guid)
 {
     mImpl.ResetShopItem(one, guid);
 }