//将战斗单位放置入战场 private void EnterBattleField(bool recordProcess) { BattleUnit battleUnit = null; List <BattleAction> actions = null; if (recordProcess) { actions = new List <BattleAction>(); } for (int i = 0; i < teams.Count; ++i) { for (int j = 0; j < teams[i].battleUnits.Count; ++j) { battleUnit = teams[i].battleUnits[j]; GridUnit bornUnit = battleMap.GetBornGrid(i, true); if (bornUnit == null) { UtilityHelper.LogError("Get born unit failed."); continue; } battleUnit.EnterBattleField(this, bornUnit, actions); //生成行动队列 actionQueue.Enqueue(battleUnit); if (recordProcess) { AppendBattleActions(actions); } } } if (recordProcess) { AppendBattleActions(actions); } }
//点击了地块、战斗单位 private void OnBattleUnitAndGridTouched(GridUnit gridTouched, BattleUnit battleUnitTouched) { #if TEST_NAV Test_Nav(gridTouched); return; #endif #if TEST_RANGE Test_Range(gridTouched); return; #endif #if TEST_REMOTE_RANGE Test_RemoteRange(gridTouched); return; #endif if (battleUnitTouched != null && battleUnitTouched.battleBehaviourSystem != null) { battleUnitTouched.battleBehaviourSystem.Think(); } UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); //通知helper处理点击反馈逻辑 manualOperationHelper.OnBattleUnitAndGridTouched(gridTouched, battleUnitTouched); }
//某个战斗单位点击了移动 public void BattleUnitMove(BattleUnit battleUnit) { if (battleUnit == null || battleUnit.battleUnitRenderer == null || !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer)) { UtilityHelper.LogError("Battle unit move failed."); return; } //显示移动范围 SetCircularRangeRenderStateActive( true, GridRenderType.MoveRange, battleUnit.mapGrid.row, battleUnit.mapGrid.column, battleUnit.battleUnitAttribute.mobility); //设定为移动状态 manualOperationState = ManualOperationState.Move; //关闭选择操作界面 HideManualActionList(); }
//某个战斗单位点击了移动 public void BattleUnitMove(BattleUnit battleUnit) { if (battleUnit == null || battleUnit.battleUnitRenderer == null || !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer)) { UtilityHelper.LogError("Battle unit move failed."); return; } //显示移动范围 SetCircularRangeRenderStateActive( true, GridRenderType.MoveRange, battleUnit.mapGrid.row, battleUnit.mapGrid.column, battleUnit.battleUnitAttribute.mobility); //设定为移动状态 manualOperationState = ManualOperationState.Move; //关闭选择操作界面 UIViewManager.Instance.HideView(UIViewName.BattleFieldPlayerActOption); }
//某个战斗单位点击了使用技能 public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill) { if (battleUnit == null || battleUnit.battleUnitRenderer == null || !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer)) { UtilityHelper.LogError("Battle unit use skill failed."); UIViewManager.Instance.HideView(UIViewName.BattleFieldPlayerActOption); return; } //获取推算的技能释放结果 usedManualReleaseAnalysisor = BattleCalculator.Instance.ManualReleaseAnalysisor; //分析结果 usedManualReleaseAnalysisor.Analysis(manualOperatingBattleUnitRenderer.battleUnit, skill); //显示技能释放范围 if (skill.releaseRadius > 0) { SetCircularRangeRenderStateActive( true, GridRenderType.SkillReleaseRange, battleUnit.mapGrid.row, battleUnit.mapGrid.column, skill.releaseRadius); } //根据类型判断技能显示状态 switch (skill.targetType) { //对单个目标 case BattleSkillTargetType.BattleUnit: //可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selectable); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } //设定技能操作类型 skillOperationType = skill.effectRadius > 0 ? SkillOperationType.SurroundBattleUnit : SkillOperationType.SingleBattleUnitTarget; break; //对范围(某一个位置)目标 case BattleSkillTargetType.GridUnit: skillOperationType = SkillOperationType.GridUnitTarget; //如果没有位置可选,则直接打开范围 if (skill.releaseRadius <= 0) { //可以被选中,标记为已被选中 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(battleUnit.mapGrid, null); } else { //需要指定范围,需要点击目标地块 } break; //以自身为中心的 case BattleSkillTargetType.Self: //可以被选中,标记为已被选中 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } skillOperationType = SkillOperationType.SurroundSelf; //省去一步点击操作,直接展示区域 OnBattleUnitAndGridTouched_StateSkill_SurroundSelf(battleUnit.mapGrid, battleUnit); break; default: break; } //切换操作状态 manualOperationState = ManualOperationState.Skill; UIViewManager.Instance.HideView(UIViewName.BattleFieldPlayerActOption); }
private void OnBattleUnitAndGridTouched(GridUnit gridTouched, BattleUnit battleUnitTouched) { //没有激活操作状态 if (manualOperationState == ManualOperationState.None) { //点中了战斗单位 if (battleUnitTouched != null) { //点中了等待手动操作的战斗单位 if (battleUnitTouched.battleUnitRenderer.Equals(manualBattleUnitRenderer)) { ShowManualActionList(); } else { UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } //点中了地图 else { UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } //选择移动状态 else if (manualOperationState == ManualOperationState.Move) { //点中了战斗单位 if (battleUnitTouched != null) { //点中了等待手动操作的战斗单位 if (battleUnitTouched.battleUnitRenderer.Equals(manualBattleUnitRenderer)) { //取消操作 manualOperationState = ManualOperationState.None; SetRangeHighlightActive(false, 0, 0, 0); } else { UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } //点中了地图 else { if (gridTouched.GridType == GridType.Obstacle) { UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } else { //点击是否超出了范围 GridUnit fromGrid = manualBattleUnitRenderer.battleUnit.mapGrid; if (fromGrid.Distance(gridTouched) > manualBattleUnitRenderer.battleUnit.mobility) { Debug.Log("超出了移动半径!"); } else { bool result = MapNavigator.Instance.Navigate( battleField.battleMap, fromGrid, gridTouched, UtilityObjs.gridUnits, null, manualBattleUnitRenderer.battleUnit.mobility ); //判断是否可以到达(导航成功且可以可以到达) if (result && UtilityObjs.gridUnits[UtilityObjs.gridUnits.Count - 1].Equals(gridTouched)) { //可以到达 ManualMoveTo(gridTouched, UtilityObjs.gridUnits.ToArray()); UtilityObjs.gridUnits.Clear(); } else { //不可以到达 Debug.Log("点击位置不可到达!"); } } } } } //选择攻击目标状态 else if (manualOperationState == ManualOperationState.Skill) { //点中了战斗单位 if (battleUnitTouched != null) { //点中了等待手动操作的战斗单位 if (battleUnitTouched.battleUnitRenderer.Equals(manualBattleUnitRenderer)) { //取消操作 manualOperationState = ManualOperationState.None; SetRangeHighlightActive(false, 0, 0, 0); } else { //判断是否可以被攻击 if (manualBattleUnitRenderer.battleUnit.battleTeam.Equals(battleUnitTouched.battleTeam)) { //同一个队伍的 Debug.Log("攻击状态点中了同一个队伍的战斗单位:" + battleUnitTouched.ToString()); } else if (battleUnitTouched.mapGrid.Distance(manualBattleUnitRenderer.battleUnit.mapGrid) > 1) { Debug.Log("不在攻击范围:" + battleUnitTouched.ToString()); } else { ManualSkill(battleUnitTouched); } } } //点中了地图 else { Debug.Log("攻击状态点中了地图单位:" + gridTouched.ToString()); } } }
public void OnEnter(BattleUnit battleUnit) { this.battleUnit = battleUnit; }
//某个战斗单位点击了待命 public void BattleUnitStay(BattleUnit battleUnit) { manualOperationHelper.BattleUnitStay(battleUnit); }
public BattleUnitWarningAction warningAction; //警告信息 public static BattleUnitAction Get(BattleUnit actionUnit) { return(new BattleUnitAction(actionUnit)); }
//点击了技能,在以自身为原点的技能情况下 private void OnBattleUnitAndGridTouched_StateSkill_SurroundSelf(GridUnit gridTouched, BattleUnit battleUnitTouched) { //当前选定的战斗单位为空,表示还没有显示攻击范围 if (selectedBattleUnitRenderer == null) { selectedBattleUnitRenderer = battleUnitTouched.battleUnitRenderer; //展示攻击区域 SetCircularRangeRenderStateActive( true, GridRenderType.SkillEffectRange, selectedBattleUnitRenderer.battleUnit.mapGrid.row, selectedBattleUnitRenderer.battleUnit.mapGrid.column, usedManualReleaseAnalysisor.battleSkill.effectRadius); } else { //点击任意位置判断为释放 ManualSkill(manualOperatingBattleUnitRenderer.battleUnit.mapGrid); } }
protected BattleHeroAction(BattleUnit actionUnit, MsgBattleHeroActionType actionType) : base(actionType) { this.actionUnit = actionUnit; }
public BattleHeroManualAction(BattleUnit actionUnit) : base(actionUnit, MsgBattleHeroActionType.Manual) { }
public BattleHeroWarningAction(BattleUnit actionUnit, string logWarning) : base(actionUnit, MsgBattleHeroActionType.Warning) { this.logWarning = logWarning; }
public BattleHerodDefeatedAction(BattleUnit actionUnit) : base(actionUnit, MsgBattleHeroActionType.Defeated) { }
public BattleHeroChangeTargetAction(BattleUnit actionUnit) : base(actionUnit, MsgBattleHeroActionType.ChangeTarget) { }
public void OnLeave() { this.battleUnit = null; UpdateRuntimePasses(false); }
public void OnEnter(BattleUnit battleUnit) { this.battleUnit = battleUnit; UpdateRuntimePasses(false); }
//点击了技能,在单体目标技能情况下 private void OnBattleUnitAndGridTouched_StateSkill_SingleBattleUnitTarget(GridUnit gridTouched, BattleUnit battleUnitTouched) { //没有点中战斗单位 if (battleUnitTouched == null) { return; } //点中了可以被使用技能的单位 if (usedManualReleaseAnalysisor.suitableUnits.Contains(battleUnitTouched)) { ManualSkill(battleUnitTouched); } //点中了超出距离的 else if (usedManualReleaseAnalysisor.distanceLimit.Contains(battleUnitTouched)) { UtilityHelper.Log("目标超出攻击范围"); } //同一个队伍 else if (usedManualReleaseAnalysisor.teamLimit.Contains(battleUnitTouched)) { UtilityHelper.Log("不能对同一个队伍的单位使用这个技能"); } else { UtilityHelper.Log("无效的目标单位"); } }
//点击了技能,在单体带环绕的技能情况下 private void OnBattleUnitAndGridTouched_StateSkill_SurroundBattleUnit(GridUnit gridTouched, BattleUnit battleUnitTouched) { //没有点中战斗单位 if (battleUnitTouched == null) { return; } //是否是有效单位 if (usedManualReleaseAnalysisor.suitableUnits.Contains(battleUnitTouched)) { //重复点击同一个有效的战斗单位,则释放技能 if (battleUnitTouched.battleUnitRenderer.Equals(selectedBattleUnitRenderer)) { ManualSkill(battleUnitTouched); return; } else if (selectedBattleUnitRenderer != null) { //取消选中 selectedBattleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } //显示新的范围 selectedBattleUnitRenderer = battleUnitTouched.battleUnitRenderer; //范围内战斗单位设置为选中 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } } SetCircularRangeRenderStateActive( true, GridRenderType.SkillEffectRange, gridTouched.row, gridTouched.column, usedManualReleaseAnalysisor.battleSkill.effectRadius); } //不是有效单位 else if (usedManualReleaseAnalysisor.distanceLimit.Contains(battleUnitTouched)) { UtilityHelper.Log("目标超出攻击范围"); } //队伍不符合 else if (usedManualReleaseAnalysisor.teamLimit.Contains(battleUnitTouched)) { UtilityHelper.Log("不能对同一个队伍的单位使用这个技能"); } else { UtilityHelper.Log("目标单位无效"); } }
public BattleHeroMotionAction(BattleUnit actionUnit) : base(actionUnit, MsgBattleHeroActionType.MotionAction) { }
//点击了技能,在以固定地点为原点的技能情况下 private void OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(GridUnit gridTouched, BattleUnit battleUnitTouched) { //如果当前有点中的格子 if (selectedGridUnitRenderer != null && (selectedGridUnitRenderer.Equals(gridTouched.gridUnitRenderer) || usedManualReleaseAnalysisor.battleSkill.releaseRadius <= 0)) { //如果当前的释放距离为0,表示无需二次点击确认,直接释放 if (usedManualReleaseAnalysisor.battleSkill.releaseRadius <= 0) { ManualSkill(manualOperatingBattleUnitRenderer.battleUnit.mapGrid); return; } //点中了重复的格子,判断是否有目标 bool hasTarget = false; for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius) { hasTarget = true; break; } } //有目标,则释放 if (hasTarget) { ManualSkill(gridTouched); } else { UtilityHelper.Log("范围内没有目标"); } } else { //这个格子不在范围内 if (manualOperatingBattleUnitRenderer.battleUnit.mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.releaseRadius) { if (selectedGridUnitRenderer != null) { //取消上一个范围显示 SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange); //取消可被攻击单位的显示 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } } //设置新的范围显示 selectedGridUnitRenderer = gridTouched.gridUnitRenderer; SetCircularRangeRenderStateActive( true, GridRenderType.SkillEffectRange, gridTouched.row, gridTouched.column, usedManualReleaseAnalysisor.battleSkill.effectRadius ); //设置新的可被攻击单位的显示 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } } } else { UtilityHelper.Log("超出区域"); UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } }
public BattleHeroSkillAction(BattleUnit actionUnit, int skillID) : base(actionUnit, MsgBattleHeroActionType.SkillAction) { this.skillID = skillID; }
protected BattleUnitAction(BattleUnit actionUnit) : base(MsgBattleActionType.BattleUnitAction) { this.actionUnit = actionUnit; }
public BattleHeroEnterBattleFieldAction(BattleUnit actionUnit) : base(actionUnit, MsgBattleHeroActionType.EnterBattleField) { }
//某个战斗单位点击了移动 public void BattleUnitMove(BattleUnit battleUnit) { manualOperationHelper.BattleUnitMove(battleUnit); }
public BattleSkillEffectAnalysis AnalyseBattleSkillEffect(SO_BattleSkill battleSkill, BattleUnit releaser = null, BattleUnit targetBattleUnit = null, GridUnit targetGridUnit = null) { battleSkillEffectAnalysis.Reset(); if (releaser == null) { UtilityHelper.LogError("Analyse Battle Skill Effect error.Releaser is none."); return(null); } switch (battleSkill.targetType) { //对战斗单位 case BattleSkillTargetType.BattleUnit: if (targetBattleUnit == null) { return(null); } else { battleSkillEffectAnalysis.battleSkill = battleSkill; //记录主要影响 battleSkillEffectAnalysis.mainReceiver.Add(targetBattleUnit); if (battleSkill.effectRadius > 0) { //暂时定为次要目标与主要目标同类 BattleTeam battleTeam = targetBattleUnit.battleField.GetBattleTeam(targetBattleUnit, true); if (battleTeam != null) { for (int i = 0; i < battleTeam.battleUnits.Count; ++i) { if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(targetBattleUnit)) { continue; } //有次要影响 if (battleTeam.battleUnits[i].mapGrid.Distance(targetBattleUnit.mapGrid) <= battleSkill.effectRadius) { battleSkillEffectAnalysis.minorReceiver.Add(battleTeam.battleUnits[i]); } } } } } break; //对自己 case BattleSkillTargetType.Self: battleSkillEffectAnalysis.battleSkill = battleSkill; //记录主要影响 battleSkillEffectAnalysis.mainReceiver.Add(releaser); if (battleSkill.effectRadius > 0) { //暂时定为次要目标与主要目标同类 BattleTeam battleTeam = releaser.battleField.GetBattleTeam(releaser, true); if (battleTeam != null) { for (int i = 0; i < battleTeam.battleUnits.Count; ++i) { if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(releaser)) { continue; } //有次要影响 if (battleTeam.battleUnits[i].mapGrid.Distance(releaser.mapGrid) <= battleSkill.effectRadius) { battleSkillEffectAnalysis.minorReceiver.Add(battleTeam.battleUnits[i]); } } } } break; //对某个地点 case BattleSkillTargetType.GridUnit: if (targetGridUnit == null) { return(null); } else { battleSkillEffectAnalysis.battleSkill = battleSkill; if (battleSkill.effectRadius > 0) { BattleTeam battleTeam = releaser.battleField.GetBattleTeam(releaser, battleSkill.damageType == BattleSkillDamageType.Heal); if (battleTeam != null) { for (int i = 0; i < battleTeam.battleUnits.Count; ++i) { if (!battleTeam.battleUnits[i].CanAction || battleTeam.battleUnits[i].Equals(releaser)) { continue; } //记录主要影响 if (battleTeam.battleUnits[i].mapGrid.Distance(targetGridUnit) <= battleSkill.effectRadius) { battleSkillEffectAnalysis.mainReceiver.Add(battleTeam.battleUnits[i]); } } } } } break; default: break; } return(battleSkillEffectAnalysis); }
//某个战斗单位点击了使用技能 public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill) { manualOperationHelper.BattleUnitUseSkill(battleUnit, skill); }
//开始战斗 private void Fight() { battleState = BattleState.Fighting; Debug.Log(string.Format("<color=#ff0000> {0} battle fight. </color>", this.ToString())); List <BattleAction> actions = new List <BattleAction>(); BattleUnit actionUnit = null; do { //没有连接渲染器,则一步一更新 //连接了渲染器,则一直更新直到结束 actionUnit = actionQueue.Dequeue(); if (actionUnit == null) { battleState = BattleState.End; break; } if (actionUnit.CanAction) { HeroActionState state = actionUnit.BattleAction(actions); switch (state) { case HeroActionState.BattleEnd: battleState = BattleState.End; break; case HeroActionState.Error: battleState = BattleState.Exception; break; case HeroActionState.Warn: UtilityHelper.LogWarning(string.Format("Warning: battle action state warning -> {0}", actionUnit.ToString())); break; case HeroActionState.WaitForPlayerChoose: battleState = BattleState.WaitForPlayer; break; default: break; } //追加动作 AppendBattleActions(actions); //考虑是否在放回队列 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(); } }
public void OnLeave() { this.battleUnit = null; }
public override void OnExit() { base.OnExit(); battleUnit = null; }