/// <summary> /// Reset values and exit the dialogue /// </summary> public void EndSpeech() { if (npcSpeech == null) { return; } npcSpeech.ResetSetNumber(); npcSpeech.currentLine = 0; player.GetComponent <PlayerMovementScript>().CanPlayerMove = true; npcInfo.InitPosition(); npcInfo.StopTalk(); npcSpeech = null; pInfo = null; npcInfo = null; speechOutline.gameObject.SetActive(false); choicePanel.gameObject.SetActive(false); speechPanel.gameObject.SetActive(false); StopCoroutine(typingCoroutine); speechText.text = ""; nameText.text = ""; textToDisplay = ""; inShop = false; inChoice = false; hasStartedTalking = false; hasFinishedTalking = false; }
private void OnTriggerExit2D(Collider2D collision) { //return if collision is not with npc because that is what we are checking for /*might need to check to see if the npc is same one we entered with, but prob not since the detector * can only hit one at a time */ if (collision.gameObject.tag.ToString() != "NPC") { return; } //reset the talking npc once we leave, incase it was premature if (isTalking) { isTalking = false; SpeechManager.ins.EndSpeech(); } canTalk = false; targetNPC = null; if (speech != null) { speech.IsPlayerInRange = false; speech = null; } }
void Start() { isTalkable = npc.isTalkable; characterName = npc.characterName; characterAge = npc.characterAge; isKeyNPC = npc.isKeyNPC; isTalkable = npc.isTalkable; isMerchant = npc.isMerchant; hasQuests = npc.hasQuests; faction = npc.faction; speech = GetComponent <NPCSpeechHolder>(); sr = GetComponent <SpriteRenderer>(); polyNav = GetComponent <PolyNav.PolyNavAgent>(); rb = GetComponent <Rigidbody2D>(); cs = GetComponent <CombatScript>(); InitPosition(); speed = defaultSpeed; runSpeed = defaultRunSpeed; }
void OnTriggerStay2D(Collider2D collision) { //return if collision is not with npc because that is what we are checking for if (collision.gameObject.tag.ToString() != "NPC") { return; } //check to see if we can talk, if we can, set the variables if (collision.gameObject.GetComponent <NPCInfo>().isTalkable) { speech = collision.gameObject.GetComponent <NPCSpeechHolder>(); speech.IsPlayerInRange = true; targetNPC = collision.gameObject; canTalk = true; } else { canTalk = false; } }
public void LoadNPCSceneData(List <NPCData> apc) { allNPCData = apc; foreach (GameObject c in allNPCsInScene) { if (c.tag.ToString() != "NPC") { continue; } foreach (NPCData data in allNPCData) { if (c.GetComponent <NPCInfo>().id == data.id) { NPCInfo a = c.GetComponent <NPCInfo>(); Stats s = c.GetComponent <Stats>(); NPCSpeechHolder h = c.GetComponent <NPCSpeechHolder>(); CombatScript cs = c.GetComponent <CombatScript>(); c.transform.position = new Vector3(data.x, data.y, 0); a.UpdateColliders(); a.direction = (CharacterInfo.Direction)data.direction; a.state = (CharacterInfo.MovementState)data.state; cs.ProgressI = data.castProgress; if (data.selectedSpellID != -1) { cs.selectedSpell = SpellManagerScript.ins.GetSpellFromID(data.selectedSpellID); } else { if (cs.spellCoroutine != null) { cs.StopCoroutine(cs.spellCoroutine); } } cs.state = (CombatScript.CombatState)data.combatState; cs.energyState = (CombatScript.EnergyState)data.energyState; a.id = data.id; a.gameObject.SetActive(data.active); a.canMove = data.canMove; if (a.inCombat) { cs.AIEndCombat(); } else { a.EnterCombat(); } a.inCombat = data.inCombat; a.SetStoppingDistance(); a.currentHealth = data.currentHealth; a.currentStamina = data.currentStamina; a.merchantMoney = data.merchantMoney; a.combatCooldown = data.combatCooldown; a.timeStoppedCombat = data.cooldown; s.intuition = data.intuition; s.intelligence = data.intelligence; s.strength = data.strength; s.charisma = data.charisma; s.precision = data.precision; s.dexterity = data.dexterity; s.perception = data.perception; s.attitude = data.attitude; s.fear = data.fear; s.danger = data.danger; s.spirituality = data.spirituality; h.currentLine = data.currentLine; h.currentSet = data.currentSet; a.merchantInventory.maxSize = data.maxSize; a.merchantInventory.ClearInventory(); foreach (InventorySlotData invSlotData in data.inventory) { a.merchantInventory.AddItemCount(ItemManagerScript.ins.GetItemFromID(invSlotData.id), invSlotData.count); } a.movementType = (NPC.MovementType)data.moveType; a.destination = new Vector3(data.areaPointX, data.areaPointY, 0); foreach (GameObject p in new List <GameObject>(a.patrolPoints)) { if (p.transform.position.x != data.patrolPointX || p.transform.position.y != data.patrolPointY) { a.patrolPoints.Remove(p); a.patrolPoints.Add(p); } else { if (!a.inCombat) { if (a.movementType == NPC.MovementType.PATROL) { a.polyNav.SetDestination(a.patrolPoints[0].transform.position); } } break; } } if (a.isWaiting) { //a.polyNav.Stop(); if (a.waitCoroutine != null) { a.StopCoroutine(a.waitCoroutine); } } a.isWaiting = data.isWaiting; a.isMoving = data.isMoving; if (a.isWaiting) { a.polyNav.Stop(); switch (a.movementType) { case NPC.MovementType.AREA: a.waitCoroutine = a.StartCoroutine(a.StartWaitingArea()); break; case NPC.MovementType.PATROL: a.waitCoroutine = a.StartCoroutine(a.StartWaitingPatrol()); break; default: break; } } break; } } } }
public List <NPCData> CollectCurrentData() { foreach (GameObject c in allNPCsInScene) { if (c.tag.ToString() != "NPC") { continue; } NPCData temp = new NPCData(); NPCInfo a = c.GetComponent <NPCInfo>(); Stats s = c.GetComponent <Stats>(); NPCSpeechHolder h = c.GetComponent <NPCSpeechHolder>(); CombatScript cs = c.GetComponent <CombatScript>(); temp.x = c.transform.position.x; temp.y = c.transform.position.y; temp.direction = (int)a.direction; temp.state = (int)a.state; temp.id = a.id; temp.active = c.gameObject.activeSelf; temp.canMove = a.canMove; temp.inCombat = a.inCombat; if (cs.selectedSpell != null) { temp.selectedSpellID = cs.selectedSpell.ID; } else { temp.selectedSpellID = -1; } temp.castProgress = cs.ProgressI; temp.combatState = (int)cs.state; temp.energyState = (int)cs.energyState; temp.currentHealth = a.currentHealth; temp.currentStamina = a.currentStamina; temp.merchantMoney = a.merchantMoney; temp.combatCooldown = a.combatCooldown; temp.cooldown = a.timeStoppedCombat; temp.intuition = s.intuition; temp.intelligence = s.intelligence; temp.strength = s.strength; temp.charisma = s.charisma; temp.precision = s.precision; temp.dexterity = s.dexterity; temp.perception = s.perception; temp.attitude = s.attitude; temp.fear = s.fear; temp.danger = s.danger; temp.spirituality = s.spirituality; temp.currentLine = h.currentLine; temp.currentSet = h.currentSet; temp.moveType = (int)a.movementType; temp.areaPointX = a.destination.x; temp.areaPointY = a.destination.y; temp.isWaiting = a.isWaiting; temp.isMoving = a.isMoving; if (a.patrolPoints.Count > 0) { temp.hasPatrol = true; temp.patrolPointX = a.patrolPoints[0].transform.position.x; temp.patrolPointY = a.patrolPoints[0].transform.position.y; } else { temp.hasPatrol = false; temp.patrolPointX = 0; temp.patrolPointY = 0; } temp.inventory = new List <InventorySlotData>(); foreach (Inventory.InventorySlot invSlot in a.merchantInventory.inventory) { InventorySlotData invSlotData = new InventorySlotData(); invSlotData.id = invSlot.item.ID; invSlotData.count = invSlot.count; temp.inventory.Add(invSlotData); } temp.maxSize = a.merchantInventory.maxSize; AddToData(temp); } return(allNPCData); }
/// <summary> /// called when the player hits space (either to enter dialogue, skip text, or see next line) /// </summary> /// <param name="player"></param> /// <param name="npc"></param> public void Speak(GameObject player, GameObject npc) { this.player = player; //set player this.npc = npc; //set actor/npc if (npcSpeech == null || pInfo == null || npcInfo == null) //get components if they are null (meaning this is the first line) { npcSpeech = npc.GetComponent <NPCSpeechHolder>(); pInfo = player.GetComponent <PlayerInfo>(); npcInfo = npc.GetComponent <NPCInfo>(); } //return if we are in the shop //useful for if we want to have the merchant talk after buying and selling if (inShop) { return; } //if not in shop, then we are either in a choice or we are in normal dialogue //either way, we need the speechOutline active speechOutline.gameObject.SetActive(true); //if we are in a choice, return so we don't mess anything up if (inChoice) { return; } //if in normal dialogue, that means we need the current line to push out NPCSpeechHolder.Dialogue dialogue = npcSpeech.Speak(); //checks to see if the first line of dialogue has been spoken if (!hasStartedTalking) { hasStartedTalking = true; player.GetComponent <PlayerMovementScript>().CanPlayerMove = false; //disable player movement DoDialogue(dialogue); //prints dialogue } else if (!hasFinishedTalking) //we havent finished dialogue, so finish it { hasFinishedTalking = true; FinishSpeech(); //print full text } else //this means that the current dialogue is done and we can move onto the next line { hasFinishedTalking = false; //checks to see if the current dialogue does not open a shop //if it does, this wont run and the shop will open from this line if (dialogue.checkQuestCondition) { changedQuestDialoguePath = true; if (CheckQuest(dialogue)) { npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForComplete); } else { npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForInProgress); } } else { changedQuestDialoguePath = false; } GiveQuest(dialogue); if (!CheckShop(dialogue)) { //check to see if we can continue talking (reached the last line) and move current dialogue to next one bool IsFinished = npcSpeech.UpdateCurrentLine(); dialogue = npcSpeech.Speak(); //get next line if (!IsFinished || changedQuestDialoguePath) //if not finished, print next line { DoDialogue(dialogue); } else //if we are finished, end the dialogue { EndSpeech(); } } } }