/// <summary> /// check to see if any characters are pulling in nearby characters in for combat /// </summary> /// <param name="colliders"></param> void CheckCollider(Collider2D[] colliders) { foreach (Collider2D c in colliders) { if (charactersChecked.Contains(c.gameObject)) { continue; } if (c.gameObject.layer == 8) //npc { NPCInfo npcInfo = c.gameObject.GetComponent <NPCInfo>(); if (!(npcInfo.inCombat || npcInfo.combatCooldown)) { //have them join combat and determine later if they will run if (!charactersRemovedFromCombat.Contains(c.gameObject)) { npcInfo.EnterCombat(); charactersInCombat.Add(c.gameObject); charactersToCheck.Add(c.gameObject); } } } else //player { PlayerInfo playerInfo = c.gameObject.GetComponent <PlayerInfo>(); if (!playerInfo.inCombat) { playerInfo.EnterCombat(); CombatManager.ins.SetPlayerHandler(this.gameObject); charactersInCombat.Add(c.gameObject); charactersToCheck.Add(c.gameObject); } } } //end of adding to combat }
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; } } } }