private void NormalStateControls() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { RaycastHit hitInfo; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, Mathf.Infinity, ~layerMaskClickGauche) == true) { GameManager.Instance.Ui.ClearActionPanel(); if (hitInfo.transform.gameObject.GetComponentInParent <Keeper>() != null) { Keeper clickedKeeper = hitInfo.transform.gameObject.GetComponentInParent <Keeper>(); if (Input.GetKey(KeyCode.LeftShift)) { if (GameManager.Instance.ListOfSelectedKeepers.Contains(clickedKeeper.getPawnInstance)) { GameManager.Instance.ListOfSelectedKeepers.Remove(clickedKeeper.getPawnInstance); clickedKeeper.IsSelected = false; } else { GameManager.Instance.AddKeeperToSelectedList(clickedKeeper.getPawnInstance); clickedKeeper.IsSelected = true; } } else { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.AddKeeperToSelectedList(clickedKeeper.getPawnInstance); GameManager.Instance.Ui.HideInventoryPanels(); clickedKeeper.IsSelected = true; } if (fTimerDoubleClick > 0 && goPreviousLeftclicked == hitInfo.transform.gameObject) { Camera.main.GetComponent <CameraManager>().UpdateCameraPosition(clickedKeeper.getPawnInstance); goPreviousLeftclicked = null; fTimerDoubleClick = 0; } else { fTimerDoubleClick = fDoubleClickCoolDown; goPreviousLeftclicked = hitInfo.transform.gameObject; } } } else { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.Ui.HideInventoryPanels(); } } } else if (Input.GetMouseButtonDown(1)) { if (!EventSystem.current.IsPointerOverGameObject()) { if (GameManager.Instance.ListOfSelectedKeepers.Count > 0) { RaycastHit hitInfo; // LayerMask layermask = 1 << LayerMask.NameToLayer("TilePortal"); // layermask = ~layermask; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, Mathf.Infinity, ~layerMask) == true) { IngameUI ui = GameManager.Instance.Ui; Cursor.SetCursor(GameManager.Instance.Texture2DUtils.iconeMouseClicked, Vector2.zero, CursorMode.Auto); Invoke("CursorNormalState", 0.5f); Tile tileHit = hitInfo.collider.gameObject.GetComponentInParent <Tile>(); Tile keeperSelectedTile = GameManager.Instance.GetFirstSelectedKeeper().CurrentTile; GameObject clickTarget = hitInfo.collider.gameObject; // Handle click on a ItemInstance if (clickTarget.GetComponent <ItemInstance>() != null) { if (tileHit == keeperSelectedTile) { //To add if we want the keepers to move to the clicked object GameManager.Instance.GoTarget = hitInfo.collider.gameObject.GetComponent <Interactable>(); ui.UpdateActionPanelUIQ(hitInfo.collider.gameObject.GetComponent <ItemInstance>().InteractionImplementer); } } else if (clickTarget.transform.parent != null && clickTarget.transform.parent.GetComponent <ItemInstance>()) { if (tileHit == keeperSelectedTile) { //To add if we want the keepers to move to the clicked object GameManager.Instance.GoTarget = hitInfo.collider.gameObject.GetComponentInParent <Interactable>(); ui.UpdateActionPanelUIQ(hitInfo.collider.gameObject.GetComponentInParent <ItemInstance>().InteractionImplementer); } } // Handle click on a ItemInstance else if (clickTarget.GetComponent <LootInstance>() != null) { if (tileHit == keeperSelectedTile) { GameManager.Instance.GoTarget = hitInfo.collider.gameObject.GetComponent <Interactable>(); ui.UpdateActionPanelUIQ(hitInfo.collider.gameObject.GetComponent <LootInstance>().InteractionImplementer); } } else if (clickTarget.GetComponent <TriggerPanneau>() != null) { if (tileHit == keeperSelectedTile) { GameManager.Instance.GoTarget = clickTarget.GetComponent <Interactable>(); ui.UpdateActionPanelUIQ(clickTarget.GetComponent <Interactable>().Interactions); } } // Handle click on a pawn else if (clickTarget.GetComponentInParent <PawnInstance>() != null) { tileHit = clickTarget.GetComponentInParent <PawnInstance>().CurrentTile; if (tileHit == keeperSelectedTile) { // If click on same keeper, do nothing if (clickTarget.GetComponentInParent <Keeper>() != null) { if (clickTarget.GetComponentInParent <PawnInstance>() == GameManager.Instance.GetFirstSelectedKeeper()) { return; } } if (clickTarget.GetComponentInParent <Escortable>() != null) { clickTarget.GetComponentInParent <Escortable>().UpdateEscortableInteractions(); if (TutoManager.s_instance != null && TutoManager.s_instance.enableTuto && TutoManager.s_instance.PlayingSequence == null && TutoManager.s_instance.GetComponent <SeqAshleyEscort>().AlreadyPlayed == false && TutoManager.s_instance.GetComponent <SeqMultiCharacters>().AlreadyPlayed == true) { TutoManager.s_instance.playSequence(TutoManager.s_instance.GetComponent <SeqAshleyEscort>()); } } GameManager.Instance.GoTarget = clickTarget.GetComponentInParent <Interactable>(); if (clickTarget.GetComponentInParent <Monster>() != null) { //NavMeshAgent agent = GameManager.Instance.GetFirstSelectedKeeper().GetComponent<NavMeshAgent>(); //if (agent != null && agent.isActiveAndEnabled) // agent.SetDestination(clickTarget.transform.position); ui.UpdateActionPanelUIQ(clickTarget.GetComponentInParent <Interactable>().Interactions); } else { ui.UpdateActionPanelUIQ(clickTarget.GetComponentInParent <PawnInstance>().GetComponent <Interactable>().Interactions); } } } else if (hitInfo.collider.gameObject.GetComponent <Arrival>() != null) { if (tileHit == keeperSelectedTile) { GameManager.Instance.GoTarget = clickTarget.GetComponentInParent <Interactable>(); ui.UpdateActionPanelUIQ(clickTarget.GetComponent <Arrival>().InterationImplementer); } } else if (hitInfo.collider.gameObject.GetComponent <TilePassage>() != null && tileHit == keeperSelectedTile) { ui.ClearActionPanel(); TilePassage tp = hitInfo.collider.gameObject.GetComponent <TilePassage>(); if (GameManager.Instance.ListOfSelectedKeepers.Count > 0) { tp.HandleClick(); } } else { ui.ClearActionPanel(); if (tileHit == keeperSelectedTile) { // Move the keeper for (int i = 0; i < GameManager.Instance.ListOfSelectedKeepers.Count; i++) { if (GameManager.Instance.ListOfSelectedKeepers[i].GetComponent <Mortal>().IsAlive&& !GameManager.Instance.ListOfSelectedKeepers[i].GetComponent <AnimatedPawn>().IsMovingBetweenTiles) { GameManager.Instance.ListOfSelectedKeepers[i].GetComponent <AnimatedPawn>().TriggerRotation(hitInfo.point); } } } else { if (GameManager.Instance.GetFirstSelectedKeeper().CurrentTile == null) { Debug.Log("First selected keeper as no current tile, he won't move !!!!"); return; } if (Array.Exists(GameManager.Instance.GetFirstSelectedKeeper().CurrentTile.Neighbors, x => x == tileHit)) { int neighbourIndex = Array.FindIndex(GameManager.Instance.GetFirstSelectedKeeper().CurrentTile.Neighbors, x => x == tileHit); Tile currentTile = GameManager.Instance.GetFirstSelectedKeeper().CurrentTile; TileTrigger tt; TilePassage tp; tt = currentTile.transform.GetChild(0).GetChild(1).GetChild(neighbourIndex).GetComponent <TileTrigger>(); tp = currentTile.transform.GetChild(0).GetChild(1).GetChild(neighbourIndex).GetComponent <TilePassage>(); Vector3 movePosition = Vector3.zero; if (tt != null) { movePosition = tt.transform.position; } if (tp != null) { movePosition = tp.transform.position; } // Move the keeper if (tp != null) { tp.HandleClick(); } } } } } } else { GameManager.Instance.Ui.ClearActionPanel(); } } } else { if (!DebugControls.isDebugModeActive) { if (Input.GetKeyDown(KeyCode.Alpha1) && GameManager.Instance.AllKeepersList.Count > 0) { if (GameManager.Instance.AllKeepersList[0].GetComponent <Mortal>().IsAlive) { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.AddKeeperToSelectedList(GameManager.Instance.AllKeepersList[0]); GameManager.Instance.AllKeepersList[0].GetComponentInParent <Keeper>().IsSelected = true; } } else if (Input.GetKeyDown(KeyCode.Alpha2) && GameManager.Instance.AllKeepersList.Count > 1) { if (GameManager.Instance.AllKeepersList[1].GetComponent <Mortal>().IsAlive) { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.AddKeeperToSelectedList(GameManager.Instance.AllKeepersList[1]); GameManager.Instance.AllKeepersList[1].GetComponentInParent <Keeper>().IsSelected = true; } } else if (Input.GetKeyDown(KeyCode.Alpha3) && GameManager.Instance.AllKeepersList.Count > 2) { if (GameManager.Instance.AllKeepersList[2].GetComponent <Mortal>().IsAlive) { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.AddKeeperToSelectedList(GameManager.Instance.AllKeepersList[2]); GameManager.Instance.AllKeepersList[2].GetComponentInParent <Keeper>().IsSelected = true; } } else if (Input.GetKeyDown(KeyCode.Alpha4) && GameManager.Instance.AllKeepersList.Count > 3) { if (GameManager.Instance.AllKeepersList[3].GetComponent <Mortal>().IsAlive) { GameManager.Instance.ClearListKeeperSelected(); GameManager.Instance.AddKeeperToSelectedList(GameManager.Instance.AllKeepersList[3]); GameManager.Instance.AllKeepersList[3].GetComponentInParent <Keeper>().IsSelected = true; } } } } }
private void SwitchToBattleStateProcess() { // Pause keepers foreach (PawnInstance pi in allKeepersList) { bool mustBeDisabled = false; for (int i = 0; i < currentFighters.Length && i < 3; i++) { if (pi == currentFighters[i]) { mustBeDisabled = true; } } if (mustBeDisabled) { pi.GetComponent <NavMeshAgent>().enabled = false; } else { NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>(); if (currentAgent != null && currentAgent.isActiveAndEnabled) { currentAgent.Stop(); pausedAgents.Add(currentAgent); pi.transform.GetChild(0).gameObject.SetActive(false); disabledModels.Add(pi.transform.GetChild(0).gameObject); if (pi.GetComponent <GlowObjectCmd>() != null) { GlowController.UnregisterObject(pi.GetComponent <GlowObjectCmd>()); unregisteredGlows.Add(pi.GetComponent <GlowObjectCmd>()); } } } pi.GetComponent <Keeper>().ShowSelectedPanelUI(false); ui.ClearActionPanel(); ui.HideInventoryPanels(); } // Pause NPCs // If needed, we should register all PNJ on tiles in TileManager so we can handle AI behaviours when the game paused // For now we'll only deal with the prisoner if (currentFighters[currentFighters.Length - 1].GetComponent <Prisoner>() != null) { NavMeshAgent prisonerAgent = currentFighters[currentFighters.Length - 1].GetComponent <NavMeshAgent>(); if (prisonerAgent != null && prisonerAgent.isActiveAndEnabled) { prisonerAgent.enabled = false; } } else { if (prisonerInstance != null) { NavMeshAgent prisonerAgent = prisonerInstance.GetComponent <NavMeshAgent>(); if (prisonerAgent != null && prisonerAgent.isActiveAndEnabled) { prisonerAgent.Stop(); pausedAgents.Add(prisonerAgent); } } } // Pause monsters foreach (Tile tile in tileManagerReference.MonstersOnTile.Keys) { if (tile != cameraManagerReference.ActiveTile) { List <PawnInstance> monsterList = tileManagerReference.MonstersOnTile[tile]; foreach (PawnInstance pi in monsterList) { NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>(); if (currentAgent != null && currentAgent.isActiveAndEnabled) { currentAgent.Stop(); pausedAgents.Add(currentAgent); } } } else { List <PawnInstance> monsterList = tileManagerReference.MonstersOnTile[tile]; foreach (PawnInstance pi in monsterList) { NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>(); if (currentAgent != null) { pi.GetComponent <AnimatedPawn>().WasAgentActiveBeforeBattle = currentAgent.isActiveAndEnabled; if (currentAgent.isActiveAndEnabled) { currentAgent.enabled = false; } } if (pi.GetComponent <GlowObjectCmd>() != null) { GlowController.RegisterObject(pi.GetComponent <GlowObjectCmd>()); } if (pi.GetComponentInChildren <AggroBehaviour>() != null) { pi.GetComponentInChildren <AggroBehaviour>().gameObject.SetActive(false); } } } } // Mask tile portals Transform tilePortals = currentFighters[0].CurrentTile.transform.GetChild(0).GetChild((int)TilePrefabChildren.PortalTriggers); for (int i = 0; i < tilePortals.childCount; i++) { if (tilePortals.GetChild(i).gameObject.activeSelf) { tilePortalsDisabled.Add(tilePortals.GetChild(i).gameObject); tilePortals.GetChild(i).gameObject.SetActive(false); } } // Mask quest reminder button gameScreens.transform.GetChild(0).GetChild((int)IngameScreensEnum.QuestReminderButton).gameObject.SetActive(false); Transform tileModel = ActiveTile.transform.GetChild(0).GetChild((int)TilePrefabChildren.Model); for (int i = 0; i < tileModel.childCount; i++) { if (tileModel.GetChild(i).name.Equals("Center")) { tileModel.GetChild(i).gameObject.SetActive(false); disabledModels.Add(tileModel.GetChild(i).gameObject); } } PawnInstance[] toDisable = ActiveTile.GetComponentsInChildren <PawnInstance>(); foreach (PawnInstance pi in toDisable) { if (pi.GetComponent <Monster>() == null) { pi.gameObject.SetActive(false); disabledModels.Add(pi.gameObject); } } LootInstance[] lootToDisable = ActiveTile.GetComponentsInChildren <LootInstance>(); foreach (LootInstance li in lootToDisable) { li.gameObject.SetActive(false); disabledModels.Add(li.gameObject); } // Make escortable disappear if (TileManager.Instance.EscortablesOnTile.ContainsKey(ActiveTile)) { foreach (PawnInstance pi in TileManager.Instance.EscortablesOnTile[ActiveTile]) { pi.gameObject.SetActive(false); disabledModels.Add(pi.gameObject); } } // Hide item instance for (int i = 1; i < ActiveTile.transform.childCount; i++) { ItemInstance curItem = ActiveTile.transform.GetChild(i).GetComponentInChildren <ItemInstance>(); if (curItem != null) { curItem.transform.parent.gameObject.SetActive(false); disabledModels.Add(curItem.transform.parent.gameObject); } } Ui.GoActionPanelQ.transform.parent.SetParent(Ui.transform); }