using System; using System.Collections.Generic; using FL.Network; using UnityEngine; using XGame; using XGame.Database; using XGame.Framework.Data; namespace FL.Data { public class PartnersData : DataSingleton, IDisposable { /// /// /// public const byte GoneUpLimit = 6; /// /// 每个星级(黄|紫|红)最多拥有5个星星数量 /// public const int MaxStarNum = 5; /// /// 最大星星阶级(颜色) /// public const int MaxStarStep = 8; //private Dictionary _goneUpMap; ///// ///// 已上阵的随从->位置 ///// key:随从的uid ///// value:位置索引(0-5) ///// //public Dictionary GoneUpMap => _goneUpMap ??= new Dictionary(); //private Dictionary _partnersMap; ///// ///// 拥有的所有随从 ///// //public Dictionary PartnersMap => // _partnersMap ??= new Dictionary(); /// /// 剑的偏移值,只记录左边的,右边对称获取 /// private Vector3[] _partnerOffsets = new Vector3[] { new Vector3(-4.5f, 1.5f, 0), new Vector3(-3.5f, 0.6f, 0), new Vector3(-2.5f, -0.3f, 0), }; #region 圣兵方案 /// /// 使用方案id /// public int UsePlanId { get; set; } /// /// 已上阵的随从->位置 /// key:随从的tableId /// value:位置索引(0-5) /// 没有上阵为-1 /// public Dictionary UpPartnerMap { get; private set; } = new(); public Dictionary UpPartnerUIDMap { get; private set; } = new(); /// /// 获取已上阵的随从->位置 /// key:随从的id /// value:位置索引(0-5) /// 没有上阵返回为-1 /// /// 圣兵id public int GetPartnerUpPosById(int id) { return UpPartnerMap.GetValueOrDefault(id, -1); } /// /// 获取已上阵的随从->位置 /// key:随从的UID /// value:位置索引(0-5) /// 没有上阵返回为-1 /// /// 圣兵uid public int GetPartnerUpPosByUID(long uid) { return UpPartnerUIDMap.GetValueOrDefault(uid, -1); } /// /// 圣兵方案 /// private Dictionary _planMap = new Dictionary(); public void ClearPlanMap() { _planMap.Clear(); } public List PlanList { get { var list = new List(); foreach (var plan in _planMap.Values) { list.Add(plan); } return list; } } /// /// 当前使用的圣兵方案 /// public PartnerPlan CurUsePlan { get { return GetPlanById(UsePlanId); } } /// /// 获取方案信息 /// /// 方案id /// /// public PartnerPlan GetPlanById(int planId) { return _planMap.GetValueOrDefault(planId); } public bool TryGetPlan(int planId, out PartnerPlan plan) { return _planMap.TryGetValue(planId, out plan); } public void AddPlanMap(PartnerPlan plan) { _planMap.Add(plan.Id, plan); } /// /// 获取方案槽位信息 /// /// /// /// public PartnerPlanSlot GetPlanSlot(int planId, int slotId) { return GetPlanById(planId)?.GetSlot(slotId); } #endregion #region 圣兵库 private Dictionary _partnerMap = new(); private Dictionary _partnerUIDMap = new(); /// /// 圣兵库列表 /// public List PartnerList { get { var list = new List(); foreach (var attr in _partnerMap.Values) { list.Add(attr); } return list; } } public PartnerAttributes GetPartnerAttrByTableId(int id) { return _partnerMap.GetValueOrDefault(id); } public bool TryGetPartnerAttrByTableId(int id, out PartnerAttributes attr) { return _partnerMap.TryGetValue(id, out attr); } public PartnerAttributes GetPartnerAttrByUID(long uid) { return _partnerUIDMap.GetValueOrDefault(uid); } public bool TryGetPartnerAttrByUID(long uid, out PartnerAttributes attr) { return _partnerUIDMap.TryGetValue(uid, out attr); } public void AddPartnerAttr(PartnerAttributes attr) { _partnerMap.Add(attr.TableId, attr); _partnerUIDMap.Add(attr.UID, attr); } public PartnerAttributes CreatePartnerAttr( int sbId, int level, int starLv, int mingwenId, int status ) { var table = PartnerTableRepo.Get(sbId); if (table == null) { Log.Debug($"圣兵的id表内不存在${sbId}"); } var size = table != null ? table.Size * 0.5f : 0; var skillId = GetSkillId(starLv, table?.Skill); var attr = new PartnerAttributes() { UID = UIDDefine.New(), TableId = sbId, Level = level, RisingStarLv = starLv, EpigraphId = mingwenId, Status = status, SkillId = skillId, Radius = size, }; attr.Attr.Hp = 500; attr.Attr.HpLimit = 500; attr.Attr.MoveSpeed = 5; attr.Attr.Attack = UnityEngine.Random.Range(5, 10); return attr; } /// /// 获取 /// /// /// public int GetSkillId(int starLv, int[] skillIdList) { if (skillIdList == null) return 0; if (skillIdList?.Length > 1) { int count = skillIdList.Length - 1; for (int i = count; i >= 0; i -= 2) { //XGame.Log.Info($"索引:{i}的技能id:{skillIdList[i]},需要的星级:{skillIdList[i-1]}"); if (starLv >= skillIdList[i - 1]) { return skillIdList[i]; } } } return skillIdList[0]; } public void ClearPartnerMap() { foreach (var partner in _partnerMap.Values) { (partner as IDisposable).Dispose(); } _partnerMap.Clear(); _partnerUIDMap.Clear(); } #endregion #region 羁绊 private Dictionary _map = new Dictionary(); public void ClearJibanRwd() { _map.Clear(); } public void SetJibanRwdState(int jibanId, int level) { var id = 100000 + jibanId * 1000 + level; _map.Add(id, true); } public bool GetJibanRwdIsGot(int jibanId, int level) { var id = 100000 + jibanId * 1000 + level; return _map.GetValueOrDefault(id, false); } #endregion /// /// 圣兵待下阵特殊状态(圣兵主界面中) /// public int UpModeSelect = 0; public Vector3 GetPartnerOffset(long partnerUID) { var index = GetPartnerUpPosByUID(partnerUID); if (index == -1) { Log.Debug($"上阵UID不存在:{partnerUID}"); index = 0; } var tmpIdx = index % 3; tmpIdx = index >= 3 ? 2 - tmpIdx : tmpIdx; var offset = _partnerOffsets[tmpIdx]; if (index >= 3) { offset.x *= -1; } //XGame.Log.Info($"PartnerOffset UID:{partnerUID} index:{index} offset:{tmpIdx}"); return offset; } /// /// 是否达到激活上限 /// public bool IsReachedLimit => UpPartnerMap.Count == GoneUpLimit; void IDisposable.Dispose() { UpPartnerMap?.Clear(); if (_partnerMap != null) { foreach (var val in _partnerMap.Values) { (val as IDisposable)?.Dispose(); } _partnerMap.Clear(); } _planMap.Clear(); } } }