public static RandomDropLogic GetInstance() { if (m_Instance == null || DateTime.UtcNow.Ticks - m_CreateInstanceTime > TimeSpan.TicksPerHour) { m_Instance = new RandomDropLogic(); m_CreateInstanceTime = DateTime.UtcNow.Ticks; } return(m_Instance); }
public void RefreshCosmosCrackInstance() { m_CosmosCrack.ChosenInstance.Clear(); var instances = GameUtils.RandomChoose(CacheSet.InstanceCosmosCrackTable.GetAllData(), InstanceCount); foreach (var instance in instances) { CosmosCrackInstance cci = new CosmosCrackInstance(); cci.RewardLevel = random.Next(MinRewardLevel, MaxRewardLevel + 1); DTDrop dropData = CacheSet.DropTable.GetData(cci.RewardLevel + 1000); RandomDropLogic rd = RandomDropLogic.GetInstance(); CacheDictionary <int, int> dropDict = new CacheDictionary <int, int>(); rd.GetDropDict(dropData, dropDict); cci.RewardItem = dropDict; m_CosmosCrack.ChosenInstance[instance.Id] = cci; } }
public CacheDictionary <int, int> GetDropItems(int dropId, int starLevel) { if (m_Instance.Count <= 0) { return(null); } RandomDropLogic random = RandomDropLogic.GetInstance(); CacheDictionary <int, int> dropItems = new CacheDictionary <int, int>(); var dropData = CacheSet.DropTable.GetData(dropId); for (int i = 0; i < starLevel; i++) { random.GetDropDict(dropData, dropItems); } m_Instance.Count -= 1; return(dropItems); }
public bool ResetRewards(bool IsFree) { RandomDropLogic random = RandomDropLogic.GetInstance(); PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); m_Chance.OpenedChanceRewards.Clear(); m_Chance.UnopenedChanceRewards.Clear(); switch (m_Type) { case ChanceType.Coin: if (!IsFree) { if (!player.DeductCoin(GameConfigs.GetInt("ChanceRefreshCost0"))) { return(false); } } for (int i = GameConsts.Chance.MinCoinChancePackId; i <= GameConsts.Chance.MaxCoinChancePackId; i++) { m_Chance.UnopenedChanceRewards.Add(i, random.GetChanceRewards(i)); } m_Chance.TotalFreeCount = 0; break; case ChanceType.Money: if (!IsFree) { if (!player.DeductMoney(GameConfigs.GetInt("ChanceRefreshCost1"))) { return(false); } } for (int i = GameConsts.Chance.MinMoneyChancePackId; i <= GameConsts.Chance.MaxMoneyChancePackId; i++) { m_Chance.UnopenedChanceRewards.Add(i - GameConsts.Chance.MaxCoinChancePackId, random.GetChanceRewards(i)); } m_Chance.TotalFreeCount = 0; break; default: break; } m_Chance.OpenedChanceRewards.Clear(); return(true); }
public static RewardChessField GetRewardChessField(int userId, ChessFieldColor color, Random r) { RewardChessField field = new RewardChessField(); field.Color = color; field.IsOpened = false; field.IsFree = false; field.ParentId = -1; field.RewardCoin = 0; field.RewardMoney = 0; if (color != ChessFieldColor.Empty) { PlayerLogic p = new PlayerLogic(); p.SetUser(userId); double baseRewardCoin = GetBaseRewardCoin(p.MyPlayer.Level); field.RewardCoin = r.Next((int)Math.Round(baseRewardCoin * 0.5), (int)Math.Round(baseRewardCoin * 1.5)); } if (color == ChessFieldColor.RewardGray) { RandomDropLogic rd = RandomDropLogic.GetInstance(); var dropDict = new CacheDictionary <int, int>(); if (r.Next(100) < GameConsts.PlayerChess.TopRewardRate) { var dropData = CacheSet.DropTable.GetData(GameConsts.PlayerChess.TopRewardDropId); rd.GetDropDict(dropData, dropDict); } else { var dropData = CacheSet.DropTable.GetData(GameConsts.PlayerChess.MidRewardDropId); rd.GetDropDict(dropData, dropDict); } if (dropDict.ContainsKey((int)GiftItemType.Money)) { field.RewardMoney += dropDict[(int)GiftItemType.Money]; dropDict.Remove((int)GiftItemType.Money); } foreach (var kv in dropDict) { field.RewardItems.Add(kv); } } return(field); }
public override bool TakeAction() { PlayerFoundryLogic pf = new PlayerFoundryLogic(); pf.SetUser(m_UserId); int[] drops = GameConsts.Foundry.FoundryRewardDropPackageId[m_RequestPacket.Level]; RandomDropLogic random = RandomDropLogic.GetInstance(); CacheDictionary <int, int> dropDict = new CacheDictionary <int, int>(); foreach (int dropId in drops) { DTDrop dataRow = CacheSet.DropTable.GetData(dropId); random.GetDropDict(dataRow, dropDict); } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(dropDict)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "package is full"; return(false); } if (!pf.GetReward(m_RequestPacket.Level)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You can not get this reward"; return(false); } PBReceivedItems receivedItems; pp.GetItems(dropDict, ReceiveItemMethodType.GearFoundry, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; m_ResponsePacket.RewardFlags.AddRange(pf.MyFoundry.CanReceiveRewards); return(true); }
public PlayerInstanceLogic() { m_UserId = 0; m_InstanceDrop = null; m_RandomDrop = RandomDropLogic.GetInstance(); }
public DropItem OpenChance(int index, bool isFree) { if (isFree) { if (DateTime.UtcNow.Ticks < m_Chance.NextFreeTime) { return(null); } switch (m_Type) { case ChanceType.Coin: PlayerCoinChance coinChance = m_Chance as PlayerCoinChance; if (coinChance.TotalFreeCount >= GameConsts.Chance.MaxFreeCountForCoinChance) { return(null); } coinChance.TotalFreeCount += 1; m_Chance.NextFreeTime = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeCoinChanceCDSeconds).Ticks; break; case ChanceType.Money: m_Chance.NextFreeTime = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeMoneyChanceCDSeconds).Ticks; PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1); break; default: return(null); } } else { var dataRow = CacheSet.ChanceCostTable.GetData(m_Chance.OpenedChanceRewards.Count + 1); PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); switch (m_Type) { case ChanceType.Coin: if (!p.DeductCoin(dataRow.CoinCost)) { return(null); } break; case ChanceType.Money: if (!p.DeductMoney(dataRow.MoneyCost)) { return(null); } PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1); break; default: return(null); } } RandomDropLogic random = RandomDropLogic.GetInstance(); int id = random.OpenChanceBox(m_Chance.UnopenedChanceRewards); DropItem di = m_Chance.UnopenedChanceRewards[id]; try { m_Chance.OpenedChanceRewards.Add(index, di.Clone() as DropItem); } catch { return(null); } m_Chance.UnopenedChanceRewards.Remove(id); return(di); }