/// <summary> /// Methodcalled on dialogue button click. Processes all additional message events. /// </summary> /// <param name="data">Dialogue data associated with dialogue button.</param> public void DialogueClicked(DialogOption data) { if (data.option == "END") { ToggleDialogueWindow(); return; } if (!MessageWindow.activeSelf) { MessageWindow.SetActive(true); } MessageWindow.transform.GetChild(0).GetComponent <Text>().text = data.response; //FRENIG if (data.option == "What is going on? I recently woke up, and met two hostile people on my way here.") { InteractiveHumanoid villageChief = worldController.banditQuestGiver.GetComponent <InteractiveHumanoid>(); DialogOption Dialogue = new DialogOption() { option = "I had spoken to Frenig, and he said you can tell me more about bandits", response = "Yes. It is simple, they came out of nowhere like three weeks ago from the east and started raiding our village. We managed to defend for now, but they grew stronger and also captured the forest. Nobody who went there has yet returned.", target = villageChief, isTemporary = true }; villageChief.DialogOptions.Add(Dialogue); } //KUKAZU else if (data.option == "What are you doing here?") { InteractiveHumanoid alchemist = worldController.alchemist.GetComponent <InteractiveHumanoid>(); DialogOption Dialogue = new DialogOption() { option = "How can I help you?", response = "I need red mushrooms. I will not gather them myself, as I am busy with my research, and bandits make things even harder. I will give you small healing potion for each one you bring to me.", target = alchemist, isTemporary = true }; alchemist.DialogOptions.Add(Dialogue); AddDialogue(Dialogue); RefreshEndDialogue(); } else if (data.option == "How can I help you?") { InteractiveHumanoid alchemist = worldController.alchemist.GetComponent <InteractiveHumanoid>(); DialogOption Dialogue = new DialogOption() { option = "I want to trade mushrooms", response = "Let's see... I will give you a healing potion for each mushroom you bring here.", target = alchemist, isTemporary = false }; alchemist.DialogOptions.Add(Dialogue); AddDialogue(Dialogue); RefreshEndDialogue(); } else if (data.option == "I want to trade mushrooms") { Player player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); int firstMushroomIndex = player.Inventory.FindIndex(x => x.Name.ToLower() == "red mushroom"); if (firstMushroomIndex != -1) { player.Inventory.RemoveAt(firstMushroomIndex); FoodItem potion = ScriptableObject.CreateInstance <FoodItem>(); potion.Name = "Small healing potion"; potion.Owner = player.gameObject; potion.HealAmount = 2; potion.Description = "A healing potion I received from Kukazu"; player.Inventory.Add(potion); //player.Inventory.Add(new FoodItem() { Name = "Small healing potion", Owner = player.gameObject, HealAmount = 2, Description = "A healing potion I received from Kukazu" }); } } //VILLAGE CHIEF else if (data.option == "I had spoken to Frenig, and he said you can tell me more about bandits") { mainCamera.ViewPoint(GameObject.FindGameObjectWithTag("ForestCameraMarker").transform.position); DialogOption Dialogue = new DialogOption() { option = "I want to help. I will try to kill the bandits.", response = "WHAT? Are you serious? Currently nobody of us can help you, as direct attack would be a suicide in our opinion. Feel free to scout though, and be careful.", target = data.target, isTemporary = true }; data.target.DialogOptions.Add(Dialogue); AddDialogue(Dialogue); RefreshEndDialogue(); } else if (data.option == "I want to help. I will try to kill the bandits.") { worldController.StartBanditMission(); } else if (data.option == "Forest bandits do not exist anymore. Does that solve bandit problem?") { worldController.StartBanditBaseMission(); } else if (data.option == "I found and destroyed bandit headquarters, their commander was a knight in black armor!") { DisplayQuickMessage("You won the game! You can now continue playing and explore the world if you want.", 60); } if (data.isTemporary) { data.target.DialogOptions.Remove(data); DeleteDialogueButton(data.option); } }
void Update() { Vector3 movementVector = Vector3.zero; Vector3 rotationVector = Vector3.zero; if (!UI.dialogueWindowActive && !UI.statWindowActive && !UI.inventoryWindowActive && !isDead) { movementVector = transform.forward * Input.GetAxis("Vertical") * Speed * Time.deltaTime; //process movement keys rotationVector = new Vector3(0, Input.GetAxis("Horizontal") + Input.GetAxis("Mouse X"), 0) * RotateSpeed; } //Debug.DrawRay(transform.position + new Vector3(0, 1, 0), transform.forward, Color.red); if (objectController.isGrounded) { RaycastHit terrainInfo; if (Physics.Raycast(transform.position, Vector3.down, out terrainInfo, 10)) //slide detection { float test = Vector3.Dot(terrainInfo.normal, Vector3.up); if (test < 0.7f && objectController.isGrounded) { isSliding = true; movementVector = new Vector3(terrainInfo.normal.x, 0, terrainInfo.normal.z) * 4 * Time.deltaTime; } else { isSliding = false; } } if (Input.GetKey(KeyCode.Space) && !isSliding) //jump { Jump(JumpHeight); } if ((Input.GetKeyDown(KeyCode.LeftControl)) && !isShooting) //attack { Attack(); } if (Input.GetKeyDown(KeyCode.T)) //talk { Debug.DrawRay(transform.position + new Vector3(0, 1, 0), transform.forward * 3, Color.red, 1); RaycastHit hitInfo; if (Physics.Raycast(transform.position + new Vector3(0, 1, 0), transform.forward, out hitInfo, 3)) { Debug.Log(hitInfo.collider.gameObject); InteractiveHumanoid target = hitInfo.collider.gameObject.GetComponent <InteractiveHumanoid>(); if (target != null && !UI.dialogueWindowActive) { foreach (DialogOption option in target.DialogOptions) { UI.AddDialogue(option); } UI.RefreshEndDialogue(); UI.ToggleDialogueWindow(); } } } } if (Input.GetKeyDown(KeyCode.BackQuote)) //open console { Debug.Log("jest!!!"); } if (Input.GetKeyDown(KeyCode.B)) //open stat window { UI.ToggleStatWindow(statsVerbal); } if (Input.GetKeyDown(KeyCode.P)) //view switch { mainCamera.FirstPerson = !mainCamera.FirstPerson; } if (Input.GetKeyDown(KeyCode.I)) { if (!UI.inventoryWindowActive) { RefreshInventoryItems(); /* foreach (InventoryItem item in Inventory) * UI.AddItem(item);*/ } UI.ToggleInventoryWindow(); } transform.Rotate(rotationVector); //rotate character depending on input if (movementVector != Vector3.zero) //move character depending on input { humanAnimator.SetBool("run", true); objectController.Move(movementVector); //treat coordinates as local and transform to global equivalents } else { humanAnimator.SetBool("run", false); } }