public override void Init() { base.Init(); settings = ResourceManager.GetItemsSettings(); spriteContainer = ResourceManager.GetSpriteContainer("CountryContainer"); var country = settings.countries[0]; minCoord = country.min; maxCoord = country.max; var regions = country.regions; var mapRectSize = new Vector2(spriteContainer.width, spriteContainer.height); root.localScale = MapCoordinateHelper.GetScaleFactor(); uiRegions = new List <UIRegionItem>(); for (int i = 0; i < regions.Count; i++) { var region = regions[i]; var sprite = spriteContainer.GetSprite(region.name); var uiRegion = Instantiate(template, root); uiRegion.Init(region, minCoord, maxCoord); uiRegion.baseImage.sprite = sprite; uiRegion.BaseRect.sizeDelta = MapCoordinateHelper.ConvertToUI(Vector2.zero, mapRectSize, sprite.rect.size); uiRegion.gameObject.SetActive(true); uiRegions.Add(uiRegion); } }
public bool CanMove(Vector3 direction) { if (direction.sqrMagnitude < 0.01f) { return(false); } if (!useCollisionMap) { Ray ray = new Ray(transform.position + new Vector3(0f, 0.2f, 0f), direction); RaycastHit[] hits = Physics.RaycastAll(ray, 1f); for (int i = 0; i < hits.Length; ++i) { if (hits[i].collider.gameObject != gameObject && !hits[i].collider.isTrigger) { return(false); } } return(true); } else { Vector3 targetPos = transform.position + direction; Vector2Int coords = MapCoordinateHelper.WorldToMapCoords(targetPos); int marking = mCollisionMap.SpaceMarking(coords.x, coords.y); return(marking == 0 || collisionIgnoreList.Contains(marking)); } }
protected override void Update() { base.Update(); var position = MapCoordinateHelper.ConvertToCoordinates(min, max, Input.mousePosition, mapRect); mousePosition.text = position.ToString("F2") + " | " + MapCoordinateHelper.ConvertToMinute(position).ToString("F2"); }
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); } }
public virtual void OnEndDrag(PointerEventData eventData) { var position = baseRect.anchoredPosition + MapCoordinateHelper.GetUIOffset(); origin.Coordinates = MapCoordinateHelper.ConvertToCoordinates(minCoordinate, maxCoordinate, position); EventHelper.SafeCall(onEndDrag); }
private List <Vector2Int> LockDownSummonLocations() { Vector2Int pos = MapCoordinateHelper.WorldToMapCoords(transform.position); List <Vector2Int> walkablePositions = WalkablePositionsInRange(pos.x, pos.y); List <Vector2Int> summonLocations = new List <Vector2Int>(); for (int i = 0; i < numEnemiesToSummon; ++i) { if (walkablePositions.Count == 0) { continue; } Vector2Int randomPos = walkablePositions.Sample(); summonLocations.Add(randomPos); walkablePositions.Remove(randomPos); Vector3 summonWorldPos = MapCoordinateHelper.MapToWorldCoords(randomPos); GameObject vfx = PrefabManager.instance.InstantiatePrefabByName("CFX3_MagicAura_B_Runic"); vfx.GetComponentInChildren <ParticleSystem>().playbackSpeed = 2.5f; vfx.transform.position = summonWorldPos + Vector3.up * 0.1f; vfx.transform.localScale = Vector3.one * 0.5f; vfx.AddComponent <DestroyAfterTimeElapsed>().time = 2f; } return(summonLocations); }
public virtual void Init(T origin, Vector2 minCoordinate, Vector2 maxCoordinate) { this.origin = origin; this.minCoordinate = minCoordinate; this.maxCoordinate = maxCoordinate; this.baseRect.anchoredPosition = MapCoordinateHelper.ConvertToUI(minCoordinate, maxCoordinate, origin.Coordinates) - MapCoordinateHelper.GetUIOffset(); }
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 OnPointerEnter(PointerEventData eventData) { base.OnPointerUp(eventData); var regionMapWindow = UIMainController.Instance.GetWindow <UIRegionMapWindow>(UIConstants.WINDOW_REGION_MAP); var solarTooltip = regionMapWindow.Tooltips.GetTooltip <UISolarTooltip>(); solarTooltip.rectTransform.anchoredPosition = MapCoordinateHelper.ConvertMousePositionToUI(eventData.position); solarTooltip.Open(Origin); }
public override void Init(RegionItem origin, Vector2 minCoordinate, Vector2 maxCoordinate) { base.Init(origin, minCoordinate, maxCoordinate); infoText.text = origin.name; gameObject.name = origin.name; baseRect.anchoredPosition = MapCoordinateHelper.ConvertToUI(minCoordinate, maxCoordinate, origin.Coordinates) - MapCoordinateHelper.GetUIOffset(); }
private void PlaceEnemy(DungeonFloorData data, Vector2Int pos2) { string enemy = ChooseEnemy(data); GameObject newEnemy = GameObject.Instantiate(PrefabManager.instance.PrefabByName(enemy), transform); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newEnemy.transform.position = pos; mCollisionMap.MarkSpace(pos2.x, pos2.y, newEnemy.GetComponent <SimpleMovement>().uniqueCollisionIdentity); }
private void PlaceExit() { Vector2Int pos = mDungeon.primaryPathPositions[mDungeon.primaryPathPositions.Count - 1]; pos = FindEmptyNearbyPosition(pos); GameObject exit = GameObject.Instantiate(PrefabManager.instance.PrefabByName("Exit"), transform); exit.transform.position = MapCoordinateHelper.MapToWorldCoords(pos, 0.4f); ClearFloorDecorations(pos); }
public override void OnBeginDrag(PointerEventData eventData) { var mouseCoordinates = MapCoordinateHelper.ConvertToCoordinates(m_Source.MinCoords, m_Source.MaxCoords, eventData.position); m_OriginTemplate.Coordinates = mouseCoordinates; targetObject = m_Source.Create(WindmillItem.Copy(m_OriginTemplate)); targetObject.Dragable = true; base.OnBeginDrag(eventData); }
private void Teleport() { if (mInterestingDisplays.Count < 1 || mSelectedDisplay == -1) { return; } MapDisplay targetDisplay = mInterestingDisplays[mSelectedDisplay]; Vector2Int target = MapCoordinateHelper.WorldToMapCoords(targetDisplay.transform.position); Game.instance.avatar.QueueTeleportation(target); GetComponentInParent <QuestR>().gameObject.SetActive(false); }
// The projectile thrower AI is intentionally a little clunky, but they shouldn't try throwing // stuff at walls right next to them. This detects if that might be the case. private bool WouldThrowProjectileAtWall() { Vector3 direction = TargetDirection(); Vector2Int currentMapCoords = MapCoordinateHelper.WorldToMapCoords(transform.position); currentMapCoords.x += Mathf.FloorToInt(direction.x); currentMapCoords.y += -Mathf.FloorToInt(direction.z); if (mCollisionMap.SpaceMarking(currentMapCoords.x, currentMapCoords.y) == 1) { return(true); } return(false); }
private void SpawnTeleporter() { // Try to spawn in the center of the boss room, but make sure we spawn a healthy // distance away from the player so they can't accidentally leave prematurely. LevelGenerator generator = GameObject.FindObjectOfType <LevelGenerator>(); Vector2Int mapPos = generator.dungeon.PositionForSpecificTile('9'); mapPos = generator.FindEmptyNearbyPosition(mapPos); Vector3 worldPos = MapCoordinateHelper.MapToWorldCoords(mapPos, 0.4f); GameObject exit = PrefabManager.instance.InstantiatePrefabByName("Exit"); exit.transform.position = worldPos; exit.GetComponent <RevealWhenAvatarIsClose>().Reveal(); }
public void FindCoordinates() { const float width = 2770; const float height = 1847; Vector2 min = new Vector2(22.15f, 44.38334f); Vector2 max = new Vector2(40.18333f, 52.333f); Vector2 position = new Vector2(226f, 102f); Vector2 size = new Vector2(384f, 411f); var mapRect = new Rect(0, 0, width, height); var uiPosition = new Vector2(position.x + size.x / 2, height - (position.y + size.y / 2)); var coords = MapCoordinateHelper.ConvertToCoordinates(min, max, uiPosition, mapRect); Debug.Log(MapCoordinateHelper.ConvertToSingle(coords).ToString("F4")); }
public override IEnumerator PlayInternal(CinematicDirector player) { GameObject.FindObjectOfType <CollisionMap>().MarkSpace(mMapX, mMapY, 1); yield return(new WaitForSeconds(Random.Range(0.2f, 0.4f))); Vector3 worldCoords = MapCoordinateHelper.MapToWorldCoords(new Vector2Int(mMapX, mMapY)); GameObject newObj = PrefabManager.instance.InstantiatePrefabByName(mPrefabName); newObj.transform.position = worldCoords; // todo bdsowers - this was rushed in for a cinematic newObj.transform.GetChild(0).localPosition = Vector3.up * 7f; newObj.transform.GetChild(0).DOLocalMove(Vector3.zero, Random.Range(0.3f, 0.6f)); yield break; }
private void DropItems(string prefabName, int num) { List <Vector2Int> emptySurroundingPositions = null; for (int i = 0; i < num; ++i) { GameObject newItem = GameObject.Instantiate(PrefabManager.instance.PrefabByName(prefabName)); Vector3 sourcePosition = transform.position; Vector3 endPosition = transform.position + VectorHelper.RandomNormalizedXZVector3() * Random.Range(0.1f, 0.3f); if (scatter) { if (emptySurroundingPositions == null) { Vector2Int mapCoords = MapCoordinateHelper.WorldToMapCoords(sourcePosition); emptySurroundingPositions = Game.instance.levelGenerator.collisionMap.EmptyOffsetsNearPosition(mapCoords, 1); } Vector2Int offsetMapPos = new Vector2Int(0, 0); if (emptySurroundingPositions.Count > 0) { offsetMapPos = emptySurroundingPositions.Sample(); } Vector3 offsetWorldPos = MapCoordinateHelper.MapToWorldCoords(offsetMapPos, 0f); endPosition += offsetWorldPos; } newItem.transform.position = sourcePosition; RevealWhenAvatarIsClose reveal = newItem.GetComponentInChildren <RevealWhenAvatarIsClose>(); if (reveal != null) { reveal.enabled = false; } Collectable collectable = newItem.GetComponent <Collectable>(); if (collectable != null) { collectable.PlayDropAnimation(sourcePosition, endPosition, i != 0); } } }
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); }
private void UpdateCollisionMapForMove(Vector3 currentPosition, Vector3 targetPosition) { if (!useCollisionMap) { return; } if (collisionIdentity < 0) { return; } Vector2Int oldCoords = MapCoordinateHelper.WorldToMapCoords(currentPosition); Vector2Int newCoords = MapCoordinateHelper.WorldToMapCoords(targetPosition); mCollisionMap.RemoveMarking(uniqueCollisionIdentity); mCollisionMap.MarkSpace(newCoords.x, newCoords.y, uniqueCollisionIdentity); }
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); }
public void OpenWindow(UIRegionItem uiRegion) { OpenWindow(); var region = uiRegion.Origin; regionName = region.name; mainImage.sprite = spriteContainer.GetSprite(region.name) ?? uiRegion.baseImage.sprite; var r = mainImage.GetRectOfPreserveAspect(); regionCoord = region.Coordinates; var uiCenter = MapCoordinateHelper.ConvertToUI(countryMinCoord, countryMaxCoord, regionCoord, r); regionMinCoord = MapCoordinateHelper.ConvertToCoordinates(countryMinCoord, countryMaxCoord, uiCenter - uiRegion.BaseRect.sizeDelta / 2, r); regionMaxCoord = MapCoordinateHelper.ConvertToCoordinates(countryMinCoord, countryMaxCoord, uiCenter + uiRegion.BaseRect.sizeDelta / 2, r); var coordinatesWindow = UIMainController.Instance.GetWindow <UIMapCoordinatesWindow>(UIConstants.WINDOW_MAP_COORDINATES); coordinatesWindow.OpenWindow(regionMinCoord, regionMaxCoord); layerController.LoadLayers(regionName, regionMinCoord, regionMaxCoord); }
// Update is called once per frame void Update() { if (!mKillable.isDead) { return; } mReviveTime -= Time.deltaTime; if (mReviveTime < 0f) { // See if we can get up - if something is on top of us, we can't Vector2Int mapPos = MapCoordinateHelper.WorldToMapCoords(transform.position); if (mCollisionMap.SpaceMarking(mapPos.x, mapPos.y) == 0) { ++mNumRevives; mReviveTime = Random.Range(60, 120) * mNumRevives; Revive(); } } }
private void PlaceAvatar() { GameObject avatar = GameObject.Find("Avatar"); avatar.transform.SetParent(transform); Vector2Int pos = mDungeon.primaryPathPositions[0]; Vector2Int guaranteedPos = mDungeon.PositionForSpecificTile('p'); if (guaranteedPos.x != -1 && guaranteedPos.y != -1) { pos = guaranteedPos; } pos = FindEmptyNearbyPosition(pos); mAvatarStartPosition = pos; mCollisionMap.MarkSpace(pos.x, pos.y, avatar.GetComponent <SimpleMovement>().uniqueCollisionIdentity); avatar.transform.position = MapCoordinateHelper.MapToWorldCoords(pos); // Also place any followers/pets adjacent to the player Follower follower = avatar.GetComponent <PlayerController>().follower; string followerId = Game.instance.playerData.followerUid; if (string.IsNullOrEmpty(followerId)) { followerId = "1"; } CharacterData followerData = Game.instance.followerData; follower.GetComponentInChildren <CharacterModel>().ChangeModel(followerData); pos = FindEmptyNearbyPosition(pos); follower.transform.position = MapCoordinateHelper.MapToWorldCoords(pos); avatar.GetComponent <Killable>().allowZeroDamage = (CurrentDungeonFloorData().roomSet == "introdungeon"); avatar.GetComponent <PlayerController>().PlaceFollowerInCorrectPosition(); }
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; }
private void PlaceHearts() { List <Vector2Int> walkablePositions = mCollisionMap.EmptyPositions(); int numHearts = 5; for (int i = 0; i < numHearts; ++i) { string prefab = "CollectableHeart"; if (Game.instance.quirkRegistry.IsQuirkActive <GoldDiggerQuirk>()) { prefab = "CollectableCoin"; } GameObject newHeart = GameObject.Instantiate(PrefabManager.instance.PrefabByName(prefab), transform); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newHeart.transform.position = pos; // Don't mark these on the collision map - entities can walk through them freely } }
public void SpawnGhosts(RandomDungeon dungeon, CollisionMap collisionMap, Vector2Int avatarStartPosition) { List <Vector2Int> walkablePositions = collisionMap.EmptyPositions(); walkablePositions.RemoveAll((pos) => VectorHelper.OrthogonalDistance(pos, avatarStartPosition) < 10); // Spawn a few cops in the level int numGhosts = Random.Range(10, 20); for (int i = 0; i < numGhosts; ++i) { if (walkablePositions.Count == 0) { return; } GameObject newGhost = GameObject.Instantiate(PrefabManager.instance.PrefabByName("Ghost")); Vector2Int pos2 = walkablePositions[Random.Range(0, walkablePositions.Count)]; walkablePositions.Remove(pos2); Vector3 pos = MapCoordinateHelper.MapToWorldCoords(pos2); newGhost.transform.position = pos; } }
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"); }