예제 #1
0
    public override IEnumerator Execute(PlayerManager pm, CardActionExecutor cae, int currentAction)
    {
        Vector3Int[]      enemyAdjs      = GridHelper.GetAdjacentTiles(pm.EnemyCoords());
        List <Vector3Int> standableTiles = new List <Vector3Int>();

        for (int i = 0; i < enemyAdjs.Length; ++i)
        {
            if (GridHelper.CanStandOn(enemyAdjs[i]))
            {
                standableTiles.Add(enemyAdjs[i]);
            }
        }

        if (standableTiles.Count > 0)
        {
            int    random = Random.Range(0, standableTiles.Count);
            Pommel pommel = PhotonNetwork.Instantiate(
                "Prefabs/Items/Pommel",
                GridHelper.grid.CellToWorld(standableTiles[random]),
                Quaternion.identity).GetComponent <Pommel>();
            pommel.photonView.RPC("SetSpawner", RpcTarget.All, pm.photonView.ViewID);
        }

        cae.cardPlayState[currentAction] = 1;
        yield return(null);
    }
예제 #2
0
    private void Explode()
    {
        Vector3Int currCords = Coords();

        for (int i = 0; i < 6; ++i)
        {
            Vector3Int          adjTile = GridHelper.GetTileInDirection(currCords, i);
            List <RaycastHit2D> hits    = GridHelper.RaycastTile(adjTile);
            foreach (var hit in hits)
            {
                IAttackable target = hit.transform.parent.GetComponent <IAttackable>();
                if (target != null)
                {
                    Vector3Int newTile = GridHelper.GetTileInDirection(adjTile, i);
                    if (GridHelper.CanStandOn(newTile))
                    {
                        target.MoveTo(newTile);
                    }
                }
            }
        }

        if (photonView.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
        }
    }
예제 #3
0
    public override void _BasicMove(Vector3Int destination)
    {
        Vector3Int[]      adjTiles    = GridHelper.GetAdjacentTiles(Coords());
        List <Vector3Int> tilesInMove = TilesInMove();

        if (!MovesAreSame(adjTiles, tilesInMove))
        {
            base._BasicMove(destination);
            return;
        }

        for (int i = 0; i < 6; ++i)
        {
            if (GridHelper.CanStandOn(adjTiles[i]))
            {
                GridHelper.groundTilemap.SetColor(adjTiles[i], Color.white);
                if (adjTiles[i] == destination && playerInfo.resolve >= MoveCost() - (i == lastBasicMoveDir ? 1 : 0))
                {
                    transform.position = GridHelper.grid.CellToWorld(destination) + cellOffset;
                    UpdateResolve(playerInfo.resolve - Mathf.Max(MoveCost() - (i == lastBasicMoveDir ? 1 : 0), 0));
                    playerInfo.moved = true;
                    playerInfo.turnDistanceTraveled++;
                    lastBasicMoveDir = i;
                }
            }
        }

        UpdateFreeMoveArrows();
    }
예제 #4
0
    public void DamageFunction(int dmg, IAttackable target, bool wpnAtk) ///WORKS ONLY WITH ATKDIST = 2
    {
        int dir = -1;

        Vector3Int[] adjs = GridHelper.GetAdjacentTiles(playerManager.Coords());
        for (int i = 0; i < 6; ++i)
        {
            if (target.Coords() == adjs[i] || target.Coords() == GridHelper.GetTileInDirection(adjs[i], i))
            {
                dir = i;
                break;
            }
        }

        Vector3Int toStandOn = GridHelper.GetTileInDirection(target.Coords(), dir);

        if (GridHelper.CanStandOn(toStandOn))
        {
            target.MoveTo(toStandOn);
        }
        else
        {
            playerManager.DamageTarget(dmg, target, wpnAtk);
        }
    }
예제 #5
0
    //<positionCoords>----------
    public void SetPlayerPosRPC(int x, int y, int z)
    {
        Vector3Int tile = new Vector3Int(x, y, z);

        if (GridHelper.CanStandOn(tile))
        {
            transform.position = GridHelper.grid.CellToWorld(tile) + cellOffset;
        }
    }
예제 #6
0
    public virtual void _BasicMoveShow()
    {
        List <Vector3Int> tiles = TilesInMove();

        foreach (var tile in tiles)
        {
            if (GridHelper.CanStandOn(tile))
            {
                GridHelper.groundTilemap.SetColor(tile, GridHelper.standableTileColor);
            }
        }
    }
예제 #7
0
    public override IEnumerator Execute(PlayerManager pm, CardActionExecutor cae, int currentAction)
    {
        Vector3Int[] adjTiles1 = GridHelper.GetAdjacentTiles(pm.Coords());
        for (int i = 0; i < 6; ++i)
        {
            if (GridHelper.CanStandOn(adjTiles1[i]))
            {
                Vector3Int cTile = GridHelper.GetChargeTile(pm.Coords(), i, chargeRange);
                GridHelper.groundTilemap.SetTileFlags(cTile, UnityEngine.Tilemaps.TileFlags.None);
                GridHelper.groundTilemap.SetColor(cTile, GridHelper.standableTileColor);
            }
        }

        bool       moved       = false;
        int        acDist      = 0;
        Vector3Int newPosition = new Vector3Int();

        while (true)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3Int mouseCoords = pm.MouseCoords();

                Vector3Int[] adjTiles = GridHelper.GetAdjacentTiles(pm.Coords());
                for (int i = 0; i < 6; ++i)
                {
                    if (GridHelper.CanStandOn(adjTiles[i]))
                    {
                        Vector3Int cTile = GridHelper.GetChargeTile(pm.Coords(), i, chargeRange, ref acDist);
                        GridHelper.groundTilemap.SetColor(cTile, Color.white);
                        if (GridHelper.CanStandOn(cTile) && cTile == mouseCoords)
                        {
                            newPosition = cTile;
                            moved       = true;
                        }
                    }
                }
                break;
            }
            yield return(null);
        }
        if (moved)
        {
            pm.MoveTo(newPosition);
            cae.cardPlayState[currentAction] = 1;
        }
        else
        {
            cae.cardPlayState[currentAction] = 2;
        }
    }
예제 #8
0
    public void MoveToRPC(int x, int y, int z)
    {
        if (!photonView.IsMine)
        {
            return;
        }

        Vector3Int tile = new Vector3Int(x, y, z);

        if (GridHelper.CanStandOn(tile))
        {
            transform.position = GridHelper.grid.CellToWorld(tile) + cellOffset;
        }
    }
예제 #9
0
    private void PushTarget(IAttackable target)
    {
        Vector3Int[]      adjs       = GridHelper.GetAdjacentTiles(target.Coords());
        List <Vector3Int> standables = new List <Vector3Int>();

        foreach (var tile in adjs)
        {
            if (GridHelper.CanStandOn(tile))
            {
                standables.Add(tile);
            }
        }

        target.MoveTo(standables[Random.Range(0, standables.Count)]);
    }
예제 #10
0
    public override IEnumerator Execute(PlayerManager pm, CardActionExecutor cae, int currentAction)
    {
        List <Vector3Int> blinkTiles = GridHelper.TilesInDistance(pm.Coords(), blinkRange);

        foreach (var tile in blinkTiles)
        {
            if (GridHelper.CanStandOn(tile))
            {
                GridHelper.groundTilemap.SetTileFlags(tile, UnityEngine.Tilemaps.TileFlags.None);
                GridHelper.groundTilemap.SetColor(tile, GridHelper.standableTileColor);
            }
        }

        Vector3Int newPosition = new Vector3Int();
        bool       moved       = false;

        while (true)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3Int mouseCoords = pm.MouseCoords();

                for (int i = 0; i < blinkTiles.Count; ++i)
                {
                    var tile = blinkTiles[i];
                    GridHelper.groundTilemap.SetColor(tile, Color.white);
                    if (GridHelper.CanStandOn(tile) && tile == mouseCoords)
                    {
                        newPosition = tile;
                        moved       = true;
                    }
                }
                break;
            }
            yield return(null);
        }
        if (moved)
        {
            pm.MoveTo(newPosition);
            cae.cardPlayState[currentAction] = 1;
        }
        else
        {
            cae.cardPlayState[currentAction] = 2;
        }

        yield return(null);
    }
예제 #11
0
    public override bool Check(PlayerManager pm)
    {
        if (!pm.CanMove())
        {
            return(false);
        }

        bool ok = false;

        Vector3Int[] adjTiles1 = GridHelper.GetAdjacentTiles(pm.Coords());
        for (int i = 0; i < 6; ++i)
        {
            bool cso = GridHelper.CanStandOn(adjTiles1[i]);
            ok |= cso;
        }
        return(ok && pm.state.CanMove());
    }
예제 #12
0
    public override bool Check(PlayerManager pm)
    {
        if (!pm.CanMove())
        {
            return(false);
        }

        blinkTiles = GridHelper.TilesInDistance(pm.Coords(), range);

        foreach (Vector3Int tile in blinkTiles)
        {
            if (GridHelper.CanStandOn(tile))
            {
                return(true);
            }
        }
        return(false);
    }
예제 #13
0
    public virtual void _BasicMove(Vector3Int destination)
    {
        List <Vector3Int> tiles = TilesInMove();

        foreach (var tile in tiles)
        {
            if (GridHelper.CanStandOn(tile))
            {
                GridHelper.groundTilemap.SetColor(tile, Color.white);
                if (tile == destination && playerInfo.resolve >= MoveCost())
                {
                    MoveTo(destination);
                    UpdateResolve(playerInfo.resolve - MoveCost());
                    playerInfo.moved        = true;
                    playerInfo.nextFreeMove = false;
                }
            }
        }
    }
예제 #14
0
    private bool MovesAreSame(Vector3Int[] adjTiles, List <Vector3Int> tilesInMove)
    {
        bool ok     = true;
        int  acSize = 0;

        for (int i = 0; i < 6; ++i)
        {
            if (GridHelper.CanStandOn(adjTiles[i]))
            {
                acSize++;
                ok &= GridHelper.TileInList(adjTiles[i], tilesInMove);
            }
            if (!ok)
            {
                break;
            }
        }

        return(ok && acSize == tilesInMove.Count);
    }
예제 #15
0
    public bool StandableChecker(Vector3Int tile)
    {
        bool ok = true;

        if (checkCanStandOn)
        {
            ok &= GridHelper.CanStandOn(tile);
        }
        if (checkOccupied)
        {
            ok &= !GridHelper.TileOccupied(tile);
        }

        List <RaycastHit2D> hits = GridHelper.RaycastTile(tile); //check item already on tile

        foreach (var hit in hits)
        {
            ok &= !(hit.transform.parent.name == itemName + "(Clone)" || hit.transform.name == itemName + "(Clone)");
        }

        return(ok);
    }
    private IEnumerator PullTargetsTowards(Vector3Int targetTile)
    {
        List <IAttackable> attackables = GridHelper.IAttackablesInTiles(GridHelper.TilesInDistance(_playerManager.Coords(), -1));

        attackables.Remove(_playerManager);

        List <List <IAttackable> >        attackablesByDist = new List <List <IAttackable> >();
        List <List <List <Vector3Int> > > availableByDist   = new List <List <List <Vector3Int> > >();

        for (int i = 0; i <= GridHelper.MAX_TILEDIST_ON_MAP; ++i)   //populate attackablesByDist
        {
            attackablesByDist.Add(new List <IAttackable>());

            foreach (var atk in attackables)
            {
                if (GridHelper.TileDistance(targetTile, atk.Coords()) == i)
                {
                    attackablesByDist[i].Add(atk);
                }
            }
        }

        for (int dist = 0; dist <= GridHelper.MAX_TILEDIST_ON_MAP; ++dist)   //populate availableByDist
        {
            availableByDist.Add(new List <List <Vector3Int> >());

            foreach (IAttackable attackable in attackablesByDist[dist])
            {
                availableByDist[dist].Add(new List <Vector3Int>());
                Vector3Int[] atkAdjs = GridHelper.GetAdjacentTiles(attackable.Coords());
                for (int i = 0; i < 6; ++i)
                {
                    if (GridHelper.groundTilemap.HasTile(atkAdjs[i]) && GridHelper.TileDistance(targetTile, atkAdjs[i]) == dist - 1)
                    {
                        availableByDist[dist][availableByDist[dist].Count - 1].Add(atkAdjs[i]);
                    }
                }
            }
        }

        //move non players
        for (int dist = 0; dist <= GridHelper.MAX_TILEDIST_ON_MAP; ++dist)
        {
            for (int attackableId = 0; attackableId < availableByDist[dist].Count; ++attackableId)
            {
                IAttackable attackable = attackablesByDist[dist][attackableId];
                if (attackable is PlayerManager) //
                {
                    continue;
                }

                foreach (var avalibleTile in availableByDist[dist][attackableId])
                {
                    if (GridHelper.CanStandOn(avalibleTile))
                    {
                        attackable.MoveTo(avalibleTile);
                        break;
                    }
                }

                yield return(new WaitForSeconds(0.1f));
            }
        }

        //move players, same code as before
        for (int dist = 0; dist <= GridHelper.MAX_TILEDIST_ON_MAP; ++dist)
        {
            for (int attackableId = 0; attackableId < availableByDist[dist].Count; ++attackableId)
            {
                IAttackable attackable = attackablesByDist[dist][attackableId];
                if (!(attackable is PlayerManager)) //only dif here
                {
                    continue;
                }

                foreach (var avalibleTile in availableByDist[dist][attackableId])
                {
                    if (GridHelper.CanStandOn(avalibleTile))
                    {
                        attackable.MoveTo(avalibleTile);
                        break;
                    }
                }


                yield return(new WaitForSeconds(0.1f));
            }
        }
    }