using System.Collections.Generic; using System.Security.Cryptography; using FL.Network; using XGame; using XGame.Database; using XGame.Framework.Data; using XGame.Framework.Network; namespace FL.Data { public class PartnersService : DataSingleton { #region 新接口 /// /// 圣兵一键上阵 /// public void RequestPartnerOneKeyUp() { NetModule.Request(new ShengbingWearAllRequest()); } public void RequestPartnerOneKeyLvUp() { NetModule.Request(new ShengbingStrongAllRequest()); } public void RequestUpdatePlanSb(int planId, int slotId, int sbId) { if (planId != PartnersData.Instance.UsePlanId) { var info = PartnersData.Instance.GetPartnerAttrByTableId(sbId); RequestUpdatePlan(planId, slotId, sbId, info?.EpigraphId ?? 0); } else { if (sbId > 0) { RequestPartnerUp(slotId, sbId); } else { RequestPartnerDown(slotId); } } } public void RequestUpdatePlanMw(int planId, int slotId, int sbId, int mwId) { if (planId != PartnersData.Instance.UsePlanId) { RequestUpdatePlan(planId, slotId, sbId, mwId); } else { var sbInfo = PartnersData.Instance.GetPartnerAttrByTableId(sbId); EpigraphService.Instance.RequestEpiInset(sbId, mwId); } } private void RequestUpdatePlan(int planId, int slotId, int sbId, int mwId) { var param = new ShengbingUpdateSuitRequest() { suit = planId, caoId = slotId, sbId = sbId, mwId = mwId, }; NetModule.Request(param); } /// /// 请求替换圣兵方案 /// /// public void RequestChangePlan(int planId) { //EventSingle.Instance.Notify(EventDefine.ShowTips, $"替换方案{planId}"); var param = new ShengbingChangeSuitRequest() { suit = planId }; NetModule.Request(param); } /// /// 修改圣兵方案名称 /// /// /// public void RequestRenamePlan(int planId, string name) { var param = new ShengbingSetNameRequest() { suit = planId, name = name }; NetModule.Request(param); } /// /// 圣兵上阵 /// /// 槽位id 0开始 /// 圣兵id public void RequestPartnerUp(int posId, int id) { var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(id); if (sbAttr == null) return; var param = new ShengbingWearRequest() { caoId = posId, sbId = id }; (param as IMessage).Context = sbAttr.UID; NetModule.Request(param); } /// /// 下阵圣兵 /// /// public void RequestPartnerDown(int sbId) { var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(sbId); var pos = PartnersData.Instance.GetPartnerUpPosById(sbId); var param = new ShengbingUnfixRequest() { caoId = pos }; (param as IMessage).Context = sbAttr.UID; NetModule.Request(param); } public void RequestStarUp(int sbId) { var param = new ShengbingUpStarRequest() { sbId = sbId }; NetModule.Request(param); } public void RequestLvUp(int sbId) { var param = new ShengbingUpLevelRequest() { sbId = sbId }; NetModule.Request(param); } private void OpenUpPartnerMode(int id) { PartnersData.Instance.UpModeSelect = id; EventSingle.Instance.Notify(EventDefine.PartnerOpenUpMode, id); } public void OpenPartnerMode(int id) { var plan = PartnersData.Instance.CurUsePlan; var selectCaoId = -1; for (int caoId = 0; caoId < PartnersData.GoneUpLimit; caoId++) { var slot = plan.GetSlot(caoId); if (slot == null || slot.SbId == 0) { selectCaoId = caoId; break; } } if (selectCaoId >= 0) { RequestPartnerUp(selectCaoId, id); } else { OpenUpPartnerMode(id); } } public void FinishUpPartnerMode() { PartnersData.Instance.UpModeSelect = 0; EventSingle.Instance.Notify(EventDefine.PartnerFinishUpMode); } /// /// 更新当前已上阵随从位置 /// public void UpdateCurUpPartnerMap() { var plan = PartnersData.Instance.CurUsePlan; PartnersData.Instance.UpPartnerMap.Clear(); PartnersData.Instance.UpPartnerUIDMap.Clear(); if (plan == null) return; foreach (var partnerSlot in plan.Slots) { if (partnerSlot.SbId > 0) { var partnerAttr = PartnersData.Instance.GetPartnerAttrByTableId( partnerSlot.SbId ); if (partnerAttr == null) { Log.Debug("槽位圣兵id不存在"); return; } PartnersData.Instance.UpPartnerMap.Add(partnerSlot.SbId, partnerSlot.CaoId); PartnersData.Instance.UpPartnerUIDMap.Add(partnerAttr.UID, partnerSlot.CaoId); } } } /// /// 更新拥有圣兵信息 /// /// public void UpdatePartnerMap(List list) { foreach (var shengBing in list) { if ( PartnersData.Instance.TryGetPartnerAttrByTableId( shengBing.sbId, out var partnerInfo ) ) { var table = PartnerTableRepo.Get(shengBing.sbId); var skillId = PartnersData.Instance.GetSkillId(shengBing.star, table?.Skill); partnerInfo.Level = shengBing.level; partnerInfo.RisingStarLv = shengBing.star; partnerInfo.EpigraphId = shengBing.mingwen; partnerInfo.Status = shengBing.status; partnerInfo.SkillId = skillId; } else { var attr = PartnersData.Instance.CreatePartnerAttr( shengBing.sbId, shengBing.level, shengBing.star, shengBing.mingwen, shengBing.status ); PartnersData.Instance.AddPartnerAttr(attr); } } } /// /// 更新方案 /// /// public void UpdatePlanMap(List suitList) { foreach (var suit in suitList) { var plan = PartnersData.Instance.GetPlanById(suit.id); if (plan != null) { var caoList = new List(); foreach (var cao in suit.cao) { var slot = new PartnerPlanSlot(); slot.Init(cao.caoId, cao.mwId, cao.sbId); caoList.Add(slot); } plan.SetData(suit.id, suit.name, caoList); } else { var caoList = new List(); foreach (var cao in suit.cao) { var slot = new PartnerPlanSlot(); slot.Init(cao.caoId, cao.mwId, cao.sbId); caoList.Add(slot); } var partnerPlan = new PartnerPlan(); partnerPlan.SetData(suit.id, suit.name, caoList); PartnersData.Instance.AddPlanMap(partnerPlan); } } } /// /// 初始化方案信息 /// /// public void InitPlanMap(List suitList) { PartnersData.Instance.ClearPlanMap(); foreach (var suit in suitList) { var caoList = new List(); foreach (var cao in suit.cao) { var slot = new PartnerPlanSlot(); slot.Init(cao.caoId, cao.mwId, cao.sbId); caoList.Add(slot); } var plan = new PartnerPlan(); plan.SetData(suit.id, suit.name, caoList); PartnersData.Instance.AddPlanMap(plan); } } public void InitPartnerMap(List list) { PartnersData.Instance.ClearPartnerMap(); foreach (var shengBing in list) { var attr = PartnersData.Instance.CreatePartnerAttr( shengBing.sbId, shengBing.level, shengBing.star, shengBing.mingwen, shengBing.status ); PartnersData.Instance.AddPartnerAttr(attr); } } /// /// 获取星星的色阶 /// /// /// public int GetStarStep(int starLevel) { int step = PartnersData.MaxStarStep - 1; for (int i = step; starLevel >= 0; i--) { if (starLevel > i * PartnersData.MaxStarNum) { return i + 1; } } return 1; } #endregion } }