コード例 #1
0
 // if there is a movement pattern planned, move in that way.
 public void ChooseMovement()
 {
     if (plannedActionData != null)
     {
         StartCoroutine(Move(plannedActionData.GetMovementPath(), MovementType.WALK));
         ChangeDirection(plannedActionData.GetAbilityDirection());
     }
     hasMoved = true;
 }
コード例 #2
0
    // this function is called when the EnemyUnit needs to know what it's going to do
    // it evaluates its possibleActions, selects the best one, and asks it to create ActionData to store
    public void NewActionData()
    {
        if (possibleActions.Count != 0)
        {
            // get data about the board-state, possible options, etc
            if (GetImmobilizedDuration() > 0 || GetDisabledDuration() > 0)
            {
                MoveableTiles = new Dictionary <Vector2Int, Direction>();
                MoveableTiles.Add(GetMapPosition(), Direction.NO_DIR);
            }
            else
            {
                MoveableTiles = FindMoveableTiles(MapController.instance.weightedMap);
            }

            foreach (AbilityOption option in possibleAbilities)
            {
                option.EvaluateAffectableTiles();
            }

            EnemyAction bestAction          = null;
            float       highestSignificance = 0.0f;

            // for each possible action:
            foreach (EnemyAction action in possibleActions)
            {
                // evaluate its significance level
                action.Evaluate();

                // check if it currently has the highest significance
                if (action.GetSignificance() > highestSignificance)
                {
                    bestAction          = action;
                    highestSignificance = action.GetSignificance();
                }
            }

            plannedActionData = bestAction.GetActionData();

            // This useful Debug statement will print to the console the details of what this Unit committed to doing
            Debug.Log(this.GetName() + " at Starting Position " + this.GetMapPosition()
                      + " has committed to moving to " + plannedActionData.GetEndingPosition() + " and using "
                      + this.AvailableAbilities[plannedActionData.GetAbilityIndex()] + " in direction "
                      + plannedActionData.GetAbilityDirection());
        }
    }