public GameObject PlaceMapPrefab(string prefabName, int tileX, int tileY, int collisionMapMark = WALKABLEMAP_DONT_MARK, float yOffset = 0f, bool floor = false) { GameObject newItem = GameObject.Instantiate(PrefabManager.instance.PrefabByName(prefabName), transform); newItem.transform.SetParent(transform); newItem.transform.position = new Vector3(tileX, yOffset, -tileY); if (collisionMapMark == WALKABLEMAP_USE_PREFAB_MARK) { int mark = newItem.GetComponent <SimpleMovement>().uniqueCollisionIdentity; mCollisionMap.MarkSpace(tileX, tileY, mark); } else if (collisionMapMark != WALKABLEMAP_DONT_MARK) { mCollisionMap.MarkSpace(tileX, tileY, collisionMapMark); } if (floor) { mFloorTiles.Add(new Vector2Int(tileX, tileY), newItem); } else { ClearFloorDecorations(tileX, tileY); } return(newItem); }
public void SpawnCops(RandomDungeon dungeon, CollisionMap collisionMap, Vector2 avatarStartPosition) { List <Vector2Int> walkablePositions = collisionMap.EmptyPositions(); walkablePositions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 10); // Spawn a few cops in the level int numCops = Random.Range(3, 6); for (int i = 0; i < numCops; ++i) { if (walkablePositions.Count == 0) { return; } string enemy = (Random.Range(0, 2) == 0 ? "CopRanged" : "CopMelee"); GameObject newEnemy = GameObject.Instantiate(PrefabManager.instance.PrefabByName(enemy)); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newEnemy.transform.position = pos; collisionMap.MarkSpace(pos2.x, pos2.y, newEnemy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); } }
protected override IEnumerator ActivationCoroutine() { yield return(base.ActivationCoroutine()); if (WasAccepted()) { NumberPopupGenerator.instance.GeneratePopup(gameObject, "Strength Increased", NumberPopupReason.Good); CharacterStatModifier modifier = Game.instance.playerStats.gameObject.AddComponent <CharacterStatModifier>(); modifier.SetRelativeModification(CharacterStatType.Strength, 2); CollisionMap collisionMap = GameObject.FindObjectOfType <CollisionMap>(); // Spawn a bunch of enemies and give the player more strength. List <Vector2Int> walkablePositions = new List <Vector2Int>(); Vector2Int playerPosition = MapCoordinateHelper.WorldToMapCoords(Game.instance.avatar.transform.position); for (int xOffset = -4; xOffset <= 4; ++xOffset) { for (int yOffset = -4; yOffset <= 4; ++yOffset) { if (Mathf.Abs(xOffset) < 2 || Mathf.Abs(yOffset) < 2) { continue; } int x = playerPosition.x + xOffset; int y = playerPosition.y + yOffset; if (collisionMap.SpaceMarking(x, y) == 0) { walkablePositions.Add(new Vector2Int(x, y)); } } } DungeonFloorData data = CurrentDungeonFloorData(); int numEnemies = 5; for (int i = 0; i < numEnemies; ++i) { if (walkablePositions.Count == 0) { continue; } string enemy = data.enemyData.rareEnemy.name; GameObject newEnemy = GameObject.Instantiate(PrefabManager.instance.PrefabByName(enemy)); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newEnemy.transform.position = pos; collisionMap.MarkSpace(pos2.x, pos2.y, newEnemy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); } } yield break; }
public override void Activate(GameObject caster) { base.Activate(caster); // Find a walkable tile nearby that is empty and move there immediately, then play an effect. CollisionMap collisionMap = GameObject.FindObjectOfType<CollisionMap>(); int x = Mathf.RoundToInt(Game.instance.avatar.transform.position.x); int y = Mathf.RoundToInt(Game.instance.avatar.transform.position.z); y = -y; List<Vector2Int> viablePositions = new List<Vector2Int>(); for (int xOffset = -13; xOffset <= 13; ++xOffset) { for (int yOffset = -13; yOffset <= 13; ++yOffset) { int testX = x + xOffset; int testY = y + yOffset; if (testX >= 0 && testY >= 0 && testX < collisionMap.width && testY < collisionMap.height && collisionMap.SpaceMarking(testX, testY) == 0) { viablePositions.Add(new Vector2Int(testX, testY)); } } } if (viablePositions.Count == 0) return; Vector2Int pos = viablePositions.Sample(); collisionMap.RemoveMarking(Game.instance.avatar.commonComponents.simpleMovement.uniqueCollisionIdentity); collisionMap.MarkSpace(pos.x, pos.y, Game.instance.avatar.GetComponent<SimpleMovement>().uniqueCollisionIdentity); Game.instance.avatar.transform.position = new Vector3(pos.x, 0, -pos.y); Game.instance.avatar.follower.transform.position = Game.instance.avatar.transform.position + new Vector3(-0.25f, 0f, 0.25f); GameObject effect = PrefabManager.instance.InstantiatePrefabByName("CFX2_WWExplosion_C"); effect.transform.position = Game.instance.avatar.transform.position; effect.AddComponent<DestroyAfterTimeElapsed>().time = 2f; Game.instance.soundManager.PlaySound("teleport"); }
private void SummonEnemy(Vector2Int mapPos) { // Only summon here if this position is still empty if (mCollisionMap.SpaceMarking(mapPos.x, mapPos.y) != 0) { return; } string enemy = summonedEntities.Sample().name; GameObject newEnemy = GameObject.Instantiate(PrefabManager.instance.PrefabByName(enemy), Game.instance.levelGenerator.transform); Vector2Int pos2 = mapPos; Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newEnemy.transform.position = pos; mCollisionMap.MarkSpace(mapPos.x, mapPos.y, newEnemy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); mSummonedEntities.Add(newEnemy); }
public override void Activate(GameObject caster) { base.Activate(caster); // Find a valid spot beside the player and spawn the decoy CollisionMap map = GameObject.FindObjectOfType <CollisionMap>(); if (map == null) { return; } Vector2Int playerPos = MapCoordinateHelper.WorldToMapCoords(Game.instance.avatar.transform.position); Vector2Int decoyPos = FindEmptyNearbyPosition(playerPos, map); GameObject decoy = PrefabManager.instance.InstantiatePrefabByName("Decoy"); decoy.name = "Decoy"; decoy.transform.position = MapCoordinateHelper.MapToWorldCoords(decoyPos); decoy.GetComponentInChildren <CharacterModel>().ChangeModel(Game.instance.followerData); map.MarkSpace(decoyPos.x, decoyPos.y, decoy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); }
private void TeleportIfPossible() { CollisionMap collisionMap = Game.instance.levelGenerator.collisionMap; List <Vector2Int> viablePositions = collisionMap.EmptyPositionsNearPosition(mTeleportTarget, 1); if (viablePositions.Count == 0) { return; } Vector2Int newTarget = viablePositions.Find(i => (i.x == mTeleportTarget.x && i.y == mTeleportTarget.y + 1)); if (newTarget.x != 0 || newTarget.y != 0) { mTeleportTarget = newTarget; } else { mTeleportTarget = viablePositions[0]; } Vector2Int currentPos = MapCoordinateHelper.WorldToMapCoords(transform.position); if (!collisionMap.RemoveMarking(commonComponents.simpleMovement.uniqueCollisionIdentity)) { Debug.LogError("CM error in PlayerController"); } collisionMap.MarkSpace(mTeleportTarget.x, mTeleportTarget.y, commonComponents.simpleMovement.uniqueCollisionIdentity); Game.instance.avatar.transform.position = MapCoordinateHelper.MapToWorldCoords(mTeleportTarget); Game.instance.avatar.follower.transform.position = Game.instance.avatar.transform.position + new Vector3(-0.25f, 0f, 0.25f); GameObject effect = PrefabManager.instance.InstantiatePrefabByName("CFX2_WWExplosion_C"); effect.transform.position = Game.instance.avatar.transform.position; effect.AddComponent <DestroyAfterTimeElapsed>().time = 2f; }
public void SpawnDebris(RandomDungeon dungeon, CollisionMap collisionMap, Vector2 avatarStartPosition) { List <Vector2Int> positions = collisionMap.EmptyPositions(); positions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 3); int numDebris = Random.Range(positions.Count / 5, positions.Count / 4); for (int i = 0; i < numDebris; ++i) { if (positions.Count == 0) { return; } Vector2Int pos = positions.Sample(); // todo bdsowers - ensure that this position is valid GameObject newDebris = PrefabManager.instance.InstantiatePrefabByName(PrefabManager.instance.debrisPrefabs.Sample().name); newDebris.transform.position = MapCoordinateHelper.MapToWorldCoords(pos); collisionMap.MarkSpace(pos.x, pos.y, newDebris.GetComponent <SimpleMovement>().uniqueCollisionIdentity); positions.Remove(pos); } }
public void Teleport(bool playerCentric = false) { teleportTimer = teleportCooldown; CollisionMap collisionMap = GameObject.FindObjectOfType <CollisionMap>(); Vector2Int pos = MapCoordinateHelper.WorldToMapCoords(transform.position); if (playerCentric) { pos = MapCoordinateHelper.WorldToMapCoords(Game.instance.avatar.transform.position); } List <Vector2Int> viablePositions = new List <Vector2Int>(); for (int xOffset = -teleportMaxDistance; xOffset <= teleportMaxDistance; ++xOffset) { for (int yOffset = -teleportMaxDistance; yOffset <= teleportMaxDistance; ++yOffset) { if (playerCentric) { if (xOffset != 0 && yOffset != 0) { continue; } } int teleDist = Mathf.Abs(xOffset) + Mathf.Abs(yOffset); if (teleDist < teleportMinDistance || teleDist > teleportMaxDistance) { continue; } int testX = pos.x + xOffset; int testY = pos.y + yOffset; if (testX >= 0 && testY >= 0 && testX < collisionMap.width && testY < collisionMap.height && collisionMap.SpaceMarking(testX, testY) == 0) { viablePositions.Add(new Vector2Int(testX, testY)); } } } if (viablePositions.Count == 0) { return; } Vector2Int targetPos = viablePositions.Sample(); collisionMap.RemoveMarking(GetComponent <SimpleMovement>().uniqueCollisionIdentity); collisionMap.MarkSpace(targetPos.x, targetPos.y, GetComponent <SimpleMovement>().uniqueCollisionIdentity); Vector3 previousPosition = transform.position; transform.position = new Vector3(targetPos.x, 0, -targetPos.y); GameObject effect = PrefabManager.instance.InstantiatePrefabByName("CFX2_WWExplosion_C"); effect.transform.position = previousPosition; effect.AddComponent <DestroyAfterTimeElapsed>().time = 2f; effect.transform.localScale = Vector3.one * 0.75f; Speedup(effect); GameObject effect2 = PrefabManager.instance.InstantiatePrefabByName("CFX2_WWExplosion_C"); effect2.transform.position = transform.position; effect2.AddComponent <DestroyAfterTimeElapsed>().time = 2f; effect2.transform.localScale = Vector3.one * 0.75f; Speedup(effect2); Game.instance.soundManager.PlaySound("teleport"); }
public void MarkSpaceUnwalkable() { Vector2Int pos = MapCoordinateHelper.WorldToMapCoords(transform.position); mCollisionMap.MarkSpace(pos.x, pos.y, uniqueCollisionIdentity); }