57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using CommonDomain.BaseModel;
|
|||
|
|
|
||
|
|
namespace CommonDomain;
|
||
|
|
|
||
|
|
public static class BattleOrderGiftProductHelper
|
||
|
|
{
|
||
|
|
public static void Enrich(BattleOrderConfig? battleOrder, GameConfig? gameConfig)
|
||
|
|
{
|
||
|
|
if (battleOrder == null || gameConfig == null) return;
|
||
|
|
|
||
|
|
var gifts = (battleOrder.LevelConfig ?? new List<BattleOrderConfig.BattleOrderLevelConfig>())
|
||
|
|
.SelectMany(level =>
|
||
|
|
(level.NormalGiftList ?? new List<GiftConfig>())
|
||
|
|
.Concat(level.LuxuryGiftList ?? new List<GiftConfig>())
|
||
|
|
.Concat(level.SupremeGiftList ?? new List<GiftConfig>()))
|
||
|
|
.Concat((battleOrder.AdvanceGift ?? new List<BattleOrderConfig.AdvanceGiftConfig>())
|
||
|
|
.SelectMany(advance => advance.GiftList ?? new List<GiftConfig>()));
|
||
|
|
|
||
|
|
foreach (var gift in gifts)
|
||
|
|
EnrichGift(gift, gameConfig);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static void EnrichGift(GiftConfig gift, GameConfig gameConfig)
|
||
|
|
{
|
||
|
|
if (gift.Type != 3 || string.IsNullOrWhiteSpace(gift.OtherId)) return;
|
||
|
|
|
||
|
|
var number = gift.OtherId.Trim();
|
||
|
|
var fragment = gameConfig.PropFragments?.FirstOrDefault(item => item.Number == number);
|
||
|
|
BaseProduct? product = fragment;
|
||
|
|
var imageUrl = fragment?.ImageUrl ?? string.Empty;
|
||
|
|
|
||
|
|
if (fragment != null && string.IsNullOrWhiteSpace(imageUrl))
|
||
|
|
{
|
||
|
|
imageUrl = gameConfig.PropConfig?
|
||
|
|
.FirstOrDefault(item => item.Number == fragment.ProductNumber)?.ImageUrl ?? string.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (product == null)
|
||
|
|
{
|
||
|
|
product = gameConfig.PropConfig?.FirstOrDefault(item => item.Number == number);
|
||
|
|
imageUrl = product?.ImageUrl ?? string.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (product == null) return;
|
||
|
|
|
||
|
|
gift.Product = new BaseProduct
|
||
|
|
{
|
||
|
|
Number = product.Number,
|
||
|
|
Name = product.Name,
|
||
|
|
Desc = product.Desc,
|
||
|
|
ImageUrl = imageUrl,
|
||
|
|
Type = product.Type,
|
||
|
|
Level = product.Level
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|