public void WakeUpEnemy(RoamingNPC roamingNpc) { if (roamingNpc.sleeping) //wake up enemy { roamingNpc.WakeUp(); // code already exists in the the enemy } roamingNpc.attacked = true; roamingNpc._x = roamingNpc.howLongWillFololwInvisiblepLayer; }
private bool AttackHits(RoamingNPC npc) { float roll = GetRoll(); if (roll < .25f) { return(false); } else { return((playerStats.__dexterity - npc.dex) >= 3); } }
public override void Calculate(RoamingNPC t) { if (t.rootDuration > 0) { t.rootDuration--; } else if (t.rooted) { t.rooted = false; } if (t.sleeping) { return; } if (!t.gameObject.transform.parent.gameObject.activeSelf) { return; } t.CurrentTarget = t.playerStats; t.LastKnownTargetPos = t.playerStats.pos; t.TriggerEffectTasks(); if (t.CurrentTarget != null && t.CurrentTarget.currHp == 0) { t.CurrentTarget = null; } if (t.CurrentTarget != null) { if (t.runCounter > 0) { Vector2Int runCell = t.__position + t.runDirection; t.runCounter--; MoveTo(t, runCell.x, runCell.y); } else { t.path = null; t.path = AStar.CalculatePathNoCollisions(t.__position, t.CurrentTarget.pos); MoveTo(t, t.path[0].x, t.path[0].y); } } }
private static void DealDamageToEnemy(RoamingNPC npc, int damage) { if (npc.sleeping) { PlayerMovement.playerMovement.WakeUpEnemy(npc); npc.TakeDamage(Mathf.FloorToInt(damage * PlayerMovement.playerMovement.sleepingDamage), ItemScriptableObject.damageType.normal); GameManager.manager.UpdateMessages($"You dealt <color=red>{damage}</color> damage to <color=#{ColorUtility.ToHtmlStringRGB(npc.EnemyColor)}>{npc.EnemyName}</color>"); } else { npc._x = npc.howLongWillFololwInvisiblepLayer; npc.TakeDamage(damage, ItemScriptableObject.damageType.normal); GameManager.manager.UpdateMessages($"You dealt <color=red>{damage}</color> damage to <color=#{ColorUtility.ToHtmlStringRGB(npc.EnemyColor)}>{npc.EnemyName}</color>"); } }
void MoveTo(RoamingNPC t, int x, int y) { try { t.Stun(0); if (t.CheckStun()) { return; } if (Random.Range(1, 20) <= 3) { float randomMessage = Random.Range(0, 1f); if (randomMessage <= 0.25f) { GameManager.manager.UpdateMessages("You hear a quiet chuckle..."); } else if (randomMessage <= .5f) { GameManager.manager.UpdateMessages("You hear a soft, child's voice utter unintelligible words..."); } else if (randomMessage <= 0.75f) { GameManager.manager.UpdateMessages("Hafh... ya..."); } } if (MapManager.map[x, y].hasPlayer) { t.runCounter = 20; t.runDirection = t.__position - MapManager.playerPos; DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); return; } else if ((MapManager.map[x, y].enemy == null || MapManager.map[x, y].enemy.GetComponent <RoamingNPC>().enemySO == t.enemySO) && !t.rooted) { MapManager.map[t.__position.x, t.__position.y].letter = ""; MapManager.map[t.__position.x, t.__position.y].enemy = null; MapManager.map[t.__position.x, t.__position.y].timeColor = new Color(0, 0, 0); t.__position = new Vector2Int(x, y); if (!t.isInvisible) { MapManager.map[x, y].letter = t.EnemySymbol; } MapManager.map[x, y].enemy = t.gameObject; MapManager.map[x, y].timeColor = t.EnemyColor; DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); return; } } catch { } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); }
public override void Calculate(RoamingNPC t) { if (t.rootDuration > 0) { t.rootDuration--; } else if (t.rooted) { t.rooted = false; } if (t.enemySO._Behaviour != EnemiesScriptableObject.E_behaviour.npc) { if (t.sleeping) { int distance = Mathf.Max(Mathf.Abs(PlayerMovement.playerMovement.position.x - t.__position.x), Mathf.Abs(PlayerMovement.playerMovement.position.y - t.__position.y)); if (distance < 7) { t.sleeping = false; } else { //Debug.Log("I am sleeping"); return; } } if (!t.gameObject.transform.parent.gameObject.activeSelf) { return; } t.TriggerEffectTasks(); bool searchEnemy = true; if (t.Board.ContainsKey("Target")) { if (t.Board["Target"] != null && t.Board["Target"] is RoamingNPC) { //Debug.Log("Has Target"); RoamingNPC testNPC = (RoamingNPC)t.Board["Target"]; if ((testNPC == null) || Vector2Int.Distance(PlayerMovement.playerMovement.position, testNPC.__position) > 5 || testNPC.gameObject == null) { t.Board["Target"] = null; } else { searchEnemy = false; } } } if (searchEnemy) { //Debug.Log("Has to search enemy"); Vector2Int enemyPos = new Vector2Int(-100, -100); float minDis = 10000; bool found = false; foreach (Vector2Int pos in FoV.GetEnemyFoV(t.__position)) { try { int dis = Mathf.Max(Mathf.Abs(PlayerMovement.playerMovement.position.x - pos.x), Mathf.Abs(PlayerMovement.playerMovement.position.y - pos.y)); if (MapManager.map[pos.x, pos.y].enemy != null && MapManager.map[pos.x, pos.y].enemy != t.gameObject && MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>().enemySO.MyTurnAI != t.enemySO.MyTurnAI && dis <= 4) { if (dis < minDis) { minDis = dis; enemyPos = pos; found = true; } } } catch { } } if (found) { //Debug.Log("Found enemy"); t.Board["Target"] = MapManager.map[enemyPos.x, enemyPos.y].enemy.GetComponent <RoamingNPC>(); } } if (t.Board.ContainsKey("Target")) { //Debug.Log("Has enemy missing: " + (t.Board["Target"] == null)); } if (t.Board.ContainsKey("Target") && t.Board["Target"] != null && t.Board["Target"] is RoamingNPC npc) { //Debug.Log("Target aquired"); int distance = Mathf.Max(Mathf.Abs(npc.__position.x - t.__position.x), Mathf.Abs(npc.__position.y - t.__position.y)); // move to target and attack var att = GetAttack(t); if (att.InRange(t.__position, npc.pos)) { att.Calculate((t, npc)); return; } else { t.path = null; t.path = AStar.CalculatePath(t.__position, npc.__position); Debug.Log(t.path.Count); if (!(PlayerMovement.playerMovement.position == t.path[0] || PlayerMovement.playerMovement.position == t.path[1])) { // Debug.Log("Move to enemy"); t.MoveTo(t.path[0].x, t.path[0].y); return; } } } // move to player // check if next to player int pDistance = Mathf.Max(Mathf.Abs(PlayerMovement.playerMovement.position.x - t.__position.x), Mathf.Abs(PlayerMovement.playerMovement.position.y - t.__position.y)); //Debug.Log(pDistance); if (pDistance == 1) { // we are too close Vector2Int diff = t.__position - PlayerMovement.playerMovement.position; // we move away from the player if (MapUtility.IsMoveable(t.__position.x + diff.x, t.__position.y + diff.y)) { t.MoveTo(t.__position.x + diff.x, t.__position.y + diff.y); } else { // find another way Vector2Int[] alternatives = MapUtility.Box1 .Copy() .Check((pos) => MapUtility.IsMoveable(pos) && MapUtility.MoveDistance(pos, PlayerMovement.playerMovement.position) == 2); if (alternatives.Length > 0) { Vector2Int target = alternatives.GetRandom(); t.MoveTo(target.x, target.y); } } } else { // check how far away // if far away follow if (pDistance > 2) { t.path = null; //Debug.Log("Follow"); t.path = AStar.CalculatePath(t.__position, PlayerMovement.playerMovement.position); //Debug.Log(t.path.Count); t.MoveTo(t.path[0].x, t.path[0].y); } else { // else go random Vector2Int[] alternatives = MapUtility.Box1 .Copy().Combine(MapUtility.Origin.Copy()) .MoveCenter(t.__position) .Check((pos) => MapUtility.IsMoveable(pos) && MapUtility.MoveDistance(pos, PlayerMovement.playerMovement.position) > 1); if (alternatives.Length > 0) { Vector2Int target = alternatives.GetRandom(); t.MoveTo(target.x, target.y); } } } } }
private static void MissEnemyWakeUp(RoamingNPC npc) { GameManager.manager.UpdateMessages("You missed!"); PlayerMovement.playerMovement.WakeUpEnemy(npc); }
public override void Calculate(RoamingNPC t) { if (t.rootDuration > 0) { t.rootDuration--; } else if (t.rooted) { t.rooted = false; } //t.playerDetected = false; if (t.sleeping) { return; } if (!t.gameObject.transform.parent.gameObject.activeSelf) { return; } t.TriggerEffectTasks(); if (t.CurrentTarget != null && t.CurrentTarget.currHp == 0) { t.CurrentTarget = null; } // check for out of sight enemy if (!(t.CurrentTarget == null)) { if (!FoV.InLineOfSight(t.pos, t.CurrentTarget.pos)) { // out of sight out of mind i guess t.LastKnownTargetPos = t.CurrentTarget.pos; t.CurrentTarget = null; // TODO: make enemy run to last known position } } // check if current target is still valid if (!(t.CurrentTarget == null)) { // we are targeting something // range here if (MapUtility.MoveDistance(t.pos, t.CurrentTarget.pos) == 1) { // the target is in attackrange so we dont change anything } else { // target may be running away. we are looking at other potential targets that are near us if (t.RetailiationList.Count > 0) { // we have recently been attacked by somebody var alt = t.RetailiationList.ToArray().Check((u) => MapUtility.MoveDistance(u.pos, t.pos) == 1); if (alt.Length > 0) { t.CurrentTarget = alt.GetRandom(); } } } } else { // look for possible target var view = FoV.GetEnemyFoV(t.__position).ToArray().Check((p) => MapManager.map[p.x, p.y].hasPlayer || MapManager.map[p.x, p.y].enemy != null); if (view.Length > 0) { List <IUnit> possibleTargets = new List <IUnit>(); IUnit nt = null; foreach (var pos in view) { if (MapManager.map[pos.x, pos.y].enemy != null && MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>().enemySO.MyTurnAI is HelperTurnBehaviour) { // we found a doggo to attack if (nt == null) { nt = MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>(); t.LastKnownTargetPos = nt.pos; } else { if (MapUtility.MoveDistance(t.pos, nt.pos) > MapUtility.MoveDistance(t.pos, pos)) { nt = MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>(); t.LastKnownTargetPos = nt.pos; } } } if (MapManager.map[pos.x, pos.y].hasPlayer) { if (nt == null) { nt = t.playerStats; t.LastKnownTargetPos = nt.pos; } else { if (MapUtility.MoveDistance(t.pos, nt.pos) > MapUtility.MoveDistance(t.pos, pos)) { nt = t.playerStats; t.LastKnownTargetPos = nt.pos; } } } } if (nt != null) { // found the closest possible target: t.CurrentTarget = nt; t.LastKnownTargetPos = nt.pos; } } } if (t.CurrentTarget != null) { var att = GetAttack(t); if (att.BlobInRange(t.__position, t.CurrentTarget.pos)) { att.Calculate((t, t.CurrentTarget)); return; } t.path = null; t.path = AStar.CalculatePath(t.__position, t.CurrentTarget.pos); BlobMoveTo(t, t.path[0].x, t.path[0].y); } else { if (t._x > 0) { t._x--; t.path = null; t.path = AStar.CalculatePath(t.__position, MapManager.playerPos); BlobMoveTo(t, t.path[0].x, t.path[0].y); } else { //BlobMoveTo(t, t.__position.x + Random.Range(-1, 2), t.__position.y + Random.Range(-1, 2)); //move to random direction } } }
void BlobMoveTo(RoamingNPC t, int x, int y) { try { t.Stun(0); if (t.CheckStun()) { return; } Debug.Log("1"); if ((MapManager.map[x, y].enemy == null || MapManager.map[x, y].enemy.GetComponent <RoamingNPC>().enemySO == t.enemySO) && !t.rooted && MapManager.map[x, y].type != "Wall") { MapManager.map[t.__position.x, t.__position.y].letter = ""; MapManager.map[t.__position.x, t.__position.y].isWalkable = true; MapManager.map[t.__position.x, t.__position.y].enemy = null; MapManager.map[t.__position.x, t.__position.y].timeColor = new Color(0, 0, 0); MapManager.map[t.__position.x - 1, t.__position.y].letter = ""; MapManager.map[t.__position.x - 1, t.__position.y].isWalkable = true; MapManager.map[t.__position.x - 1, t.__position.y].enemy = null; MapManager.map[t.__position.x - 1, t.__position.y].timeColor = new Color(0, 0, 0); MapManager.map[t.__position.x + 1, t.__position.y].letter = ""; MapManager.map[t.__position.x + 1, t.__position.y].isWalkable = true; MapManager.map[t.__position.x + 1, t.__position.y].enemy = null; MapManager.map[t.__position.x + 1, t.__position.y].timeColor = new Color(0, 0, 0); MapManager.map[t.__position.x, t.__position.y + 1].letter = ""; MapManager.map[t.__position.x, t.__position.y + 1].isWalkable = true; MapManager.map[t.__position.x, t.__position.y + 1].enemy = null; MapManager.map[t.__position.x, t.__position.y + 1].timeColor = new Color(0, 0, 0); MapManager.map[t.__position.x, t.__position.y - 1].letter = ""; MapManager.map[t.__position.x, t.__position.y - 1].isWalkable = true; MapManager.map[t.__position.x, t.__position.y - 1].enemy = null; MapManager.map[t.__position.x, t.__position.y - 1].timeColor = new Color(0, 0, 0); t.__position = new Vector2Int(x, y); if (!t.isInvisible) { MapManager.map[x, y].letter = t.EnemySymbol; } MapManager.map[x, y].isWalkable = false; MapManager.map[x, y].enemy = t.gameObject; MapManager.map[x, y].timeColor = t.EnemyColor; if (MapManager.map[x + 1, y].isWalkable) { if (!t.isInvisible) { MapManager.map[x + 1, y].letter = t.EnemySymbol; } MapManager.map[x + 1, y].isWalkable = false; MapManager.map[x + 1, y].enemy = t.gameObject; MapManager.map[x + 1, y].timeColor = t.EnemyColor; } if (MapManager.map[x - 1, y].isWalkable) { if (!t.isInvisible) { MapManager.map[x - 1, y].letter = t.EnemySymbol; } MapManager.map[x - 1, y].isWalkable = false; MapManager.map[x - 1, y].enemy = t.gameObject; MapManager.map[x - 1, y].timeColor = t.EnemyColor; } if (MapManager.map[x, y - 1].isWalkable) { if (!t.isInvisible) { MapManager.map[x, y - 1].letter = t.EnemySymbol; } MapManager.map[x, y - 1].isWalkable = false; MapManager.map[x, y - 1].enemy = t.gameObject; MapManager.map[x, y - 1].timeColor = t.EnemyColor; } if (MapManager.map[x, y + 1].isWalkable) { if (!t.isInvisible) { MapManager.map[x, y + 1].letter = t.EnemySymbol; } MapManager.map[x, y + 1].isWalkable = false; MapManager.map[x, y + 1].enemy = t.gameObject; MapManager.map[x, y + 1].timeColor = t.EnemyColor; } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); return; } } catch { } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); }
public void Update() { Targeting.UpdateTargeting(); if (usingWand) { if (usedWand._spellType == WandSO.spellType.ray) { if (!usedWand.AllowTargetingMove()) { Targeting.Revert(); } wand_path = LineAlg.GetPointsOnLine( MapManager.playerPos.x, MapManager.playerPos.y, Targeting.Position.x, Targeting.Position.y); foreach (var cell in wand_path) { MapManager.map[cell.x, cell.y].decoy = $"<color=yellow>\u205C</color>"; } } else if (usedWand._spellType == WandSO.spellType.point) { if (!usedWand.AllowTargetingMove()) { Targeting.Revert(); } wand_path = LineAlg.GetPointsOnLine( MapManager.playerPos.x, MapManager.playerPos.y, Targeting.Position.x, Targeting.Position.y); foreach (var cell in wand_path) { MapManager.map[cell.x, cell.y].decoy = $"<color=yellow>\u205C</color>"; } } //todo else { if (usedWand.IsValidTarget()) { usingWand = false; Targeting.IsTargeting = false; usedWand.UseWandSpell(); usedWand = null; PlayerMovement.playerMovement.canMove = true; } else { // you cannot target that guys Debug.Log("not the right target"); } } if (Controls.GetKeyDown(Controls.Inputs.Use)) { if (usedWand.IsValidTarget()) { usingWand = false; Targeting.IsTargeting = false; usedWand.UseWandSpell(); usedWand = null; gameManager.ApplyChangesInInventory(null); PlayerMovement.playerMovement.canMove = true; } else { // you cannot target that guys Debug.Log("not the right target"); } } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); } if (usingSpellScroll) { if (PlayerMovement.playerMovement.canMove) { Debug.Log(MapManager.playerPos + " " + Targeting.Position); PlayerMovement.playerMovement.canMove = false; gameManager.UpdateMessages("Choose target of your spell. <color=pink>(Numpad 8 4 6 2, Enter/Space to confirm, Escape to cancel)</color>"); } if (usedScrollOrBook is IRestrictTargeting check) { if (check.IsValidTarget()) { MapManager.map[Targeting.Position.x, Targeting.Position.y].decoy = $"<color=yellow>\u205C</color>"; } else { MapManager.map[Targeting.Position.x, Targeting.Position.y].decoy = $"<color={ColorUtility.ToHtmlStringRGB(Color.gray)}>\u205C</color>"; } } else { MapManager.map[Targeting.Position.x, Targeting.Position.y].decoy = $"<color=yellow>\u205C</color>"; } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); if (Controls.GetKeyDown(Controls.Inputs.Use)) { if (usedScrollOrBook is IRestrictTargeting target) { if (target.IsValidTarget()) { PlayerMovement.playerMovement.canMove = true; Targeting.IsTargeting = false; usingSpellScroll = false; if (usedScrollOrBook is ScrollSO scroll) { scroll.UseSpell(this); } else if (usedScrollOrBook is SpellbookSO book) { book.UseSpell(this); } usedScrollOrBook = null; gameManager.ApplyChangesInInventory(null); } } DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); } if (Controls.GetKeyDown(Controls.Inputs.CancelButton)) { PlayerMovement.playerMovement.canMove = true; Targeting.IsTargeting = false; usingSpellScroll = false; usedScrollOrBook = null; DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); } } if (dialogue) { if (PlayerMovement.playerMovement.canMove) { GameManager.manager.player.StopAllCoroutines(); PlayerMovement.playerMovement.canMove = false; gameManager.UpdateMessages("<b><color=red>???</color></b>: <i>Ahh, you're no jailer are you? No, no, you're from far away...</i>"); gameManager.UpdateMessages("<color=red><b>???</b></color>: <i>These bastards locked me here. I'm not asking for much, just cut the knots on my wrists, I'll be fine somehow, but in return I can give you something that I took from the priests.</i>"); gameManager.UpdateMessages("<color=red><b>???</b></color>: <i>We are alike, we should support each other.</i>"); gameManager.UpdateMessages("\n <i>[1. Help] [2. Refuse] [3. Cancel]</i>"); } if (Controls.GetKeyDown(Controls.Inputs.InventoryChoice1)) { gameManager.UpdateMessages("\n <b><color=red>Grim</color></b>: <i>Very well. I am Grim, I am grateful for your help. As I promised, in return for your help...</i>"); GameObject rewardObject = Instantiate(gameManager.itemSpawner.itemPrefab); rewardObject.GetComponent <Item>().iso = npcDialogue.enemySO.rewardItem; rewardObject.transform.SetParent(MapManager.CurrentFloor.GO.transform); Pickup(rewardObject, rewardObject.GetComponent <Item>().iso, new Vector2Int(100, 100)); dialogue = false; PlayerMovement.playerMovement.canMove = true; npcDialogue.enemySO.finishedDialogue = true; npcDialogue = null; } if (Controls.GetKeyDown(Controls.Inputs.InventoryChoice2)) { gameManager.UpdateMessages("\n <b><color=red>???</color></b>: <i>Yes, well, why should you? But if you change your mind, give me a shout, eh?</i>"); dialogue = false; PlayerMovement.playerMovement.canMove = true; npcDialogue = null; } if (Controls.GetKeyDown(Controls.Inputs.InventoryChoice3)) { PlayerMovement.playerMovement.canMove = true; gameManager.UpdateMessages("\n <b><color=red>???</color></b>: <i>I will wait...</i>"); dialogue = false; npcDialogue = null; } } }
private void Attack(GameObject e, int x, int y) //float damageMultiplier, WeaponsSO.additionalEffects effect { for (int y2 = position.y - 2; y2 < position.y + 2; y2++) { for (int x2 = position.x - 2; x2 < position.x + 2; x2++) { try { if (MapManager.map[x2, y2].enemy != null) { MapManager.map[x2, y2].enemy.GetComponent <RoamingNPC>().TestToWakeUp(); } } catch { } } } if (playerStats._Lhand?.iso is WeaponsSO w) { w.onHit(playerStats); } if (playerStats._Rhand?.iso is WeaponsSO w2) { w2.onHit(playerStats); } if (playerStats.isInvisible) { playerStats.RemoveInvisibility(); } RoamingNPC roamingNpcScript = e.GetComponent <RoamingNPC>(); int damageLeftHand = 0; int damageRightHand = 0; ItemScriptableObject.damageType leftHandDamageType = ItemScriptableObject.damageType.normal; ItemScriptableObject.damageType rightHandDamageType = ItemScriptableObject.damageType.normal; int r = Random.Range(1, 100); int valueRequiredToHit = 0; //value required to hit the monster if (roamingNpcScript.sleeping) { valueRequiredToHit = r + playerStats.__dexterity - roamingNpcScript.dex / 4 - roamingNpcScript.AC; } else { valueRequiredToHit = r + playerStats.__dexterity - roamingNpcScript.dex - roamingNpcScript.AC; } if (r <= 0) { manager.UpdateMessages("You missed!"); WakeUpEnemy(roamingNpcScript); return; } if (valueRequiredToHit > 50 || r >= 80) //Do we hit? { if (playerStats._Lhand?.iso is WeaponsSO weaponL) { leftHandDamageType = weaponL.I_damageType; for (x = 0; x < weaponL.attacks.Count; x++) { damageLeftHand += Random.Range(1, weaponL.attacks[x].y + 1); //IF WEAPON IS BLOOD SWORD WE INCREASE ITS DAMAGE if (weaponL.I_name == "Bloodsword") { weaponL.attacks[0] = new Vector2Int(1, weaponL.attacks[0].y + 1); weaponL.bloodSwordCounter = manager.tasks.bloodSwordCooldown; } } } if (playerStats._Rhand?.iso is WeaponsSO weaponR) { rightHandDamageType = weaponR.I_damageType; for (x = 0; x < weaponR.attacks.Count; x++) { damageRightHand += Random.Range(1, weaponR.attacks[x].y + 1); //IF WEAPON IS BLOOD SWORD WE INCREASE ITS DAMAGE if (weaponR.I_name == "Bloodsword") { weaponR.attacks[0] = new Vector2Int(1, weaponR.attacks[0].y + 1); weaponR.bloodSwordCounter = manager.tasks.bloodSwordCooldown; } } } //CRIT? if (Random.Range(1, 100) < 10 - roamingNpcScript.AC + roamingNpcScript.dex - playerStats.__dexterity) { if (playerStats._Lhand?.iso is WeaponsSO) { damageLeftHand += Mathf.FloorToInt((Random.Range(1, 4) + Mathf.FloorToInt(playerStats.__strength / 5)) * 1.5f); } } else { //damageLeftHand += Random.Range(1, 4) + Mathf.FloorToInt(playerStats.__strength / 5); } if (Random.Range(1, 100) < 10 - roamingNpcScript.AC + roamingNpcScript.dex - playerStats.__dexterity) { if ((playerStats._Lhand?.iso is WeaponsSO)) { damageRightHand += Mathf.FloorToInt((Random.Range(1, 4) + Mathf.FloorToInt(playerStats.__strength / 5)) * 1.5f); } } else { // damageRightHand += Random.Range(1, 4) + Mathf.FloorToInt(playerStats.__strength / 5); } if (damageLeftHand == 0) { damageLeftHand = Random.Range(1, 4); } if (damageRightHand == 0) { damageRightHand = Random.Range(1, 4); } if (roamingNpcScript.sleeping) { damage = Mathf.FloorToInt(damageLeftHand * sleepingDamage) + Mathf.FloorToInt(damageRightHand * sleepingDamage); manager.UpdateMessages($"You dealt <color=red>{damage}</color> damage to <color=#{ColorUtility.ToHtmlStringRGB(roamingNpcScript.EnemyColor)}>{roamingNpcScript.EnemyName}</color>"); WakeUpEnemy(roamingNpcScript); roamingNpcScript.TakeDamage(Mathf.FloorToInt(damageLeftHand * sleepingDamage), leftHandDamageType); roamingNpcScript.TakeDamage(Mathf.FloorToInt(damageRightHand * sleepingDamage), rightHandDamageType); } else { damage = damageLeftHand + damageRightHand; manager.UpdateMessages($"You dealt <color=red>{damage}</color> damage to <color=#{ColorUtility.ToHtmlStringRGB(roamingNpcScript.EnemyColor)}>{roamingNpcScript.EnemyName}</color>"); roamingNpcScript._x = roamingNpcScript.howLongWillFololwInvisiblepLayer; if (playerStats._Lhand != null) { RunManager.CurrentRun.Set(RunManager.Stats.CurrentAttackInfoLeft, ((WeaponsSO)playerStats._Lhand.iso)._weaponType); } if (playerStats._Rhand != null) { RunManager.CurrentRun.Set(RunManager.Stats.CurrentAttackInfoRight, ((WeaponsSO)playerStats._Rhand.iso)._weaponType); } roamingNpcScript.TakeDamage(damageLeftHand, leftHandDamageType); roamingNpcScript.TakeDamage(damageRightHand, rightHandDamageType); if (playerStats._Lhand != null) { RunManager.CurrentRun.Set(RunManager.Stats.CurrentAttackInfoRight, null); } if (playerStats._Rhand != null) { RunManager.CurrentRun.Set(RunManager.Stats.CurrentAttackInfoLeft, null); } } RunManager.CurrentRun.Set(RunManager.Names.EnemiesAttacked, RunManager.CurrentRun.Get <int>(RunManager.Names.EnemiesAttacked) + 1); } else //WE MISSED BUT WE WAKE UP ENEMY { manager.UpdateMessages("You missed!"); WakeUpEnemy(roamingNpcScript); } }
public override void Calculate(RoamingNPC t) { if (t.rootDuration > 0) { t.rootDuration--; } else if (t.rooted) { t.rooted = false; } if (t.enemySO._Behaviour != EnemiesScriptableObject.E_behaviour.npc) { if (t.sleeping) { return; } if (!t.gameObject.transform.parent.gameObject.activeSelf) { return; } t.TriggerEffectTasks(); if (t.CurrentTarget != null && t.CurrentTarget.currHp == 0) { t.CurrentTarget = null; } // check for out of sight enemy if (!(t.CurrentTarget == null)) { if (!FoV.InLineOfSight(t.pos, t.CurrentTarget.pos)) { // out of sight out of mind i guess t.CurrentTarget = null; } } // check if current target is still valid if (!(t.CurrentTarget == null)) { // we are targeting something // range here if (MapUtility.MoveDistance(t.pos, t.CurrentTarget.pos) == 1) { // the target is in attackrange so we dont change anything } else { // target may be running away. we are looking at other potential targets that are near us if (t.RetailiationList.Count > 0) { // we have recently been attacked by somebody var alt = t.RetailiationList.ToArray().Check((u) => MapUtility.MoveDistance(u.pos, t.pos) == 1); if (alt.Length > 0) { t.CurrentTarget = alt.GetRandom(); } } } } else { // look for possible target var view = FoV.GetEnemyFoV(t.__position).ToArray().Check((p) => MapManager.map[p.x, p.y].hasPlayer || MapManager.map[p.x, p.y].enemy != null); if (view.Length > 0) { List <IUnit> possibleTargets = new List <IUnit>(); IUnit nt = null; foreach (var pos in view) { if (MapManager.map[pos.x, pos.y].enemy != null) { // we found somebody to attack if (nt == null) { nt = MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>(); t.LastKnownTargetPos = nt.pos; } else { if (MapUtility.MoveDistance(t.pos, nt.pos) > MapUtility.MoveDistance(t.pos, pos)) { nt = MapManager.map[pos.x, pos.y].enemy.GetComponent <RoamingNPC>(); t.LastKnownTargetPos = nt.pos; } } } if (MapManager.map[pos.x, pos.y].hasPlayer) { if (nt == null) { nt = t.playerStats; t.LastKnownTargetPos = nt.pos; } else { if (MapUtility.MoveDistance(t.pos, nt.pos) > MapUtility.MoveDistance(t.pos, pos)) { nt = t.playerStats; t.LastKnownTargetPos = nt.pos; } } } } if (nt != null) { // found the closest possible target: t.CurrentTarget = nt; t.LastKnownTargetPos = nt.pos; } } } switch (t.enemySO._Behaviour) { case EnemiesScriptableObject.E_behaviour.cowardly: if (t.__currentHp <= (t.maxHp / 2) && (int)Random.Range(0, 2) == 1 && t.runCounter > 0 || (t.runCounter > 0 && t.runCounter < 5)) //RUN FROM PLAYER { t.runDirection = t.__position - MapManager.playerPos; Vector2Int runCell = t.__position + t.runDirection; t.runCounter--; t.path = null; t.path = AStar.CalculatePath(t.__position, runCell); t.MoveTo(t.path[0].x, t.path[0].y); return; } else { t.runCounter = 5; } break; case EnemiesScriptableObject.E_behaviour.recovers: if (t.__currentHp <= (t.maxHp / 2) && t.hpRegenCooldown == 0) { t.hpRegenCooldown--; t.__currentHp += Mathf.FloorToInt(t.maxHp * .25f); return; } else if (t.hpRegenCooldown < 10 && t.hpRegenCooldown > 0) { t.hpRegenCooldown--; } break; } if (t.CurrentTarget != null) { var att = GetAttack(t); if (att.InRange(t.__position, t.CurrentTarget.pos)) { att.Calculate((t, t.CurrentTarget)); return; } /* * if (new Vector2Int(t.__position.x - 1, t.__position.y) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x + 1, t.__position.y) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x, t.__position.y - 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x, t.__position.y + 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x - 1, t.__position.y - 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x + 1, t.__position.y - 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x - 1, t.__position.y + 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } * else if (new Vector2Int(t.__position.x + 1, t.__position.y + 1) == MapManager.playerPos) * { * GetAttack(t).Attack(t, t.playerStats); * return; * } */ t.path = null; t.path = AStar.CalculatePath(t.__position, t.CurrentTarget.pos); t.MoveTo(t.path[0].x, t.path[0].y); } else { t.MoveTo(t.__position.x + Random.Range(-1, 2), t.__position.y + Random.Range(-1, 2)); //move to random direction } } else { if (!t.gameObject.transform.parent.gameObject.activeSelf) { return; } if (t.enemySO.finishedDialogue) { t.MoveTo(t.__position.x + (int)Random.Range(-1, 2), t.__position.y + (int)Random.Range(-1, 2)); //move to random direction } } }
public void SpawnAt(Floor floor, int x, int y, EnemiesScriptableObject enemySO = null, string sleep = "") { try{ if (floor.Tiles[x, y].type != "Floor" || floor.Tiles[x, y].structure != null || floor.Tiles[x, y].hasPlayer) { return; } } catch {}; __position = new Vector2Int(x, y); if (enemySO == null) { enemySO = GetRandomEnemy(floor); } try { floor.Tiles[__position.x, __position.y].timeColor = enemySO.E_color; } catch { return; } floor.Tiles[__position.x, __position.y].letter = enemySO.E_symbol; floor.Tiles[__position.x, __position.y].isWalkable = false; //DungeonGenerator.dungeonGenerator.DrawMap(true, floor.Tiles); GameObject enemy; try { enemy = Instantiate(enemyPrefab, transform.position, Quaternion.identity); } catch { enemy = Instantiate(GameManager.manager.enemyPrefab, transform.position, Quaternion.identity); } RoamingNPC so = enemy.GetComponent <RoamingNPC>(); so.__position = __position; so.enemySO = enemySO; if (sleep != "") { so.sleepDecided = true; if (sleep == "true") { so.sleeping = true; } else if (sleep == "false") { so.sleeping = false; } } else { so.SpawnSleep(MapManager.GetIndexOfFloor(floor)); } so.__currentHp = enemySO.maxHealth; so.str = enemySO.strength; so.dex = enemySO.dexterity; so.intell = enemySO.intelligence; so.end = enemySO.endurance; //so.__currentHp = Mathf.FloorToInt(so.str + (so.end * 3) - 5); so.xpDrop = Mathf.RoundToInt((so.str + so.dex + so.intell + so.end) / 3); manager.enemies.Add(enemy.gameObject); enemy.transform.SetParent(floor.GO.transform); floor.Tiles[__position.x, __position.y].enemy = enemy.gameObject; spawnedEnemies.Add(enemy.gameObject); }
public override void Calculate(RoamingNPC t) { Corps corpse = new Corps(); bool droppedItem = false; if (Random.Range(1, 100) <= 100 && t.enemySO.E_possileDrops != null && t.enemySO.E_possileDrops.Count > 0) { corpse.itemInCorpse = t.enemySO.E_possileDrops[Random.Range(0, t.enemySO.E_possileDrops.Count)]; droppedItem = true; } if (MapManager.map[t.__position.x, t.__position.y].structure == null) { Debug.Log("blob kill 1"); if (droppedItem) { GameManager.manager.itemSpawner.SpawnAt(MapManager.CurrentFloor, t.__position.x, t.__position.y, corpse.itemInCorpse); } MapManager.map[t.__position.x, t.__position.y].baseChar = t.EnemySymbol; MapManager.map[t.__position.x, t.__position.y].exploredColor = new Color(0.2784f, 0, 0); MapManager.map[t.__position.x, t.__position.y].letter = ""; MapManager.map[t.__position.x, t.__position.y].enemy = null; MapManager.map[t.__position.x, t.__position.y].isWalkable = true; corpse.enemyBody = t.enemySO; MapManager.map[t.__position.x, t.__position.y].structure = corpse; } if (MapManager.map[t.__position.x + 1, t.__position.y].structure == null && MapManager.map[t.__position.x + 1, t.__position.y].enemy?.GetComponent <RoamingNPC>().enemySO == t.enemySO) { Debug.Log("blob kill 2"); MapManager.map[t.__position.x + 1, t.__position.y].baseChar = t.EnemySymbol; MapManager.map[t.__position.x + 1, t.__position.y].exploredColor = new Color(0.2784f, 0, 0); MapManager.map[t.__position.x + 1, t.__position.y].letter = ""; MapManager.map[t.__position.x + 1, t.__position.y].enemy = null; MapManager.map[t.__position.x + 1, t.__position.y].isWalkable = true; corpse = new Corps(); corpse.enemyBody = t.enemySO; MapManager.map[t.__position.x + 1, t.__position.y].structure = corpse; } if (MapManager.map[t.__position.x - 1, t.__position.y].structure == null && MapManager.map[t.__position.x - 1, t.__position.y].enemy?.GetComponent <RoamingNPC>().enemySO == t.enemySO) { Debug.Log("blob kill 3"); MapManager.map[t.__position.x - 1, t.__position.y].baseChar = t.EnemySymbol; MapManager.map[t.__position.x - 1, t.__position.y].exploredColor = new Color(0.2784f, 0, 0); MapManager.map[t.__position.x - 1, t.__position.y].letter = ""; MapManager.map[t.__position.x - 1, t.__position.y].enemy = null; MapManager.map[t.__position.x - 1, t.__position.y].isWalkable = true; corpse = new Corps(); corpse.enemyBody = t.enemySO; MapManager.map[t.__position.x - 1, t.__position.y].structure = corpse; } if (MapManager.map[t.__position.x, t.__position.y + 1].structure == null && MapManager.map[t.__position.x, t.__position.y + 1].enemy?.GetComponent <RoamingNPC>().enemySO == t.enemySO) { MapManager.map[t.__position.x, t.__position.y + 1].baseChar = t.EnemySymbol; MapManager.map[t.__position.x, t.__position.y + 1].exploredColor = new Color(0.2784f, 0, 0); MapManager.map[t.__position.x, t.__position.y + 1].letter = ""; MapManager.map[t.__position.x, t.__position.y + 1].enemy = null; MapManager.map[t.__position.x, t.__position.y + 1].isWalkable = true; corpse = new Corps(); corpse.enemyBody = t.enemySO; MapManager.map[t.__position.x, t.__position.y + 1].structure = corpse; } if (MapManager.map[t.__position.x, t.__position.y - 1].structure == null && MapManager.map[t.__position.x, t.__position.y - 1].enemy?.GetComponent <RoamingNPC>().enemySO == t.enemySO) { Debug.Log("5"); MapManager.map[t.__position.x, t.__position.y - 1].baseChar = t.EnemySymbol; MapManager.map[t.__position.x, t.__position.y - 1].exploredColor = new Color(0.2784f, 0, 0); MapManager.map[t.__position.x, t.__position.y - 1].letter = ""; MapManager.map[t.__position.x, t.__position.y - 1].enemy = null; MapManager.map[t.__position.x, t.__position.y - 1].isWalkable = true; corpse = new Corps(); corpse.enemyBody = t.enemySO; MapManager.map[t.__position.x, t.__position.y - 1].structure = corpse; } t.manager.playerStats.__sanity += 15; t.manager.UpdateMessages($"You have killed the <color={t.EnemyColor}>{t.EnemyName}</color>"); RunManager.CurrentRun.Set(RunManager.Names.EnemiesKilled, RunManager.CurrentRun.Get <int>(RunManager.Names.EnemiesKilled) + 1); RunManager.UnitKilledWithAttack(); t.manager.playerStats.UpdateLevel(t.xpDrop); t.manager.StartPlayersTurn(); //t.manager.gameObject.GetComponent<Bestiary>().UpdateEnemyList(t.enemySO); t.manager.enemies.Remove(t.gameObject); DungeonGenerator.dungeonGenerator.DrawMap(MapManager.map); Destroy(t.gameObject); }