public void RefreshPosition() { GameTile tile = gameManager.GetTile(this.GetCoordinates()); if (tile != null) { Debug.Assert(tile.GetCharacter() == null || tile.GetCharacter() == this); if (tile.GetCharacter() != this) { Debug.LogError("Player moved to tile, but tile was not updated"); tile.SetCharacter(this); } } }
public Character GetTarget() { List <Character> targets = new List <Character>(); foreach (Vector2 rangeCoords in attackShape) { GameTile tile = gameManager.GetTile(character.GetCoordinates() + rangeCoords); if (tile == null) { continue; } Character target = tile.GetCharacter(); if (target != null) { targets.Add(target); } } if (targets.Count < 1) { return(null); } int index = Random.Range(0, targets.Count); return(targets[index]); }
public List <Character> GetTargets() { List <Character> targets = new List <Character>(); foreach (Vector2 rangeCoords in attackShape) { GameTile tile = gameManager.GetTile(character.GetCoordinates() + rangeCoords); if (tile == null) { continue; } Character target = tile.GetCharacter(); if (target != null) { targets.Add(target); } } return(targets); }
void SpawnPickup(Pickup pickup) { List <GameTile> valid_tiles = new List <GameTile>(RoomTiles); while (valid_tiles.Count > 0) { int idx = Random.Range(0, valid_tiles.Count); GameTile tile = RoomTiles[idx]; if (tile.IsWalkable() || tile.GetCharacter() != null) { Pickup instance = Instantiate <Pickup>(pickup); instance.transform.position = tile.transform.position; tile.AddPickup(instance); break; } else { valid_tiles.RemoveAt(idx); } } Debug.Assert(valid_tiles.Count > 0); }
public override void SetCharacter(Character character) { Character oldCharacter = this.character; this.character = character; if (!this.sprung && oldCharacter == null) { Dialog dialog = this.GetComponent <Dialog>(); if (dialog != null && this.character is Player) { dialog.DisplayDialogMessage(); } bool trapActive = false; switch (trapDependency) { case TrapDependency.Health: if (this.character.GetHealth() < minDependency || this.character.GetHealth() > maxDependency) { trapActive = true; } break; case TrapDependency.Level: if (this.character.GetLevel() < minDependency || this.character.GetLevel() > maxDependency) { trapActive = true; } break; case TrapDependency.Gold: if (this.character.GetGold() < minDependency || this.character.GetGold() > maxDependency) { trapActive = true; } break; default: trapActive = true; break; } if (trapActive) { if (achievement != "" && this.character is Player) { if (achievement == "Game Complete") { switch (curGm.difficulty) { case GameManager.Difficulty.Extreme: ((Player)character).completeAchievement("Game Complete Extreme"); goto case GameManager.Difficulty.Hard; case GameManager.Difficulty.Hard: ((Player)character).completeAchievement("Game Complete Hard"); goto case GameManager.Difficulty.Normal; case GameManager.Difficulty.Normal: ((Player)character).completeAchievement("Game Complete Normal"); goto case GameManager.Difficulty.Easy; case GameManager.Difficulty.Easy: ((Player)character).completeAchievement("Game Complete Easy"); break; default: break; } } else { ((Player)character).completeAchievement(achievement); } } if (damage > 0) { character.ReceiveDamage(damage); } if (!resetting) { this.sprung = true; } if (newLevel != "" && this.character is Player) { curGm.GetSaveManager().SaveData(); PlayerPrefs.SetString("levelname", newLevel); Debug.Log(newLevel); curGm.loadNewLevel(newLevel); } if (spawnLocation != null) { if (spawnLocation.GetCharacter() == null && spawnLocation.IsWalkable()) { switch (curGm.difficulty) { case GameManager.Difficulty.Easy: Instantiate(whatToSpawnEasy, spawnLocation.GetCoordinates(), Quaternion.identity); break; case GameManager.Difficulty.Hard: Instantiate(whatToSpawnHard, spawnLocation.GetCoordinates(), Quaternion.identity); break; case GameManager.Difficulty.Extreme: Instantiate(whatToSpawnExtreme, spawnLocation.GetCoordinates(), Quaternion.identity); break; default: Instantiate(whatToSpawnNormal, spawnLocation.GetCoordinates(), Quaternion.identity); break; } } } if (achievementShowcase != "" && this.character is Player) { ((Player)character).displayAchievement(achievementShowcase); } if (test) { //These are test functions to run them easily somewhere, just //make sure test is false for real game tiles //also try to remember to comment out tests as a double safety //((Player)character).wipeAchievements(); } } } base.SetCharacter(character); }