using cfg.VihecleCultivateCfg;
using Framework;
using Gameplay;
using Gameplay.Level;
using Gameplay.Net;
using Gameplay.Vehicle.Data;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public static class VehicleDataHelper
{
public const int NotAdapt = 0;
public const int Adapt = 1;
public const int VeryAdapt = 2;
public static int GetVehicleSkillId(int vehicleId, bool isProCultivateData = false)
{
if (!isProCultivateData)
{
VehicleCultivateData vehicleInfo = VehicleCultivateDataManager.Instance.GetVehicleCultivateData((uint)vehicleId) as VehicleCultivateData;
int skillLv = 1;//(int)vehicleInfo.SumBonus(BonusType.SkillLv);
var skillLevelInfo = TableManager.Instance.Tables.VehicleSkllUpgrade.Get(vehicleInfo.Cfg.ID);
if (skillLevelInfo == null || skillLevelInfo.SkillIdList.Count == 0)
{
DebugUtil.LogError("载具id为{0}技能等级为{1}的表没配", vehicleInfo.Cfg.ID, skillLv);
return -1;
}
var levelIndex = skillLv;
if (levelIndex >= skillLevelInfo.SkillIdList.Count)
{
DebugUtil.LogError($"数据需求等级{skillLv}超过配置等级{skillLevelInfo.SkillIdList.Count},此处返回最大等级");
return skillLevelInfo.SkillIdList[^1];//-1;
}
return skillLevelInfo.SkillIdList[levelIndex];
}
else
{
var vehicleInfo = VehicleCultivateDataManager.Instance.GetVehicleCultivateData((uint)vehicleId);
var skillLv = 1;
var skillLevelInfo = TableManager.Instance.Tables.VehicleSkllUpgrade.Get(vehicleInfo.Cfg.ID);
if (skillLevelInfo == null || skillLevelInfo.SkillIdList.Count == 0)
{
DebugUtil.LogError("载具id为{0}技能等级为{1}的表没配", vehicleInfo.Cfg.ID, skillLv);
return -1;
}
var levelIndex = skillLv;
if (levelIndex >= skillLevelInfo.SkillIdList.Count)
{
DebugUtil.LogError($"数据需求等级{skillLv}超过配置等级{skillLevelInfo.SkillIdList.Count},此处返回最大等级");
return skillLevelInfo.SkillIdList[^1];//-1;
}
return skillLevelInfo.SkillIdList[levelIndex];
}
}
public static int GetVehicleSkillId(VehicleCultivateData vehicleInfo)
{
var skillLv = 1;
var skillLevelInfo = TableManager.Instance.Tables.VehicleSkllUpgrade.Get(vehicleInfo.Cfg.ID);
if (skillLevelInfo == null || skillLevelInfo.SkillIdList.Count == 0)
{
DebugUtil.LogError("载具id为{0}技能等级为{1}的表没配", vehicleInfo.Cfg.ID, skillLv);
return -1;
}
var levelIndex = skillLv;
if (levelIndex >= skillLevelInfo.SkillIdList.Count)
{
DebugUtil.LogError($"数据需求等级{skillLv}超过配置等级{skillLevelInfo.SkillIdList.Count},此处返回最大等级");
return skillLevelInfo.SkillIdList[^1];//-1;
}
return skillLevelInfo.SkillIdList[levelIndex];
}
public static BonusType GetBonusTypeByTerrainID(int terrainId)
{
switch (terrainId)
{
case 1:
return BonusType.TerrainPlain;
case 2:
return BonusType.TerrainMountain;
case 4:
return BonusType.TerrainForest;
case 5:
return BonusType.TerrainSnow;
}
DebugUtil.LogError("因为VehicleBonusType暂时不需要其他地形类型,所以妹写");
return BonusType.TerrainPlain;
}
public static string GetTerrainAdaptStr(int terrainAdaptVal)
{
switch (terrainAdaptVal)
{
case NotAdapt:
return CommonUtils. GetLocalizeText("vehicleCultivate_NotAdapt");
case Adapt:
return CommonUtils.GetLocalizeText("vehicleCultivate_Adapt");
case VeryAdapt:
return CommonUtils.GetLocalizeText("vehicleCultivate_TeHua");
}
DebugUtil.LogError("载具的地形适应配置错了:载具upbonus表");
return "拉取中";
}
///
/// 获取载具头像路径
///
///
///
public static string GetVehiclePicPath(int iD)
{
var vehicleCfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault(iD);
if (vehicleCfg == null)
{
DebugUtil.LogError("载具配置表中没有id为{0}的配置", iD);
return null;
}
return CommonUtils.GetDefaultVehicleHeadPath((uint)iD);
}
///
/// 获取载具高清图片路径
///
///
///
public static string GetVehicleIconPath(int id)
{
var vehicleCfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault(id);
if (vehicleCfg == null)
{
DebugUtil.LogError("载具配置表中没有id为{0}的配置", id);
return null;
}
return vehicleCfg.Icon;
}
public static VehicleConfigData CombineConfigData(VehicleCultivateData infoData)
{
var rawConfig = infoData;
// 临时写死
var level = 1;
// 因为里面有-1
var skillLevel = 1;//infoData.SkillLevel() +
var configData = new VehicleConfigData();
configData.Init(rawConfig, level, skillLevel);
return configData;
}
public static VehicleConfigData CombineMonsterConfigData(LevelData.NPCInfo npcInfo)
{
var monsterConfig = TableManager.Instance.Tables.Monster.GetOrDefault(npcInfo.id);
var configData = new VehicleConfigData();
configData.Init(monsterConfig);
return configData;
}
public static string GetVehicleLocalizeName(int id)
{
var vehicleLocalNameKey = "vehicle_name_" + (id % 100).ToString("D2");
return CommonUtils.GetLocalizeText(vehicleLocalNameKey);
}
public static string GetVehicleOrganization(int id)
{
var vehicleCfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault(id);
if (vehicleCfg == null)
{
DebugUtil.LogError("载具配置表中没有id为{0}的配置", id);
return null;
}
return CommonUtils.GetLocalizeText("VehicleOrg_" + vehicleCfg.VehicleType);
}
public static string GetVehicleCategory(int id)
{
var vehicleCfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault(id);
if (vehicleCfg == null)
{
DebugUtil.LogError("载具配置表中没有id为{0}的配置", id);
return null;
}
return CommonUtils.GetLocalizeText("VehicleCategory_" + vehicleCfg.Category);
}
public static bool IsVehicleSkinUnlock(int skinID)
{
var table = TableManager.Instance.Tables.VehiclePaint;
var cfg = table.GetOrDefault(skinID);
if (cfg == null)
{
DebugUtil.LogError("VehiclePaint表中没有id为{0}的配置", skinID);
return false;
}
var itemID = cfg.ItemID;
return CategoryManager.Instance.GetItemCount(itemID) > 0;
}
public static string GetVehicleSkinName(int skinID)
{
var table = TableManager.Instance.Tables.VehiclePaint;
var cfg = table.GetOrDefault(skinID);
if (cfg == null)
{
DebugUtil.LogError("VehiclePaint表中没有id为{0}的配置", skinID);
return null;
}
return CommonUtils.GetLocalizeText("VehiclePaint_name_" + skinID);
}
///
/// 从升级部件中找到最高等级的武器
///
///
///
public static long FindMaxLevelWeapon(List UpgradeComponent)
{
var MaxLevelFort = 0L;
var maxLevel = 0;
var compCfg = TableManager.Instance.Tables.VehicleComponent;
foreach (var fort in UpgradeComponent)
{
var cfg = compCfg.GetOrDefault(fort);
if(cfg == null)
{
DebugUtil.Log("VehicleComponent表中没有id为{0}的配置", fort);
continue;
}
if (cfg.ComponentType == ComponentType.Component_2)
{
var level = fort % 100;
if (level > maxLevel)
{
maxLevel = (int)level;
MaxLevelFort = fort;
}
}
}
return MaxLevelFort;
}
public static DataVehiclePaint GetVehiclePartPaint(int vehicleID, PaintType type)
{
var cfg = Actor.Instance.Character.GetVehicleDevelopment(vehicleID);
if (cfg == null)
{
DebugUtil.LogError("没有找到id为{0}的载具涂装配置", vehicleID);
return null;
}
var paintID = cfg.paint_set[(int)type];
var paintCfg = TableManager.Instance.Tables.VehiclePaint.GetOrDefault((int)paintID);
return paintCfg;
}
public static GameObject FindVehiclePartRoot(GameObject vehicleModel, int Vehicle, PaintType type)
{
var vehicleID = $"{Vehicle % 100:D2}";
string goName = "";
switch (type)
{
case PaintType.Entirety:
goName = string.Format("C000{0}/G_C000{0}_M", vehicleID);
break;
case PaintType.Fort:
var allTrans = vehicleModel.GetComponentsInChildren();
var pointName = "Battery_point01";
var fireTrans = allTrans.First(t => t.name == pointName).GetChild(0);
if (fireTrans != null)
{
var renderers = fireTrans.GetComponentsInChildren();
if (renderers != null && renderers.Length > 0)
{
return renderers[0].gameObject;
}
}
break;
case PaintType.CaterpillarBelt:
goName = string.Format("C000{0}/G_C000{0}_D", vehicleID);
break;
default:
DebugUtil.Log("未知涂装类型");
break;
}
var body = CommonUtils.GetGameObject(vehicleModel, goName);
return body;
}
}