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

namespace pcd_g1
{
	class SwitchItemStageObject : ItemStageObject
	{
		string switchName;
		int switchValue;
		public SwitchItemStageObject (int x, int y, Stage stg, string name = "", int value = 0) : base(x, y, stg)
		{
			switchName = name;
			switchValue = value;
			image = ImageManager.Search("926");
		}

		Storyboard story = new Storyboard(new MessageStoryBoard("スイッチを押した。\n"));
		Storyboard story2 = new Storyboard(new MessageStoryBoard("スイッチはすでに押されている。\n"));

		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)
					{
						if (switchName != "")
						{
							if (StageManager.CurrentDataSet.GetInt(switchName) != switchValue)
							{
								StageManager.CurrentDataSet.Set(switchName, switchValue);
								story.Run();
								MainForm.PlayEffectSound("switch");
							}
							else
							{
								story2.Run();
							}
						}
						
						break;
					}
				}
			}
			base.Update(keyStatus, out vx, out vy);
		}
	}
}
