using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pcd_g1
{
	class DoorItemStageObject : ItemStageObject
	{
		Type stage;
		string stageAi;
		int nextX, nextY;
		public DoorItemStageObject (int x, int y, Stage stg, Type nextStg, int nx = -1, int ny = -1) : base(x, y, stg)
		{
			stage = nextStg;
			stageAi = "";
			image = ImageManager.Search("923-1");
			nextX = nx; nextY = ny;
		}

		public DoorItemStageObject(int x, int y, Stage stg, string nextStg, int nx = -1, int ny = -1)
			: base(x, y, stg)
		{
			stageAi = nextStg;
			stage = null;
			image = ImageManager.Search("923-1");
			nextX = nx; nextY = ny;
		}

		bool downKeyPushed = false;
		public override void Update(int keyStatus, out int vx, out int vy)
		{
			if ((keyStatus & (int)MainForm.KEYBOARD.Down) != 0)
			{
				foreach (IStageObject item in owner.GetCollidedStageObjects(this))
				{
					if (item is MainCharacterStageObject)
					{
						image = ImageManager.Search("923-2");
						downKeyPushed = true;
						break;
					}
				}
			}
			else
			{
				if (downKeyPushed)
				{
					foreach (IStageObject item in owner.GetCollidedStageObjects(this))
					{
						if (item is MainCharacterStageObject)
						{
							if (stage == null)
							{
								StageManager.RunStage(stageAi,nextX,nextY);
							}
							else
							{
								StageManager.RunStage(stage,nextX,nextY);
							}
							//MainForm.PlayEffectSound("warp");
							break;
						}
					}
					downKeyPushed = false;
				}
			}
			base.Update(keyStatus, out vx, out vy);
		}
	}
}
