using Amazon.SecurityToken.Model.Internal.MarshallTransformations; using Common.Utils; using System.Text.Json.Serialization; using CommonDomain.Enum; using MongoDB.Bson.Serialization.Attributes; using static CommonDomain.BaseModel.BossConfig.BossBombConfig; namespace CommonDomain.BaseModel { public static class GlobalRandom { private static readonly Random _instance = new Random(); private static readonly object _lock = new object(); public static int Next(int maxValue) => Next(0, maxValue); public static int Next(int minValue, int maxValue) { lock (_lock) { return _instance.Next(minValue, maxValue); } } public static long NextInt64(long minValue, long maxValue) { lock (_lock) { return _instance.NextInt64(minValue, maxValue); } } public static int NextInclusive(int value1, int value2) { var minValue = Math.Min(value1, value2); var maxValue = Math.Max(value1, value2); if (minValue == maxValue) return minValue; lock (_lock) { return (int)_instance.NextInt64(minValue, (long)maxValue + 1); } } public static double NextDouble() { lock (_lock) { return _instance.NextDouble(); } } } [BsonIgnoreExtraElements] public class FishTypeConfig { public string FishNumber { get; set; } = string.Empty; public string FishName { get; set; } = string.Empty; public string FishBrief { get; set; } = string.Empty; public FishTypeEnum FishType { get; set; } public int FishScore { get; set; } = 0; public int KillWeight { get; set; } = 0; [BsonElement("pathList")] public List PathList { get; set; } = new List(); public string FishImage { get; set; } = string.Empty; public string FishMultipleDesc { get; set; } = string.Empty; } [BsonIgnoreExtraElements] public class RoomConfig { public string RoomNumber { get; set; } = string.Empty; public string RoomName { get; set; } = string.Empty; public GameTypeEnum GameType { get; set; } public int RoomLevel { get; set; } = 0; public int RoomPartitionNum { get; set; } = 0; public int RoomCount { get; set; } = 0; public int RoomGoldLimit { get; set; } = 0; public List CannonMultipleList { get; set; } = new List(); } [BsonIgnoreExtraElements] public class RoomFishConfig { public GameTypeEnum GameType { get; set; } public List NormalFishList { get; set; } = new List(); public List RoomFishLevelList { get; set; } = new List(); public List RoomFishProbabilityList { get; set; } = new List(); } public class RoomFishProbabilityConfig { public int RoomLevel { get; set; } = 0; public int Type { get; set; } = 0; public FishTypeEnum FishType { get; set; } public List FirstFishCountRange { get; set; } public List TimeRange { get; set; } public List CountRange { get; set; } public List MaxCountRange { get; set; } } [BsonIgnoreExtraElements] public class RoomFishLevelConfig : RoomFishDetailConfig { public int RoomLevel { get; set; } = 0; } [BsonIgnoreExtraElements] public class RoomFishDetailConfig { public int Type { get; set; } = 0; public string FishNumber { get; set; } = string.Empty; public int FishWeight { get; set; } = 0; public int FishFrequency { get; set; } = 0; public int MaxCount { get; set; } = 0; public int Times { get; set; } = 0; } [BsonIgnoreExtraElements] public class FishArrayConfig { public FishArrayConfig() { } public FishArrayConfig(string fishArrayNumber, string name, string fishNumber, int fishCount, string bossFishNumber, int boosCount, string arrayNumber, List thresholdList) { FishArrayNumber = fishArrayNumber; Name = name; FishNumber = fishNumber; FishCount = fishCount; BossFishNumber = bossFishNumber; BoosCount = boosCount; ArrayNumber = arrayNumber; ThresholdList = thresholdList; } public string FishArrayNumber { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; public string FishNumber { get; set; } = string.Empty; public int FishCount { get; set; } = 0; public string BossFishNumber { get; set; } = string.Empty; public int BoosCount { get; set; } = 0; public string ArrayNumber { get; set; } = string.Empty; public List ThresholdList { get; set; } = new List(); public double GenerateFrequency { get; set; } = 0.2; } [BsonIgnoreExtraElements] public class UserLevelConfig { public int Level { get; set; } = 0; public long ExpMin { get; set; } = 0; public long ExpMax { get; set; } = 0; public long Gold { get; set; } = 0; public int Diamond { get; set; } = 0; public List ProductList { get; set; } = new List(); public List GiftList { get; set; } = new List(); } [BsonIgnoreExtraElements] public class PropInfConfig : BasePropInfo { public List GameNumber { get; set; } = new List(); public int Day { get; set; } = 0; } [BsonIgnoreExtraElements] public class PropFragmentConfig : BasePropInfo { public int FragmentCount { get; set; } = 0; public string ProductNumber { get; set; } = string.Empty; } [BsonIgnoreExtraElements] public class BasePropInfo : BaseProduct { public SaleTypeEnum SaleType { get; set; } = SaleTypeEnum.金币; public int Price { get; set; } = 0; public int SaleCount { get; set; } = 1; public int VIPPrice { get; set; } = 0; public int DealerPrice { get; set; } = 0; public bool IsEnable { get; set; } = true; public bool IsSale { get; set; } = true; } [BsonIgnoreExtraElements] public class VipLevelConfig { public int Level { get; set; } = 0; public long ExpMax { get; set; } = 0; public long ExpMin { get; set; } = 0; public double SignInAdd { get; set; } = 0; public string Remark { get; set; } = string.Empty; public List GiftList { get; set; } = new List(); public List DailyGift { get; set; } = new List(); } [BsonIgnoreExtraElements] public class GiftConfig { public int Type { get; set; } = 0; public string OtherId { get; set; } = string.Empty; public bool IsRandom { get; set; } = false; public int Count { get; set; } = 0; public int MinCount { get; set; } = 0; public int MaxCount { get; set; } = 0; [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public BaseProduct? Product { get; set; } } [BsonIgnoreExtraElements] public class KillConfig { public int NormalizationFactorPlayer { get; set; } = 50000; public double MinPlayerModifier { get; set; } = 0.3; public double MaxPlayerModifier { get; set; } = 2.0; public int TargetSystemProfit { get; set; } = 1000000; public int NormalizationFactorSystem { get; set; } = 10000000; public double MinSystemModifier { get; set; } = 0.95; public double MaxSystemModifier { get; set; } = 1.05; public int DaySystemGold { get; set; } = 100000; public int IPCount { get; set; } = 5; public double ViolateValue { get; set; } = 0.2; public CompensateRateParam CompensateRate { get; set; } = new CompensateRateParam(); public CompensateRateParam PenaltyRate { get; set; } = new CompensateRateParam(); public long GlobalAnnounceMinGold { get; set; } = 0; } [BsonIgnoreExtraElements] public class CompensateRateParam { public double BossRate { get; set; } = 1; public double GoldRate { get; set; } = 1; public double SpecialRate { get; set; } = 1; public double Ordinary { get; set; } = 1; } [BsonIgnoreExtraElements] public class BossConfig { public List LuckWheel { get; set; } = new List(); public LuckPokerConfig LuckPoker { get; set; } = new LuckPokerConfig(); public List LuckFlyDisk { get; set; } = new List(); public BaseBossConfig FullScreen { get; set; } = new BaseBossConfig(); public BaseBossConfig Range { get; set; } = new BaseBossConfig(); public AmmunitionBoxConfig AmmunitionBox { get; set; } = new AmmunitionBoxConfig(); public InterstellarCruiseConfig InterstellarCruise { get; set; } = new InterstellarCruiseConfig(); public BossFlameStormConfig FlameStorm { get; set; } = new BossFlameStormConfig(); public BossBombConfig Bomb { get; set; } = new BossBombConfig(); public BossScorpionConfig Scorpion { get; set; } = new BossScorpionConfig(); public List Probability { get; set; } = new List(); public List LuckDragon { get; set; } = new List(); public static int GetBossProbabilityConfigResponse(List configParams) { int totalWeight = configParams.Sum(p => p.TriggerRate); if (totalWeight <= 0) { return 0; } int randomValue = GlobalRandom.Next(0, totalWeight); int currentWeightSum = 0; foreach (var param in configParams) { currentWeightSum += param.TriggerRate; if (randomValue < currentWeightSum) { return GlobalRandom.NextInclusive(param.Min, param.Max); } } return 0; } public static CruiseConfigCount GetRandomCountConfigOption(List options) { if (options == null || !options.Any()) { return null; } long totalWeight = options.Sum(o => (long)o.TriggerRate); if (totalWeight <= 0) { return null; } long randomValue = GlobalRandom.NextInt64(0, totalWeight); long currentWeightSum = 0; foreach (var option in options) { currentWeightSum += option.TriggerRate; if (randomValue < currentWeightSum) { return option; } } return options.FirstOrDefault(o => o.TriggerRate > 0); } public class CruiseConfigCount { public int Count { get; set; } public int TriggerRate { get; set; } = 0; public int KillRate { get; set; } = 0; } public class LuckDragonConfig:BaseBossConfig { public List OuterConfig { get; set; } = new List(); public List MiddleConfig { get; set; } = new List(); public List InnerConfig { get; set; } = new List(); public (List option, int beizhu, string ringName) GetResponse() { int beishu = 1; var result = new List(); string ringName = "外圈"; int outerResult = GetBossProbabilityConfigResponse(OuterConfig); result.Add(outerResult); if (outerResult == -1) { int middleResult = GetBossProbabilityConfigResponse(MiddleConfig); result.Add(middleResult); if (middleResult == -1) { int innerResult = GetBossProbabilityConfigResponse(InnerConfig); result.Add(innerResult); beishu = innerResult; ringName = "内圈"; } else { beishu = middleResult; ringName = "中圈"; } } else { beishu = outerResult; ringName = "外圈"; } return (result, beishu, ringName); } } public class BossBombConfig:BaseBossConfig { public List CountConfig { get; set; } = new List(); public List OneDeathConfig { get; set; } = new List(); public List TwoDeathConfig { get; set; } = new List(); public (int beishu, int type) GetResponse(string fishId) { int beishu = 0; var countConfig = GetRandomCountConfigOption(CountConfig); if (countConfig == null) return (1, 1); if (countConfig.Count == 1) { beishu = GetBossProbabilityConfigResponse(OneDeathConfig); return (beishu, 1); } else { beishu = GetBossProbabilityConfigResponse(TwoDeathConfig); return (beishu, 2); } } } public class ScorpionItemCountConfig { public int Count { get; set; } = 0; public int Weight { get; set; } = 0; } public class ScorpionItemConfig { public string PropNumber { get; set; } = string.Empty; public int Count { get; set; } = 0; public int Weight { get; set; } = 0; } public class BossScorpionConfig : BaseBossConfig { public List ItemCountConfig { get; set; } = new List(); public List ItemConfig { get; set; } = new List(); public List GoldConfig { get; set; } = new List(); public int CompositeMultiplier { get; set; } = 650; public double KillProbability { get { return CompositeMultiplier <= 0 ? 0 : 1.0 / CompositeMultiplier; } } public double ComputedWeight { get { return CompositeMultiplier <= 0 ? 0 : 10000.0 / CompositeMultiplier; } } private static ScorpionItemCountConfig GetRandomItemCount(List options) { if (options == null || !options.Any()) return null; long totalWeight = options.Sum(o => (long)o.Weight); if (totalWeight <= 0) return null; long randomValue = GlobalRandom.NextInt64(0, totalWeight); long currentWeightSum = 0; foreach (var option in options) { currentWeightSum += option.Weight; if (randomValue < currentWeightSum) return option; } return options.FirstOrDefault(o => o.Weight > 0); } private static ScorpionItemConfig GetRandomItem(List options) { if (options == null || !options.Any()) return null; long totalWeight = options.Sum(o => (long)o.Weight); if (totalWeight <= 0) return null; long randomValue = GlobalRandom.NextInt64(0, totalWeight); long currentWeightSum = 0; foreach (var option in options) { currentWeightSum += option.Weight; if (randomValue < currentWeightSum) return option; } return options.FirstOrDefault(o => o.Weight > 0); } public (int beishu, List items) GetResponse() { int beishu = GetBossProbabilityConfigResponse(GoldConfig); var items = new List(); var countConfig = GetRandomItemCount(ItemCountConfig); int itemCount = countConfig?.Count ?? 0; for (int i = 0; i < itemCount; i++) { var item = GetRandomItem(ItemConfig); if (item != null) items.Add(item); } return (beishu, items); } } public class BossFlameStormConfig : BaseBossConfig { public List CountConfig { get; set; } = new List(); public List> DeathConfigs { get; set; } = new List>(); public (bool isKill, int beishu, string fishId, int animId) GetResponse(string fishId) { var countConfig = GetRandomCountConfigOption(CountConfig); if (countConfig == null) return (true, 1, fishId, GlobalRandom.Next(2, 5)); if (DeathConfigs.Count == 0) return (countConfig.Count > 1, 1, fishId, countConfig.Count > 1 ? GlobalRandom.Next(2, 5) : 1); int index = Math.Max(0, countConfig.Count - 1); if (index >= DeathConfigs.Count) index = DeathConfigs.Count - 1; int beishu = GetBossProbabilityConfigResponse(DeathConfigs[index]); if (countConfig.Count == 1) return (false, beishu, fishId, 1); return (true, beishu, fishId, GlobalRandom.Next(2, 5)); } } public class InterstellarCruiseConfig : BaseBossConfig { public List CountConfig { get; set; } = new List(); public List> DeathConfigs { get; set; } = new List>(); public (bool isKill, int beishu, string fishId, int animId) GetResponse(string fishId) { var countConfig = GetRandomCountConfigOption(CountConfig); if (countConfig == null) return (true, 1, fishId, GlobalRandom.Next(2, 5)); if (DeathConfigs.Count == 0) return (countConfig.Count > 1, 1, fishId, countConfig.Count > 1 ? GlobalRandom.Next(2, 5) : 1); int index = Math.Max(0, countConfig.Count - 1); if (index >= DeathConfigs.Count) index = DeathConfigs.Count - 1; int beishu = GetBossProbabilityConfigResponse(DeathConfigs[index]); if (countConfig.Count == 1) return (false, beishu, fishId, 1); return (true, beishu, fishId, GlobalRandom.Next(2, 5)); } } public class BossProbabilityConfig : BaseBossConfig { public List configParams { get; set; } = new List(); public int GetResponse() { int totalWeight = configParams.Sum(p => p.TriggerRate); if (totalWeight <= 0) { return 0; } int randomValue = GlobalRandom.Next(0, totalWeight); int currentWeightSum = 0; foreach (var param in configParams) { currentWeightSum += param.TriggerRate; if (randomValue < currentWeightSum) { return GlobalRandom.NextInclusive(param.Min, param.Max); } } return 0; } } public class AmmunitionBoxConfig : BaseBossConfig { public List OptionList { get; set; } = new List(); public List GetResponse() { var opt = RandomBossOption.GetRandomBossOption(OptionList); if (opt == null) return null; return new List() { opt }; } } public class LuckFlyDiskConfig : BaseBossConfig { public List InnerOptionList { get; set; } = new List(); public List OuterOptionList { get; set; } = new List(); public List GetResponse() { List result = new List(); var opt = RandomBossOption.GetRandomBossOption(InnerOptionList); result.Add(opt); var opt1 = RandomBossOption.GetRandomBossOption(OuterOptionList); result.Add(opt1); return result; } } public class LuckPokerConfig : BaseBossConfig { public List OptionList { get; set; } = new List(); public List GetResponse() { var opt = RandomBossOption.GetRandomBossOption(OptionList); if (opt == null) return null; return new List() { opt }; } } public class LuckWheelConfig : BaseBossConfig { public List OptionList { get; set; } = new List(); public List CountList { get; set; } = new List(); public List GetResponse() { List count = new List(); List option = new List(); foreach (var item in CountList) { if (item.TriggerRate >= 100) { count.Add(item.OptionId); continue; } if (GlobalRandom.Next(100) < item.TriggerRate) { count.Add(item.OptionId); continue; } break; } foreach (var item in count) { var opt = RandomBossOption.GetRandomBossOption(OptionList); if (opt == null) continue; option.Add(opt); } return option; } } public class BaseBossConfig { public List FishNumber { get; set; } = new List(); } public class BossProbabilityConfigParam { public BossProbabilityConfigParam(int min, int max, int triggerRate) { Min = min; Max = max; TriggerRate = triggerRate; } public int Min { get; set; } public int Max { get; set; } public int TriggerRate { get; set; } = 0; } } public class BossDropItemConfig { public string PropNumber { get; set; } = string.Empty; public string PropName { get; set; } = string.Empty; public int Count { get; set; } = 1; public int Weight { get; set; } = 0; } public class BossDropConfig { public int NoDropWeight { get; set; } = 5000; public List DropItems { get; set; } = new List(); } public class BossOptionBaseParam { public BossOptionBaseParam(double optionId, int triggerRate, double score = 0) { OptionId = optionId; TriggerRate = triggerRate; Score = score; } public double OptionId { get; set; } public int TriggerRate { get; set; } = 0; public double Score { get; set; } = 0; } public static class RandomBossOption { public static BossOptionBaseParam GetRandomBossOption(List options) { if (options == null || !options.Any()) { return null; } long totalWeight = options.Sum(o => (long)o.TriggerRate); if (totalWeight <= 0) { return null; } long randomValue = GlobalRandom.NextInt64(0, totalWeight); long currentWeightSum = 0; foreach (var option in options) { currentWeightSum += option.TriggerRate; if (randomValue < currentWeightSum) { return option; } } return options.FirstOrDefault(o => o.TriggerRate > 0); } } public class ScratchCardConfig { public int Type { get; set; } = 0; public BaseProduct? BaseProduct { get; set; } public int Count { get; set; } = 0; public int Weight { get; set; } = 0; } public class ChessConfig { public List CreateRoomLimit { get; set; } = new List(); public long MinBetGold { get; set; } = 1000; public List BetGoldLimits { get; set; } = new List(); public List CreateRoomVipLevels { get; set; } = new List(); } public class FishRoomConfig { public List SeatSelectLimit { get; set; } = new List(); public List SeatSelectVipLevels { get; set; } = new List(); } public class TorpedoRewardConfig { public int MinGold { get; set; } public int MaxGold { get; set; } public int Weight { get; set; } } public class TorpedoItemConfig { public string Number { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; public string Color { get; set; } = string.Empty; public List RewardRanges { get; set; } = new(); } }