335 lines
9.7 KiB
C#
335 lines
9.7 KiB
C#
using cfg.ActorCfg;
|
|
using cfg.VehicleCfg;
|
|
using cfg.VihecleCultivateCfg;
|
|
using Framework;
|
|
using PhxhSDK;
|
|
using System.Collections.Generic;
|
|
using Gameplay;
|
|
using DG.Tweening;
|
|
using NLDPB;
|
|
using UnityEngine;
|
|
|
|
public class VehicleCultivateDataManager : Singlenton<VehicleCultivateDataManager>, IInitable
|
|
{
|
|
public List<VehicleCultivateData> DataList;
|
|
public Dictionary<uint, VehicleCultivateData> DataDic;
|
|
|
|
void IInitable.Init()
|
|
{
|
|
DataList = new List<VehicleCultivateData>();
|
|
DataDic = new Dictionary<uint, VehicleCultivateData>();
|
|
|
|
}
|
|
|
|
void IInitable.Release()
|
|
{
|
|
DataList.Clear();
|
|
DataDic.Clear();
|
|
}
|
|
public void Add(Gameplay.Net.VehicleInfo info)
|
|
{
|
|
|
|
if (TableManager.Instance.Tables.VehicleConfig.GetOrDefault((int)info.nID) == null)
|
|
{
|
|
DebugUtil.LogError("载具配置表中没有ID为{0}的载具", info.nID);
|
|
return;
|
|
}
|
|
|
|
if (DataDic.TryGetValue(info.nID, out var info2))
|
|
{
|
|
DataDic[info.nID].Refresh(info);
|
|
}
|
|
else
|
|
{
|
|
info2 = new VehicleCultivateData();
|
|
info2.Refresh(info);
|
|
DataList.Add(info2);
|
|
DataDic[info.nID] = info2;
|
|
|
|
}
|
|
}
|
|
|
|
public void AddAllCfgVehicles()
|
|
{
|
|
var allConfigList = TableManager.Instance.Tables.VehicleConfig.DataList;
|
|
for (int i = 0; i < allConfigList.Count; i++)
|
|
{
|
|
var configItem = allConfigList[i];
|
|
var isAvailable = _CheckVehicleCfgAvailable(configItem);
|
|
if (!isAvailable)
|
|
{
|
|
DebugUtil.LogError($"载具配置不可用:{configItem.ID}");
|
|
continue;
|
|
}
|
|
|
|
var nId = (uint)configItem.ID;
|
|
if (DataDic.ContainsKey(nId))
|
|
{
|
|
continue;
|
|
}
|
|
var info2 = new VehicleCultivateData();
|
|
info2.Cfg = configItem;
|
|
info2.nID = nId;
|
|
DataList.Add(info2);
|
|
DataDic[nId] = info2;
|
|
}
|
|
}
|
|
|
|
private bool _CheckVehicleCfgAvailable(DataVehicle checkCfg)
|
|
{
|
|
if (checkCfg == null)
|
|
{
|
|
DebugUtil.LogError("载具配置为空");
|
|
return false;
|
|
}
|
|
if (checkCfg.ID == 0)
|
|
{
|
|
DebugUtil.LogError("载具配置ID为0");
|
|
return false;
|
|
}
|
|
|
|
var upgradeAttack = TableManager.Instance.Tables.VehicleUpgrade.Get(checkCfg.ID, VihecleUpgradeType.Damage);
|
|
if (upgradeAttack == null)
|
|
{
|
|
DebugUtil.LogError("载具配置ID为{0}的攻击升级配置为空", checkCfg.ID);
|
|
return false;
|
|
}
|
|
|
|
var skillCfg = TableManager.Instance.Tables.VehicleSkllUpgrade.Get(checkCfg.ID);
|
|
if (skillCfg == null)
|
|
{
|
|
DebugUtil.LogError("载具配置ID为{0}的技能升级配置为空", checkCfg.ID);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public VehicleCultivateData GetVehicleCultivateData(uint selectID)
|
|
{
|
|
VehicleCultivateData info;
|
|
if (DataDic.TryGetValue(selectID, out info))
|
|
{
|
|
return info;
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.LogError("该角色找不到没有Id为 {0}的载具", selectID);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class VehicleCultivateData : Gameplay.Net.VehicleInfo
|
|
{
|
|
public DataVehicle Cfg;
|
|
|
|
public VehicleCultivateData(uint ID,
|
|
ushort[] UpgradeCountParam)
|
|
{
|
|
nID = ID;
|
|
for (ushort i = 0; i < UpgradeCount.Length; i++)
|
|
{
|
|
UpgradeCount[i] = UpgradeCountParam[i];
|
|
|
|
}
|
|
}
|
|
public VehicleCultivateData() {}
|
|
|
|
public string Name => CommonUtils.GetLocalizeText(Cfg.NameLocal);
|
|
|
|
public int Hp()
|
|
{
|
|
|
|
var baseValue = Cfg.HP + Mathf.RoundToInt(SumUpgrades(VihecleUpgradeType.HP));
|
|
var scale = SumBonus(BonusType.Hp) + 1f;
|
|
var finalValue = Mathf.RoundToInt(baseValue * scale);
|
|
|
|
return finalValue;
|
|
}
|
|
public float SumUpgrades(VihecleUpgradeType viType)
|
|
{
|
|
DataVehicleUpgrade dataVehicleUpgrade = VehicleUpgradeTableHelper.Get(Cfg.ID, viType);
|
|
|
|
return dataVehicleUpgrade.PowerUpAmount * UpgradeCount[(int)viType];
|
|
|
|
|
|
}
|
|
public float MaxUpgrades(VihecleUpgradeType viType)
|
|
{
|
|
DataVehicleUpgrade dataVehicleUpgrade = VehicleUpgradeTableHelper.Get(Cfg.ID, viType);
|
|
|
|
return dataVehicleUpgrade.PowerUpAmount * dataVehicleUpgrade.MaxCount;
|
|
|
|
|
|
}
|
|
public float SumBonus(BonusType bType)
|
|
{
|
|
float count = 0;
|
|
VehicleUpgradeBonusAttri vTable = TableManager.Instance.Tables.VehicleUpgradeBonusAttri;
|
|
for (int i = 0; i < vTable.DataList.Count; i++)
|
|
{
|
|
if ((vTable.DataList[i].BonusType == bType) && (vTable.DataList[i].SumCount < SumPowerLevel()))
|
|
{
|
|
count += (int)vTable.DataList[i].BonusPropertyCount;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
public int Attack()
|
|
{
|
|
|
|
var baseDamage = Cfg.Damage + Mathf.RoundToInt(SumUpgrades(VihecleUpgradeType.Damage));
|
|
var scale = SumBonus(BonusType.AttackPercent) + 1f;
|
|
var finalDamage = Mathf.RoundToInt(baseDamage * scale);
|
|
return finalDamage;
|
|
|
|
}
|
|
public float MoveSpeed()
|
|
{
|
|
return Cfg.MoveSpeed + SumBonus(BonusType.MoveSpeed);
|
|
}
|
|
public int BulletCapacity()
|
|
{
|
|
return Cfg.BulletCount;
|
|
}
|
|
public int Defense()
|
|
{
|
|
//if (Cfg.Defenses.Count <= UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.Defense])
|
|
//{
|
|
// DebugUtil.LogError("载具id为{0}的Defense没有配到{1}位", Cfg.ID, UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.Defense]);
|
|
// return 0;
|
|
//}
|
|
//return Cfg.Defenses[UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.Defense]];
|
|
return Cfg.Damage + (int)SumUpgrades(VihecleUpgradeType.Defense);
|
|
|
|
}
|
|
|
|
public int SkillLevel()
|
|
{
|
|
return (int)SumBonus(BonusType.SkillLv);
|
|
}
|
|
|
|
public void Refresh(Gameplay.Net.VehicleInfo info)
|
|
{
|
|
nID = info.nID;
|
|
for (int i = 0; i < info.UpgradeCount.Length; i++)
|
|
{
|
|
UpgradeCount[i] = (ushort)info.UpgradeCount[i];
|
|
|
|
}
|
|
Cfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault((int)nID);
|
|
}
|
|
|
|
public int SumPowerLevel()
|
|
{
|
|
int lv = 0;
|
|
for (int i = 0; i < UpgradeCount.Length; i++)
|
|
{
|
|
lv += UpgradeCount[i];
|
|
}
|
|
return lv;
|
|
}
|
|
public float GetMaxHp()
|
|
{
|
|
|
|
return Cfg.HP + MaxUpgrades(VihecleUpgradeType.HP) + VehicleCulitvateLevelUpBonusTableHelper.GetMaxValBonusByID(nID, BonusType.Hp);
|
|
|
|
}
|
|
public float GetMaxAttack()
|
|
{
|
|
// return Cfg.Damages[Cfg.Damages.Count - 1];
|
|
return Cfg.Damage + MaxUpgrades(VihecleUpgradeType.Damage);
|
|
|
|
}
|
|
public float GetMaxDenfense()
|
|
{
|
|
// return Cfg.Defenses[Cfg.Defenses.Count - 1];
|
|
return Cfg.Defense + MaxUpgrades(VihecleUpgradeType.Defense);
|
|
|
|
}
|
|
public int SeatCount()
|
|
{
|
|
return Cfg.SeatCount + Mathf.RoundToInt(SumBonus(BonusType.SeatCount));
|
|
}
|
|
|
|
public float AttackShiledScale()
|
|
{
|
|
return Cfg.AttackShiledScale + SumBonus(BonusType.AttackShiledScale);
|
|
}
|
|
|
|
public float AttackHpScale()
|
|
{
|
|
return Cfg.AttackHpScale + SumBonus(BonusType.AttackHpScale);
|
|
}
|
|
|
|
public float ScaleForHuman()
|
|
{
|
|
return Cfg.ScaleForHuman + SumBonus(BonusType.ScaleForHuman);
|
|
}
|
|
|
|
public float ScaleForVehicle()
|
|
{
|
|
return Cfg.ScaleForVehicle + SumBonus(BonusType.ScaleForVehicle);
|
|
}
|
|
|
|
public int SumPowerMaxLevel()
|
|
{
|
|
int lv = 0;
|
|
|
|
VehicleUpgrade vehicleUpgradeTab = TableManager.Instance.Tables.VehicleUpgrade;
|
|
for (int i = 0; i < vehicleUpgradeTab.DataList.Count; i++)
|
|
{
|
|
if (vehicleUpgradeTab.DataList[i].ID == Cfg.ID)
|
|
{
|
|
lv += vehicleUpgradeTab.DataList[i].MaxCount;
|
|
}
|
|
}
|
|
return lv;
|
|
|
|
}
|
|
public bool IsMaxHpLv()
|
|
{
|
|
return UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.HP] >= TableManager.Instance.Tables.VehicleUpgrade.Get((int)nID, cfg.ActorCfg.VihecleUpgradeType.HP).MaxCount;
|
|
}
|
|
public bool IsMaxDamageLv()
|
|
{
|
|
return UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.Damage] >= TableManager.Instance.Tables.VehicleUpgrade.Get((int)nID, cfg.ActorCfg.VihecleUpgradeType.Damage).MaxCount;
|
|
}
|
|
public bool IsMaxMoveSpeedLv()
|
|
{
|
|
return UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.MoveSpeed - 1] >= TableManager.Instance.Tables.VehicleUpgrade.Get((int)nID, cfg.ActorCfg.VihecleUpgradeType.MoveSpeed).MaxCount;
|
|
}
|
|
public bool IsMaxBulletCountLv()
|
|
{
|
|
return UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.BulletCount - 1] >= TableManager.Instance.Tables.VehicleUpgrade.Get((int)nID, cfg.ActorCfg.VihecleUpgradeType.BulletCount).MaxCount;
|
|
}
|
|
public bool IsMaxDefenseCountLv()
|
|
{
|
|
return UpgradeCount[(int)cfg.ActorCfg.VihecleUpgradeType.Defense - 1] >= TableManager.Instance.Tables.VehicleUpgrade.Get((int)nID, cfg.ActorCfg.VihecleUpgradeType.Defense).MaxCount;
|
|
}
|
|
|
|
public string GetTerrainAdapt(BonusType terrainType) //仅供地形使用
|
|
{
|
|
VehicleUpgradeBonusAttri vTable = TableManager.Instance.Tables.VehicleUpgradeBonusAttri;
|
|
int terrinBonusVal = Cfg.TerrainPlain;
|
|
for (int i = 0; i < vTable.DataList.Count; i++)
|
|
{
|
|
if (vTable.DataList[i].SumCount < SumPowerLevel())
|
|
{
|
|
if (vTable.DataList[i].BonusType == BonusType.TerrainPlain)
|
|
{
|
|
terrinBonusVal = (int)vTable.DataList[i].BonusPropertyCount;
|
|
}
|
|
}
|
|
}
|
|
return VehicleDataHelper.GetTerrainAdaptStr(terrinBonusVal);
|
|
|
|
}
|
|
|
|
|
|
}
|