Пример #1
0
    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));
        }
    }
Пример #2
0
    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;
    }
Пример #3
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);
    }
Пример #4
0
    private bool IsPositionEmpty(Vector2Int pos)
    {
        int  tileType      = mDungeon.TileType(pos);
        bool possiblyEmpty = (tileType == RandomDungeonTileData.WALKABLE_TILE ||
                              tileType == RandomDungeonTileData.EXIT_TILE ||
                              tileType == AVATAR_POSITION);

        if (!possiblyEmpty)
        {
            return(false);
        }

        return(mCollisionMap.SpaceMarking(pos.x, pos.y) == 0);
    }
Пример #5
0
    // 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);
    }
Пример #6
0
    private Vector2Int FindEmptyNearbyPosition(Vector2Int sourcePos, CollisionMap collisionMap)
    {
        for (int xOffset = -1; xOffset <= 1; ++xOffset)
        {
            for (int yOffset = 1; yOffset >= -1; --yOffset)
            {
                Vector2Int pos = sourcePos + new Vector2Int(xOffset, yOffset);
                if (collisionMap.SpaceMarking(pos.x, pos.y) == 0 &&
                    Mathf.Abs(xOffset) != Mathf.Abs(yOffset))
                {
                    return(pos);
                }
            }
        }

        return(sourcePos);
    }
Пример #7
0
    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");
    }
Пример #8
0
    // 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();
            }
        }
    }
Пример #9
0
    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");
    }