123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using XGame;
- using XGame.Database;
- using XGame.Framework.Data;
- using Random = UnityEngine.Random;
- namespace FL.Data
- {
- public class PartnersService : DataSingleton<PartnersService>
- {
- /// <summary>
- /// 模拟初始化数据
- /// </summary>
- public void Mock()
- {
- var tableIds = new List<int> { 20511, 20521, 20541, 20531, 20561, 20551 };
- var goneUpMap = PartnersData.Instance.GoneUpMap;
- var partnersMap = PartnersData.Instance.PartnersMap;
- var allTables = PartnerTableRepo.GetAll();
- foreach (var table in allTables)
- {
- int starLv = Random.Range(0, 6);//随机数的取值范围包括min,但不包括max
- int skillId = GetSkillId(starLv, table.Skill);
- var entityAttr = new PartnerAttributes()
- {
- TableId = table.Id,
- UID = UIDDefine.New(),
- Name = table.Name,
- Level = Random.Range(1, 10),
- RisingStarLv = starLv,
- SkillId = skillId,
- Radius = table.Size * 0.5f,
- };
- entityAttr.Attr.Hp = 500;
- entityAttr.Attr.HpLimit = 500;
- entityAttr.Attr.MoveSpeed = PlayerData.Instance.Attr.MoveSpeed;
- entityAttr.Attr.Attack = Random.Range(5, 10);
- var idx = tableIds.IndexOf(table.Id);
- if (idx >= 0)
- {
- goneUpMap.Add(entityAttr.UID, idx);
- }
- partnersMap.Add(entityAttr.UID, entityAttr);
- }
- // 模拟圣兵方案数据
- PartnersData.Instance.usePlanIndex = 0;
- var lineupPlanNameList = PartnersData.Instance.LineupPlanNameList;
- var lineupPlanList = PartnersData.Instance.LineupPlanList;
- for (int i = 0; i < 5; i++)
- {
- lineupPlanNameList.Add($"方案{i + 1}");
- int numberOfItems = i == 0 ? 5 : UnityEngine.Random.Range(0, 7); // 你想获取的随机项数
- var dataList = new List<long>();
- for (int j = 0; j < 6; j++)
- {
- long partnerUid = 0;
- if (j <= numberOfItems)
- {
- foreach (var item in goneUpMap)
- {
- if (item.Value == j)
- {
- partnerUid = item.Key;
- }
- }
- }
- dataList.Add(partnerUid);
- }
- lineupPlanList.Add(dataList);
- }
- }
- /// <summary>
- /// 获取
- /// </summary>
- /// <param name="starLv"></param>
- /// <param name="skillIdList"></param>
- private int GetSkillId(int starLv, int[] skillIdList)
- {
- 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 RequestPartnerUp(long partnerUID)
- {
- if (PartnersData.Instance.IsReachedLimit)
- {
- EventSingle.Instance.Notify(EventDefine.ShowTips, "随从已经达到出战数量上限.");
- return;
- }
- var goneUpMap = PartnersData.Instance.GoneUpMap;
- for (var i = 0; i < PartnersData.GoneUpLimit; i++)
- {
- if (goneUpMap.Values.Contains(i))
- {
- continue;
- }
- goneUpMap.Add(partnerUID, i);
- EventSingle.Instance.Notify(EventDefine.PartnerUp, partnerUID);
- break;
- }
- }
- public void RequestPartnerDown(long partnerUID)
- {
- if (!PartnersData.Instance.GoneUpMap.ContainsKey(partnerUID))
- {
- return;
- }
- PartnersData.Instance.GoneUpMap.Remove(partnerUID);
- EventSingle.Instance.Notify(EventDefine.PartnerDown, partnerUID);
- var useLineupPlanList = PartnersData.Instance.LineupPlanList[PartnersData.Instance.usePlanIndex];
- if (useLineupPlanList?.Count > 0)
- {
- }
- if (PartnersData.Instance.IsWaitForDownState)
- EventSingle.Instance.Notify(EventDefine.WaitForDownPartner, false);
- }
- //public void ExchangePartners()
- //{
- // var all = PartnerTableRepo.GetAll();
- // var activePartnerIds = PartnersData.Instance.ActiveUIDs;
- // var addPartners = new List<int>();
- // foreach (var table in all)
- // {
- // if (activePartnerIds.Contains(table.Id))
- // {
- // continue;
- // }
- // addPartners.Add(table.Id);
- // }
- // EventSingle.Instance.Notify(EventDefine.GameMainMapExchangePartner, addPartners);
- //}
- /// <summary>
- /// 请求替换圣兵方案
- /// </summary>
- /// <param name="lineupPlanIndex"></param>
- public void RequestToChangeLineupPlan(int lineupPlanIndex)
- {
- EventSingle.Instance.Notify(EventDefine.ShowTips, $"替换方案{lineupPlanIndex}");
- }
- /// <summary>
- /// 修改圣兵方案名称
- /// </summary>
- /// <param name="lineupPlanNameIndex"></param>
- /// <param name="changeName"></param>
- public void RequestToAlterLineupPlanName(int lineupPlanNameIndex, string changeName)
- {
- }
- }
- }
|