public static HashSet <string> ExtractVarsFromEvent(QuestData.Event e) { HashSet <string> vars = new HashSet <string>(); foreach (VarOperation op in e.operations) { vars.Add(op.var); if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } if (e.tests == null) { return(vars); } foreach (VarTestsComponent tc in e.tests.VarTestsComponents) { if (tc is VarOperation) { VarOperation op = (VarOperation)tc; if (op.var.Length > 0 && op.var[0] != '#') { vars.Add(op.var); } if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } } return(vars); }
private HashSet <string> ExtractVarsFromEvent(QuestData.Event e) { HashSet <string> vars = new HashSet <string>(); foreach (QuestData.Event.VarOperation op in e.operations) { vars.Add(op.var); if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } foreach (QuestData.Event.VarOperation op in e.conditions) { if (op.var.Length > 0 && op.var[0] != '#') { vars.Add(op.var); } if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } return(vars); }
public void SetTrigger() { Game game = Game.Get(); Dictionary <string, Color> triggers = new Dictionary <string, Color>(); triggers.Add("", Color.white); bool startPresent = false; bool noMorale = false; foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { QuestData.Event e = kv.Value as QuestData.Event; if (e != null) { if (e.trigger.Equals("EventStart")) { startPresent = true; } if (e.trigger.Equals("NoMorale")) { noMorale = true; } } } if (startPresent) { triggers.Add("EventStart", Color.grey); } else { triggers.Add("EventStart", Color.white); } if (noMorale) { triggers.Add("NoMorale", Color.grey); } else { triggers.Add("NoMorale", Color.white); } triggers.Add("EndRound", Color.white); foreach (KeyValuePair <string, MonsterData> kv in game.cd.monsters) { triggers.Add("Defeated" + kv.Key, Color.white); triggers.Add("DefeatedUnique" + kv.Key, Color.white); } for (int i = 1; i <= 25; i++) { triggers.Add("EndRound" + i, Color.white); } triggerESL = new EditorSelectionList("Select Trigger", triggers, delegate { SelectEventTrigger(); }); triggerESL.SelectItem(); }
public DialogWindow(QuestData.Event e) { eventData = e; heroList = new List <Game.Hero>(); Game game = Game.Get(); game.eventList.Push(eventData); if (!eventData.heroListName.Equals("")) { if (!game.qd.heroSelection.ContainsKey(eventData.heroListName)) { Debug.Log("Warning: Hero selection in event: " + eventData.name + " from event " + eventData.heroListName + " with no data."); } else { foreach (Game.Hero h in game.qd.heroSelection[eventData.heroListName]) { h.selected = true; } game.heroCanvas.UpdateStatus(); } } CreateWindow(); }
public HashSet <string> GetQuestVars() { HashSet <string> vars = new HashSet <string>(); Game game = Game.Get(); foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.Event) { QuestData.Event e = kv.Value as QuestData.Event; foreach (QuestData.Event.VarOperation op in e.operations) { vars.Add(op.var); if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } foreach (QuestData.Event.VarOperation op in e.conditions) { if (op.var.Length > 0 && op.var[0] != '#') { vars.Add(op.var); } if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } } } return(vars); }
// Construct with quest info and reference to Game public ShopInterface(List <string> items, Game gameObject, string eventName) : base(gameObject) { game = gameObject; if (!game.quest.shops.ContainsKey(eventName)) { List <string> contentItems = new List <string>(); foreach (string s in items) { if (game.quest.itemSelect.ContainsKey(s)) { contentItems.Add(game.quest.itemSelect[s]); } } game.quest.shops.Add(eventName, contentItems); } eventData = game.quest.qd.components[eventName] as QuestData.Event; // Find quest UI panel panel = GameObject.Find("QuestUIPanel"); if (panel == null) { // Create UI Panel panel = new GameObject("QuestUIPanel"); panel.tag = Game.BOARD; panel.transform.SetParent(game.uICanvas.transform); panel.transform.SetAsFirstSibling(); panel.AddComponent <RectTransform>(); panel.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, Screen.height); panel.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, Screen.width); } Update(); }
// Initialise from a token public TokenControl(QuestData.Token t) { UnityEngine.UI.Button button = t.gameObject.AddComponent <UnityEngine.UI.Button>(); button.interactable = true; button.onClick.AddListener(delegate { startEvent(); }); e = t; }
public static void QueueEvent(string name) { Game game = Game.Get(); // Check if the event doesn't exists - quest fault if (!game.qd.components.ContainsKey(name)) { Debug.Log("Warning: Missing event called: " + name); return; } QuestData.Event e = (QuestData.Event)game.qd.components[name]; if (game.eventList.Count == 0) { game.eventList.Push(e); TriggerEvent(); } else { QuestData.Event ce = game.eventList.Pop(); game.eventList.Push(e); game.eventList.Push(ce); } }
// Create event from quest data public Event(string name) { game = Game.Get(); if (game.quest.qd.components.ContainsKey(name)) { qEvent = game.quest.qd.components[name] as QuestData.Event; } }
// Create event from quest data public Event(string name, bool addsFallbackContinueButton = true) { this.addsFallbackContinueButton = addsFallbackContinueButton; game = Game.Get(); if (game.quest.qd.components.ContainsKey(name)) { qEvent = game.quest.qd.components[name] as QuestData.Event; } }
public EditorComponentEventNextEvent(string nameIn) : base() { Game game = Game.Get(); eventComponent = game.quest.qd.components[nameIn] as QuestData.Event; component = eventComponent; name = component.sectionName; Update(); }
public void AddFlag(string type) { HashSet <string> flags = new HashSet <string>(); flags.Add("{NEW}"); Game game = Game.Get(); foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.Event) { QuestData.Event e = kv.Value as QuestData.Event; foreach (string s in e.flags) { if (s.IndexOf("#") != 0) { flags.Add(s); } } foreach (string s in e.setFlags) { flags.Add(s); } foreach (string s in e.clearFlags) { flags.Add(s); } } } if (type.Equals("flag")) { flags.Add("#monsters"); flags.Add("#2hero"); flags.Add("#3hero"); flags.Add("#4hero"); flags.Add("#5hero"); foreach (ContentData.ContentPack pack in Game.Get().cd.allPacks) { if (pack.id.Length > 0) { flags.Add("#" + pack.id); } } } List <string> list = new List <string>(flags); flagsESL = new EditorSelectionList("Select Flag", list, delegate { SelectAddFlag(type); }); flagsESL.SelectItem(); }
public static void AddQuestVars(UIWindowSelectionListTraits list) { HashSet <string> vars = new HashSet <string>(); HashSet <string> dollarVars = new HashSet <string>(); Game game = Game.Get(); foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.Event) { QuestData.Event e = kv.Value as QuestData.Event; foreach (string s in ExtractVarsFromEvent(e)) { if (s[0] != '$') { vars.Add(s); } } } } Dictionary <string, IEnumerable <string> > traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { "Quest" }); foreach (string s in vars) { list.AddItem(s, traits); } foreach (PerilData e in game.cd.Values <PerilData>()) { foreach (string s in ExtractVarsFromEvent(e)) { if (s[0] == '$') { dollarVars.Add(s); } } } traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { "$" }); foreach (string s in dollarVars) { list.AddItem(s, traits); } }
public List <EditorSelectionList.SelectionListEntry> GetQuestVars() { HashSet <string> vars = new HashSet <string>(); HashSet <string> dollarVars = new HashSet <string>(); List <EditorSelectionList.SelectionListEntry> list = new List <EditorSelectionList.SelectionListEntry>(); Game game = Game.Get(); foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.Event) { QuestData.Event e = kv.Value as QuestData.Event; foreach (string s in ExtractVarsFromEvent(e)) { if (s[0] != '$') { vars.Add(s); } } } } foreach (string s in vars) { list.Add(new EditorSelectionList.SelectionListEntry(s, "Quest")); } foreach (PerilData e in game.cd.perils.Values) { foreach (string s in ExtractVarsFromEvent(e)) { if (s[0] == '$') { dollarVars.Add(s); } } } foreach (string s in dollarVars) { list.Add(new EditorSelectionList.SelectionListEntry(s, "$")); } return(list); }
// Construct with quest info and reference to Game public ShopInterface(List <string> items, Game gameObject, string eventName) : base(gameObject) { game = gameObject; if (!game.quest.shops.ContainsKey(eventName)) { List <string> contentItems = new List <string>(); foreach (string s in items) { if (game.quest.itemSelect.ContainsKey(s)) { contentItems.Add(game.quest.itemSelect[s]); } } game.quest.shops.Add(eventName, contentItems); } eventData = game.quest.qd.components[eventName] as QuestData.Event; Update(); }
public static void EventTriggerType(string type) { Game game = Game.Get(); foreach (KeyValuePair <string, QuestData.QuestComponent> k in game.qd.components) { QuestData.QuestComponent c = k.Value; // Check if it is an event if (c is QuestData.Event) { QuestData.Event e = (QuestData.Event)c; if (e.trigger.Equals(type)) { QueueEvent(e.name); } } } }
// Add highlight for event public void AddHighlight(QuestData.Event e) { string item = ""; int items = 0; foreach (string s in e.addComponents) { if (s.IndexOf("QItem") == 0) { item = s; items++; } } if (items != 1 || !Game.Get().quest.itemSelect.ContainsKey(item)) { AddHighlight(e.location); } else { AddItem(e.location, item); } }
public static bool IsEnabled(string name) { Game game = Game.Get(); // Check if the event doesn't exists - quest fault if (!game.qd.components.ContainsKey(name)) { Debug.Log("Warning: Missing event called: " + name); return(false); } QuestData.Event e = (QuestData.Event)game.qd.components[name]; // If the flags are not set do not trigger event foreach (string s in e.flags) { if (!game.qd.flags.Contains(s)) { return(false); } } return(true); }
override protected void RefreshReference() { base.RefreshReference(); eventComponent = component as QuestData.Event; }
// Add highlight for event public void AddHighlight(QuestData.Event e) { AddHighlight(e.location); }
// Event ended public void EndEvent(QuestData.Event eventData, int state = 0) { // Get list of next events List <string> eventList = new List <string>(); if (eventData.nextEvent.Count > state) { eventList = eventData.nextEvent[state]; } // Only take enabled events from list List <string> enabledEvents = new List <string>(); foreach (string s in eventList) { // Check if the event doesn't exists - quest fault if (!events.ContainsKey(s)) { if (File.Exists(Path.GetDirectoryName(game.quest.qd.questPath) + "/" + s)) { events.Add(s, new StartQuestEvent(s)); enabledEvents.Add(s); } else { game.quest.log.Add(new Quest.LogEntry("Warning: Missing event called: " + s, true)); } } else if (!game.quest.eManager.events[s].Disabled()) { enabledEvents.Add(s); } } // Does this event end the quest? if (eventData.sectionName.IndexOf("EventEnd") == 0) { Destroyer.MainMenu(); return; } currentEvent = null; // Are there any events? if (enabledEvents.Count > 0) { // Are we picking at random? if (eventData.randomEvents) { // Add a random event game.quest.eManager.QueueEvent(enabledEvents[UnityEngine.Random.Range(0, enabledEvents.Count)], false); } else { // Add the first valid event game.quest.eManager.QueueEvent(enabledEvents[0], false); } } // Add any custom triggered events AddCustomTriggers(); if (eventStack.Count == 0) { monsterImage = null; monsterHealth = false; if (game.quest.phase == Quest.MoMPhase.monsters) { game.roundControl.MonsterActivated(); return; } } // Trigger a stacked event TriggerEvent(); }
// Event ended public void EndEvent(QuestData.Event eventData, int state = 0) { // Get list of next events List <string> eventList = new List <string>(); if (eventData.buttons.Count > state) { eventList = eventData.buttons[state].EventNames; } // Only take enabled events from list List <string> enabledEvents = new List <string>(); foreach (string s in eventList) { // Check if the event doesn't exists - quest fault if (!events.ContainsKey(s)) { string questToTransition = game.quest.originalPath + Path.DirectorySeparatorChar + s; if (game.quest.fromSavegame) { questToTransition = ContentData.ValkyrieLoadQuestPath + Path.DirectorySeparatorChar + s; } if (File.Exists(questToTransition)) { events.Add(s, new StartQuestEvent(s)); enabledEvents.Add(s); } else { ValkyrieDebug.Log("Warning: Missing event called: " + s); game.quest.log.Add(new Quest.LogEntry("Warning: Missing event called: " + s, true)); } } else if (!game.quest.eManager.events[s].Disabled()) { enabledEvents.Add(s); } } // Has the quest ended? if (game.quest.vars.GetValue("$end") != 0) { game.quest.questHasEnded = true; if (Path.GetFileName(game.quest.originalPath).StartsWith("EditorScenario") || !Path.GetFileName(game.quest.originalPath).EndsWith(".valkyrie")) { // do not show score screen for scenario with a non customized name, or if the scenario is not a package (most probably a test) GameStateManager.MainMenu(); } else { new EndGameScreen(); } return; } currentEvent = null; // Are there any events? if (enabledEvents.Count > 0) { // Are we picking at random? if (eventData.randomEvents) { // Add a random event game.quest.eManager.QueueEvent(enabledEvents[UnityEngine.Random.Range(0, enabledEvents.Count)], false); } else { // Add the first valid event game.quest.eManager.QueueEvent(enabledEvents[0], false); } } // Add any custom triggered events AddCustomTriggers(); if (eventStack.Count == 0) { monsterImage = null; monsterHealth = false; if (game.quest.phase == Quest.MoMPhase.monsters) { game.roundControl.MonsterActivated(); return; } } // Trigger a stacked event TriggerEvent(); }
public void SetTrigger() { Game game = Game.Get(); List <EditorSelectionList.SelectionListEntry> triggers = new List <EditorSelectionList.SelectionListEntry>(); triggers.Add(new EditorSelectionList.SelectionListEntry("", Color.white)); bool startPresent = false; bool noMorale = false; bool eliminated = false; foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { QuestData.Event e = kv.Value as QuestData.Event; if (e != null) { if (e.trigger.Equals("EventStart")) { startPresent = true; } if (e.trigger.Equals("NoMorale")) { noMorale = true; } if (e.trigger.Equals("Eliminated")) { eliminated = true; } } } if (startPresent) { triggers.Add(new EditorSelectionList.SelectionListEntry("EventStart", "General", Color.grey)); } else { triggers.Add(new EditorSelectionList.SelectionListEntry("EventStart", "General")); } if (noMorale) { triggers.Add(new EditorSelectionList.SelectionListEntry("NoMorale", "General", Color.grey)); } else { triggers.Add(new EditorSelectionList.SelectionListEntry("NoMorale", "General")); } if (eliminated) { triggers.Add(new EditorSelectionList.SelectionListEntry("Eliminated", "General", Color.grey)); } else { triggers.Add(new EditorSelectionList.SelectionListEntry("Eliminated", "General")); } triggers.Add(new EditorSelectionList.SelectionListEntry("Mythos", "General")); triggers.Add(new EditorSelectionList.SelectionListEntry("EndRound", "General")); triggers.Add(new EditorSelectionList.SelectionListEntry("StartRound", "General")); foreach (KeyValuePair <string, MonsterData> kv in game.cd.monsters) { triggers.Add(new EditorSelectionList.SelectionListEntry("Defeated" + kv.Key, "Monsters")); triggers.Add(new EditorSelectionList.SelectionListEntry("DefeatedUnique" + kv.Key, "Monsters")); } foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.UniqueMonster) { triggers.Add(new EditorSelectionList.SelectionListEntry("Defeated" + kv.Key, "Quest")); } } triggerESL = new EditorSelectionList("Select Trigger", triggers, delegate { SelectEventTrigger(); }); triggerESL.SelectItem(); }
public static void TriggerEvent() { Game game = Game.Get(); RoundHelper.CheckNewRound(); if (game.eventList.Count == 0) { return; } QuestData.Event e = game.eventList.Pop(); // If the flags are not set do not trigger event foreach (string s in e.flags) { if (!game.qd.flags.Contains(s)) { return; } } // Add set flags foreach (string s in e.setFlags) { if (!game.qd.flags.Contains(s)) { Debug.Log("Notice: Setting quest flag: " + s); game.qd.flags.Add(s); } } // Remove clear flags foreach (string s in e.clearFlags) { if (game.qd.flags.Contains(s)) { Debug.Log("Notice: Clearing quest flag: " + s); game.qd.flags.Remove(s); } } // If a dialog window is open we force it closed (this shouldn't happen) foreach (GameObject go in GameObject.FindGameObjectsWithTag("dialog")) { Object.Destroy(go); } // If this is a monster event then add the monster group if (e is QuestData.Monster) { QuestData.Monster qm = (QuestData.Monster)e; // Is this type new? Game.Monster oldMonster = null; foreach (Game.Monster m in game.monsters) { if (m.monsterData.name.Equals(qm.mData.name)) { oldMonster = m; } } // Add the new type if (oldMonster == null) { game.monsters.Add(new Game.Monster(qm)); game.monsterCanvas.UpdateList(); } else if (qm.unique) { oldMonster.unique = true; oldMonster.uniqueText = qm.uniqueText; oldMonster.uniqueTitle = qm.uniqueTitle; } // Display the location game.tokenBoard.AddMonster(qm); } if (e.highlight) { game.tokenBoard.AddHighlight(e); } new DialogWindow(e); foreach (string s in e.addComponents) { if (game.qd.components.ContainsKey(s)) { game.qd.components[s].SetVisible(true); } else { Debug.Log("Warning: Attempting to show missing item: " + s); } } foreach (string s in e.removeComponents) { if (game.qd.components.ContainsKey(s)) { game.qd.components[s].SetVisible(false); } else { Debug.Log("Warning: Attempting to hide missing item: " + s); } } if (e.locationSpecified) { CameraController.SetCamera(e.location); } }
public void SetTrigger() { if (GameObject.FindGameObjectWithTag(Game.DIALOG) != null) { return; } Game game = Game.Get(); UIWindowSelectionListTraits select = new UIWindowSelectionListTraits(SelectEventTrigger, new StringKey("val", "SELECT", CommonStringKeys.TRIGGER)); Dictionary <string, IEnumerable <string> > traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { new StringKey("val", "GENERAL").Translate() }); select.AddItem("{NONE}", "", traits); bool startPresent = false; bool noMorale = false; bool eliminated = false; foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { QuestData.Event e = kv.Value as QuestData.Event; if (e != null) { if (e.trigger.Equals("EventStart")) { startPresent = true; } if (e.trigger.Equals("NoMorale")) { noMorale = true; } if (e.trigger.Equals("Eliminated")) { eliminated = true; } } } if (startPresent) { select.AddItem("EventStart", traits, Color.gray); } else { select.AddItem("EventStart", traits); } if (noMorale) { select.AddItem("NoMorale", traits, Color.gray); } else { select.AddItem("NoMorale", traits); } if (eliminated) { select.AddItem("Eliminated", traits, Color.gray); } else { select.AddItem("Eliminated", traits); } select.AddItem("Mythos", traits); select.AddItem("EndRound", traits); select.AddItem("StartRound", traits); traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { CommonStringKeys.MONSTER.Translate() }); foreach (KeyValuePair <string, MonsterData> kv in game.cd.monsters) { select.AddItem("Defeated" + kv.Key, traits); select.AddItem("DefeatedUnique" + kv.Key, traits); } HashSet <string> vars = new HashSet <string>(); foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components) { if (kv.Value is QuestData.CustomMonster) { select.AddItem("Defeated" + kv.Key, traits); select.AddItem("DefeatedUnique" + kv.Key, traits); } if (kv.Value is QuestData.Event) { QuestData.Event e = kv.Value as QuestData.Event; foreach (string s in ExtractVarsFromEvent(e)) { if (s[0] == '@') { vars.Add(s); } } } } traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { new StringKey("val", "VARS").Translate() }); foreach (string s in vars) { select.AddItem("Var" + s.Substring(1), traits); } select.Draw(); }