123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- 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<PartnersService>
- {
- #region 新接口
- /// <summary>
- /// 圣兵一键上阵
- /// </summary>
- 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);
- }
- /// <summary>
- /// 请求替换圣兵方案
- /// </summary>
- /// <param name="planId"></param>
- public void RequestChangePlan(int planId)
- {
- //EventSingle.Instance.Notify(EventDefine.ShowTips, $"替换方案{planId}");
- var param = new ShengbingChangeSuitRequest() { suit = planId };
- NetModule.Request(param);
- }
- /// <summary>
- /// 修改圣兵方案名称
- /// </summary>
- /// <param name="planId"></param>
- /// <param name="name"></param>
- public void RequestRenamePlan(int planId, string name)
- {
- var param = new ShengbingSetNameRequest() { suit = planId, name = name };
- NetModule.Request(param);
- }
- /// <summary>
- /// 圣兵上阵
- /// </summary>
- /// <param name="posId">槽位id 0开始</param>
- /// <param name="id">圣兵id</param>
- 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);
- }
- /// <summary>
- /// 下阵圣兵
- /// </summary>
- /// <param name="sbId"></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);
- }
- /// <summary>
- /// 更新当前已上阵随从位置
- /// </summary>
- 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);
- }
- }
- }
- /// <summary>
- /// 更新拥有圣兵信息
- /// </summary>
- /// <param name="list"></param>
- public void UpdatePartnerMap(List<ActShengBingList> 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);
- }
- }
- }
- /// <summary>
- /// 更新方案
- /// </summary>
- /// <param name="suitList"></param>
- public void UpdatePlanMap(List<ActShengBingSuit> suitList)
- {
- foreach (var suit in suitList)
- {
- var plan = PartnersData.Instance.GetPlanById(suit.id);
- if (plan != null)
- {
- var caoList = new List<PartnerPlanSlot>();
- 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<PartnerPlanSlot>();
- 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);
- }
- }
- }
- /// <summary>
- /// 初始化方案信息
- /// </summary>
- /// <param name="suitList"></param>
- public void InitPlanMap(List<ActShengBingSuit> suitList)
- {
- PartnersData.Instance.ClearPlanMap();
- foreach (var suit in suitList)
- {
- var caoList = new List<PartnerPlanSlot>();
- 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<ActShengBingList> 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);
- }
- }
- /// <summary>
- /// 获取星星的色阶
- /// </summary>
- /// <param name="starLv"></param>
- /// <returns></returns>
- 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
- }
- }
|