//进入战场 public void EnterBattleField(BattleField battleField, GridUnit bornGrid) { if (battleField != null && bornGrid != null) { this.battleField = battleField; //设置敌方队伍 enemyTeam = battleField.GetBattleTeam(this, false); //重置属性 battleUnitAttribute.RandomAttributes(); battleUnitAttribute.Reset(); //重置bbsys battleBehaviourSystem.ResetSystem(); EnterGrid(bornGrid); BattleUnitAction battleUnitAction = BattleUnitAction.Create(this); battleUnitAction.enterBattleFieldAction = BattleUnitEnterBattleFieldAction.Get(); battleUnitAction.enterBattleFieldAction.bornGrid = bornGrid; battleUnitAction.enterBattleFieldAction.attribute = new BattleUnitSyncAttribute(); battleUnitAction.enterBattleFieldAction.attribute.hpChanged = 0; battleUnitAction.enterBattleFieldAction.attribute.currentHP = battleUnitAttribute.hp; battleUnitAction.enterBattleFieldAction.attribute.energyChanged = 0; battleUnitAction.enterBattleFieldAction.attribute.currentEnergy = 0; //创建进入战场的消息 battleField.AppendBattleAction(battleUnitAction); //初始化战斗行为系统 battleBehaviourSystem.Init(this, battleField); } }
//自动搓招 private void AutoUseSkill(BattleUnitAction battleUnitAction) { //计算每个技能对目标单位的使用得分 BattleCalculator.Instance.AutoReleaseAnalysisor.Ananlysis(this, targetBattleUnit, battleUnitAttribute.battleSkills); //获取得分最高的技能 BattleSkillAutoReleaseAnalysisItem analysisResult = BattleCalculator.Instance.AutoReleaseAnalysisor.GetResult(); if (analysisResult != null) { //使用技能 switch (analysisResult.battleSkill.targetType) { case BattleSkillTargetType.BattleUnit: UseSkill(battleUnitAction, analysisResult.battleSkill, targetBattleUnit); break; case BattleSkillTargetType.GridUnit: UseSkill(battleUnitAction, analysisResult.battleSkill, null, analysisResult.targetGridUnit); break; case BattleSkillTargetType.Self: UseSkill(battleUnitAction, analysisResult.battleSkill); break; default: break; } } //重置分析器 BattleCalculator.Instance.AutoReleaseAnalysisor.Reset(); }
//自动搓招 private void AutoUseSkill(BattleUnitAction battleUnitAction, BattleBehaviourSystem.BattleDecision decision) { if (decision == null) { return; } if (decision.battleSkill != null) { //使用技能 switch (decision.battleSkill.targetType) { case BattleSkillTargetType.BattleUnit: UseSkill(battleUnitAction, decision.battleSkill, decision.skillTargetBattleUnit); break; case BattleSkillTargetType.GridUnit: UseSkill(battleUnitAction, decision.battleSkill, null, decision.skillTargetGrid); break; case BattleSkillTargetType.Self: UseSkill(battleUnitAction, decision.battleSkill); break; default: break; } } }
//自动 private HeroActionState AutoAction(BattleUnitAction battleUnitAction) { BattleBehaviourSystem.BattleDecision decision = battleBehaviourSystem.Think(); if (decision == null) { battleUnitAction.warningAction = BattleUnitWarningAction.Get(); battleUnitAction.warningAction.logWarning = "No target:" + ID; return(HeroActionState.Normal); } //判断是否切换目标 if (decision.targetBattleUnit != null && !decision.targetBattleUnit.Equals(targetBattleUnit)) { battleUnitAction.changeTargetAction = BattleUnitChangeTargetAction.Get(); battleUnitAction.changeTargetAction.lastTargetUnit = targetBattleUnit; battleUnitAction.changeTargetAction.newTargetUnit = decision.targetBattleUnit; targetBattleUnit = decision.targetBattleUnit; } //需要移动 if (decision.movePath != null && decision.movePath.Length > 0) { MoveToTargetGrid(battleUnitAction, targetBattleUnit, decision.movePath[decision.movePath.Length - 1], decision.movePath); } //自动搓招儿 AutoUseSkill(battleUnitAction, decision); return(HeroActionState.Normal); }
//进入战场 public void EnterBattleField(BattleField battleField, GridUnit bornGrid, List <BattleAction> heroActions) { if (battleField != null && bornGrid != null) { this.battleField = battleField; //设置敌方队伍 enemyTeam = battleField.GetBattleTeam(this, false); //重置仇恨记录器 hatredRecorder.Reset(this, enemyTeam); EnterGrid(bornGrid); if (heroActions != null) { BattleUnitAction battleUnitAction = BattleUnitAction.Get(this); battleUnitAction.enterBattleFieldAction = BattleUnitEnterBattleFieldAction.Get(); battleUnitAction.enterBattleFieldAction.bornGrid = bornGrid; battleUnitAction.enterBattleFieldAction.attribute = new BattleUnitSyncAttribute(); battleUnitAction.enterBattleFieldAction.attribute.hpChanged = 0; battleUnitAction.enterBattleFieldAction.attribute.currentHP = battleUnitAttribute.hp; battleUnitAction.enterBattleFieldAction.attribute.energyChanged = 0; battleUnitAction.enterBattleFieldAction.attribute.currentEnergy = 0; heroActions.Add(battleUnitAction); } } }
//自动 private HeroActionState AutoAction(BattleUnitAction battleUnitAction) { //自动选择目标 AutoSelectTarget(battleUnitAction); //找不到目标单位,这个就很奇怪了... if (targetBattleUnit == null && battleUnitAction != null) { battleUnitAction.warningAction = BattleUnitWarningAction.Get(); battleUnitAction.warningAction.logWarning = "No target:" + battleUnitID; return(HeroActionState.Warn); } //需要移动 if (battleUnitAction != null && toTargetPath.Count > 0) { MoveToTargetGrid(battleUnitAction, targetBattleUnit, toTargetPath[toTargetPath.Count - 1], toTargetPath.ToArray()); } //自动搓招儿 AutoUseSkill(battleUnitAction); //战斗结束判断 if (battleField.CheckBattleEnd()) { return(HeroActionState.BattleEnd); } else { return(HeroActionState.Normal); } }
//手动选择移动目标 private void ManualMoveTo(GridUnit grid, GridUnit[] path) { //添加一个行动 BattleUnitAction battleUnitAction = BattleUnitAction.Create(manualOperatingBattleUnitRenderer.battleUnit); //为行动添加移动数据 manualOperatingBattleUnitRenderer.battleUnit.MoveToTargetGrid(battleUnitAction, null, grid, path); fieldRenderer.battleField.AppendBattleAction(battleUnitAction); fieldRenderer.PlayBattle(AfterManualMove); }
//手动操作 private HeroActionState ManualAction(BattleUnitAction battleUnitAction) { //重置手动操作状态 manualActionState |= ManualActionState.Move; manualActionState |= ManualActionState.Skill; //创建一个手动操作的行动用于显示 if (battleUnitAction != null) { battleUnitAction.manualAction = LiteSingleton <BattleUnitManualAction> .Instance; } return(HeroActionState.WaitForPlayerChoose); }
//向目标格子移动 public void MoveToTargetGrid(BattleUnitAction battleUnitAction, BattleUnit targetUnit, GridUnit targetGrid, GridUnit[] gridPath) { //是否需要记录过程 if (battleUnitAction != null) { battleUnitAction.motionAction = BattleUnitMotionAction.Get(); battleUnitAction.motionAction.targetUnit = targetUnit; battleUnitAction.motionAction.fromGrid = mapGrid; battleUnitAction.motionAction.gridPath = gridPath; battleUnitAction.motionAction.moveRange = battleUnitAttribute.mobility; } //进入格子,直接设置数据 EnterGrid(targetGrid); }
//使用技能 public void UseSkill(BattleUnitAction battleUnitAction, SO_BattleSkill battleSkill, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null) { if (battleSkill == null) { UtilityHelper.LogError("Use skill error. Battle skill is none."); return; } BattleSkillEffectAnalysis analysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(battleSkill, this, targetBattleUnit, targetGridUnit); if (analysis == null) { UtilityHelper.LogError("Use skill error. Analysis failed:" + battleSkill.skillName); return; } List <BattleUnitSkillResult> skillResults = new List <BattleUnitSkillResult>(); //主要影响 for (int i = 0; i < analysis.mainReceiver.Count; ++i) { skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.mainReceiver[i], battleSkill, true)); } //次要影响 for (int i = 0; i < analysis.minorReceiver.Count; ++i) { skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.minorReceiver[i], battleSkill, false)); } //产生使用技能的动作 if (battleUnitAction != null) { battleUnitAction.skillAction = BattleUnitSkillAction.Get(); battleUnitAction.skillAction.battleSkill = battleSkill; battleUnitAction.skillAction.skillResult = skillResults.ToArray(); battleUnitAction.skillAction.targetBattleUnit = targetBattleUnit; battleUnitAction.skillAction.targetGrid = targetGridUnit; battleUnitAction.skillAction.selfAttribute = BattleSkillCostEnergy(battleSkill); } //伤害产生效果,计算仇恨 for (int i = 0; i < skillResults.Count; ++i) { skillResults[i].battleUnit.AcceptSkillResult(skillResults[i].syncAttribute, battleUnitAction); //产生仇恨 if (battleSkill.damageType != BattleSkillDamageType.Heal && !skillResults[i].battleUnit.Equals(this)) { skillResults[i].battleUnit.hatredRecorder.RecoredHatred(this.battleUnitID, skillResults[i].syncAttribute.hpChanged < 0 ? -skillResults[i].syncAttribute.hpChanged : skillResults[i].syncAttribute.hpChanged); } } }
//被使用技能 private void AcceptSkillResult(BattleUnitSyncAttribute sync, BattleUnitAction battleUnitAction) { if (sync != null) { battleUnitAttribute.hp = sync.currentHP; if (battleUnitAttribute.hp <= 0) { //被击败了 //从格子中移除 LeaveGrid(); } } }
private void RecoverEnergy(BattleUnitAction battleUnitAction) { //数值改变 battleUnitAttribute.energy += EGameConstL.EnergyRecoverPerRound; battleUnitAttribute.energy = battleUnitAttribute.energy > battleUnitAttribute.maxEnergy ? battleUnitAttribute.maxEnergy : battleUnitAttribute.energy; //创建一个Action if (battleUnitAction != null) { battleUnitAction.attributeUpdate = BattleUnitAttributeUpdate.Get(); battleUnitAction.attributeUpdate.attribute = new BattleUnitSyncAttribute(); battleUnitAction.attributeUpdate.attribute.hpChanged = 0; battleUnitAction.attributeUpdate.attribute.currentHP = battleUnitAttribute.hp; battleUnitAction.attributeUpdate.attribute.energyChanged = EGameConstL.EnergyRecoverPerRound; battleUnitAction.attributeUpdate.attribute.currentEnergy = battleUnitAttribute.energy; } }
/// <summary> /// 战斗单位动作的顺序是,移动->攻击 /// </summary> /// <param name="heroActions"></param> /// <returns></returns> public HeroActionState BattleAction(BattleUnitAction battleUnitAction) { //恢复能量 RecoverEnergy(battleUnitAction); //手动 if (battleUnitAttribute.manualOperation) { return(ManualAction(battleUnitAction)); } //自动 else { return(AutoAction(battleUnitAction)); } }
//手动释放技能(对具体的目标) private void ManualSkill(BattleUnit targetBattleUnit) { if (targetBattleUnit == null) { return; } //添加一个行动 BattleUnitAction battleUnitAction = BattleUnitAction.Create(manualOperatingBattleUnitRenderer.battleUnit); //为行动添加技能释放数据 manualOperatingBattleUnitRenderer.battleUnit.UseSkill(battleUnitAction, usedManualReleaseAnalysisor.battleSkill, targetBattleUnit); fieldRenderer.battleField.AppendBattleAction(battleUnitAction); //行动结束 ManualOperationComplete(); }
//运行英雄动作 public IEnumerator RunHeroAction(BattleUnitAction heroAction) { if (heroAction == null) { yield break; } //进入战场 if (heroAction.enterBattleFieldAction != null) { yield return(PlayEnterBattleFieldAction(heroAction.enterBattleFieldAction)); } //恢复能量 if (heroAction.attributeUpdate != null) { yield return(PlayAttributeUpdateAction(heroAction.attributeUpdate)); } //切换目标 if (heroAction.changeTargetAction != null) { yield return(PlayChangeTargetAction(heroAction.changeTargetAction)); } //移动 if (heroAction.motionAction != null) { yield return(PlayMotionAction(heroAction.motionAction)); } //使用技能 if (heroAction.skillAction != null) { yield return(PlaySkillAction(heroAction.skillAction)); } //手动操作 if (heroAction.manualAction != null) { yield return(PlayManualAction(heroAction.manualAction)); } //警告动作 if (heroAction.warningAction != null) { UtilityHelper.LogWarning(heroAction.ToString()); yield return(EGameConstL.WaitForTouchScreen); } yield return(null); }
//播放战场动作 private IEnumerator PlayBattleByCoroutine(System.Action callback) { if (battleField == null || battleField.msgAction.battleActions == null || battleField.msgAction.battleActions.Count == 0) { UtilityHelper.LogError(string.Format("Play battle action failed. -> {0}", battleField.battleID)); yield break; } UtilityHelper.Log("Play battle actions"); //遍历所有战斗动作 var msgAction = battleField.msgAction; while (battleField.currentIndex < msgAction.battleActions.Count) { if (msgAction.battleActions[battleField.currentIndex] == null) { UtilityHelper.LogError(string.Format("Play action error. Action is none or type is none, index = {0}", battleField.currentIndex)); continue; } BattleUnitAction heroAction = null; //一个英雄动作 if (msgAction.battleActions[battleField.currentIndex] is BattleUnitAction) { heroAction = (BattleUnitAction)msgAction.battleActions[battleField.currentIndex]; //有对应的战斗单位,且这个战斗单位已经连接了战斗单位渲染器 if (heroAction.actionUnit != null && heroAction.actionUnit.battleUnitRenderer != null) { yield return(heroAction.actionUnit.battleUnitRenderer.RunHeroAction(heroAction)); } } ++battleField.currentIndex; } UtilityHelper.Log("Play Msg Action fin"); if (callback != null) { callback(); } }
//手动释放技能(对具体的地块) private void ManualSkill(GridUnit targetGrid) { if (targetGrid == null) { return; } //添加一个行动 BattleUnitAction battleUnitAction = BattleUnitAction.Create(manualOperatingBattleUnitRenderer.battleUnit); manualOperatingBattleUnitRenderer.battleUnit.UseSkill(battleUnitAction, usedManualReleaseAnalysisor.battleSkill, null, targetGrid); fieldRenderer.battleField.AppendBattleAction(battleUnitAction); //取消范围高亮显示 SetCircularRangeRenderStateActive(false, GridRenderType.SkillReleaseRange); SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange); //行动结束 ManualOperationComplete(); }
/// <summary> /// 战斗单位动作的顺序是,移动->攻击 /// </summary> /// <param name="heroActions"></param> /// <returns></returns> public HeroActionState BattleAction() { BattleUnitAction battleUnitAction = BattleUnitAction.Create(this); battleField.AppendBattleAction(battleUnitAction); //恢复能量 RecoverEnergy(battleUnitAction); //冷静 battleBehaviourSystem.RageLevelCooldown(); //手动 if (battleUnitAttribute.manualOperation) { return(ManualAction(battleUnitAction)); } //自动 else { return(AutoAction(battleUnitAction)); } }
//播放战场动作 private IEnumerator PlayBattleByCoroutine(System.Action callback) { if (battleField == null || battleField.battleActions == null || battleField.battleActions.Count == 0) { UtilityHelper.LogError(string.Format("Play battle action failed. -> {0}", battleField.ID)); yield break; } //遍历所有战斗动作 while (currentActionIndex < battleField.battleActions.Count) { BattleUnitAction heroAction = null; //一个英雄动作 if (battleField.battleActions[currentActionIndex] is BattleUnitAction) { heroAction = (BattleUnitAction)battleField.battleActions[currentActionIndex]; //有对应的战斗单位,且这个战斗单位已经连接了战斗单位渲染器 if (heroAction.actionUnit != null && heroAction.actionUnit.battleUnitRenderer != null) { yield return(heroAction.actionUnit.battleUnitRenderer.RunHeroAction(heroAction)); } #if UNITY_EDITOR if (DebugHelper.Instance.playBattleByStep) { yield return(EGameConstL.WaitForTouchScreen); } #endif } ++currentActionIndex; } if (callback != null) { callback(); } }
//开始战斗 private void Fight() { battleState = BattleState.Fighting; UtilityHelper.Log(string.Format("<color=#ff0000> {0} battle fight. </color>", this.ToString())); BattleUnit actionUnit = null; do { //没有连接渲染器,则一步一更新 //连接了渲染器,则一直更新直到结束 actionUnit = actionQueue.Dequeue(); if (actionUnit == null) { battleState = BattleState.End; break; } if (actionUnit.CanAction) { BattleUnitAction battleUnitAction = BattleUnitAction.Get(actionUnit); HeroActionState state = actionUnit.BattleAction(battleUnitAction); switch (state) { case HeroActionState.BattleEnd: battleState = BattleState.End; break; case HeroActionState.Error: battleState = BattleState.Exception; break; case HeroActionState.Warn: battleState = BattleState.Exception; UtilityHelper.LogWarning(string.Format("Warning: battle action state warning -> {0}", actionUnit.ToString())); break; case HeroActionState.WaitForPlayerChoose: battleState = BattleState.WaitForPlayer; break; default: break; } //追加动作 AppendBattleAction(battleUnitAction); } //考虑是否在放回队列 CalculateNextAction(actionUnit); ++actionCount; if (actionCount >= EGameConstL.BattleFieldMaxActions) { battleState = BattleState.Exception; } } while (battleFieldRenderer == null && battleState != BattleState.End && battleState != BattleState.Exception); //连接了渲染器,一步一更新 if (battleFieldRenderer != null) { Debug.Log("Play actions"); if (battleState == BattleState.End || battleState == BattleState.Exception) { battleFieldRenderer.PlayBattle(BattleEnd); } else if (battleState == BattleState.WaitForPlayer) { battleFieldRenderer.PlayBattle(null); } else { battleFieldRenderer.PlayBattle(Fight); } } else { //没有连接渲染器,自动战斗 BattleEnd(); } }
//开始战斗 private void Fight() { battleState = BattleState.Fighting; BattleUnit actionUnit = null; do { //连接渲染器,则一步一更新 //没有连接渲染器,则一直计算直到结束 actionUnit = actionQueue.Dequeue(); if (actionUnit == null) { battleState = BattleState.End; break; } if (actionUnit.CanAction) { BattleUnitAction battleUnitAction = BattleUnitAction.Create(actionUnit); HeroActionState state = actionUnit.BattleAction(); switch (state) { case HeroActionState.Normal: battleState = BattleState.Fighting; break; case HeroActionState.WaitForPlayerChoose: battleState = BattleState.WaitForPlayer; break; case HeroActionState.Error: battleState = BattleState.Exception; break; case HeroActionState.Warn: battleState = BattleState.Exception; UtilityHelper.LogWarning(string.Format("Warning: battle action state warning -> {0}", actionUnit.ToString())); break; default: break; } } //考虑是否在放回队列 CalculateNextAction(actionUnit); if (battleActions.Count > EGameConstL.BattleFieldMaxActions) { UtilityHelper.LogError("Battle actions overflow max limit."); battleState = BattleState.Exception; } else { //只在这种情况下做战斗结束的判断 if (!actionUnit.CanAction || actionUnit.targetBattleUnit == null || !actionUnit.targetBattleUnit.CanAction) { CheckBattleEnd(); } } } while (battleFieldRenderer == null && battleState != BattleState.End && battleState != BattleState.Exception); //连接了渲染器,一步一表现 if (battleFieldRenderer != null) { if (battleState == BattleState.WaitForPlayer) { battleFieldRenderer.PlayBattle(null); } else { battleFieldRenderer.PlayBattle(Run); } } else { Run(); } }
//输出分析战报 private void OutputBattleReport(string path) { StringBuilder strBuilder = new StringBuilder(); if (!File.Exists(path)) { strBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}\n", "BattleID", "State", "SN", "AtkTeam", "FirstAction", "Attacker", "SufferTeam", "Sufferer", "SkillName", "SkillType", "Damage/HP"); } foreach (var item in battleActions) { switch (item.actionType) { case MsgBattleActionType.None: case MsgBattleActionType.Warning: case MsgBattleActionType.BattleUnitAction: BattleUnitAction battleUnitAction = item as BattleUnitAction; if (battleUnitAction != null && battleUnitAction.skillAction != null) { foreach (var skillResult in battleUnitAction.skillAction.skillResult) { BattleTeam firstActionTeam = ((resetTimes & 1) == 0) ? teams[1] : teams[0]; strBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}\n", resetTimes, "Action", item.sn, battleUnitAction.actionUnit.battleTeam, firstActionTeam.Equals(battleUnitAction.actionUnit.battleTeam) ? 1 : 0, battleUnitAction.actionUnit.battleUnitAttribute.battleUnitName, skillResult.battleUnit.battleTeam, skillResult.battleUnit.battleUnitAttribute.battleUnitName, battleUnitAction.skillAction.battleSkill.skillName, battleUnitAction.skillAction.battleSkill.damageType.ToString(), skillResult.syncAttribute.hpChanged); //统计击杀 if (skillResult.syncAttribute.currentHP <= 0) { strBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}\n", resetTimes, "Kill", item.sn, battleUnitAction.actionUnit.battleTeam, firstActionTeam.Equals(battleUnitAction.actionUnit.battleTeam) ? 1 : 0, battleUnitAction.actionUnit.battleUnitAttribute.battleUnitName, skillResult.battleUnit.battleTeam, skillResult.battleUnit.battleUnitAttribute.battleUnitName, battleUnitAction.skillAction.battleSkill.skillName, battleUnitAction.skillAction.battleSkill.damageType.ToString(), skillResult.syncAttribute.hpChanged); } } } break; case MsgBattleActionType.BattleStart: break; case MsgBattleActionType.End: break; default: break; } } foreach (var team in teams) { foreach (var bu in team.battleUnits) { BattleTeam firstActionTeam = ((resetTimes & 1) == 0) ? teams[1] : teams[0]; strBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}\n", resetTimes, "End", string.Empty, bu.battleTeam, firstActionTeam.Equals(bu.battleTeam) ? 1 : 0, bu.battleUnitAttribute.battleUnitName, string.Empty, string.Empty, string.Empty, string.Empty, bu.battleUnitAttribute.hp); } } File.AppendAllText(path, strBuilder.ToString()); }
//使用技能 public void UseSkill(BattleUnitAction battleUnitAction, SO_BattleSkill battleSkill, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null) { if (battleSkill == null) { UtilityHelper.LogError("Use skill error. Battle skill is none."); return; } BattleSkillEffectAnalysis analysis = BattleCalculator.Instance.AnalyseBattleSkillEffect(battleSkill, this, targetBattleUnit, targetGridUnit); if (analysis == null) { UtilityHelper.LogError("Use skill error. Analysis failed:" + battleSkill.skillName); return; } List <BattleUnitSkillResult> skillResults = new List <BattleUnitSkillResult>(); //主要影响 for (int i = 0; i < analysis.mainReceiver.Count; ++i) { skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.mainReceiver[i], battleSkill, true)); } //次要影响 for (int i = 0; i < analysis.minorReceiver.Count; ++i) { skillResults.Add(BattleCalculator.Instance.CalcSingle(this, analysis.minorReceiver[i], battleSkill, false)); } //产生使用技能的动作 if (battleUnitAction != null) { battleUnitAction.skillAction = BattleUnitSkillAction.Get(); battleUnitAction.skillAction.battleSkill = battleSkill; battleUnitAction.skillAction.skillResult = skillResults.ToArray(); battleUnitAction.skillAction.targetBattleUnit = targetBattleUnit; battleUnitAction.skillAction.targetGrid = targetGridUnit; battleUnitAction.skillAction.selfAttribute = BattleSkillCostEnergy(battleSkill); } //伤害产生效果,计算仇恨 for (int i = 0; i < skillResults.Count; ++i) { //接收伤害,属性变更 skillResults[i].battleUnit.AcceptSkillResult(skillResults[i].syncAttribute, battleUnitAction); //产生仇恨 if (battleSkill.damageType != BattleSkillDamageType.Heal && !skillResults[i].battleUnit.Equals(this)) { //新仇记录 for (int j = 0; j < enemyTeam.battleUnits.Count; ++j) { if (!enemyTeam.battleUnits[j].CanAction) { continue; } //每个战斗单位都需要知道发生了什么 enemyTeam.battleUnits[j].battleBehaviourSystem.RecordSkillResult(this, skillResults[i]); } } } }
//自动选择目标 private void AutoSelectTarget(BattleUnitAction battleUnitAction) { int stopDistance = SkillStopDistance; //从仇恨列表中确定目标 BattleUnit hatredUnit = null; //按照仇恨列表获取目标 for (int i = 0; i < hatredRecorder.HatredCount; ++i) { hatredUnit = hatredRecorder.GetHatredByIdx(i, i == 0); if (!hatredUnit.CanAction) { //已经排序过了,找到不能行动的单位,就表示没有单位可以行动了 hatredUnit = null; break; } //判断这个单位是否可以到达 bool catched = false; //如果这个单位就在身边 if (mapGrid.Distance(hatredUnit.mapGrid) <= stopDistance) { toTargetPath.Clear(); catched = true; } else { catched = MapNavigator.Instance.Navigate( battleField.battleMap, mapGrid, hatredUnit.mapGrid, toTargetPath, null, battleUnitAttribute.mobility, stopDistance ); } //寻路不可达 if (!catched) { hatredUnit = null; continue; } //找到了 else { break; } } //没有目标 if (hatredUnit == null) { targetBattleUnit = null; return; } //判断是否切换目标 if (battleUnitAction != null && !hatredUnit.Equals(targetBattleUnit)) { battleUnitAction.changeTargetAction = BattleUnitChangeTargetAction.Get(); battleUnitAction.changeTargetAction.lastTargetUnit = targetBattleUnit; battleUnitAction.changeTargetAction.newTargetUnit = hatredUnit; targetBattleUnit = hatredUnit; } }