迁移数据表到 Luban,移除 JsonNet、EnumUtility
This commit is contained in:
@@ -18,7 +18,7 @@ namespace SepCore.UI
|
||||
public WeaponData WeaponData;
|
||||
public PropItem PropData;
|
||||
public ItemType ItemType;
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
public Action<int, int> OnRecycle;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class LevelUpRawData
|
||||
{
|
||||
public List<DRLevelUpReward> Rewards;
|
||||
public List<LevelUpRewardConfig> Rewards;
|
||||
public int RefreshPrice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using Random = UnityEngine.Random;
|
||||
using UnityGameFramework.Runtime;
|
||||
using SepCore.CustomUtility;
|
||||
using GameFramework.DataTable;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
@@ -16,10 +14,9 @@ namespace SepCore.UI
|
||||
{
|
||||
private const int BaseRefreshPrice = 2;
|
||||
private readonly Action _onCompleted;
|
||||
private readonly DRLevelUpReward[] _allRewards;
|
||||
private readonly IDataTable<DRLevelRarity> _levelRarityTable;
|
||||
private readonly Dictionary<ItemRarity, List<DRLevelUpReward>> _rewardsByRarity = new();
|
||||
private readonly List<DRLevelUpReward> _validRewards = new();
|
||||
private readonly LevelUpRewardConfig[] _allRewards;
|
||||
private readonly Dictionary<Rarity, List<LevelUpRewardConfig>> _rewardsByRarity = new();
|
||||
private readonly List<LevelUpRewardConfig> _validRewards = new();
|
||||
|
||||
private int _refreshCount;
|
||||
private LevelUpRawData _currentModel;
|
||||
@@ -30,8 +27,7 @@ namespace SepCore.UI
|
||||
{
|
||||
_player = player;
|
||||
_onCompleted = onCompleted;
|
||||
_allRewards = GameEntry.DataTable.GetDataTable<DRLevelUpReward>().ToArray();
|
||||
_levelRarityTable = GameEntry.DataTable.GetDataTable<DRLevelRarity>();
|
||||
_allRewards = GameEntry.Luban.GetTable<LevelUpRewardConfig>().ToArray();
|
||||
|
||||
BuildRewardRarityPools();
|
||||
}
|
||||
@@ -105,13 +101,13 @@ namespace SepCore.UI
|
||||
}
|
||||
|
||||
int finalCount = count > 0 ? Mathf.Min(count, _allRewards.Length) : _allRewards.Length;
|
||||
List<DRLevelUpReward> selections = new List<DRLevelUpReward>(finalCount);
|
||||
List<LevelUpRewardConfig> selections = new List<LevelUpRewardConfig>(finalCount);
|
||||
|
||||
int currentLevel = _player != null ? _player.CurrentLevel : 1;
|
||||
for (int i = 0; i < finalCount; i++)
|
||||
{
|
||||
ItemRarity rarity = RarityUtility.SelectRarityForLevel(_levelRarityTable, currentLevel);
|
||||
DRLevelUpReward reward = PickRewardByRarity(rarity);
|
||||
Rarity rarity = RarityUtility.SelectRarityForLevel(currentLevel);
|
||||
LevelUpRewardConfig reward = PickRewardByRarity(rarity);
|
||||
if (reward == null)
|
||||
{
|
||||
Log.Warning("LevelUpFormUseCase::BuildModel(): No available reward for selection.");
|
||||
@@ -128,7 +124,7 @@ namespace SepCore.UI
|
||||
};
|
||||
}
|
||||
|
||||
private void ApplyReward(DRLevelUpReward reward)
|
||||
private void ApplyReward(LevelUpRewardConfig reward)
|
||||
{
|
||||
if (reward == null)
|
||||
{
|
||||
@@ -141,7 +137,7 @@ namespace SepCore.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (reward.Modifiers == null || reward.Modifiers.Length == 0)
|
||||
if (reward.Modifiers == null || reward.Modifiers.Count == 0)
|
||||
{
|
||||
Log.Warning("LevelUpFormUseCase::ApplyReward: Reward modifiers are empty");
|
||||
return;
|
||||
@@ -157,19 +153,19 @@ namespace SepCore.UI
|
||||
|
||||
if (_allRewards == null) return;
|
||||
|
||||
foreach (DRLevelUpReward reward in _allRewards)
|
||||
foreach (LevelUpRewardConfig reward in _allRewards)
|
||||
{
|
||||
if (reward == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemRarity rarity = reward.Rarity;
|
||||
Rarity rarity = reward.Rarity;
|
||||
_validRewards.Add(reward);
|
||||
|
||||
if (!_rewardsByRarity.TryGetValue(rarity, out List<DRLevelUpReward> list))
|
||||
if (!_rewardsByRarity.TryGetValue(rarity, out List<LevelUpRewardConfig> list))
|
||||
{
|
||||
list = new List<DRLevelUpReward>();
|
||||
list = new List<LevelUpRewardConfig>();
|
||||
_rewardsByRarity.Add(rarity, list);
|
||||
}
|
||||
|
||||
@@ -177,9 +173,9 @@ namespace SepCore.UI
|
||||
}
|
||||
}
|
||||
|
||||
private DRLevelUpReward PickRewardByRarity(ItemRarity rarity)
|
||||
private LevelUpRewardConfig PickRewardByRarity(Rarity rarity)
|
||||
{
|
||||
if (_rewardsByRarity.TryGetValue(rarity, out List<DRLevelUpReward> list) && list.Count > 0)
|
||||
if (_rewardsByRarity.TryGetValue(rarity, out List<LevelUpRewardConfig> list) && list.Count > 0)
|
||||
{
|
||||
return list[Random.Range(0, list.Count)];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace SepCore.UI
|
||||
public class DisplayItemRawData
|
||||
{
|
||||
public string IconAssetName;
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public bool IsWeapon;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace SepCore.UI
|
||||
{
|
||||
public class GoodsItemRawData
|
||||
{
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public ItemType ItemType;
|
||||
public int Price;
|
||||
public DataRowBase DataRow;
|
||||
public object DataRow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.Entity.Weapon;
|
||||
using GameFramework.DataTable;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
using Random = UnityEngine.Random;
|
||||
@@ -34,13 +32,10 @@ namespace SepCore.UI
|
||||
private readonly int _currentLevel;
|
||||
private readonly Action _onShopFinish;
|
||||
|
||||
private readonly DRGoods[] _allGoods;
|
||||
private readonly IDataTable<DRProp> _propDataTable;
|
||||
private readonly IDataTable<DRWeapon> _weaponDataTable;
|
||||
private readonly IDataTable<DRLevelRarity> _levelRarityTable;
|
||||
private readonly IReadOnlyList<GoodsConfig> _allGoods;
|
||||
|
||||
private readonly List<DRGoods> _validGoods = new();
|
||||
private readonly Dictionary<ItemRarity, List<DRGoods>> _goodsByRarity = new();
|
||||
private readonly List<GoodsConfig> _validGoods = new();
|
||||
private readonly Dictionary<Rarity, List<GoodsConfig>> _goodsByRarity = new();
|
||||
|
||||
private readonly List<ShopGoodsSelection> _selections = new();
|
||||
private int _refreshTime;
|
||||
@@ -59,10 +54,7 @@ namespace SepCore.UI
|
||||
_player = player;
|
||||
_currentLevel = currentLevel;
|
||||
_onShopFinish = onShopFinish;
|
||||
_allGoods = GameEntry.DataTable.GetDataTable<DRGoods>().ToArray();
|
||||
_propDataTable = GameEntry.DataTable.GetDataTable<DRProp>();
|
||||
_weaponDataTable = GameEntry.DataTable.GetDataTable<DRWeapon>();
|
||||
_levelRarityTable = GameEntry.DataTable.GetDataTable<DRLevelRarity>();
|
||||
_allGoods = GameEntry.Luban.GetTable<GoodsConfig>();
|
||||
|
||||
BuildGoodsRarityPools();
|
||||
}
|
||||
@@ -155,13 +147,13 @@ namespace SepCore.UI
|
||||
|
||||
private List<GoodsItemRawData> BuildRandomGoodsItems(int count)
|
||||
{
|
||||
if (_allGoods == null || _allGoods.Length == 0)
|
||||
if (_allGoods == null || _allGoods.Count == 0)
|
||||
{
|
||||
Log.Error("ShopFormUseCase::BuildRandomGoodsItems(): _allGoods is empty");
|
||||
return null;
|
||||
}
|
||||
|
||||
int finalCount = Mathf.Min(count, _allGoods.Length);
|
||||
int finalCount = Mathf.Min(count, _allGoods.Count);
|
||||
List<GoodsItemRawData> goodsItems = new List<GoodsItemRawData>(finalCount);
|
||||
_selections.Clear();
|
||||
|
||||
@@ -169,9 +161,9 @@ namespace SepCore.UI
|
||||
|
||||
for (int i = 0; i < finalCount; i++)
|
||||
{
|
||||
ItemRarity rarity = RarityUtility.SelectRarityForLevel(_levelRarityTable, currentLevel);
|
||||
DRGoods drGoods = PickGoodsByRarity(rarity);
|
||||
if (drGoods == null)
|
||||
Rarity rarity = RollRarity(currentLevel);
|
||||
GoodsConfig goodsConfig = PickGoodsByRarity(rarity);
|
||||
if (goodsConfig == null)
|
||||
{
|
||||
Log.Warning("ShopFormUseCase::BuildRandomGoodsItems: No available goods for selection.");
|
||||
break;
|
||||
@@ -180,40 +172,32 @@ namespace SepCore.UI
|
||||
GoodsItemRawData goodsItem = new GoodsItemRawData();
|
||||
int price;
|
||||
|
||||
if (drGoods.GoodsType == GoodsType.Prop)
|
||||
if (goodsConfig.GoodsType == GoodsType.Prop)
|
||||
{
|
||||
DRProp drProp = _propDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
if (drProp == null)
|
||||
{
|
||||
Log.Warning(
|
||||
$"ShopFormUseCase::BuildRandomGoodsItems: Missing DRProp, id = {drGoods.GoodsTypeId}");
|
||||
continue;
|
||||
}
|
||||
PropConfig propConfig = GameEntry.Luban.Get<PropConfig>(goodsConfig.GoodsTypeId);
|
||||
int basePrice = propConfig.Price;
|
||||
float randomPercent = 0.05f;
|
||||
|
||||
price = CalculateRandomizedPrice(drProp.Price, drProp.PriceRandomPercent);
|
||||
price = CalculateRandomizedPrice(basePrice, randomPercent);
|
||||
goodsItem.ItemType = ItemType.Prop;
|
||||
goodsItem.Rarity = drProp.Rarity;
|
||||
goodsItem.DataRow = drProp;
|
||||
goodsItem.Rarity = propConfig.Rarity;
|
||||
goodsItem.DataRow = propConfig;
|
||||
}
|
||||
else if (drGoods.GoodsType == GoodsType.Weapon)
|
||||
else if (goodsConfig.GoodsType == GoodsType.Weapon)
|
||||
{
|
||||
DRWeapon drWeapon = _weaponDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
if (drWeapon == null)
|
||||
{
|
||||
Log.Warning(
|
||||
$"ShopFormUseCase::BuildRandomGoodsItems: Missing DRWeapon, id = {drGoods.GoodsTypeId}");
|
||||
continue;
|
||||
}
|
||||
WeaponConfig weaponConfig = GameEntry.Luban.Get<WeaponConfig>(goodsConfig.GoodsTypeId);
|
||||
int basePrice = weaponConfig.Price;
|
||||
float randomPercent = 0.05f;
|
||||
|
||||
price = CalculateRandomizedPrice(drWeapon.Price, drWeapon.PriceRandomPercent);
|
||||
price = CalculateRandomizedPrice(basePrice, randomPercent);
|
||||
goodsItem.ItemType = ItemType.Weapon;
|
||||
goodsItem.Rarity = drWeapon.Rarity;
|
||||
goodsItem.DataRow = drWeapon;
|
||||
goodsItem.Rarity = weaponConfig.Rarity;
|
||||
goodsItem.DataRow = weaponConfig;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning(
|
||||
$"ShopFormUseCase::BuildRandomGoodsItems: Unsupported goods type = {drGoods.GoodsType}");
|
||||
$"ShopFormUseCase::BuildRandomGoodsItems: Unsupported goods type = {goodsConfig.GoodsType}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -221,8 +205,8 @@ namespace SepCore.UI
|
||||
|
||||
_selections.Add(new ShopGoodsSelection
|
||||
{
|
||||
GoodsType = drGoods.GoodsType,
|
||||
GoodsTypeId = drGoods.GoodsTypeId,
|
||||
GoodsType = goodsConfig.GoodsType,
|
||||
GoodsTypeId = goodsConfig.GoodsTypeId,
|
||||
Price = price
|
||||
});
|
||||
|
||||
@@ -239,20 +223,20 @@ namespace SepCore.UI
|
||||
|
||||
if (_allGoods == null) return;
|
||||
|
||||
foreach (DRGoods goods in _allGoods)
|
||||
foreach (GoodsConfig goods in _allGoods)
|
||||
{
|
||||
if (goods == null) continue;
|
||||
|
||||
if (!TryGetGoodsRarity(goods, out ItemRarity rarity))
|
||||
if (!TryGetGoodsRarity(goods, out Rarity rarity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_validGoods.Add(goods);
|
||||
|
||||
if (!_goodsByRarity.TryGetValue(rarity, out List<DRGoods> list))
|
||||
if (!_goodsByRarity.TryGetValue(rarity, out List<GoodsConfig> list))
|
||||
{
|
||||
list = new List<DRGoods>();
|
||||
list = new List<GoodsConfig>();
|
||||
_goodsByRarity.Add(rarity, list);
|
||||
}
|
||||
|
||||
@@ -260,9 +244,9 @@ namespace SepCore.UI
|
||||
}
|
||||
}
|
||||
|
||||
private DRGoods PickGoodsByRarity(ItemRarity rarity)
|
||||
private GoodsConfig PickGoodsByRarity(Rarity rarity)
|
||||
{
|
||||
if (_goodsByRarity.TryGetValue(rarity, out List<DRGoods> list) && list.Count > 0)
|
||||
if (_goodsByRarity.TryGetValue(rarity, out List<GoodsConfig> list) && list.Count > 0)
|
||||
{
|
||||
return list[Random.Range(0, list.Count)];
|
||||
}
|
||||
@@ -275,9 +259,9 @@ namespace SepCore.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool TryGetGoodsRarity(DRGoods goods, out ItemRarity rarity)
|
||||
private bool TryGetGoodsRarity(GoodsConfig goods, out Rarity rarity)
|
||||
{
|
||||
rarity = ItemRarity.None;
|
||||
rarity = Rarity.None;
|
||||
if (goods == null)
|
||||
{
|
||||
return false;
|
||||
@@ -285,34 +269,27 @@ namespace SepCore.UI
|
||||
|
||||
if (goods.GoodsType == GoodsType.Prop)
|
||||
{
|
||||
DRProp drProp = _propDataTable.GetDataRow(goods.GoodsTypeId);
|
||||
if (drProp == null)
|
||||
{
|
||||
Log.Warning($"ShopFormUseCase::TryGetGoodsRarity: Missing DRProp, id = {goods.GoodsTypeId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
rarity = drProp.Rarity;
|
||||
PropConfig propConfig = GameEntry.Luban.Get<PropConfig>(goods.GoodsTypeId);
|
||||
rarity = propConfig.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;
|
||||
WeaponConfig weaponConfig = GameEntry.Luban.Get<WeaponConfig>(goods.GoodsTypeId);
|
||||
rarity = weaponConfig.Rarity;
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.Warning($"ShopFormUseCase::TryGetGoodsRarity: Unsupported goods type = {goods.GoodsType}");
|
||||
Log.Error("ShopUseCase.TryGetGoodsRarity: Unsupported goods type '{0}'.", goods.GoodsType);
|
||||
return false;
|
||||
}
|
||||
|
||||
private Rarity RollRarity(int level)
|
||||
{
|
||||
return RarityUtility.SelectRarityForLevel(level);
|
||||
}
|
||||
|
||||
private static int CalculateRandomizedPrice(int basePrice, float priceRandomPercent)
|
||||
{
|
||||
float normalizedPercent = priceRandomPercent > 1f ? priceRandomPercent / 100f : priceRandomPercent;
|
||||
@@ -331,18 +308,18 @@ namespace SepCore.UI
|
||||
|
||||
if (goods.GoodsType == GoodsType.Prop)
|
||||
{
|
||||
DRProp drProp = _propDataTable != null ? _propDataTable.GetDataRow(goods.GoodsTypeId) : null;
|
||||
if (drProp == null || drProp.Modifiers == null || drProp.Modifiers.Length == 0)
|
||||
PropConfig propConfig = GameEntry.Luban.Get<PropConfig>(goods.GoodsTypeId);
|
||||
if (propConfig.Modifiers == null || propConfig.Modifiers.Count == 0)
|
||||
{
|
||||
Log.Warning("ShopFormUseCase::ApplyGoodsPurchase: Prop modifiers are empty");
|
||||
return null;
|
||||
}
|
||||
|
||||
Player.AddProp(new PropItem(drProp.Modifiers, drProp.Rarity, drProp.Title, drProp.IconAssetName));
|
||||
Player.AddProp(new PropItem(propConfig));
|
||||
return new DisplayItemRawData
|
||||
{
|
||||
IconAssetName = drProp.IconAssetName,
|
||||
Rarity = drProp.Rarity,
|
||||
IconAssetName = propConfig.IconAssetName,
|
||||
Rarity = propConfig.Rarity,
|
||||
IsWeapon = false
|
||||
};
|
||||
}
|
||||
@@ -355,16 +332,9 @@ namespace SepCore.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
DRWeapon drWeapon = _weaponDataTable.GetDataRow(goods.GoodsTypeId);
|
||||
|
||||
WeaponConfig weaponConfig = GameEntry.Luban.Get<WeaponConfig>(goods.GoodsTypeId);
|
||||
int id = GameEntry.Entity.NextId();
|
||||
var weaponData = EntityDataFactory.Create(id, drWeapon, Player.Id, CampType.Player);
|
||||
if (weaponData == null)
|
||||
{
|
||||
Log.Warning(
|
||||
$"ShopFormUseCase::ApplyGoodsPurchase: Unsupported weapon type id = {goods.GoodsTypeId}");
|
||||
return null;
|
||||
}
|
||||
var weaponData = EntityDataFactory.Create(id, weaponConfig, Player.Id, CampType.Player);
|
||||
|
||||
WeaponBase weapon = await Player.AddWeaponAsync(weaponData);
|
||||
if (weapon == null)
|
||||
@@ -376,8 +346,8 @@ namespace SepCore.UI
|
||||
|
||||
return new DisplayItemRawData
|
||||
{
|
||||
IconAssetName = drWeapon.IconAssetName,
|
||||
Rarity = drWeapon.Rarity,
|
||||
IconAssetName = weaponConfig.IconAssetName,
|
||||
Rarity = weaponConfig.Rarity,
|
||||
IsWeapon = true
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user