增加收获属性逻辑,优化掉落物表现效果

This commit is contained in:
2026-10-05 17:02:29 +08:00
parent d55b1013ca
commit 7590d78e74
53 changed files with 1633 additions and 241 deletions
@@ -13,8 +13,11 @@ namespace SepCore.UI
{
public class ShopUseCase : IUIUseCase
{
public const int ShopRerollBaseCost = 1;
private readonly Player _player;
private readonly int _currentLevel;
private readonly Func<int> _getCurrentLevel;
private int _currentLevel;
private readonly Action _onShopFinish;
private readonly IReadOnlyList<GoodsConfig> _allGoods;
@@ -23,28 +26,45 @@ namespace SepCore.UI
private readonly Dictionary<Rarity, List<GoodsConfig>> _goodsByRarity = new();
private readonly List<ShopGoodsSelection> _selections = new();
private int _refreshTime;
private int _rollTimesInThisShop;
public ShopUseCase(Player player, int currentLevel, Action onShopFinish)
public int CurrentLevel => _getCurrentLevel != null ? _getCurrentLevel() : _currentLevel;
public int RollTimesInThisShop => _rollTimesInThisShop;
public IReadOnlyList<ShopGoodsSelection> Selections => _selections;
public ShopUseCase(Player player, Func<int> getCurrentLevel, Action onShopFinish)
{
_player = player;
_currentLevel = currentLevel;
_getCurrentLevel = getCurrentLevel;
_currentLevel = getCurrentLevel != null ? getCurrentLevel() : 1;
_onShopFinish = onShopFinish;
_allGoods = GameEntry.Luban.GetTable<GoodsConfig>();
BuildGoodsRarityPools();
}
public ShopUseCase(Player player, int currentLevel, Action onShopFinish)
: this(player, () => currentLevel, onShopFinish)
{
}
public static int CalculateRefreshPrice(int wave, int rollTimes)
{
return ShopRerollBaseCost + (Mathf.Max(1, wave) * 1) + (Mathf.Max(0, rollTimes) * 2);
}
public ShopRawData CreateInitialModel()
{
_refreshTime = 0;
_currentLevel = _getCurrentLevel != null ? _getCurrentLevel() : _currentLevel;
_rollTimesInThisShop = 0;
int initialRefreshPrice = CalculateRefreshPrice(_currentLevel, _rollTimesInThisShop);
return new ShopRawData
{
CurrentLevel = _currentLevel,
RefreshPrice = _currentLevel,
RefreshPrice = initialRefreshPrice,
PlayerCoin = _player.Coin,
GoodsItems = BuildRandomGoodsItems(GameEntry.Luban.Global.ShopGoodsCount),
GoodsItems = RefreshGoodsSlots(GameEntry.Luban.Global.ShopGoodsCount),
PropItems = _player.Props,
PropMaxCount = GameEntry.Luban.Global.PropMaxCount,
WeaponItems = _player.Weapons,
@@ -84,17 +104,34 @@ namespace SepCore.UI
}
_player.Coin -= cost;
int refreshPrice = (_refreshTime + 1) * _currentLevel;
_refreshTime++;
_rollTimesInThisShop++;
int nextRefreshPrice = CalculateRefreshPrice(_currentLevel, _rollTimesInThisShop);
return new ShopRefreshResult
{
GoodsItems = BuildRandomGoodsItems(GameEntry.Luban.Global.ShopGoodsCount),
RefreshPrice = refreshPrice
GoodsItems = RefreshGoodsSlots(GameEntry.Luban.Global.ShopGoodsCount),
RefreshPrice = nextRefreshPrice
};
}
public bool ToggleLock(int goodsIndex)
{
if (goodsIndex < 0 || goodsIndex >= _selections.Count)
{
Log.Error("ShopUseCase::ToggleLock: Invalid goodsIndex {0}.", goodsIndex);
return false;
}
ShopGoodsSelection selection = _selections[goodsIndex];
if (selection == null)
{
return false;
}
selection.IsLocked = !selection.IsLocked;
return selection.IsLocked;
}
public async UniTask<ShopPurchaseResult> TryPurchaseAsync(int goodsIndex)
{
if (goodsIndex < 0 || goodsIndex >= _selections.Count)
@@ -137,76 +174,117 @@ namespace SepCore.UI
_onShopFinish?.Invoke();
}
private List<GoodsItemRawData> BuildRandomGoodsItems(int count)
private List<GoodsItemRawData> RefreshGoodsSlots(int count)
{
if (_allGoods.Count == 0)
{
Log.Error("ShopFormUseCase::BuildRandomGoodsItems(): _allGoods is empty");
Log.Error("ShopUseCase::RefreshGoodsSlots(): _allGoods is empty");
return null;
}
int finalCount = Mathf.Min(count, _allGoods.Count);
List<GoodsItemRawData> goodsItems = new List<GoodsItemRawData>(finalCount);
_selections.Clear();
while (_selections.Count < finalCount)
{
_selections.Add(null);
}
int currentLevel = _currentLevel;
float priceRandomPercent = GameEntry.Luban.Global.ShopPriceRandomPercent;
List<GoodsItemRawData> goodsItems = new List<GoodsItemRawData>(finalCount);
for (int i = 0; i < finalCount; i++)
{
ShopGoodsSelection existing = _selections[i];
if (existing != null && existing.IsLocked)
{
goodsItems.Add(CreateGoodsItemRawData(existing));
continue;
}
Rarity rarity = RollRarity(currentLevel);
GoodsConfig goodsConfig = PickGoodsByRarity(rarity);
if (goodsConfig == null)
{
Log.Error("ShopFormUseCase::BuildRandomGoodsItems: No available goods for selection.");
Log.Error("ShopUseCase::RefreshGoodsSlots: No available goods for selection.");
break;
}
GoodsItemRawData goodsItem = new GoodsItemRawData();
int price;
object dataRow;
ItemType itemType;
if (goodsConfig.GoodsType == GoodsType.Prop)
{
PropConfig propConfig = GameEntry.Luban.Get<PropConfig>(goodsConfig.RefId);
int basePrice = propConfig.Price;
price = CalculateRandomizedPrice(basePrice, priceRandomPercent);
goodsItem.ItemType = ItemType.Prop;
goodsItem.Rarity = propConfig.Rarity;
goodsItem.DataRow = propConfig;
itemType = ItemType.Prop;
rarity = propConfig.Rarity;
dataRow = propConfig;
}
else if (goodsConfig.GoodsType == GoodsType.Weapon)
{
WeaponConfig weaponConfig = GameEntry.Luban.Get<WeaponConfig>(goodsConfig.RefId);
int basePrice = weaponConfig.Price;
price = CalculateRandomizedPrice(basePrice, priceRandomPercent);
goodsItem.ItemType = ItemType.Weapon;
goodsItem.Rarity = weaponConfig.Rarity;
goodsItem.DataRow = weaponConfig;
itemType = ItemType.Weapon;
rarity = weaponConfig.Rarity;
dataRow = weaponConfig;
}
else
{
Log.Warning(
$"ShopFormUseCase::BuildRandomGoodsItems: Unsupported goods type = {goodsConfig.GoodsType}");
$"ShopUseCase::RefreshGoodsSlots: Unsupported goods type = {goodsConfig.GoodsType}");
continue;
}
goodsItem.Price = price;
_selections.Add(new ShopGoodsSelection
_selections[i] = new ShopGoodsSelection
{
GoodsType = goodsConfig.GoodsType,
RefId = goodsConfig.RefId,
Price = price
});
Price = price,
IsLocked = false
};
goodsItems.Add(goodsItem);
goodsItems.Add(new GoodsItemRawData
{
Price = price,
Rarity = rarity,
ItemType = itemType,
DataRow = dataRow,
IsLocked = false
});
}
return goodsItems;
}
private GoodsItemRawData CreateGoodsItemRawData(ShopGoodsSelection selection)
{
GoodsItemRawData item = new GoodsItemRawData
{
Price = selection.Price,
IsLocked = selection.IsLocked
};
if (selection.GoodsType == GoodsType.Prop)
{
PropConfig propConfig = GameEntry.Luban.Get<PropConfig>(selection.RefId);
item.ItemType = ItemType.Prop;
item.Rarity = propConfig.Rarity;
item.DataRow = propConfig;
}
else if (selection.GoodsType == GoodsType.Weapon)
{
WeaponConfig weaponConfig = GameEntry.Luban.Get<WeaponConfig>(selection.RefId);
item.ItemType = ItemType.Weapon;
item.Rarity = weaponConfig.Rarity;
item.DataRow = weaponConfig;
}
return item;
}
private void BuildGoodsRarityPools()
{
_goodsByRarity.Clear();
@@ -270,7 +348,8 @@ namespace SepCore.UI
private Rarity RollRarity(int level)
{
return RarityUtility.SelectRarityForLevel(level);
float luck = _player?.StatComponent != null ? _player.StatComponent.GetStatValue(StatType.Luck) : 0f;
return RarityUtility.SelectRarityForLevel(level, luck);
}
private static int CalculateRandomizedPrice(int basePrice, float priceRandomPercent)