using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;

[System.Serializable]
public class TriggerAction { // action on quest node process

	[System.Serializable]
	public enum Type {
		[XmlEnum("set")] SetTriggerValue,
		[XmlEnum("inc")] IncreaseTrigger,
		[XmlEnum("dec")] DecreaseTrigger
	}

	[XmlAttribute ("type")]
	public Type type = Type.SetTriggerValue;
	[XmlAttribute ("name")]
	public string triggerName = ""; // name of trigger or item
	[XmlAttribute ("value")]
	public int subjectValue = 0; // new value of action - how many moneys give, or new trigger value

	public TriggerAction() {}

	public TriggerAction(Type newType, string name, int value = 1) {
		type = newType;
		triggerName = name;
		subjectValue = value;
	}

	public void Invoke() {
		switch (type) {
		case Type.SetTriggerValue:
			Logic.triggers[triggerName] = subjectValue;
			break;
		case Type.IncreaseTrigger:
			Logic.triggers[triggerName] += subjectValue;
			break;
		case Type.DecreaseTrigger:
			Logic.triggers[triggerName] -= subjectValue;
			break;
		}
	}
}