123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using System.Collections.Generic;
- using Common.Utility.CombatEvent;
- using Core.Utility;
- using Excel2Json;
- using Fort23.Core;
- using Fort23.UTool;
- using GameLogic.Bag;
- namespace GameLogic.Hero
- {
- public class HeroController
- {
-
-
-
- /// <summary>
- /// 所有英雄
- /// </summary>
- public Dictionary<int, HeroInfo> allHeroDic = new Dictionary<int, HeroInfo>();
-
- /// <summary>
- /// 也可以叫主力(afk的共鸣英雄),替补英雄等级=主力英雄的最低等级(和afk一样的)
- /// 主力英雄不一定等于上阵英雄,主力英雄只是决定了共鸣等级
- /// </summary>
- public Dictionary<int, HeroInfo> heroDicInLead = new Dictionary<int, HeroInfo>(4);
- /// <summary>
- /// 后备英雄(共享等级)
- /// </summary>
- public Dictionary<int, HeroInfo> heroDicInBack = new Dictionary<int, HeroInfo>();
- public int mainLevel => m_MainLevel;
-
- private int m_MainLevel;
- private void CalMainLevel()
- {
- //计算主力英雄的最低等级
- int tmpLv = 9999;
- foreach (var keyValuePair in heroDicInLead)
- {
- if (keyValuePair.Value.level.Value < tmpLv)
- {
- tmpLv = keyValuePair.Value.level.Value;
- }
- }
-
- m_MainLevel = tmpLv;
-
- EventManager.Instance.Dispatch(CustomEventType.MainLvUp, new SimpleEventData(){intData = m_MainLevel});
- }
- public HeroUpResultType CanPromote(HeroInfo heroInfo)
- {
- long curHeroCount = BagController.Instance.GetItemInfo(heroInfo.modelConfig.itemID).count.Value;
- int costHeroCount = heroInfo.promoteConfig.costCount;
- if (curHeroCount < costHeroCount)
- {
- return HeroUpResultType.ResNotEnough;
- }
-
- return HeroUpResultType.Success;
- }
-
- public HeroUpResultType CanUpgrade(HeroInfo heroInfo, bool isOpenPre = false)
- {
- if (PlayerManager.Instance.gameConstantConfig.maxLv <= heroInfo.level.Value)
- {
- LogTool.Log("已到达最高等级:" + PlayerManager.Instance.gameConstantConfig.maxLv);
- return HeroUpResultType.MaxLv;
- }
-
- //计算主力英雄等级差, 如果再升一级,就大于最大等级差了,就不允许升了.
- if (heroInfo.level.Value - m_MainLevel >= GlobalParam.Max_Main_Level_Difference)
- {
- LogTool.Log(heroInfo.modelID + "主力英雄等级差不能超过:" + GlobalParam.Max_Main_Level_Difference);
- return HeroUpResultType.MainLevelNotEnough;
- }
- //每10级,要打开预览界面后,再升级(如果已经打开,就不判断了)
- if (!isOpenPre && (heroInfo.level.Value + 1) % 10 == 1)
- {
- return HeroUpResultType.NeedOpenPreUI;
- }
-
- if (BagController.Instance.IsEnough(GlobalParam.Item_HeroExp_ID, heroInfo.powerUpConfig.levelUpExp))
- {
- if (isOpenPre)
- {
- return HeroUpResultType.PlayUpgradeEftFirst;
- }
- return HeroUpResultType.Success;
- }
- else
- {
- return HeroUpResultType.ExpNotEnough;
- }
- }
- private void DoUpgrade(HeroInfo heroInfo)
- {
- heroInfo.Upgrade();
- PlayerManager.Instance.SaveHeroData(heroInfo);
- //如果当前英雄等级等于主力等级,则升级时需要重新计算主力等级
- if (heroInfo.level.Value - 1 == m_MainLevel)
- {
- CalMainLevel();
- }
- // SendEvent(HeroUpType.Level, heroInfo, HeroUpResultType.Success);
- }
- public HeroUpResultType PromoteHeroLogic(HeroInfo heroInfo)
- {
-
- HeroUpResultType resultType = CanPromote(heroInfo);
- if (resultType == HeroUpResultType.Success)
- {
- //扣除碎片
- bool isOk = BagController.Instance.DeductItem(heroInfo.modelConfig.itemID, heroInfo.promoteConfig.costCount);
- if (isOk)
- {
- if (resultType == HeroUpResultType.Success)
- {
- heroInfo.Promote();
- PlayerManager.Instance.SaveHeroData(heroInfo);
- // SendEvent(HeroUpType.Promote, heroInfo, resultType);
- }
- }
- }
-
- return resultType;
-
- }
- /// <summary>
- /// 英雄升级逻辑,主要是改数据,不在这里做UI表现
- /// </summary>
- /// <param name="heroInfo"></param>
- public HeroUpResultType UpgradeHeroLogic(HeroInfo heroInfo, bool isOpenPre = false)
- {
- HeroUpResultType resultType = CanUpgrade(heroInfo, isOpenPre);
- if (resultType == HeroUpResultType.Success || resultType == HeroUpResultType.PlayUpgradeEftFirst)
- {
- //扣除经验
- bool isOk = BagController.Instance.DuctHeroExp(heroInfo.powerUpConfig.levelUpExp);
- if (isOk)
- {
- if (resultType == HeroUpResultType.Success)
- {
- DoUpgrade(heroInfo);
- }
- else if (resultType == HeroUpResultType.PlayUpgradeEftFirst)
- {
- //执行逻辑,返回播放特效的类型
- DoUpgrade(heroInfo);
- return resultType;
- }
- return HeroUpResultType.Success;
- }
- }
- return resultType;
- }
-
- // /// <summary>
- // /// 发送英雄提升的事件
- // /// </summary>
- // /// <param name="upType">提升类型:升级、升星等.</param>
- // public void SendEvent(HeroUpType upType, HeroInfo heroInfo, HeroUpResultType resultType = HeroUpResultType.None)
- // {
- // HeroPowerUpEventData data = new HeroPowerUpEventData();
- // data.heroModelID = heroInfo.modelID;
- // data.upType = upType;
- // data.ResultType = resultType;
- //
- // PlayerManager.Instance.lastHeroInfo = heroInfo;
- //
- // if (upType == HeroUpType.Level)
- // {
- // SkillUpConfig upConfig = PlayerManager.Instance.heroController
- // .GetSkillUpConfig4Lv(heroInfo.level.Value);
- //
- //
- // if (upConfig.ID > 0)
- // {
- // heroInfo.SkillData.UpdateSkills();
- // data.isSkillUp = true;
- // }
- //
- // EventManager.Instance.Dispatch(CustomEventType.HeroLvUp, data);
- // }
- // else if (upType == HeroUpType.Promote)
- // {
- // // SkillUpConfig upConfig = PlayerManager.Instance.heroController
- // // .IsStarUpGetNewSkill(heroInfo.star.Value);
- //
- // // data.isSkillUp = upConfig.ID > 0;
- //
- // // SkillUpConfig upConfig = PlayerManager.Instance.heroController.GetSkillUpConfig4Star(heroInfo.star.Value);
- // //
- // // if (upConfig.ID > 0)
- // // {
- // // heroInfo.SkillData.UpdateSkills();
- // // data.isSkillUp = true;
- // // }
- //
- // EventManager.Instance.Dispatch(CustomEventType.HeroPromote, data);
- // }
- // EventManager.Instance.Dispatch(CustomEventType.HeroPowerUp, data);
- // }
- //
- public void InitHeroes()
- {
-
- CalMainLevel();
- }
-
- /// <summary>
- /// 获取英雄
- /// </summary>
- /// <param name="modelID">英雄ID modelID</param>
- /// <returns></returns>
- public CombatHeroInfo GetHeroInfo(int modelID)
- {
- if (allHeroDic.ContainsKey(modelID))
- {
- return allHeroDic[modelID];
- }
-
- LogTool.Error("没有这个英雄" + modelID);
- return null;
- }
-
-
- /// <summary>
- /// 添加英雄
- /// </summary>
- /// <param name="heroInfo"></param>
- public void AddHero(HeroInfo heroInfo)
- {
- if (heroInfo.isLead)
- {
- DeployHeroToLead(heroInfo);
- }
- else
- {
- DeployHeroToBack(heroInfo);
- }
- }
- /// <summary>
- /// 进入主力队伍
- /// </summary>
- /// <param name="heroInfo"></param>
- public void DeployHeroToLead(HeroInfo heroInfo)
- {
- if (heroDicInLead.Count >= GlobalParam.Max_Deploy_HERO)
- {
- return;
- }
- if (heroDicInLead.ContainsKey(heroInfo.modelID))
- {
- LogTool.Error("heroDicInLead不应该出现相同的英雄ID=" + heroInfo.modelID);
- return;
- }
-
- heroDicInLead.Add(heroInfo.modelID, heroInfo);
- heroInfo.isLead = true;
-
- allHeroDic.Add(heroInfo.modelID, heroInfo);
- CalMainLevel();
- }
- /// <summary>
- /// 更换主力
- /// </summary>
- /// <param name="heroInfo"></param>
- public void ChangeLeadHero(HeroInfo backHero, HeroInfo leadHero)
- {
- if (!heroDicInLead.ContainsKey(leadHero.modelID))
- {
- LogTool.Error("不是主力" + leadHero.modelID);
- return;
- }
-
- if (!heroDicInBack.ContainsKey(backHero.modelID))
- {
- LogTool.Error("不是替补" + backHero.modelID);
- return;
- }
-
- //从主力中移除,并加入后补
- heroDicInLead.Remove(leadHero.modelID);
- DeployHeroToBack(leadHero);
- //从后补中移除,并加入主力
- heroDicInBack.Remove(backHero.modelID);
- DeployHeroToLead(backHero);
-
-
- }
-
- /// <summary>
- /// 进入后备队伍(英雄背包)
- /// </summary>
- /// <param name="heroInfo"></param>
- public void DeployHeroToBack(HeroInfo heroInfo)
- {
- if (heroDicInBack.ContainsKey(heroInfo.modelID))
- {
- LogTool.Error("heroDicInBack不应该出现相同的英雄ID=" + heroInfo.modelID);
- return;
- }
-
- heroDicInBack.Add(heroInfo.modelID, heroInfo);
- heroInfo.isLead = false;
-
- allHeroDic.Add(heroInfo.modelID, heroInfo);
- }
-
-
-
- }
- }
|