Beispiel #1
0
        //进入战场
        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 void ManualMoveTo(GridUnit grid, GridUnit[] path)
        {
            //添加一个行动
            BattleUnitAction battleUnitAction = BattleUnitAction.Get(manualOperatingBattleUnitRenderer.battleUnit);

            //为行动添加移动数据
            manualOperatingBattleUnitRenderer.battleUnit.MoveToTargetGrid(battleUnitAction, null, grid, path);
            fieldRenderer.battleField.AppendBattleAction(battleUnitAction);
            fieldRenderer.PlayBattle(AfterManualMove);
        }
        //手动释放技能(对具体的目标)
        private void ManualSkill(BattleUnit targetBattleUnit)
        {
            if (targetBattleUnit == null)
            {
                return;
            }

            //添加一个行动
            BattleUnitAction battleUnitAction = BattleUnitAction.Get(manualOperatingBattleUnitRenderer.battleUnit);

            //为行动添加技能释放数据
            manualOperatingBattleUnitRenderer.battleUnit.UseSkill(battleUnitAction, usedManualReleaseAnalysisor.battleSkill, targetBattleUnit);
            fieldRenderer.battleField.AppendBattleAction(battleUnitAction);

            //行动结束
            ManualOperationComplete();
        }
        //手动释放技能(对具体的地块)
        private void ManualSkill(GridUnit targetGrid)
        {
            if (targetGrid == null)
            {
                return;
            }

            //添加一个行动
            BattleUnitAction battleUnitAction = BattleUnitAction.Get(manualOperatingBattleUnitRenderer.battleUnit);

            manualOperatingBattleUnitRenderer.battleUnit.UseSkill(battleUnitAction, usedManualReleaseAnalysisor.battleSkill, null, targetGrid);
            fieldRenderer.battleField.AppendBattleAction(battleUnitAction);

            //取消范围高亮显示
            SetCircularRangeRenderStateActive(false, GridRenderType.SkillReleaseRange);
            SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange);

            //行动结束
            ManualOperationComplete();
        }
Beispiel #5
0
        //开始战斗
        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();
            }
        }