using FL.Network;
using System;
using System.Collections.Generic;
using XGame.Database;
using XGame.Framework.Data;
using static FL.Network.ActArtifactFumo;
namespace FL
{
public struct ArtifactEnchantParam
{
public int elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
public int elementId; // 槽位附魔的元素id
public int holePosition;// 部位id(孔位索引值)
}
public struct ElementInfoParam
{
public int elementId; // 元素id
public int level; // 元素等级
public int state; // 0_未出战 1_已出战(已附魔)
public long power; // 元素拥有战力
}
///
/// 元素孔位数据
///
public struct HolepositionParam
{
public EElementType elementType; // 元素类型,元素之力显示顺序(火-毒-冰-雷-风)
public ArtifactEnchantParam enchantData;
public bool bUpgradeUI; // 是否元素升级页签UI
}
public struct ElementPowerParam
{
public int holePosition; // 孔位(槽位)索引
public long starPower; // 拥有效果的战力(受升级影响)
public long wearPower; // 佩戴效果的战力(固定)
}
///
/// 神器数据
///
public class ArtifactData : DataSingleton,IDisposable
{
///
/// 每个星级(黄|紫|红)最多拥有5个星星数量
///
public const int MaxStarNum = 5;
#region 神器附魔数据
///
/// 每种元素拥有的最大附魔孔位
///
public const int MaxHolePosition = 5;
///
/// 每种元素最高级品质等级
///
public const int MaxElementQuality = 6;
///
/// 神器附魔数据
/// key:元素枚举类型(火-毒-冰-雷-风)
/// value:附魔的元素数据:key_孔位索引值
///
private Dictionary> _enchantDataMap;
public Dictionary> EnchantDataMap => _enchantDataMap ??= new Dictionary>();
///
/// 升级(解锁)的元素信息(升级成功界面UI展示用数据)
///
public List UpgradeElementList { set; get; }
///
/// 已解锁的元素数据
/// key:元素id
/// value:元素信息
///
private Dictionary _unlockElementMap;
public Dictionary UnlockElementMap => _unlockElementMap ??= new Dictionary();
///
/// 元素战力数据
/// key:元素id
///
private Dictionary _elementPowerMap = new Dictionary();
///
/// 核心元素名字
///
///
///
public string GetElementName(EElementType elementType)
{
switch (elementType)
{
case EElementType.Fire:
return StringDefine.FireElement;
case EElementType.Thunder:
return StringDefine.ThunderElement;
case EElementType.Ice:
return StringDefine.IceElement;
case EElementType.Poison:
return StringDefine.PoisonElement;
case EElementType.Wind:
return StringDefine.WindElement;
default:
return string.Empty;
}
}
///
/// 是否已解锁的元素id
///
///
///
public bool IsUnlockElement(int elementId)
{
return UnlockElementMap.ContainsKey(elementId) ? true : false;
}
///
/// 获取核心元素数据(等级和穿戴信息)
///
///
///
public ElementInfoParam GetElementUpgradeInfo(int elementId)
{
return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId] : new ElementInfoParam();
}
///
/// 获取某个元素的战力值
///
///
///
public long GetElementPower(int elementId)
{
return UnlockElementMap.ContainsKey(elementId) ? _unlockElementMap[elementId].power : 0;
}
///
/// 获取元素的等级
///
///
///
public int GetElementLevel(int elementId)
{
return UnlockElementMap.ContainsKey(elementId) ? UnlockElementMap[elementId].level : 0;
}
///
/// 获取元素类型的孔位上附魔的元素信息列表
///
///
public Dictionary GetElementHolepositionData(EElementType elementType)
{
return EnchantDataMap.ContainsKey(elementType) ? EnchantDataMap[elementType] : new Dictionary();
}
///
/// 获取某种元素类型的穿戴战力总值
///
///
///
public long GetWearPower(EElementType elementType)
{
long wearPower = 0;
if (EnchantDataMap.ContainsKey(elementType))
{
foreach (var item in EnchantDataMap[elementType])
{
if (_elementPowerMap.ContainsKey(item.Value.elementId))
wearPower += _elementPowerMap[item.Value.elementId].wearPower;
}
}
return wearPower;
}
///
/// 获取元素的穿戴战力值
///
///
///
public long GetElementWearPower(int elementId)
{
return _elementPowerMap.ContainsKey(elementId) ? _elementPowerMap[elementId].wearPower : 0;
}
///
/// 获取元素类型孔位上附魔的元素信息
///
///
public ArtifactEnchantParam GetHolepositionElementInfo(EElementType elementType, int holePosition)
{
if (EnchantDataMap != null && EnchantDataMap.ContainsKey(elementType))
{
if (EnchantDataMap[elementType].ContainsKey(holePosition))
return EnchantDataMap[elementType][holePosition];
else
new ArtifactEnchantParam();
}
return new ArtifactEnchantParam();
}
///
/// 获取元素表格信息(元素类型*1000+品质*100+孔位索引)
///
/// 元素类型
/// 品质
/// 孔位
///
public artifactYuansuTable GetElementConfigInfo(int elementType, int quality, int holePonsiton)
{
return artifactYuansuTableRepo.Get(elementType * 1000 + quality * 100 + holePonsiton);
}
///
/// 获取元素附魔表格信息(元素核心id*1000+等级)
///
/// 元素表格信息id
/// 等级
///
public artifactFumoTable GetElementEnchantConfigInfo(int elementTableId, int level)
{
return artifactFumoTableRepo.Get(elementTableId * 1000 + level);
}
///
/// 5种元素类型在其5个孔位上的附魔数据
///
///
public void OnchangeEnchantDataMap(List enchantDataList)
{
foreach (var item in enchantDataList)
{
if (EnchantDataMap.ContainsKey((EElementType)item.type))
{
EnchantDataMap[(EElementType)item.type] = GetHolepositionEnchantMap(item.type, item.buwei);
}
else
{
EnchantDataMap.Add((EElementType)item.type, GetHolepositionEnchantMap(item.type, item.buwei));
}
}
}
private Dictionary GetHolepositionEnchantMap(int elementType, List dataList)
{
var artifactEnchantMap = new Dictionary();
foreach (var item in dataList)
{
var enchantParam = new ArtifactEnchantParam()
{
elementType = elementType,
holePosition = item.bwId,
elementId = item.elementId
};
artifactEnchantMap.Add(item.bwId, enchantParam);
}
return artifactEnchantMap;
}
///
/// 元素的战力值变化
///
///
///
private void OnchangElementPowerData(int elementId, long starPower)
{
if (_elementPowerMap.ContainsKey(elementId))
{
var elementPowerData = _elementPowerMap[elementId];
elementPowerData.starPower = starPower;
}
else
{
var elementPowerData = new ElementPowerParam();
elementPowerData.starPower = starPower;
var elementConfig = artifactYuansuTableRepo.Get(elementId);
if (elementConfig?.Trunk > 0)
elementPowerData.holePosition = elementConfig.Trunk;
if (elementConfig?.Wear_attr?.Length > 1)
{
elementPowerData.wearPower = AttrDescTableRepo.GetAttributePower(elementConfig.Wear_attr[0], elementConfig.Wear_attr[1]);
}
_elementPowerMap.Add(elementId, elementPowerData);
}
}
///
/// 解锁的元素数据
///
///
public void OnchangeUnlockElementMap(List unlockElementList)
{
foreach (var item in unlockElementList)
{
var elementInfo = new ElementInfoParam()
{
elementId = item.elementId,
level = item.level,
state = item.status,
power = item.power,
};
if (UnlockElementMap.ContainsKey(item.elementId))
{
UnlockElementMap[item.elementId] = elementInfo;
}
else
{
UnlockElementMap.Add(item.elementId, elementInfo);
}
OnchangElementPowerData(item.elementId,item.power);
}
}
///
/// (激活)升级的元素列表
///
///
public void SetUpgradeElementList(List unlockElementList)
{
if (UpgradeElementList == null)UpgradeElementList = new List();
foreach (var item in unlockElementList)
{
var elementInfo = new ElementInfoParam()
{
elementId = item.elementId,
level = item.level,
state = item.status
};
UpgradeElementList.Add(elementInfo);
}
}
#endregion
#region 普通神器数据
///
/// 普通神器当前升级到的星级信息id(artifactInfo分表序号ID)
///
public int ArtifactInfoId { get; set; }
///
/// 普通神器当前升星经验
///
public int ArtifactExp { get; set; }
#endregion
#region 高级神器数据
///
/// 启用技能的高级神器的id
///
public int UsingAdvanceArtifactId { set; get; }
///
/// 已解锁的神器星级数据
/// key:artifactBase.id
/// value:star(星级)
///
private Dictionary _advancedArtifactMap;
public Dictionary AdvancedArtifactMap => _advancedArtifactMap ??= new Dictionary();
///
/// 高级神器是否已解锁状态
///
///
///
public bool IsUnLock(int artifactId)
{
return _advancedArtifactMap.ContainsKey(artifactId);
}
///
/// 获取高级神器的星级
///
///
public int GetAdvancedArtifactLevel(int artifactId)
{
return _advancedArtifactMap.ContainsKey(artifactId) ? _advancedArtifactMap[artifactId] : 0;
}
///
/// 根据神器id和星级获取星级表id
///
///
///
/// 10000*秘宝id+星级
public int GetArtifactStarId(int artifactId, int level)
{
return artifactId*10000 + level;
}
///
/// 根据神器id和星级获取通用神器信息表id
///
///
///
/// 秘宝id*10000+阶级*100+星级
public int GetArtifactInfoId(int artifactId, int step, int starLv)
{
return artifactId * 10000 + step *100 + starLv;
}
#endregion
///
/// 当前使用的神器外观模型id(通用神器用的是artifactInfo表格,高级神器对应的是artifactBase表格)
/// 此字段只在神器内部使用,如果外部需要使用神器外观,请使用GetWearAppearance()
///
public int AppearanceId { set; get; }
///
/// 获取当前穿戴的神器外观
///
///
public string GetWearAppearance()
{
if (AppearanceId == 0) return string.Empty;
var artifactBaseInfo = artifactBaseTableRepo.Get(AppearanceId);
if (artifactBaseInfo != null) return artifactBaseInfo.Spine;
var artifactInfo = artifactInfoTableRepo.Get(AppearanceId);
return artifactInfo == null ? string.Empty : artifactInfo.Spine;
}
void IDisposable.Dispose()
{
_elementPowerMap.Clear();
_advancedArtifactMap?.Clear();
_advancedArtifactMap = null;
_enchantDataMap?.Clear();
_enchantDataMap = null;
}
}
}