Example #1
0
    public HorrorCheck(Quest.Monster m)
    {
        Game game = Game.Get();

        QuestMonster qm = m.monsterData as QuestMonster;

        if (qm != null && game.quest.qd.components.ContainsKey(qm.cMonster.horrorEvent))
        {
            game.quest.eManager.monsterImage = m;
            game.quest.eManager.QueueEvent(qm.cMonster.horrorEvent);
        }
        else
        {
            PickHorror(m);
        }
    }
Example #2
0
    public InfoDialog(Quest.Monster m)
    {
        if (m == null)
        {
            ValkyrieDebug.Log("Warning: Invalid monster type requested.");
            return;
        }

        // box with monster info
        UIElement ui = new UIElement();

        ui.SetLocation(10, 0.5f, UIScaler.GetWidthUnits() - 20, 12);
        ui.SetText(m.monsterData.info);
        new UIElementBorder(ui);

        // Unique monsters have additional info
        if (m.unique && m.uniqueText.KeyExists())
        {
            ui = new UIElement();
            ui.SetLocation(12, 13, UIScaler.GetWidthUnits() - 24, 2);
            ui.SetText(m.uniqueTitle, Color.red);
            ui.SetFontSize(UIScaler.GetMediumFont());
            new UIElementBorder(ui, Color.red);

            string uniqueText = EventManager.OutputSymbolReplace(m.uniqueText.Translate().Replace("\\n", "\n"));
            ui = new UIElement();
            ui.SetLocation(10, 15, UIScaler.GetWidthUnits() - 20, 8);
            ui.SetText(uniqueText);
            new UIElementBorder(ui, Color.red);

            ui = new UIElement();
            ui.SetLocation(UIScaler.GetWidthUnits() - 21, 23.5f, 10, 2);
            ui.SetText(CommonStringKeys.CLOSE);
            ui.SetFontSize(UIScaler.GetMediumFont());
            ui.SetButton(onClose);
            new UIElementBorder(ui);
        }
        else
        {
            ui = new UIElement();
            ui.SetLocation(UIScaler.GetWidthUnits() - 21, 13, 10, 2);
            ui.SetText(CommonStringKeys.CLOSE);
            ui.SetFontSize(UIScaler.GetMediumFont());
            ui.SetButton(onClose);
            new UIElementBorder(ui);
        }
    }
Example #3
0
    public static void DrawMonster(Quest.Monster monster)
    {
        Game game = Game.Get();

        Texture2D newTex          = ContentData.FileToTexture(monster.monsterData.image);
        Texture2D dupeTex         = Resources.Load("sprites/monster_duplicate_" + monster.duplicate) as Texture2D;
        Sprite    iconSprite      = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        Sprite    duplicateSprite = null;

        if (dupeTex != null)
        {
            duplicateSprite = Sprite.Create(dupeTex, new Rect(0, 0, dupeTex.width, dupeTex.height), Vector2.zero, 1);
        }

        GameObject mImg = new GameObject("monsterImg" + monster.monsterData.name);

        mImg.tag = Game.DIALOG;
        mImg.transform.SetParent(game.uICanvas.transform);

        RectTransform trans = mImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 1f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());
        mImg.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image icon = mImg.AddComponent <UnityEngine.UI.Image>();
        icon.sprite = iconSprite;
        icon.rectTransform.sizeDelta = new Vector2(8f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Image iconDupe = null;
        if (duplicateSprite != null)
        {
            GameObject mImgDupe = new GameObject("monsterDupe" + monster.monsterData.name);
            mImgDupe.tag = Game.DIALOG;
            mImgDupe.transform.SetParent(game.uICanvas.transform);

            RectTransform dupeFrame = mImgDupe.AddComponent <RectTransform>();
            dupeFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 5f * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit() * 4f);
            dupeFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 5f * UIScaler.GetPixelsPerUnit(), 4f * UIScaler.GetPixelsPerUnit());
            mImgDupe.AddComponent <CanvasRenderer>();

            iconDupe        = mImgDupe.AddComponent <UnityEngine.UI.Image>();
            iconDupe.sprite = duplicateSprite;
            iconDupe.rectTransform.sizeDelta = new Vector2(4f * UIScaler.GetPixelsPerUnit(), 4f * UIScaler.GetPixelsPerUnit());
        }
    }
Example #4
0
    public InvestigatorEvade(Quest.Monster monster)
    {
        m = monster;
        Game game = Game.Get();

        QuestMonster qm = m.monsterData as QuestMonster;

        if (qm != null && game.quest.qd.components.ContainsKey(qm.cMonster.evadeEvent))
        {
            game.quest.eManager.monsterImage = m;
            game.quest.eManager.QueueEvent(qm.cMonster.evadeEvent);
        }
        else
        {
            PickEvade(m);
        }
    }
Example #5
0
    public InvestigatorAttack(Quest.Monster m)
    {
        monster = m;
        Game game = Game.Get();

        attacks    = new List <AttackData>();
        attackType = new HashSet <string>();
        foreach (KeyValuePair <string, AttackData> kv in game.cd.investigatorAttacks)
        {
            if (m.monsterData.ContainsTrait(kv.Value.target))
            {
                attacks.Add(kv.Value);
                attackType.Add(kv.Value.attackType);
            }
        }
        AttackOptions();
    }
Example #6
0
    public HorrorCheck(Quest.Monster m)
    {
        Game game = Game.Get();
        List <HorrorData> horrors = new List <HorrorData>();

        foreach (KeyValuePair <string, HorrorData> kv in game.cd.horrorChecks)
        {
            if (m.monsterData.sectionName.Equals("Monster" + kv.Value.monster))
            {
                horrors.Add(kv.Value);
            }
        }

        QuestMonster qm = m.monsterData as QuestMonster;

        if (horrors.Count == 0 && qm != null && qm.derivedType.Length > 0)
        {
            foreach (KeyValuePair <string, HorrorData> kv in game.cd.horrorChecks)
            {
                if (qm.derivedType.Equals("Monster" + kv.Value.monster))
                {
                    horrors.Add(kv.Value);
                }
            }
        }

        // If a dialog window is open we force it closed (this shouldn't happen)
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("dialog"))
        {
            Object.Destroy(go);
        }

        string    text = horrors[Random.Range(0, horrors.Count)].text.Translate().Replace("{0}", m.monsterData.name.Translate());
        DialogBox db   = new DialogBox(new Vector2(10, 0.5f), new Vector2(UIScaler.GetWidthUnits() - 20, 8),
                                       new StringKey(null, text, false));

        db.AddBorder();

        new TextButton(new Vector2(UIScaler.GetHCenter(-6f), 9f), new Vector2(12, 2), CommonStringKeys.FINISHED, delegate { Destroyer.Dialog(); });

        MonsterDialogMoM.DrawMonster(m);
    }
Example #7
0
        public MonsterIcon(Quest.Monster monster, int i = 0)
        {
            m     = monster;
            index = i;

            game = Game.Get();

            // Get monster image and grame
            Texture2D newTex = ContentData.FileToTexture(m.monsterData.image);
            // FIXME: should be game type specific
            Texture2D frameTex = Resources.Load("sprites/borders/Frame_Monster_1x1") as Texture2D;
            Texture2D dupeTex  = Resources.Load("sprites/monster_duplicate_" + m.duplicate) as Texture2D;

            iconSprite  = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
            frameSprite = Sprite.Create(frameTex, new Rect(0, 0, frameTex.width, frameTex.height), Vector2.zero, 1);
            if (dupeTex != null)
            {
                duplicateSprite = Sprite.Create(dupeTex, new Rect(0, 0, dupeTex.width, dupeTex.height), Vector2.zero, 1);
            }
        }
Example #8
0
    public static void Defeated(Quest.Monster monster)
    {
        Destroyer.Dialog();
        Game game = Game.Get();

        // Remove this monster group
        game.quest.monsters.Remove(monster);
        game.monsterCanvas.UpdateList();

        game.quest.vars.SetValue("#monsters", game.quest.monsters.Count);

        game.audioControl.PlayTrait("defeated");

        // Trigger defeated event
        game.quest.eManager.EventTriggerType("Defeated" + monster.monsterData.sectionName);
        // If unique trigger defeated unique event
        if (monster.unique)
        {
            game.quest.eManager.EventTriggerType("DefeatedUnique" + monster.monsterData.sectionName);
        }
    }
Example #9
0
    public InvestigatorEvade(Quest.Monster m)
    {
        Game             game   = Game.Get();
        List <EvadeData> evades = new List <EvadeData>();

        foreach (KeyValuePair <string, EvadeData> kv in game.cd.investigatorEvades)
        {
            if (m.monsterData.sectionName.Equals("Monster" + kv.Value.monster))
            {
                evades.Add(kv.Value);
            }
        }

        QuestMonster qm = m.monsterData as QuestMonster;

        if (evades.Count == 0 && qm != null && qm.derivedType.Length > 0)
        {
            foreach (KeyValuePair <string, EvadeData> kv in game.cd.investigatorEvades)
            {
                if (qm.derivedType.Equals("Monster" + kv.Value.monster))
                {
                    evades.Add(kv.Value);
                }
            }
        }

        // If a dialog window is open we force it closed (this shouldn't happen)
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("dialog"))
        {
            Object.Destroy(go);
        }


        string    text = evades[Random.Range(0, evades.Count)].text.Translate().Replace("{0}", m.monsterData.name.Translate());
        DialogBox db   = new DialogBox(new Vector2(10, 0.5f), new Vector2(UIScaler.GetWidthUnits() - 20, 8), text);

        db.AddBorder();

        new TextButton(new Vector2(UIScaler.GetHCenter(-6f), 9f), new Vector2(12, 2), "Finished", delegate { Destroyer.Dialog(); });
    }
Example #10
0
    // Activate a monster
    override public bool ActivateMonster()
    {
        Game game = Game.Get();

        // Search for unactivated monsters
        List <int> notActivated = new List <int>();

        // Get the index of all monsters that haven't activated
        for (int i = 0; i < game.quest.monsters.Count; i++)
        {
            if (!game.quest.monsters[i].activated)
            {
                notActivated.Add(i);
            }
        }

        if (notActivated.Count > 0)
        {
            // Find a random unactivated monster
            Quest.Monster toActivate = game.quest.monsters[notActivated[Random.Range(0, notActivated.Count)]];

            // Find out of this monster is quest specific
            QuestMonster qm = toActivate.monsterData as QuestMonster;
            if (qm != null && qm.activations != null && qm.activations.Length == 1 && qm.activations[0].IndexOf("Event") == 0)
            {
                toActivate.masterStarted         = true;
                game.quest.eManager.monsterImage = toActivate;
                game.quest.eManager.QueueEvent(qm.activations[0]);
            }
            else
            {
                ActivateMonster(toActivate);
            }
            // Return false as activations remain
            return(false);
        }
        return(true);
    }
Example #11
0
    protected void Draw(HorrorData horror, Quest.Monster m)
    {
        Game game = Game.Get();

        // If a dialog window is open we force it closed (this shouldn't happen)
        foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.DIALOG))
        {
            Object.Destroy(go);
        }

        string    text = horror.text.Translate().Replace("{0}", m.monsterData.name.Translate());
        UIElement ui   = new UIElement();

        ui.SetLocation(UIScaler.GetHCenter(-14), 0.5f, 28, 8);
        ui.SetText(text);
        new UIElementBorder(ui);

        game.quest.log.Add(new Quest.LogEntry(text.Replace("\n", "\\n")));

        new TextButton(new Vector2(UIScaler.GetHCenter(-6f), 9f), new Vector2(12, 2), CommonStringKeys.FINISHED, delegate { Destroyer.Dialog(); });

        MonsterDialogMoM.DrawMonster(m);
    }
Example #12
0
 public MonsterDialogMoM(Quest.Monster m) : base(m)
 {
 }
Example #13
0
    // 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();
    }
Example #14
0
    // Activate a monster
    virtual public bool ActivateMonster(Quest.Monster m)
    {
        List <ActivationData> adList = new List <ActivationData>();
        Game game = Game.Get();

        bool        customActivations = false;
        MonsterData md = m.monsterData;

        // Find out of this monster is quest specific
        QuestMonster qm = md as QuestMonster;

        if (qm != null)
        {
            // Get the base monster type
            if (game.cd.ContainsKey <MonsterData>(qm.derivedType))
            {
                md = game.cd.Get <MonsterData>(qm.derivedType);
            }
            // Determine if the monster has quest specific activations
            customActivations = !qm.useMonsterTypeActivations;
        }

        // A monster with quest specific activations
        if (customActivations)
        {
            if (!qm.useMonsterTypeActivations)
            {
                adList = new List <ActivationData>();
                // Get all custom activations
                foreach (string s in qm.activations)
                {
                    // Find the activation in quest data
                    if (game.quest.qd.components.ContainsKey("Activation" + s) &&
                        game.quest.vars.Test((game.quest.qd.components["Activation" + s] as QuestData.Activation).tests)
                        )
                    {
                        adList.Add(new QuestActivation(game.quest.qd.components["Activation" + s] as QuestData.Activation));
                    }
                    // Otherwise look for the activation in content data
                    else if (game.cd.TryGet("MonsterActivation" + s, out ActivationData activationData))
                    {
                        adList.Add(activationData);
                    }
                    else // Invalid activation
                    {
                        game.quest.log.Add(new Quest.LogEntry("Warning: Unable to find activation: " + s + " for monster type: " + m.monsterData.sectionName, true));
                    }
                }
            }
        }
        else // Content Data activations only
        {
            // Find all possible activations
            foreach (KeyValuePair <string, ActivationData> kv in game.cd.GetAll <ActivationData>())
            {
                // Is this activation for this monster type? (replace "Monster" with "MonsterActivation", ignore specific variety)
                if (kv.Key.IndexOf("MonsterActivation" + md.sectionName.Substring("Monster".Length)) == 0)
                {
                    adList.Add(kv.Value);
                }
            }
            // Search for additional common activations
            foreach (string s in md.activations)
            {
                if (game.cd.TryGet("MonsterActivation" + s, out ActivationData activationData))
                {
                    adList.Add(activationData);
                }
                else
                {
                    ValkyrieDebug.Log("Warning: Unable to find activation: " + s + " for monster type: " + md.sectionName);
                }
            }
        }

        // Check for no activations
        if (adList.Count == 0)
        {
            ValkyrieDebug.Log("Error: Unable to find any activation data for monster type: " + md.name);
            Application.Quit();
        }

        // No current activation
        if (m.currentActivation == null)
        {
            // Pick a random activation
            ActivationData activation = adList[Random.Range(0, adList.Count)];
            m.NewActivation(activation);
        }

        // MoM has a special activation
        if (game.gameType is MoMGameType)
        {
            m.masterStarted = true;
            new ActivateDialogMoM(m);
            return(false);
        }

        // If no minion activation just do master
        if (m.currentActivation.ad.minionActions.fullKey.Length == 0)
        {
            m.minionStarted = true;
            m.masterStarted = true;
            new ActivateDialog(m, true, true);
            return(false);
        }

        // If no master activation just do minion
        if (m.currentActivation.ad.masterActions.fullKey.Length == 0)
        {
            m.minionStarted = true;
            m.masterStarted = true;
            new ActivateDialog(m, false, true);
            return(false);
        }

        // Random pick Minion or master (both available)
        m.minionStarted = Random.Range(0, 2) == 0;

        // If order specificed then use that instead
        if (m.currentActivation.ad.masterFirst)
        {
            m.minionStarted = false;
        }
        if (m.currentActivation.ad.minionFirst)
        {
            m.minionStarted = true;
        }

        // Master is opposite of minion as this is the first activation
        m.masterStarted = !m.minionStarted;

        // Create activation window
        new ActivateDialog(m, m.masterStarted);

        // More groups unactivated
        return(false);
    }
Example #15
0
 public InvestigatorAttack(Quest.Monster m)
 {
     monster = m;
     AttackOptions();
 }
Example #16
0
 // Create an activation window, if master is false then it is for minions
 public ActivateDialogMoM(Quest.Monster m) : base(m, true)
 {
 }
Example #17
0
    // Trigger next event in stack
    public void TriggerEvent()
    {
        // First check if things need to be added to the queue at end round
        Game.Get().roundControl.CheckNewRound();

        // No events to trigger
        if (eventStack.Count == 0)
        {
            return;
        }

        // Get the next event
        Event e = eventStack.Pop();

        currentEvent = e;

        // Event may have been disabled since added
        if (e.Disabled())
        {
            return;
        }

        // Perform var operations
        game.quest.vars.Perform(e.qEvent.operations);

        // 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 MonsterEvent)
        {
            MonsterEvent qe = (MonsterEvent)e;

            // Is this type new?
            Quest.Monster oldMonster = null;
            foreach (Quest.Monster m in game.quest.monsters)
            {
                if (m.monsterData.sectionName.Equals(qe.cMonster.sectionName))
                {
                    // Matched existing monster
                    oldMonster = m;
                }
            }

            // Add the new type
            if (!game.gameType.MonstersGrouped() || oldMonster == null)
            {
                game.quest.monsters.Add(new Quest.Monster(qe));
                game.monsterCanvas.UpdateList();
                // Update monster var
                game.quest.vars.SetValue("#monsters", game.quest.monsters.Count);
            }
            // There is an existing group, but now it is unique
            else if (qe.qMonster.unique)
            {
                oldMonster.unique      = true;
                oldMonster.uniqueText  = qe.qMonster.uniqueText;
                oldMonster.uniqueTitle = qe.GetUniqueTitle();
            }

            // Display the location(s)
            if (qe.qEvent.locationSpecified && e.GetText().Length > 0)
            {
                game.tokenBoard.AddMonster(qe);
            }
        }

        // Highlight a space on the board
        if (e.qEvent.highlight)
        {
            game.tokenBoard.AddHighlight(e.qEvent);
        }

        // Add board components
        game.quest.Add(e.qEvent.addComponents);
        // Remove board components
        game.quest.Remove(e.qEvent.removeComponents);

        // Add delayed events
        foreach (QuestData.Event.DelayedEvent de in e.qEvent.delayedEvents)
        {
            game.quest.delayedEvents.Add(new QuestData.Event.DelayedEvent(de.delay + game.quest.round, de.eventName));
        }

        // Move camera
        if (e.qEvent.locationSpecified)
        {
            CameraController.SetCamera(e.qEvent.location);
        }

        if (e.qEvent is QuestData.Puzzle)
        {
            QuestData.Puzzle p = e.qEvent as QuestData.Puzzle;
            if (p.puzzleClass.Equals("slide"))
            {
                new PuzzleSlideWindow(e);
            }
            if (p.puzzleClass.Equals("code"))
            {
                new PuzzleCodeWindow(e);
            }
            if (p.puzzleClass.Equals("image"))
            {
                new PuzzleImageWindow(e);
            }
            return;
        }

        // Set camera limits
        if (e.qEvent.minCam)
        {
            CameraController.SetCameraMin(e.qEvent.location);
        }
        if (e.qEvent.maxCam)
        {
            CameraController.SetCameraMax(e.qEvent.location);
        }

        // Only raise dialog if there is text, otherwise auto confirm
        if (e.GetText().Length == 0)
        {
            EndEvent();
        }
        else
        {
            new DialogWindow(e);
        }
    }
Example #18
0
 // Constuct the button list
 public MonsterDialog(Quest.Monster m)
 {
     monster = m;
     CreateWindow();
 }
Example #19
0
 // Create an activation window, if master is false then it is for minions
 public ActivateDialog(Quest.Monster m, bool masterIn, bool singleStep = false)
 {
     monster = m;
     master  = masterIn;
     CreateWindow(singleStep);
 }
Example #20
0
 // Create an activation window, if master is false then it is for minions
 public ActivateDialog(Quest.Monster m, bool masterIn)
 {
     monster = m;
     master  = masterIn;
     CreateWindow();
 }
Example #21
0
    public void TriggerEvent()
    {
        RoundHelper.CheckNewRound();

        if (eventStack.Count == 0)
        {
            return;
        }

        Event e = eventStack.Pop();

        currentEvent = e;

        // Event may have been disabled since added
        if (e.Disabled())
        {
            return;
        }

        // Add set flags
        foreach (string s in e.qEvent.setFlags)
        {
            Debug.Log("Notice: Setting quest flag: " + s + System.Environment.NewLine);
            game.quest.flags.Add(s);
        }

        // Remove clear flags
        foreach (string s in e.qEvent.clearFlags)
        {
            Debug.Log("Notice: Clearing quest flag: " + s + System.Environment.NewLine);
            game.quest.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 MonsterEvent)
        {
            // Set monster tag if not already
            game.quest.flags.Add("#monsters");

            MonsterEvent qe = (MonsterEvent)e;

            // Is this type new?
            Quest.Monster oldMonster = null;
            foreach (Quest.Monster m in game.quest.monsters)
            {
                if (m.monsterData.name.Equals(qe.cMonster.name))
                {
                    oldMonster = m;
                }
            }
            // Add the new type
            if (oldMonster == null)
            {
                game.quest.monsters.Add(new Quest.Monster(qe));
                game.monsterCanvas.UpdateList();
            }
            // There is an existing tpye, but now it is unique
            else if (qe.qMonster.unique)
            {
                oldMonster.unique      = true;
                oldMonster.uniqueText  = qe.qMonster.uniqueText;
                oldMonster.uniqueTitle = qe.GetUniqueTitle();
            }

            // Display the location
            game.tokenBoard.AddMonster(qe);
        }

        if (e.qEvent.highlight)
        {
            game.tokenBoard.AddHighlight(e.qEvent);
        }

        game.quest.Add(e.qEvent.addComponents);
        game.quest.Remove(e.qEvent.removeComponents);
        game.quest.threat += e.qEvent.threat;
        if (e.qEvent.absoluteThreat)
        {
            if (e.qEvent.threat != 0)
            {
                Debug.Log("Setting threat to: " + e.qEvent.threat + System.Environment.NewLine);
            }
            game.quest.threat = e.qEvent.threat;
        }
        else if (e.qEvent.threat != 0)
        {
            Debug.Log("Changing threat by: " + e.qEvent.threat + System.Environment.NewLine);
        }

        foreach (QuestData.Event.DelayedEvent de in e.qEvent.delayedEvents)
        {
            game.quest.delayedEvents.Add(new QuestData.Event.DelayedEvent(de.delay + game.quest.round, de.eventName));
        }

        if (e.qEvent.locationSpecified)
        {
            CameraController.SetCamera(e.qEvent.location);
        }

        // Only raise dialog if there is text, otherwise auto confirm
        if (e.GetText().Length == 0)
        {
            EndEvent();
        }
        else
        {
            new DialogWindow(e);
        }
    }
Example #22
0
    public static bool ActivateMonster(Quest.Monster m)
    {
        List <ActivationData> adList = new List <ActivationData>();
        Game game = Game.Get();

        bool        customActivations = false;
        MonsterData md = m.monsterData;

        QuestMonster qm = md as QuestMonster;

        if (qm != null)
        {
            if (game.cd.monsters.ContainsKey(qm.derivedType))
            {
                md = game.cd.monsters[qm.derivedType];
            }
            customActivations = !qm.useMonsterTypeActivations;
        }

        if (customActivations)
        {
            if (!qm.useMonsterTypeActivations)
            {
                adList = new List <ActivationData>();
                foreach (string s in qm.activations)
                {
                    // This should check for quest activations!
                    if (game.quest.qd.components.ContainsKey("Activation" + s))
                    {
                        adList.Add(new QuestActivation(game.quest.qd.components["Activation" + s] as QuestData.Activation));
                    }
                    else if (game.cd.activations.ContainsKey("MonsterActivation" + s))
                    {
                        adList.Add(game.cd.activations["MonsterActivation" + s]);
                    }
                    else
                    {
                        Debug.Log("Warning: Unable to find activation: " + s + " for monster type: " + m.monsterData.sectionName);
                    }
                }
            }
        }
        else
        {
            // Find all possible activations
            foreach (KeyValuePair <string, ActivationData> kv in game.cd.activations)
            {
                // Is this activation for this monster type? (replace "Monster" with "MonsterActivation", ignore specific variety)
                if (kv.Key.IndexOf("MonsterActivation" + md.sectionName.Substring("Monster".Length)) == 0)
                {
                    adList.Add(kv.Value);
                }
            }
            // Search for additional common activations
            foreach (string s in md.activations)
            {
                if (game.cd.activations.ContainsKey("MonsterActivation" + s))
                {
                    adList.Add(game.cd.activations["MonsterActivation" + s]);
                }
                else
                {
                    Debug.Log("Warning: Unable to find activation: " + s + " for monster type: " + md.sectionName);
                }
            }
        }

        // Check for no activations
        if (adList.Count == 0)
        {
            Debug.Log("Error: Unable to find any activation data for monster type: " + md.name);
            Application.Quit();
        }

        if (m.currentActivation == null)
        {
            // Pick a random activation
            ActivationData activation = adList[Random.Range(0, adList.Count)];
            m.NewActivation(activation);
        }

        // If no minion activation just do master
        if (m.currentActivation.ad.minionActions.Length == 0)
        {
            m.minionStarted = true;
            m.masterStarted = true;
            new ActivateDialog(m, true);
            return(false);
        }

        // If no master activation just do minion
        if (m.currentActivation.ad.masterActions.Length == 0)
        {
            m.minionStarted = true;
            m.masterStarted = true;
            new ActivateDialog(m, false);
            return(false);
        }

        // Pick Minion or master
        m.minionStarted = Random.Range(0, 2) == 0;
        if (m.currentActivation.ad.masterFirst)
        {
            m.minionStarted = false;
        }
        if (m.currentActivation.ad.minionFirst)
        {
            m.minionStarted = true;
        }

        m.masterStarted = !m.minionStarted;

        // Create activation window
        new ActivateDialog(m, m.masterStarted);

        // More groups unactivated
        return(false);
    }
Example #23
0
    // Trigger next event in stack
    public void TriggerEvent()
    {
        Game game = Game.Get();

        // First check if things need to be added to the queue at end round
        if (game.roundControl.CheckNewRound())
        {
            return;
        }

        // No events to trigger
        if (eventStack.Count == 0)
        {
            return;
        }

        // Get the next event
        Event e = eventStack.Pop();

        currentEvent = e;

        // Move to another quest
        if (e is StartQuestEvent)
        {
            // This loads the game
            game.quest.ChangeQuest((e as StartQuestEvent).name);
            return;
        }

        // Event may have been disabled since added
        if (e.Disabled())
        {
            currentEvent = null;
            TriggerEvent();
            return;
        }

        // Play audio
        if (game.cd.TryGet(e.qEvent.audio, out AudioData audioData))
        {
            game.audioControl.Play(audioData.file);
        }
        else if (e.qEvent.audio.Length > 0)
        {
            game.audioControl.Play(Quest.FindLocalisedMultimediaFile(e.qEvent.audio, Path.GetDirectoryName(game.quest.qd.questPath)));
        }

        // Set Music
        if (e.qEvent.music.Count > 0)
        {
            List <string> music = new List <string>();
            foreach (string s in e.qEvent.music)
            {
                if (game.cd.TryGet(s, out AudioData musicData))
                {
                    music.Add(musicData.file);
                }
                else
                {
                    music.Add(Quest.FindLocalisedMultimediaFile(s, Path.GetDirectoryName(game.quest.qd.questPath)));
                }
            }
            game.audioControl.PlayMusic(music);
            if (music.Count > 0)
            {
                game.quest.music = new List <string>(e.qEvent.music);
            }
        }

        // Perform var operations
        game.quest.vars.Perform(e.qEvent.operations);
        // Update morale change
        if (game.gameType is D2EGameType)
        {
            game.quest.AdjustMorale(0);
        }
        if (game.quest.vars.GetValue("$restock") == 1)
        {
            game.quest.GenerateItemSelection();
        }

        // If a dialog window is open we force it closed (this shouldn't happen)
        foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.DIALOG))
        {
            UnityEngine.Object.Destroy(go);
        }

        // If this is a monster event then add the monster group
        if (e is MonsterEvent)
        {
            MonsterEvent qe = (MonsterEvent)e;

            qe.MonsterEventSelection();

            // Is this type new?
            Quest.Monster oldMonster = null;
            foreach (Quest.Monster m in game.quest.monsters)
            {
                if (m.monsterData.sectionName.Equals(qe.cMonster.sectionName))
                {
                    // Matched existing monster
                    oldMonster = m;
                }
            }

            // Add the new type
            if (!game.gameType.MonstersGrouped() || oldMonster == null)
            {
                var monster = new Quest.Monster(qe);
                game.quest.monsters.Add(monster);
                game.monsterCanvas.UpdateList();
                // Update monster var
                game.quest.vars.SetValue("#monsters", game.quest.monsters.Count);
            }
            // There is an existing group, but now it is unique
            else if (qe.qMonster.unique)
            {
                oldMonster.unique      = true;
                oldMonster.uniqueText  = qe.qMonster.uniqueText;
                oldMonster.uniqueTitle = qe.GetUniqueTitle();
                oldMonster.healthMod   = Mathf.RoundToInt(qe.qMonster.uniqueHealthBase + (Game.Get().quest.GetHeroCount() * qe.qMonster.uniqueHealthHero));
            }

            // Display the location(s)
            if (qe.qEvent.locationSpecified && e.qEvent.display)
            {
                game.tokenBoard.AddMonster(qe);
            }
        }

        // Highlight a space on the board
        if (e.qEvent.highlight)
        {
            game.tokenBoard.AddHighlight(e.qEvent);
        }

        // Is this a shop?
        List <string> itemList = new List <string>();

        foreach (string s in e.qEvent.addComponents)
        {
            if (s.IndexOf("QItem") == 0)
            {
                // Fix #998
                if (game.gameType.TypeName() == "MoM" && itemList.Count == 1)
                {
                    ValkyrieDebug.Log("WARNING: only one QItem can be used in event " + e.qEvent.sectionName + ", ignoring other items");
                    break;
                }
                itemList.Add(s);
            }
        }
        // Add board components
        game.quest.Add(e.qEvent.addComponents, itemList.Count > 1);
        // Remove board components
        game.quest.Remove(e.qEvent.removeComponents);

        // Move camera
        if (e.qEvent.locationSpecified && !(e.qEvent is QuestData.UI))
        {
            CameraController.SetCamera(e.qEvent.location);
        }

        if (e.qEvent is QuestData.Puzzle)
        {
            QuestData.Puzzle p = e.qEvent as QuestData.Puzzle;
            if (p.puzzleClass.Equals("slide"))
            {
                new PuzzleSlideWindow(e);
            }
            if (p.puzzleClass.Equals("code"))
            {
                new PuzzleCodeWindow(e);
            }
            if (p.puzzleClass.Equals("image"))
            {
                new PuzzleImageWindow(e);
            }
            if (p.puzzleClass.Equals("tower"))
            {
                new PuzzleTowerWindow(e);
            }
            return;
        }

        // Set camera limits
        if (e.qEvent.minCam)
        {
            CameraController.SetCameraMin(e.qEvent.location);
        }
        if (e.qEvent.maxCam)
        {
            CameraController.SetCameraMax(e.qEvent.location);
        }

        // Is this a shop?
        if (itemList.Count > 1 && !game.quest.boardItems.ContainsKey("#shop"))
        {
            game.quest.boardItems.Add("#shop", new ShopInterface(itemList, Game.Get(), e.qEvent.sectionName));
            game.quest.ordered_boardItems.Add("#shop");
        }
        else if (!e.qEvent.display)
        {
            // Only raise dialog if there is text, otherwise auto confirm

            var firstEnabledButtonIndex = e.qEvent.buttons
                                          .TakeWhile(b => !IsButtonEnabled(b, game.quest.vars))
                                          .Count();
            EndEvent(firstEnabledButtonIndex);
        }
        else
        {
            if (monsterImage != null)
            {
                MonsterDialogMoM.DrawMonster(monsterImage, true);
                if (monsterHealth)
                {
                }
            }
            new DialogWindow(e);
        }
    }
Example #24
0
    public void Init(Dictionary <string, string> data)
    {
        game = Game.Get();

        // This is filled out later but is required for loading saves
        game.quest.eManager = this;

        events     = new Dictionary <string, Event>();
        eventStack = new Stack <Event>();

        // Find quest events
        foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components)
        {
            if (kv.Value is QuestData.Event)
            {
                // If the event is a monster type cast it
                if (kv.Value is QuestData.Spawn)
                {
                    events.Add(kv.Key, new MonsterEvent(kv.Key));
                }
                else if (kv.Value is QuestData.Token)
                {
                    events.Add(kv.Key, new Token(kv.Key));
                }
                else
                {
                    events.Add(kv.Key, new Event(kv.Key));
                }
            }
        }

        // Add game content perils as available events
        foreach (string perilKey in game.cd.Keys <PerilData>())
        {
            events.Add(perilKey, new Peril(perilKey));
        }

        if (data != null)
        {
            if (data.ContainsKey("queue"))
            {
                foreach (string s in data["queue"].Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries))
                {
                    eventStack.Push(events[s]);
                }
            }
            if (data.ContainsKey("monsterimage"))
            {
                monsterImage = Quest.Monster.GetMonster(data["monsterimage"]);
            }
            if (data.ContainsKey("monsterhealth"))
            {
                bool.TryParse(data["monsterhealth"], out monsterHealth);
            }
            if (data.ContainsKey("currentevent") && game.quest.activeShop != data["currentevent"])
            {
                currentEvent = events[data["currentevent"]];
                ResumeEvent();
            }
        }
    }
Example #25
0
    // 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();
    }