- 调整项目结构以适应打包需求

- 添加控制台便于在游戏运行过程中调试各项功能
- 添加 LevelRarity 表,增加了随关卡数动态调整的商品道具品质刷新概率
This commit is contained in:
SepComet
2026-02-18 22:53:33 +08:00
parent e151619c69
commit b4bc8b0445
202 changed files with 5160 additions and 3393 deletions
@@ -7,6 +7,8 @@ using Entity;
using Procedure;
using UnityEngine;
using UnityGameFramework.Runtime;
using Game.Utility;
using GameFramework.DataTable;
namespace UI
{
@@ -15,6 +17,9 @@ namespace UI
private const int BaseRefreshPrice = 2;
private readonly GameStateLevelUp _gameStateLevelUp;
private readonly DRLevelUpReward[] _allRewards;
private readonly IDataTable<DRLevelRarity> _levelRarityTable;
private readonly Dictionary<ItemRarity, List<DRLevelUpReward>> _rewardsByRarity = new();
private readonly List<DRLevelUpReward> _validRewards = new();
private int _refreshCount;
private LevelUpFormRawData _currentModel;
@@ -26,6 +31,9 @@ namespace UI
_player = player;
_gameStateLevelUp = gameStateLevelUp;
_allRewards = GameEntry.DataTable.GetDataTable<DRLevelUpReward>().ToArray();
_levelRarityTable = GameEntry.DataTable.GetDataTable<DRLevelRarity>();
BuildRewardRarityPools();
}
public LevelUpFormRawData CreateInitialModel(int count = 4)
@@ -99,10 +107,18 @@ namespace UI
int finalCount = count > 0 ? System.Math.Min(count, _allRewards.Length) : _allRewards.Length;
List<DRLevelUpReward> selections = new List<DRLevelUpReward>(finalCount);
int currentLevel = _player != null ? _player.CurrentLevel : 1;
for (int i = 0; i < finalCount; i++)
{
int index = Random.Range(0, _allRewards.Length);
selections.Add(_allRewards[index]);
ItemRarity rarity = RarityUtility.SelectRarityForLevel(_levelRarityTable, currentLevel);
DRLevelUpReward reward = PickRewardByRarity(rarity);
if (reward == null)
{
Log.Warning("LevelUpFormUseCase::BuildModel(): No available reward for selection.");
break;
}
selections.Add(reward);
}
return new LevelUpFormRawData
@@ -131,7 +147,49 @@ namespace UI
return;
}
_player.AddProp(new PropItem(reward.Modifiers, ItemRarity.White, reward.Title, reward.IconAssetName));
_player.AddProp(new PropItem(reward.Modifiers, reward.Rarity, reward.Title, reward.IconAssetName));
}
private void BuildRewardRarityPools()
{
_rewardsByRarity.Clear();
_validRewards.Clear();
if (_allRewards == null) return;
foreach (DRLevelUpReward reward in _allRewards)
{
if (reward == null)
{
continue;
}
ItemRarity rarity = reward.Rarity;
_validRewards.Add(reward);
if (!_rewardsByRarity.TryGetValue(rarity, out List<DRLevelUpReward> list))
{
list = new List<DRLevelUpReward>();
_rewardsByRarity.Add(rarity, list);
}
list.Add(reward);
}
}
private DRLevelUpReward PickRewardByRarity(ItemRarity rarity)
{
if (_rewardsByRarity.TryGetValue(rarity, out List<DRLevelUpReward> list) && list.Count > 0)
{
return list[Random.Range(0, list.Count)];
}
if (_validRewards.Count > 0)
{
return _validRewards[Random.Range(0, _validRewards.Count)];
}
return null;
}
}
}
}
@@ -33,6 +33,10 @@ namespace UI
private readonly DRGoods[] _allGoods;
private readonly IDataTable<DRProp> _propDataTable;
private readonly IDataTable<DRWeapon> _weaponDataTable;
private readonly IDataTable<DRLevelRarity> _levelRarityTable;
private readonly List<DRGoods> _validGoods = new();
private readonly Dictionary<ItemRarity, List<DRGoods>> _goodsByRarity = new();
private readonly List<ShopGoodsSelection> _selections = new();
private int _refreshTime;
@@ -53,6 +57,9 @@ namespace UI
_allGoods = GameEntry.DataTable.GetDataTable<DRGoods>().ToArray();
_propDataTable = GameEntry.DataTable.GetDataTable<DRProp>();
_weaponDataTable = GameEntry.DataTable.GetDataTable<DRWeapon>();
_levelRarityTable = GameEntry.DataTable.GetDataTable<DRLevelRarity>();
BuildGoodsRarityPools();
}
public ShopFormRawData CreateInitialModel()
@@ -148,10 +155,18 @@ namespace UI
List<GoodsItemContext> goodsItems = new List<GoodsItemContext>(finalCount);
_selections.Clear();
int currentLevel = _procedureGame != null ? _procedureGame.CurrentLevel : 1;
for (int i = 0; i < finalCount; i++)
{
int index = Random.Range(0, _allGoods.Length);
DRGoods drGoods = _allGoods[index];
ItemRarity rarity = RarityUtility.SelectRarityForLevel(_levelRarityTable, currentLevel);
DRGoods drGoods = PickGoodsByRarity(rarity);
if (drGoods == null)
{
Log.Warning("ShopFormUseCase::BuildRandomGoodsItems: No available goods for selection.");
break;
}
GoodsItemContext goodsItem = new GoodsItemContext();
int price;
@@ -208,6 +223,87 @@ namespace UI
return goodsItems;
}
private void BuildGoodsRarityPools()
{
_goodsByRarity.Clear();
_validGoods.Clear();
if (_allGoods == null) return;
foreach (DRGoods goods in _allGoods)
{
if (goods == null) continue;
if (!TryGetGoodsRarity(goods, out ItemRarity rarity))
{
continue;
}
_validGoods.Add(goods);
if (!_goodsByRarity.TryGetValue(rarity, out List<DRGoods> list))
{
list = new List<DRGoods>();
_goodsByRarity.Add(rarity, list);
}
list.Add(goods);
}
}
private DRGoods PickGoodsByRarity(ItemRarity rarity)
{
if (_goodsByRarity.TryGetValue(rarity, out List<DRGoods> list) && list.Count > 0)
{
return list[Random.Range(0, list.Count)];
}
if (_validGoods.Count > 0)
{
return _validGoods[Random.Range(0, _validGoods.Count)];
}
return null;
}
private bool TryGetGoodsRarity(DRGoods goods, out ItemRarity rarity)
{
rarity = ItemRarity.None;
if (goods == null)
{
return false;
}
if (goods.GoodsType == GoodsType.Prop)
{
DRProp drProp = _propDataTable != null ? _propDataTable.GetDataRow(goods.GoodsTypeId) : null;
if (drProp == null)
{
Log.Warning($"ShopFormUseCase::TryGetGoodsRarity: Missing DRProp, id = {goods.GoodsTypeId}");
return false;
}
rarity = drProp.Rarity;
return true;
}
if (goods.GoodsType == GoodsType.Weapon)
{
DRWeapon drWeapon = _weaponDataTable != null ? _weaponDataTable.GetDataRow(goods.GoodsTypeId) : null;
if (drWeapon == null)
{
Log.Warning($"ShopFormUseCase::TryGetGoodsRarity: Missing DRWeapon, id = {goods.GoodsTypeId}");
return false;
}
rarity = drWeapon.Rarity;
return true;
}
Log.Warning($"ShopFormUseCase::TryGetGoodsRarity: Unsupported goods type = {goods.GoodsType}");
return false;
}
private static int CalculateRandomizedPrice(int basePrice, float priceRandomPercent)
{
float normalizedPercent = priceRandomPercent > 1f ? priceRandomPercent / 100f : priceRandomPercent;