Exemplo n.º 1
0
    public void AnswerClick(int i) // 1, 2, or 3
    {
        UserSessionLoggerBehavior uslb = GameObject.Find("UserSessionLogger").GetComponent <UserSessionLoggerBehavior>();

        uslb.LogToDatabase("Player selects mayor option --> " + GameObject.Find("AnswerText" + i).GetComponent <Text>().text, UserSessionLoggerBehavior.UserAction.LeftClickButton);

        ct = ct.NextTrees[i - 1];
        if (ct == null || ct.SpeakerText == null)
        {
            SceneManager.LoadScene("city_hall_3");
            return;
        }

        Debug.Log("SpeakerText = " + ct.SpeakerText);
        while (ct.SpeakerText[0] == '/')
        {
            Debug.Log("SpeakerText = " + ct.SpeakerText);
            //SE -- SEND EVENT
            string s = ct.SpeakerText.Substring(4);
            GameObject.Find("CampaignManager").GetComponent <CampaignManager>().CheckEvent(new SpeakEvent(SpeakerType.Mayor, 1, s));
            ct = ct.NextTrees[0];

            if (ct == null || ct.SpeakerText == null)
            {
                SceneManager.LoadScene("city_hall_3");
                return;
            }
        }

        UpdateDialogue();
    }
Exemplo n.º 2
0
 public void PlayConversationTree(ConversationTree tree, Action onConversationFinish)
 {
     OnConversationFinish = onConversationFinish;
     Clear();
     conversationTree = ConversationTreeLoader.GetTree("GenericFirstPartSupply");
     conversationTree.currentReader = this;
     conversationTree.StartTree(conversationTree.elements[0], this);
 }
Exemplo n.º 3
0
    public void AnswerClick(int i) // 1, 2, or 3
    {
        UserSessionLoggerBehavior uslb = GameObject.Find("UserSessionLogger").GetComponent <UserSessionLoggerBehavior>();

        uslb.LogToDatabase("Player selects shop option --> " + GameObject.Find("AnswerText" + i).GetComponent <Text>().text, UserSessionLoggerBehavior.UserAction.LeftClickButton);
        ct = ct.NextTrees[i - 1];
        if (ct == null || ct.SpeakerText == null)
        {
            SceneManager.LoadScene("city_hall_3");
            return;
        }

        while (ct.SpeakerText[0] == '/')
        {
            if (ct.SpeakerText[1] == 'O' && ct.SpeakerText[2] == 'G')
            {
                //OG -- OPEN GUI
                if (ct.SpeakerText.Substring(4) == "ShopGUI")
                {
                    Transact();
                    return;
                }
            }
            else
            {
                //SE -- SEND EVENT
                Debug.Log("SpeakerText = " + ct.SpeakerText);
                //SE -- SEND EVENT
                string s = ct.SpeakerText.Substring(4);
                GameObject.Find("CampaignManager").GetComponent <CampaignManager>().CheckEvent(new SpeakEvent(SpeakerType.ShopKeeper, 1, s));

                try
                {
                    ct = ct.NextTrees[0];
                }
                catch (System.IndexOutOfRangeException x)
                {
                    //...
                }

                if (ct == null || ct.SpeakerText == null)
                {
                    SceneManager.LoadScene("city_hall_3");
                    return;
                }
            }
        }

        UpdateDialogue();
    }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        GameObject      g  = GameObject.Find("CampaignManager");
        CampaignManager cm = g.GetComponent <CampaignManager>();

        ct = cm.GetConversation(SpeakerType.Mayor, 1);
        //ct = GameObject.Find("CampaignManager").GetComponent<CampaignManager>().GetConversation(SpeakerType.Mayor, 1);
        dialogue = GameObject.Find("Dialogue").GetComponent <Text>();
        answer1  = GameObject.Find("AnswerText1").GetComponent <Text>();
        answer2  = GameObject.Find("AnswerText2").GetComponent <Text>();
        answer3  = GameObject.Find("AnswerText3").GetComponent <Text>();
        a1       = GameObject.Find("AnswerText1").GetComponent <Button>();
        a2       = GameObject.Find("AnswerText2").GetComponent <Button>();
        a3       = GameObject.Find("AnswerText3").GetComponent <Button>();

        UpdateDialogue();
    }
Exemplo n.º 5
0
    public void CancelTransaction()
    {
        UserSessionLoggerBehavior uslb = GameObject.Find("UserSessionLogger").GetComponent <UserSessionLoggerBehavior>();

        uslb.LogToDatabase("Player cancels transaction", UserSessionLoggerBehavior.UserAction.LeftClickButton);
        buyOrSell = false;
        //back1.SetActive(true);
        //back2.SetActive(false);
        shop_dialogue.SetActive(true);
        shop_gui.SetActive(false);

        cost   = 0;
        refund = 0;

        ct = GameObject.Find("CampaignManager").GetComponent <CampaignManager>().GetConversation(SpeakerType.ShopKeeper, 1);
        UpdateDialogue();
    }
Exemplo n.º 6
0
    public static ConversationTree LoadFromJSON(string json)
    {
        ConversationTree tree = JsonUtility.FromJson <ConversationTree>(json);

        return(tree);
    }
Exemplo n.º 7
0
    // Update is called once per frame
    public void StartInteraction()
    {
        // If NPC is waiting for the player to interact
        if (interactingState == InteractingState.WAITING_PLAYER)
        {
            if (Player.instance.talkToNPC)
            {
                // and it's the first time he has been close to the NPC
                if (Player.instance.interactionState != Player.InteractionState.NEAR_NPC)
                {
                    GameManager.Instance.CancelUserPrompt();
                    Player.instance.talkToNPC = false;
                    // Hide Sherlocks' dialogue window
                    Sherlock.Instance.StartCoroutine(Sherlock.Instance.SetDialogue(null));
                    // Notify player that is near the NPC
                    Player.instance.interactionState = Player.InteractionState.NEAR_NPC;

                    Player.instance.SetCutscene(true);

                    Player.instance.interactingNPC = this;
                    // Enable the input on the NPCs
                    NPCs.Instance.EnableInput();

                    GameObject cutSceneGO = null;
                    // If there is an event to be triggered when player is near the NPC
                    if (nearPlayerEvent != null)
                    {
                        // Load cut scene prefab and instantiate it
                        GameObject cutScenePrefab = ResourceManager.LoadNPCCutScene(NPCName());
                        if (cutScenePrefab != null)
                        {
                            cutSceneGO = Instantiate(cutScenePrefab) as GameObject;
                            cutSceneGO.transform.parent = GameManager.Instance.UIPanel;
                            cutScene = cutSceneGO.GetComponent<CutScene>();

                            // Update references in cut scene to NPC
                            nearPlayerEvent.ClearObjectsToNotify();
                            nearPlayerEvent.AddObjectToNotify(cutSceneGO);

                            foreach (SCEvent cutSceneEvent in cutSceneGO.GetComponentsInChildren<SCEvent>(true))
                            {
                                List<GameObject> gameObjects = cutSceneEvent.gameObjectsToNotify;
                                for (int i = 0, count = gameObjects.Count; i < count; i++)
                                    if (gameObjects [i] == null)
                                    {
                                        gameObjects [i] = this.gameObject;
                                    }
                            }

                            // Trigger it
                            nearPlayerEvent.TriggerEvent(true);
                        } else
                        {
                            Debug.LogWarning("No cut scene prefab found for " + NPCName());
                        }
                    }

                    // Load conversation prefab and instantiate it
                    GameObject conversationPrefab = ResourceManager.LoadNPCConversation(NPCName());
                    if (conversationPrefab != null)
                    {
                        GameObject conversationRoot = Instantiate(conversationPrefab) as GameObject;
                        conversationRoot.transform.parent = this.transform;
                        conversationTree = conversationRoot.GetComponent<ConversationTree>();

                        // Update references in conversation events to NPC
                        foreach (SCEvent conversationEvent in conversationRoot.GetComponentsInChildren<SCEvent>(true))
                        {
                            int nullGO = 0;
                            List<GameObject> gameObjects = conversationEvent.gameObjectsToNotify;
                            for (int i = 0, count = gameObjects.Count; i < count; i++)
                                if (gameObjects [i] == null)
                                {
                                    nullGO++;
                                    if (nullGO == 2)
                                        gameObjects [i] = cutSceneGO;
                                    else
                                        gameObjects [i] = this.gameObject;
                                }
                        }

                        GameObject voiceOversPrefab = ResourceManager.LoadNPCVoiceOver(NPCName(), ApplicationState.Instance.selectedCharacter);
                        DialogueVoiceOver voiceOver =  (DialogueVoiceOver) ((voiceOversPrefab != null) ? voiceOversPrefab.GetComponent<DialogueVoiceOver>() : null);
                        // Upate owner of each dialogue to NPC
                        foreach (Dialogue dialogue in conversationRoot.GetComponentsInChildren<Dialogue>(true))
                        {
                            dialogue.owner = this;

                            if (voiceOver != null && dialogue.voiceOverID != DialogueVoiceOver.VoiceOverID.NATIVE && dialogue.voiceOverID != DialogueVoiceOver.VoiceOverID.NONE)
                            {
                                dialogue.voiceOver = voiceOver.RetrieveVoiceOverAudio(dialogue.voiceOverID);
                            }
                        }

                        foreach (Reply reply in conversationRoot.GetComponentsInChildren<Reply>(true))
                        {
                            if (voiceOver != null && reply.voiceOverID != DialogueVoiceOver.VoiceOverID.NATIVE && reply.voiceOverID != DialogueVoiceOver.VoiceOverID.NONE)
                            {
                                reply.voiceOver = voiceOver.RetrieveVoiceOverAudio(reply.voiceOverID);
                            }
                        }

                        voiceOversPrefab = null;
                        Resources.UnloadUnusedAssets();
                    } else
                    {
                        Debug.LogWarning("No conversation prefab found for " + NPCName());
                    }
                }
            }
            // else if the player is not close to the NPC but the player was interacting with the NPC before
            else if (Player.instance.interactingNPC == this)
            {
                // Notify plyer that he is away from the NPC
                Player.instance.interactionState = Player.InteractionState.NONE;
                Player.instance.interactingNPC = null;
                NPCs.Instance.EnableInput();
                //Player.instance.SetGoToCharacter(true);
                Player.instance.Navigate(transform.position, false);
            } else
            {
                //Player.instance.interactionBubble.IgnoreNPC();
                //Player.instance.SetGoToCharacter(true);
                Player.instance.SetInteractiveBubbleNPC(this);
                Player.instance.Navigate(transform.position, false);
            }
        } else
        {
            if (interactingState == InteractingState.INTERACTING_WITH_PLAYER || interactingState == InteractingState.TALKING_PLAYER)
            {
                //if (Player.instance.PlayerDistance(transform.position) < 3f)
                if (Player.instance.GetDistance(this.transform.position) < 0.02f)
                {
                    // Then talk with the player
                    Player.instance.TalkNPC(this);
                }
                else
                {
                    //Player.instance.SetGoToCharacter(true);
                    Player.instance.Navigate(transform.position, false);
                }
            }
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Handle Event: OnQuestCompleted
    /// </summary>
    public void OnQuestCompleted()
    {
        if (miniGame != null)
        {
            ResourceManager.UnloadAsset(miniGame.gameObject);
            Destroy(miniGame.gameObject);
        }

        Destroy(conversationTree.gameObject);
        conversationTree = null;

        Destroy(cutScene.gameObject);
        cutScene = null;

        Resources.UnloadUnusedAssets();

        InputManager.Instance.ReceivedUIInput();
        Player.instance.PlayRewardPortrait(playerRewardPortrait, missingToy, foundToyColor, celebratingTime);

        //Add interaction Completed in interaction table
        //RecordAnswers("Emotions");
        //RecordAnswers("Comprehension");
        //RecordAnswers("ConversationStart");
        //RecordAnswers("MaintainConversation");
        //RecordAnswers("ProblemSolving");
        interactionID = MainDatabase.Instance.getIDs("Select Max(InteractionID) from Interaction;");
        MainDatabase.Instance.UpdateSql("UPDATE Interaction SET Completed='True' WHERE InteractionID=" + interactionID + ";");
        int NPCID = MainDatabase.Instance.getIDs("Select NPCID from Interaction where InteractionID=" + interactionID + ";");
        //changing the status of NPC to completed by assigning to 1
        MainDatabase.Instance.ChangeUserNPCStatus(ApplicationState.Instance.userID, NPCID, 1);
        //Adding toy to userToy table.
        DBToyInfo toyAchieved = MainDatabase.Instance.getToyInfoByInteractionID(interactionID);
        MainDatabase.Instance.InsertSql("INSERT INTO UserToy (UserID,ToyID,InteractionID) VALUES ('" + ApplicationState.Instance.userID + "','"+toyAchieved.ToyID+ "','"+interactionID+ "');");

        // Remove glowing effect around NPC
        RemoveGlow();
        Markers.Instance.OnQuestCompleted(toyWorldPosition, NPCs.Instance.GetNpcID(this));
        interactingState = InteractingState.COMPLETED_TASK;
        NPCs.Instance.UpdateNPCStatus();

        NPCs.Instance.EnableInput();
        GameManager.Instance.PrepareUserPrompt();
    }
    static ConversationTreeLoader()
    {
        Debug.Log("Loading Conversations");
        DirectoryInfo d = new DirectoryInfo(Application.dataPath + "/Resources/Text/Conversations");

        FileInfo[] files = d.GetFiles("*.txt");
        List <ConversationTree> trees = new List <ConversationTree>();
        int count = 0;

        foreach (FileInfo file in files)
        {
            count += 1;
            ConversationTree           tree     = new ConversationTree();
            List <ConversationElement> elements = new List <ConversationElement>();
            string[] lines = File.ReadAllLines(file.FullName);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("#"))
                {
                    continue;
                }
                else if (lines[i].Length == 0)
                {
                    continue;
                }
                List <string> topLevelStrings = Utility.SplitOnTopLevelBrackets(lines[i]);

                if (topLevelStrings[0] == "END")
                {
                    elements.Add(new ConversationElement());
                    continue;
                }

                int next = -1;
                int.TryParse(topLevelStrings[1], out next);
                switch (topLevelStrings[0])
                {
                case "TEXT":
                    elements.Add(new ConversationElement(topLevelStrings[2], next));
                    break;

                case "CHOICE":
                    List <string> choices        = SplitCommaSeperatedList(topLevelStrings[2]);
                    List <string> responseKeys   = SplitCommaSeperatedList(topLevelStrings[3]);
                    List <bool>   responseValues = new List <bool>();
                    foreach (string s in SplitCommaSeperatedList(topLevelStrings[4]))
                    {
                        if (s == "true")
                        {
                            responseValues.Add(true);
                        }
                        else
                        {
                            responseValues.Add(false);
                        }
                    }
                    elements.Add(new ConversationElement(choices, responseKeys, responseValues, next));
                    break;

                case "BRANCH":
                    List <List <string> > branchVariables = new List <List <string> >();
                    foreach (string s in Utility.SplitOnTopLevelBrackets(topLevelStrings[2]))
                    {
                        branchVariables.Add(SplitCommaSeperatedList(s));
                    }

                    List <List <bool> > branchConditions = new List <List <bool> >();
                    foreach (string s in Utility.SplitOnTopLevelBrackets(topLevelStrings[3]))
                    {
                        List <bool> cons = new List <bool>();
                        foreach (string b in SplitCommaSeperatedList(s))
                        {
                            if (s == "true")
                            {
                                cons.Add(true);
                            }
                            else
                            {
                                cons.Add(false);
                            }
                        }
                        branchConditions.Add(cons);
                    }

                    List <int> branchDestinations = new List <int>();
                    foreach (string s in SplitCommaSeperatedList(topLevelStrings[4]))
                    {
                        int destination = -1;
                        int.TryParse(s, out destination);
                        branchDestinations.Add(destination);
                    }
                    elements.Add(new ConversationElement(branchVariables, branchConditions, branchDestinations, next));
                    break;

                default:
                    Debug.LogError("Couldn't parse conversation key " + topLevelStrings[0] + " in " + file.Name);
                    break;
                }
            }
            tree.elements = elements;

            string fileName = file.Name.Substring(0, file.Name.Length - 4); //trim off the .txt;

            //check if the last digits are "thing_###"
            //We store those together, not in new entries
            //that way when we search "thing" we can get all "thing_001" "thing_002" ...
            if (
                char.IsNumber(fileName[fileName.Length - 1]) &&
                char.IsNumber(fileName[fileName.Length - 2]) &&
                char.IsNumber(fileName[fileName.Length - 3]) &&
                fileName[fileName.Length - 4] == '_')
            {
                string numberlessFileName = fileName.Substring(0, fileName.Length - 4);
                if (allTrees.ContainsKey(numberlessFileName))
                {
                    allTrees[numberlessFileName].Add(tree);
                }
                else
                {
                    allTrees.Add(numberlessFileName, new List <ConversationTree>()
                    {
                        tree
                    });
                }
            }
            else
            {
                if (allTrees.ContainsKey(fileName))
                {
                    allTrees[fileName].Add(tree);
                }
                else
                {
                    allTrees.Add(fileName, new List <ConversationTree>()
                    {
                        tree
                    });
                }
            }
        }
        Debug.Log("Loaded " + count + " files");
    }
Exemplo n.º 10
0
    /*ConversationTree ct;
     *
     * Button a1;
     * Button a2;
     * Button a3;
     * Text answer1;
     * Text answer2;
     * Text answer3;
     * Text dialogue;*/

    // Use this for initialization
    void Start()
    {
        Camera.main.GetComponent <CameraMovement>().IsDriving(false);
        GameObject      g  = GameObject.Find("CampaignManager");
        CampaignManager cm = g.GetComponent <CampaignManager>();

        ct       = cm.GetConversation(SpeakerType.ShopKeeper, 1);
        dialogue = GameObject.Find("Dialogue").GetComponent <Text>();
        answer1  = GameObject.Find("AnswerText1").GetComponent <Text>();
        answer2  = GameObject.Find("AnswerText2").GetComponent <Text>();
        answer3  = GameObject.Find("AnswerText3").GetComponent <Text>();
        a1       = GameObject.Find("AnswerText1").GetComponent <Button>();
        a2       = GameObject.Find("AnswerText2").GetComponent <Button>();
        a3       = GameObject.Find("AnswerText3").GetComponent <Button>();
        Camera.main.GetComponent <CameraMovement>().IsDriving(false);

        try
        {
            b        = GameObject.Find("Player").GetComponent <PlayerControls>().GetBackpack();
            backpack = b.GetBackpack();
        }
        catch (System.NullReferenceException nre)
        {
            b        = new Backpack();
            backpack = new ArrayList();
            backpack.Add(new Item(0, 3));
            backpack.Add(new Item(1, 4));
            backpack.Add(new Item(2, 5));
            backpack.Add(new Item(3, 6));
            backpack.Add(new Item(4, 500));
            b.CheatSetBackpack(backpack);
        }

        GameObject.Find("MoneyAmount").GetComponent <Text>().text = ((Item)backpack[4]).quantity.ToString();

        shop_dialogue = GameObject.Find("ShopDialogue");
        shop_gui      = GameObject.Find("ShopGUI");

        costAmount   = GameObject.Find("CostAmount").GetComponent <Text>();
        refundAmount = GameObject.Find("RefundAmount").GetComponent <Text>();

        ct = GameObject.Find("CampaignManager").GetComponent <CampaignManager>().GetConversation(SpeakerType.ShopKeeper, 1);

        buyOrSell = false;
        //back1 = GameObject.Find("Cube");
        //back2 = GameObject.Find("Cube (1)");
        cost   = 0;
        refund = 0;

        len   = 4;
        names = new string[len];
        int p = 30;

        names[0]       = "Overclock";
        names[1]       = "VirusBeGone";
        names[2]       = "WormBeGone";
        names[3]       = "Invincibility";
        buyQuantities  = new int[len];
        sellQuantities = new int[len];
        buyAmountText  = new Text[len];
        sellAmountText = new Text[len];
        storeStock     = new int[len];
        buyAdd         = new Button[len];
        buySubtract    = new Button[len];
        sellAdd        = new Button[len];
        sellSubtract   = new Button[len];
        priceText      = new Text[len];

        refunds    = new int[len];
        prices     = new int[len];
        refundText = new Text[len];

        for (int i = 0; i < len; i++)
        {
            prices[i] = p;
            p        += 10;
        }



        buyAdd[0] = GameObject.Find(names[0] + "Plus").GetComponent <Button>();
        buyAdd[0].onClick.RemoveAllListeners();
        buyAdd[0].onClick.AddListener(() => { BuyAddOne(0); });
        buyAdd[1] = GameObject.Find(names[1] + "Plus").GetComponent <Button>();
        buyAdd[1].onClick.RemoveAllListeners();
        buyAdd[1].onClick.AddListener(() => { BuyAddOne(1); });
        buyAdd[2] = GameObject.Find(names[2] + "Plus").GetComponent <Button>();
        buyAdd[2].onClick.RemoveAllListeners();
        buyAdd[2].onClick.AddListener(() => { BuyAddOne(2); });
        buyAdd[3] = GameObject.Find(names[3] + "Plus").GetComponent <Button>();
        buyAdd[3].onClick.RemoveAllListeners();
        buyAdd[3].onClick.AddListener(() => { BuyAddOne(3); });

        buySubtract = new Button[len];

        buySubtract[0] = GameObject.Find(names[0] + "Minus").GetComponent <Button>();
        buySubtract[0].onClick.RemoveAllListeners();
        buySubtract[0].onClick.AddListener(() => { BuySubtractOne(0); });
        buySubtract[1] = GameObject.Find(names[1] + "Minus").GetComponent <Button>();
        buySubtract[1].onClick.RemoveAllListeners();
        buySubtract[1].onClick.AddListener(() => { BuySubtractOne(1); });
        buySubtract[2] = GameObject.Find(names[2] + "Minus").GetComponent <Button>();
        buySubtract[2].onClick.RemoveAllListeners();
        buySubtract[2].onClick.AddListener(() => { BuySubtractOne(2); });
        buySubtract[3] = GameObject.Find(names[3] + "Minus").GetComponent <Button>();
        buySubtract[3].onClick.RemoveAllListeners();
        buySubtract[3].onClick.AddListener(() => { BuySubtractOne(3); });

        sellAdd = new Button[len];

        sellAdd[0] = GameObject.Find(names[0] + "SellPlus").GetComponent <Button>();
        sellAdd[0].onClick.RemoveAllListeners();
        sellAdd[0].onClick.AddListener(() => { SellAddOne(0); });
        sellAdd[1] = GameObject.Find(names[1] + "SellPlus").GetComponent <Button>();
        sellAdd[1].onClick.RemoveAllListeners();
        sellAdd[1].onClick.AddListener(() => { SellAddOne(1); });
        sellAdd[2] = GameObject.Find(names[2] + "SellPlus").GetComponent <Button>();
        sellAdd[2].onClick.RemoveAllListeners();
        sellAdd[2].onClick.AddListener(() => { SellAddOne(2); });
        sellAdd[3] = GameObject.Find(names[3] + "SellPlus").GetComponent <Button>();
        sellAdd[3].onClick.RemoveAllListeners();
        sellAdd[3].onClick.AddListener(() => { SellAddOne(3); });

        sellSubtract = new Button[len];

        sellSubtract[0] = GameObject.Find(names[0] + "SellMinus").GetComponent <Button>();
        sellSubtract[0].onClick.RemoveAllListeners();
        sellSubtract[0].onClick.AddListener(() => { SellSubtractOne(0); });
        sellSubtract[1] = GameObject.Find(names[1] + "SellMinus").GetComponent <Button>();
        sellSubtract[1].onClick.RemoveAllListeners();
        sellSubtract[1].onClick.AddListener(() => { SellSubtractOne(1); });
        sellSubtract[2] = GameObject.Find(names[2] + "SellMinus").GetComponent <Button>();
        sellSubtract[2].onClick.RemoveAllListeners();
        sellSubtract[2].onClick.AddListener(() => { SellSubtractOne(2); });
        sellSubtract[3] = GameObject.Find(names[3] + "SellMinus").GetComponent <Button>();
        sellSubtract[3].onClick.RemoveAllListeners();
        sellSubtract[3].onClick.AddListener(() => { SellSubtractOne(3); });


        for (int i = 0; i < len; i++)
        {
            //storeStock[i] = ((len-1) * 478) / 131;
            storeStock[i]          = (len - i) * 2;
            priceText[i]           = GameObject.Find(names[i] + "Price").GetComponent <Text>();
            priceText[i].text      = "Price: " + prices[i];
            refunds[i]             = prices[i] / 3;
            refundText[i]          = GameObject.Find(names[i] + "Refund").GetComponent <Text>();
            refundText[i].text     = "Refund: " + refunds[i];
            buyQuantities[i]       = 0;
            sellQuantities[i]      = 0;
            buyAmountText[i]       = GameObject.Find(names[i] + "Quantity").GetComponent <Text>();
            buyAmountText[i].text  = "0";
            sellAmountText[i]      = GameObject.Find(names[i] + "SellQuantity").GetComponent <Text>();
            sellAmountText[i].text = "0";
        }

        //back2.SetActive(false);
        shop_gui.SetActive(false);

        UpdateDialogue();
    }
Exemplo n.º 11
0
 public void Clear()
 {
     conversationTree = null;
     chatMessages.Clear();
 }
    // Use this for initialization
    void Start()
    {
        GameObject      g  = GameObject.Find("CampaignManager");
        CampaignManager cm = g.GetComponent <CampaignManager>();

        ct       = cm.GetConversation(SpeakerType.ShopKeeper, 1);
        dialogue = GameObject.Find("Dialogue").GetComponent <Text>();
        answer1  = GameObject.Find("AnswerText1").GetComponent <Text>();
        answer2  = GameObject.Find("AnswerText2").GetComponent <Text>();
        answer3  = GameObject.Find("AnswerText3").GetComponent <Text>();
        a1       = GameObject.Find("AnswerText1").GetComponent <Button>();
        a2       = GameObject.Find("AnswerText2").GetComponent <Button>();
        a3       = GameObject.Find("AnswerText3").GetComponent <Button>();

        try
        {
            b        = GameObject.Find("Player").GetComponent <PlayerControls>().GetBackpack();
            backpack = b.GetBackpack();
        }
        catch (System.NullReferenceException nre)
        {
            b        = new Backpack();
            backpack = new ArrayList();
            backpack.Add(new Item(0, 3));
            backpack.Add(new Item(1, 4));
            backpack.Add(new Item(2, 5));
            backpack.Add(new Item(3, 6));
            backpack.Add(new Item(4, 500));
            b.CheatSetBackpack(backpack);
        }

        GameObject.Find("MoneyAmount").GetComponent <Text>().text = ((Item)backpack[4]).quantity.ToString();

        shop_dialogue = GameObject.Find("ShopDialogue");
        shop_gui      = GameObject.Find("ShopGUI");

        costAmount   = GameObject.Find("CostAmount").GetComponent <Text>();
        refundAmount = GameObject.Find("RefundAmount").GetComponent <Text>();

        ct = GameObject.Find("CampaignManager").GetComponent <CampaignManager>().GetConversation(SpeakerType.ShopKeeper, 1);

        /*dialogue.text = "Hello there! Welcome to my store! How may I help you today?";
         * answer1.text = "Let's see what you've got.";
         * answer2.text = "Nevermind";
         * a1.onClick.RemoveAllListeners();
         * a1.onClick.AddListener(() => { Transact(); buyOrSell = true; });
         * a2.onClick.RemoveAllListeners();
         * a2.onClick.AddListener(() => { SceneManager.LoadScene("city_hall_3"); });*/

        buyOrSell = false;
        back1     = GameObject.Find("Cube");
        back2     = GameObject.Find("Cube (1)");
        cost      = 0;
        refund    = 0;

        len   = 4;
        names = new string[len];

        names[0] = "Overclock";
        names[1] = "VirusBeGone";
        names[2] = "WormBeGone";
        names[3] = "Invincibility";

        storeStock = new int[len];
        for (int i = 0; i < len; i++)
        {
            //storeStock[i] = ((len-1) * 478) / 131;
            storeStock[i] = (len - i) * 2;
        }

        int p = 30;

        prices = new int[len];
        for (int i = 0; i < len; i++)
        {
            prices[i] = p;
            p        += 10;
        }

        priceText = new Text[len];
        for (int i = 0; i < len; i++)
        {
            priceText[i]      = GameObject.Find(names[i] + "Price").GetComponent <Text>();
            priceText[i].text = "Price: " + prices[i];
        }

        refunds = new int[len];
        for (int i = 0; i < len; i++)
        {
            refunds[i] = prices[i] / 3;
        }

        refundText = new Text[len];
        for (int i = 0; i < len; i++)
        {
            refundText[i]      = GameObject.Find(names[i] + "Refund").GetComponent <Text>();
            refundText[i].text = "Refund: " + refunds[i];
        }

        buyAdd = new Button[len];

        buyAdd[0] = GameObject.Find(names[0] + "Plus").GetComponent <Button>();
        buyAdd[0].onClick.RemoveAllListeners();
        buyAdd[0].onClick.AddListener(() => { BuyAddOne(0); });
        buyAdd[1] = GameObject.Find(names[1] + "Plus").GetComponent <Button>();
        buyAdd[1].onClick.RemoveAllListeners();
        buyAdd[1].onClick.AddListener(() => { BuyAddOne(1); });
        buyAdd[2] = GameObject.Find(names[2] + "Plus").GetComponent <Button>();
        buyAdd[2].onClick.RemoveAllListeners();
        buyAdd[2].onClick.AddListener(() => { BuyAddOne(2); });
        buyAdd[3] = GameObject.Find(names[3] + "Plus").GetComponent <Button>();
        buyAdd[3].onClick.RemoveAllListeners();
        buyAdd[3].onClick.AddListener(() => { BuyAddOne(3); });

        buySubtract = new Button[len];

        buySubtract[0] = GameObject.Find(names[0] + "Minus").GetComponent <Button>();
        buySubtract[0].onClick.RemoveAllListeners();
        buySubtract[0].onClick.AddListener(() => { BuySubtractOne(0); });
        buySubtract[1] = GameObject.Find(names[1] + "Minus").GetComponent <Button>();
        buySubtract[1].onClick.RemoveAllListeners();
        buySubtract[1].onClick.AddListener(() => { BuySubtractOne(1); });
        buySubtract[2] = GameObject.Find(names[2] + "Minus").GetComponent <Button>();
        buySubtract[2].onClick.RemoveAllListeners();
        buySubtract[2].onClick.AddListener(() => { BuySubtractOne(2); });
        buySubtract[3] = GameObject.Find(names[3] + "Minus").GetComponent <Button>();
        buySubtract[3].onClick.RemoveAllListeners();
        buySubtract[3].onClick.AddListener(() => { BuySubtractOne(3); });

        sellAdd = new Button[len];

        sellAdd[0] = GameObject.Find(names[0] + "SellPlus").GetComponent <Button>();
        sellAdd[0].onClick.RemoveAllListeners();
        sellAdd[0].onClick.AddListener(() => { SellAddOne(0); });
        sellAdd[1] = GameObject.Find(names[1] + "SellPlus").GetComponent <Button>();
        sellAdd[1].onClick.RemoveAllListeners();
        sellAdd[1].onClick.AddListener(() => { SellAddOne(1); });
        sellAdd[2] = GameObject.Find(names[2] + "SellPlus").GetComponent <Button>();
        sellAdd[2].onClick.RemoveAllListeners();
        sellAdd[2].onClick.AddListener(() => { SellAddOne(2); });
        sellAdd[3] = GameObject.Find(names[3] + "SellPlus").GetComponent <Button>();
        sellAdd[3].onClick.RemoveAllListeners();
        sellAdd[3].onClick.AddListener(() => { SellAddOne(3); });

        sellSubtract = new Button[len];

        sellSubtract[0] = GameObject.Find(names[0] + "SellMinus").GetComponent <Button>();
        sellSubtract[0].onClick.RemoveAllListeners();
        sellSubtract[0].onClick.AddListener(() => { SellSubtractOne(0); });
        sellSubtract[1] = GameObject.Find(names[1] + "SellMinus").GetComponent <Button>();
        sellSubtract[1].onClick.RemoveAllListeners();
        sellSubtract[1].onClick.AddListener(() => { SellSubtractOne(1); });
        sellSubtract[2] = GameObject.Find(names[2] + "SellMinus").GetComponent <Button>();
        sellSubtract[2].onClick.RemoveAllListeners();
        sellSubtract[2].onClick.AddListener(() => { SellSubtractOne(2); });
        sellSubtract[3] = GameObject.Find(names[3] + "SellMinus").GetComponent <Button>();
        sellSubtract[3].onClick.RemoveAllListeners();
        sellSubtract[3].onClick.AddListener(() => { SellSubtractOne(3); });

        buyQuantities = new int[len];
        for (int i = 0; i < len; i++)
        {
            buyQuantities[i] = 0;
        }

        sellQuantities = new int[len];
        for (int i = 0; i < len; i++)
        {
            sellQuantities[i] = 0;
        }

        buyAmountText = new Text[len];
        for (int i = 0; i < len; i++)
        {
            buyAmountText[i]      = GameObject.Find(names[i] + "Quantity").GetComponent <Text>();
            buyAmountText[i].text = "0";
        }

        sellAmountText = new Text[len];
        for (int i = 0; i < len; i++)
        {
            sellAmountText[i]      = GameObject.Find(names[i] + "SellQuantity").GetComponent <Text>();
            sellAmountText[i].text = "0";
        }

        back2.SetActive(false);
        shop_gui.SetActive(false);
    }