public AudioClip interactSFX, contactSFX; // Sound effects to play on an NPC when they perform interaction and contact behaviors. // Set up the Singleton design pattern. private void Awake() { if (instance == null) { instance = this; } }
public void AddNewTarget(Transform tr) { NPC_Manager npc = tr.GetComponent <NPC_Manager>(); if (npc != null) { if (!npc.IsDead()) { if (!targetList.Contains(tr)) { targetList.Add(tr); } } } if (tr.gameObject.CompareTag("Player")) { if (!Managers.player.IsDead()) { if (!targetList.Contains(tr)) { targetList.Add(tr); } } } }
private void OnDestroy() { if (this == _instance) { _instance = null; } }
void Start() { // Get the NPC manager from the parent. _npcManager = _parent.GetComponent <NPC_Manager>(); // Set that there is an Action Key Dialogue on here. _npcManager.NPCState.HasActionKeyDialogue = true; _npcManager.NPCState.ActionKeyDialogue = this; // Set the start of the dialogueIndex. dialogueIndex = 0; }
void Start() { // Set the index to 0 for the start. _locationIndex = 0; // Grab the transform for more efficiency. _transform = gameObject.transform; // Grab the manager of this gameobject. _npcManager = GetComponent <NPC_Manager>(); // Lets start moving! StartCoroutine(GoToNextLocation()); }
void SetInitialReferences() { npcMaster = GetComponent <NPC_Manager>(); if (GetComponent <NavMeshAgent>() != null) { myNavMeshAgent = GetComponent <NavMeshAgent>(); } checkRate = Random.Range(0.3f, 0.4f); myTransform = transform; }
private void Awake() { if (_instance != null && _instance != this) { Debug.LogWarning("Attempted to Instantiate multiple NPC_Manager objects in one scene!"); Destroy(this.gameObject); } else { _instance = this; } }
void SetInitialReferences() { enemyMaster = GetComponent <NPC_Manager>(); myTransform = transform; if (head == null) { head = myTransform; } checkRate = Random.Range(0.8f, 1.2f); }
//Выполнить все дейсвтия после нажатия на варианте диалога void ExecuteDialogOptionAction(int optionNum) { for (int i = 0; i < nodes[currentNode].options[optionNum].actions.Length; i++) { DialogAction currentAction = nodes[currentNode].options[optionNum].actions[i].action; if (currentAction == DialogAction.ACTIVATE_QUEST) { Managers.questMgr.ActivateQuest(nodes[currentNode].options[optionNum].actions[i].questID); } else if (currentAction == DialogAction.COMPLETE_QUEST) { Managers.questMgr.CompleteQuest(nodes[currentNode].options[optionNum].actions[i].questID); } else if (currentAction == DialogAction.RETURN_ITEM) { //Передать предмет NPC NPC_Manager thisNpc = gameObject.GetComponent <NPC_Manager>(); if (thisNpc != null) { thisNpc.gameItemList.Add(nodes[currentNode].options[optionNum].actions[i].item); } Managers.inventory.RemoveItemFromInventory(nodes[currentNode].options[optionNum].actions[i].item, false); } } //=== if (!nodes[currentNode].options[optionNum].endOption) { nodes[currentNode].options[optionNum].isActive = false;//Сделать неактивным вариант диалога currentNode = nodes[currentNode].options[optionNum].toNode; UpdateDialogButton(); Managers.textDialogMgr.TextDialogWindow.SetActive(true); Managers.textDialogMgr.FullTextDialog.SetActive(false); } else//Завершение диалога { Managers.textDialogMgr.TextDialogWindow.SetActive(false); Managers.textDialogMgr.FullTextDialog.SetActive(false); NPC_Manager npc = gameObject.GetComponent <NPC_Manager>(); if (npc != null) { npc.EndNpcDialogue(); } } }
//Проверить условия для появления варианта диалога bool CheckDialogOptionConditions(int optionNum) { bool isActive = true; for (int i = 0; i < nodes[currentNode].options[optionNum].conditions.Length; i++) { ActivationCondition currentCondition = nodes[currentNode].options[optionNum].conditions[i].condition; bool bValue; switch (currentCondition) { case ActivationCondition.QUEST_IS_ACTIVE: bValue = Managers.questMgr.QuestIsActive(nodes[currentNode].options[optionNum].conditions[i].questID); isActive = isActive & bValue; break; case ActivationCondition.HAVE_AN_ITEM: bValue = Managers.inventory.HaveAnItem(nodes[currentNode].options[optionNum].conditions[i].requiredItem); isActive = isActive & bValue; break; case ActivationCondition.NPC_IS_DEAD: bValue = false; NPC_Manager npc = nodes[currentNode].options[optionNum].conditions[i].npc; if (npc != null) { bValue = npc.IsDead(); } isActive = isActive & bValue; break; case ActivationCondition.QUEST_IS_COMPLETED: bValue = Managers.questMgr.QuestIsComleted(nodes[currentNode].options[optionNum].conditions[i].questID); isActive = isActive & bValue; break; } } return(isActive); }
// Update is called once per frame void Update() { if (Managers.player.moveBlock) { return; } if (selectedObject != null) { IInteractiveObject iObject = selectedObject.gameObject.GetComponent <IInteractiveObject>(); if (iObject != null) { iObject.HideObjectName(); } } selectedObject = null; if (Managers.player.battleMode) { return; //Нельзя в боевом режиме собирать предметы или обращаться к НПС } float prevDotValue = 0; //Предыдущее значение скалярного произведения Collider[] hitColliders = Physics.OverlapSphere(transform.position, 2.5f); //Обработка выделения ближайшего объекта foreach (Collider hitCollider in hitColliders) { InteractiveObject laObject = hitCollider.GetComponent <InteractiveObject>(); if (laObject != null) { Vector3 dis = laObject.transform.position - transform.position; //Debug.Log("Dot select" + Vector3.Dot(transform.forward, dis.normalized)); if (Vector3.Dot(transform.forward, dis.normalized) > 0.5) { //Из всех предметов которы расположены перед персонажем выбираем тот на которого ближе смотрит камера Vector3 camLookForward = new Vector3(myCam.transform.forward.x, 0, myCam.transform.forward.z); if (Vector3.Dot(camLookForward, dis.normalized) > prevDotValue) { selectedObject = laObject; prevDotValue = Vector3.Dot(camLookForward, dis.normalized); } } } } //Отображение имени объекта if (selectedObject != null) { IInteractiveObject iObject = selectedObject.gameObject.GetComponent <IInteractiveObject>(); if (iObject != null) { iObject.ShowObjectName(); } } //Обарботка нажатия на выделенном объекте (выделенным объектом может быть игровой перс, игр предмет или механизм) //- Добавление в инвентарь if (selectedObject != null && Input.GetMouseButtonDown(0) && Managers.inventory.inventoryPanelWindow.activeSelf == false) { GameItem _item = selectedObject.gameObject.GetComponent <GameItem>(); if (_item != null) { StartCoroutine(AddItem(_item)); } NPC_Manager _npc = selectedObject.gameObject.GetComponent <NPC_Manager>(); if (_npc != null) { _npc.ExploreNpc(); } } }
IEnumerator CheckBattleModeCondition() { while (true) { yield return(null); Collider[] hitColliders = Physics.OverlapSphere(transform.position, 15f); //Проверить всех НПС вокруг foreach (Collider hitCollider in hitColliders) { NPC_Manager npc = hitCollider.gameObject.GetComponent <NPC_Manager>(); BattleMode bm = hitCollider.gameObject.GetComponent <BattleMode>(); if (npc == null && bm == null) { continue; } if (!thisNPC.friendList.Contains(hitCollider.gameObject.tag)) { Vector3 dist = hitCollider.gameObject.transform.position - transform.position; //Проверяем видим ли мы игровой объект float angle = Mathf.Abs(Vector3.Angle(gameObject.transform.forward, dist.normalized));//Угол между направлением взгляда и персонажем if (angle < 75) { RaycastHit hitInfo; if (Physics.Linecast(transform.position + transform.up, hitCollider.gameObject.transform.position + hitCollider.gameObject.transform.up, out hitInfo)) { if (hitInfo.transform.gameObject == hitCollider.gameObject) { AddNewTarget(hitCollider.gameObject.transform); } } } } } //Выбираем текущую цель if (targetList.Count > 0) { if (currentTarget == null) { // ============= Первая установка цели (Начало боя) ================= currentTarget = targetList[0]; thisNPC.battleMode = true; Debug.Log("currentTarget = NULL "); StopAllCoroutines(); StartState(AI_STATE.BATTLE_STATE); } else { //============== В течении боя ====================== float dist = Vector3.Distance(transform.position, currentTarget.position); NPC_Manager npc = currentTarget.GetComponent <NPC_Manager>(); if (npc != null) { if (npc.IsDead() || dist > 25) { if (targetList.Remove(currentTarget)) { StopAllCoroutines(); currentTarget = null; if (targetList.Count > 0) { currentTarget = targetList[0]; StartState(AI_STATE.BATTLE_STATE); } else { thisNPC.battleMode = false; //StartCurrentState(); StartCoroutine(OffBattleModeState());//Переход к мирному состоянию } yield break; } } } if (currentTarget != null) { if (currentTarget.gameObject.CompareTag("Player")) { if (Managers.player.IsDead() || dist > 25) { Debug.Log("Player is Dead , target count = " + targetList.Count); if (targetList.Remove(currentTarget)) { StopAllCoroutines(); currentTarget = null; if (targetList.Count > 0) { currentTarget = targetList[0]; StartState(AI_STATE.BATTLE_STATE); } else { thisNPC.battleMode = false; StartCoroutine(OffBattleModeState());//Переход к мирному состоянию } yield break; } } } } } } } }
// Update is called once per frame void Update() { if (selectedObject != null) { selectedObject.bDrwaHpBar = false; //IInteractiveObject iObject = selectedObject.gameObject.GetComponent<IInteractiveObject>(); //if (iObject != null) iObject.HideObjectName(); } selectedObject = null; //--------------------- if (Managers.player.battleMode) { if (Input.GetKeyDown(KeyCode.Mouse0) && attack == false)//Нажатие левой кнопки мыши { StartCoroutine(Attack()); } //====================================== float prevDotValue = 0;//Предыдущее значение скалярного произведения Collider[] hitColliders = Physics.OverlapSphere(transform.position, 12.0f); //Обработка выделения ближайшего объекта foreach (Collider hitCollider in hitColliders) { NPC_Manager enemyPlayer = hitCollider.GetComponent <NPC_Manager>(); if (enemyPlayer != null && !enemyPlayer.IsDead()) { Vector3 dis = enemyPlayer.transform.position - transform.position; //if (Vector3.Dot(transform.forward, dis.normalized) > 0.5) //{ //Из всех предметов которы расположены перед персонажем выбираем тот на которого ближе смотрит камера Vector3 camLookForward = new Vector3(myCam.transform.forward.x, 0, myCam.transform.forward.z); if (Vector3.Dot(camLookForward, dis.normalized) > prevDotValue) { selectedObject = enemyPlayer; prevDotValue = Vector3.Dot(camLookForward, dis.normalized); } //} } } //Отображение хп бара объекта if (selectedObject != null) { selectedObject.bDrwaHpBar = true; //IInteractiveObject iObject = selectedObject.gameObject.GetComponent<IInteractiveObject>(); //if (iObject != null) iObject.ShowObjectName(); } } }
private void OnWeaponCollision(Collider other) { if (thisPlayerWeapon) { NPC_Manager npcDamage = other.GetComponent <NPC_Manager>(); if (npcDamage != null) { Vector3 dist = npcDamage.transform.position - Managers.player.playerT.position; if (!damagaList.Contains(npcDamage) && (Mathf.Rad2Deg * Mathf.Acos(Vector3.Dot(Managers.player.playerT.forward, dist.normalized))) < 55) { if (npcDamage.IsDead()) { return; } npcDamage.GetDamage(Managers.player.currentWeapon.physicalDamage, Managers.player.playerT); damagaList.Add(npcDamage); AudioSource aSrc = npcDamage.gameObject.GetComponent <AudioSource>(); if (aSrc != null) { aSrc.clip = npcDamage.damageClip; aSrc.Play(); } } } } else if (npc != null) { if (npc.IsDead()) { return; } //Обработка нанесения урона нашему игроку if (other.gameObject.tag == "Player") { Vector3 dist = other.transform.position - npc.transform.position; if (!damagaListPM.Contains(Managers.player) && (Mathf.Rad2Deg * Mathf.Acos(Vector3.Dot(npc.transform.forward, dist.normalized))) < 55) { //if (npc.friendList.Contains(other.tag)) return; Managers.player.GetDamage(npc.currentWeapon.physicalDamage); damagaListPM.Add(Managers.player); AudioSource aSrc = Managers.player.playerT.gameObject.GetComponent <AudioSource>(); if (aSrc != null) { aSrc.clip = Managers.player.damageClip; aSrc.Play(); } } } //Обработка нанесения урона NPC ===> NPC NPC_Manager npcDamage = other.GetComponent <NPC_Manager>(); if (npcDamage != null) { Vector3 dist = npcDamage.gameObject.transform.position - npc.gameObject.transform.position;; if (!damagaList.Contains(npcDamage) && (Mathf.Rad2Deg * Mathf.Acos(Vector3.Dot(npc.gameObject.transform.forward, dist.normalized))) < 55) { if (npc.friendList.Contains(npcDamage.tag) || npc.IsDead()) { return; } npcDamage.GetDamage(npc.currentWeapon.physicalDamage, npc.gameObject.transform); damagaList.Add(npcDamage); AudioSource aSrc = npcDamage.gameObject.GetComponent <AudioSource>(); if (aSrc != null) { aSrc.clip = npcDamage.damageClip; aSrc.Play(); } } } } }