Files

868 lines
27 KiB
C#
Raw Permalink Normal View History

2026-10-12 16:22:04 +08:00
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<int> PathList { get; set; } = new List<int>();
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<int> CannonMultipleList { get; set; } = new List<int>();
}
[BsonIgnoreExtraElements]
public class RoomFishConfig
{
public GameTypeEnum GameType { get; set; }
public List<RoomFishDetailConfig> NormalFishList { get; set; } = new List<RoomFishDetailConfig>();
public List<RoomFishLevelConfig> RoomFishLevelList { get; set; } = new List<RoomFishLevelConfig>();
public List<RoomFishProbabilityConfig> RoomFishProbabilityList { get; set; } = new List<RoomFishProbabilityConfig>();
}
public class RoomFishProbabilityConfig
{
public int RoomLevel { get; set; } = 0;
public int Type { get; set; } = 0;
public FishTypeEnum FishType { get; set; }
public List<int> FirstFishCountRange { get; set; }
public List<int> TimeRange { get; set; }
public List<int> CountRange { get; set; }
public List<int> 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<int> 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<int> ThresholdList { get; set; } = new List<int>();
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<BaseProductCount> ProductList { get; set; } = new List<BaseProductCount>();
public List<GiftConfig> GiftList { get; set; } = new List<GiftConfig>();
}
[BsonIgnoreExtraElements]
public class PropInfConfig : BasePropInfo
{
public List<string> GameNumber { get; set; } = new List<string>();
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<GiftConfig> GiftList { get; set; } = new List<GiftConfig>();
public List<GiftConfig> DailyGift { get; set; } = new List<GiftConfig>();
}
[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<LuckWheelConfig> LuckWheel { get; set; } = new List<LuckWheelConfig>();
public LuckPokerConfig LuckPoker { get; set; } = new LuckPokerConfig();
public List<LuckFlyDiskConfig> LuckFlyDisk { get; set; } = new List<LuckFlyDiskConfig>();
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<BossProbabilityConfig> Probability { get; set; } = new List<BossProbabilityConfig>();
public List<LuckDragonConfig> LuckDragon { get; set; } = new List<LuckDragonConfig>();
public static int GetBossProbabilityConfigResponse(List<BossProbabilityConfigParam> 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<CruiseConfigCount> 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<BossProbabilityConfigParam> OuterConfig { get; set; } = new List<BossProbabilityConfigParam>();
public List<BossProbabilityConfigParam> MiddleConfig { get; set; } = new List<BossProbabilityConfigParam>();
public List<BossProbabilityConfigParam> InnerConfig { get; set; } = new List<BossProbabilityConfigParam>();
public (List<int> option, int beizhu, string ringName) GetResponse()
{
int beishu = 1;
var result = new List<int>();
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<CruiseConfigCount> CountConfig { get; set; } = new List<CruiseConfigCount>();
public List<BossProbabilityConfigParam> OneDeathConfig { get; set; } = new List<BossProbabilityConfigParam>();
public List<BossProbabilityConfigParam> TwoDeathConfig { get; set; } = new List<BossProbabilityConfigParam>();
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<ScorpionItemCountConfig> ItemCountConfig { get; set; } = new List<ScorpionItemCountConfig>();
public List<ScorpionItemConfig> ItemConfig { get; set; } = new List<ScorpionItemConfig>();
public List<BossProbabilityConfigParam> GoldConfig { get; set; } = new List<BossProbabilityConfigParam>();
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<ScorpionItemCountConfig> 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<ScorpionItemConfig> 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<ScorpionItemConfig> items) GetResponse()
{
int beishu = GetBossProbabilityConfigResponse(GoldConfig);
var items = new List<ScorpionItemConfig>();
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<CruiseConfigCount> CountConfig { get; set; } = new List<CruiseConfigCount>();
public List<List<BossProbabilityConfigParam>> DeathConfigs { get; set; } = new List<List<BossProbabilityConfigParam>>();
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<CruiseConfigCount> CountConfig { get; set; } = new List<CruiseConfigCount>();
public List<List<BossProbabilityConfigParam>> DeathConfigs { get; set; } = new List<List<BossProbabilityConfigParam>>();
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<BossProbabilityConfigParam> configParams { get; set; } = new List<BossProbabilityConfigParam>();
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<BossOptionBaseParam> OptionList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> GetResponse()
{
var opt = RandomBossOption.GetRandomBossOption(OptionList);
if (opt == null)
return null;
return new List<BossOptionBaseParam>() { opt };
}
}
public class LuckFlyDiskConfig : BaseBossConfig
{
public List<BossOptionBaseParam> InnerOptionList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> OuterOptionList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> GetResponse()
{
List<BossOptionBaseParam> result = new List<BossOptionBaseParam>();
var opt = RandomBossOption.GetRandomBossOption(InnerOptionList);
result.Add(opt);
var opt1 = RandomBossOption.GetRandomBossOption(OuterOptionList);
result.Add(opt1);
return result;
}
}
public class LuckPokerConfig : BaseBossConfig
{
public List<BossOptionBaseParam> OptionList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> GetResponse()
{
var opt = RandomBossOption.GetRandomBossOption(OptionList);
if (opt == null)
return null;
return new List<BossOptionBaseParam>() { opt };
}
}
public class LuckWheelConfig : BaseBossConfig
{
public List<BossOptionBaseParam> OptionList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> CountList { get; set; } = new List<BossOptionBaseParam>();
public List<BossOptionBaseParam> GetResponse()
{
List<double> count = new List<double>();
List<BossOptionBaseParam> option = new List<BossOptionBaseParam>();
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<string> FishNumber { get; set; } = new List<string>();
}
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<BossDropItemConfig> DropItems { get; set; } = new List<BossDropItemConfig>();
}
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<BossOptionBaseParam> 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<int> CreateRoomLimit { get; set; } = new List<int>();
public long MinBetGold { get; set; } = 1000;
public List<long> BetGoldLimits { get; set; } = new List<long>();
public List<int> CreateRoomVipLevels { get; set; } = new List<int>();
}
public class FishRoomConfig
{
public List<int> SeatSelectLimit { get; set; } = new List<int>();
public List<int> SeatSelectVipLevels { get; set; } = new List<int>();
}
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<TorpedoRewardConfig> RewardRanges { get; set; } = new();
}
}