﻿using UnityEngine;
using System.Collections.Generic;

public class MoveAction : RoleAction
{
	private List<Vector2Int> pathList;

	private int waitTimes;

	private Vector2Int nowPos;

	public void Init (Vector2Int pos, Role role)
	{
		pathList = role.GetPath (pos.X, pos.Y);
		pathList.RemoveAt (pathList.Count - 1);
		BuildNowPos (role);
	}

	public override bool DoAction (Role role)
	{
		if (waitTimes > 0) {
			waitTimes--;
			return false;
		} else {
			//role move
			role.MoveToCell (nowPos.X, nowPos.Y);
			if (pathList.Count == 0) {
				return true;
			} else {
				BuildNowPos (role);
				return false;
			}
		}
	}

	private void BuildNowPos (Role role)
	{
		nowPos = pathList [pathList.Count - 1];
		pathList.RemoveAt (pathList.Count - 1);
		waitTimes = role.GetMoveValue (nowPos.X, nowPos.Y);
	}
}
