Exemplo n.º 1
0
        // Check to see if action exists for A button press in that direction
        public void aButtonPress()
        {
            // Later: if action exists, change UI to proper action
            // This should include end message and sending user back to movement UI

            Vector2      start = transform.position;
            Vector2      end   = transform.position;
            RaycastHit2D ray;

            switch (playerFacing)
            {
            case Direction.North:
                end.y++;
                break;

            case Direction.East:
                end.x++;
                break;

            case Direction.South:
                end.y--;
                break;

            case Direction.West:
                end.x--;
                break;
            }
            ray = Physics2D.Linecast(start, end, LayerMask.GetMask("StopPlayer"));

            if ((ray.collider != null) && (ray.collider.tag == "Action"))
            {
                StopMoving();
                InteractAction ia = ray.collider.gameObject.GetComponent <InteractAction>();
                if ((ia.actionT == actionType.itemWithNext) || (ia.actionT == actionType.itemWithoutNext))
                {
                    if (!ia.hasBeenViewed)
                    {
                        ia.hasBeenViewed = true;

                        // Present player with messages
                        foreach (string message in ia.messages)
                        {
                            UIManager.StartMessage(message);
                        }

                        // Award player items
                        foreach (ItemClass item in ia.items)
                        {
                            GameManager.AddItem(item, item.numberOfItem);
                        }

                        // Award player coins
                        if (ia.coins > 0)
                        {
                            GameManager.coins += ia.coins;
                            UIManager.StartMessage(GameManager.playerName + " received " + ia.coins + " coins!", null,
                                                   () => SoundEffectManager.Inst.PlaySoundImmediate("coinDing"));
                        }
                        UIManager.StartMessage(null, null, () => destroyQuestAndPresentChild(ia));
                    }
                    else
                    {
                        UIManager.StartMessage("There is nothing more of interest here");
                    }
                }
                else if (ia.actionT == actionType.message)
                {
                    foreach (string message in ia.messages)
                    {
                        UIManager.StartMessage(message);
                    }
                }
                else if (ia.actionT == actionType.quest)
                {
                    ItemData questItem = null;

                    if (ia.needsItem)
                    {
                        questItem = GameManager.allItems.Find(item => item.itemName.Equals(ia.questItem.itemName));

                        // Player doesn't have item
                        if (questItem == null)
                        {
                            foreach (string message in ia.messages)
                            {
                                UIManager.StartMessage(message, null, null);
                            }
                            UIManager.StartMessage(null, null, () => ResumeMoving());
                            return;
                        }
                        // Player doesn't have enough of the item
                        else if (questItem.numberOfItem < ia.numberOfItemsNeeded)
                        {
                            foreach (string message in ia.messages)
                            {
                                UIManager.StartMessage(message, null, null);
                            }
                            UIManager.StartMessage("You need " + (ia.numberOfItemsNeeded - questItem.numberOfItem) + " more of this item!", null, () => ResumeMoving());
                            return;
                        }
                    }
                    // Check if player has enough coins to proceed
                    if (ia.coinsNeeded > 0)
                    {
                        if (GameManager.coins < ia.coinsNeeded)
                        {
                            foreach (string message in ia.messages)
                            {
                                UIManager.StartMessage(message, null, null);
                            }
                            UIManager.StartMessage("You need " + (ia.coinsNeeded - GameManager.coins) + " more coins!", null, () => ResumeMoving());
                            return;
                        }
                        // Player has enough coins
                        else
                        {
                            GameManager.coins -= ia.coinsNeeded;
                            SoundEffectManager.Inst.PlaySoundImmediate("coinDing");
                        }
                    }

                    // Remove items
                    if (ia.needsItem)
                    {
                        questItem.numberOfItem -= ia.numberOfItemsNeeded;
                        // Remove item/s from inventory
                        if (questItem.numberOfItem < 1)
                        {
                            GameManager.allItems.Remove(questItem);
                        }
                    }

                    // Print quest completion messages
                    foreach (string message in ia.questCompletionMessages)
                    {
                        UIManager.StartMessage(message);
                    }
                    // Destroy completed quest object, update player quests
                    UIManager.StartMessage(null, null, (() => destroyQuestAndPresentChild(ia)));
                }
                else if (ia.actionT == actionType.trainer)
                {
                    NPCInteraction trainer = ia.transform.parent.GetComponent <NPCInteraction>();

                    // If trainer has already been defeated, present with end battle messages
                    if (GameManager.Inst.curSceneData.trainers[trainer.index])
                    {
                        trainer.DefeatedDialogue();
                    }
                    else
                    {
                        trainer.OnTriggerEnter2D(null);
                        return;
                    }
                }
                UIManager.StartMessage(null, null, () => ResumeMoving());
            }
        }
Exemplo n.º 2
0
        // Load the scene interactable data
        public bool UpdateSceneData(string sceneName)
        {
            // Put player and UI in the scene
            GameObject testForReferenceObject = GameObject.FindGameObjectWithTag("EditorOnly");

            if (testForReferenceObject != null)
            {
                PlayerMovement.Inst.transform.SetParent(testForReferenceObject.transform.root);
            }
            else
            {
                Debug.Log("> ERROR: No Ref obj found for player!");
            }
            GameObject testForUI = GameObject.FindGameObjectWithTag("UI");

            if (testForUI != null)
            {
                UIManager.EntireUI.SetParent(testForUI.transform);
            }

            SceneInteractionData load = sceneInteractions.Find(si => si.sceneName == sceneName);

            if (load != null)
            {
                // Set current scene interaction data
                curSceneData = load;

                // Find GameObjects containing scene interactables, trainers
                GameObject interactables = GameObject.FindGameObjectWithTag("Interactables");
                GameObject trainers      = GameObject.FindGameObjectWithTag("Trainers");

                // Find objects that have been interacted with and remove them
                for (int i = 0; i < load.interactables.Length; i++)
                {
                    InteractAction ia = interactables.transform.GetChild(i).GetComponent <InteractAction>();
                    if (ia != null)
                    {
                        ia.index = i;
                        if (load.interactables[i])
                        {
                            GameObject nextTile = ia.nextTile;
                            if (nextTile != null)
                            {
                                nextTile.SetActive(true);
                                ia.gameObject.SetActive(false);
                            }
                            else
                            {
                                ia.hasBeenViewed = true;
                                if ((ia.actionT == actionType.message) || (ia.actionT == actionType.itemWithNext))
                                {
                                    ia.gameObject.SetActive(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        interactables.transform.GetChild(i).gameObject.SetActive(!load.interactables[i]);
                    }
                }
                // Find trainers that have been defeated with and set their hasTriggered bool
                for (int i = 0; i < load.trainers.Length; i++)
                {
                    NPCInteraction trainer = trainers.transform.GetChild(i).GetComponent <NPCInteraction>();
                    if (trainer == null)
                    {
                        Debug.Log("NULL TRAINER!");
                    }
                    trainer.index = i;
                    if (load.trainers[i])
                    {
                        trainer.hasTriggered = true;
                    }
                }

                return(true);
            }
            else
            {
                // Some scenes do not require scene data
                // Ex. Main menu, New Game, Recovery Center and Shop
                //Debug.Log ("> ERROR: Scene data not present!");
                return(false);
            }
        }