Beispiel #1
0
    //private void AddExitSpot (ExitSpotData data) {
    //    ExitSpot prop = new ExitSpot (this, data);
    //    allTiles.Add (prop);
    //    objectsAddedThisMove.Add(prop);
    //    goalObjects.Add (prop);
    //}
    private void AddGenericTile(GenericTileData data)
    {
        GenericTile obj = new GenericTile(this, data);

        allTiles.Add(obj);
        objectsAddedThisMove.Add(obj);
    }
Beispiel #2
0
    public virtual void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix, Color color)
    {
        InternalSetTile(position, tile);

        tilemap.SetColor(position, color);
        tilemap.SetTransformMatrix(position, transformMatrix);
        subsystemManager?.UpdateAt(position);
    }
Beispiel #3
0
    /// <summary>
    /// Set tile and invoke tile changed event.
    /// </summary>
    protected bool InternalSetTile(Vector3Int position, GenericTile tile)
    {
        bool HasTile = tilemap.HasTile(position);

        tilemap.SetTile(position, tile);
        OnTileChanged.Invoke(position, tile);
        return(HasTile);
    }
 public void launchFight(GameObject attack, GenericTile attackerTile, GameObject defense, GenericTile victimTile)
 {
     attacker        = attack;
     defender        = defense;
     attackerLastPos = attack.transform.position;
     defenderLastPos = defense.transform.position;
     departPos       = attack.transform.position;
     goalPos         = defender.transform.position;
     phase           = 0;
 }
Beispiel #5
0
    /// <summary>
    /// Set tile and invoke tile changed event.
    /// </summary>
    protected bool InternalSetTile(Vector3Int position, GenericTile tile)
    {
        var hasTile = tilemap.HasTile(position);

        tilemap.SetTile(position, tile);
        if (recalculateBoundsHandle == null)
        {
            this.RestartCoroutine(RecalculateBoundsNextFrame(), ref recalculateBoundsHandle);
        }
        return(hasTile);
    }
 public void PlaceTile(Vector3Int position, GenericTile tile, Matrix4x4 matrixTransform)
 {
     if (tile is LayerTile)
     {
         PlaceLayerTile(position, (LayerTile)tile, matrixTransform);
     }
     else if (tile is MetaTile)
     {
         PlaceMetaTile(position, (MetaTile)tile, matrixTransform);
     }
 }
Beispiel #7
0
    void findPath(int movementPoint, GenericTile tile, GenericTile parent)
    {
        if (tile.value != 100000 && tile.value > movementPoint)
        {
            return;
        }
        if (movementPoint <= 0 || (parent != null && parent.parent != null && parent.parent == tile))
        {
            return;
        }
        if (tile.pos == ground.WorldToCell(selectedCharacter.transform.position))
        {
            return;
        }
        GenericTile tmp;

        Vector3Int characterLayerPos = characterLayer.WorldToCell(ground.CellToWorld(tile.pos));

        tile.value  = movementPoint;
        tile.parent = parent;
        movement.SetTile(new Vector3Int(tile.pos.x, tile.pos.y, 0), possibleMovement);
        TileBase t = movement.GetTile(new Vector3Int(tile.pos.x, tile.pos.y, 0));

        tmp = Instantiate(t) as GenericTile;
        possibleMovement.StartUp(new Vector3Int(tile.pos.x, tile.pos.y, 0), tmp.tilemap, tmp.gameObject);
        tmp.value  = movementPoint;
        tmp.parent = parent;
        movement.SetTile(new Vector3Int(tile.pos.x, tile.pos.y, 0), tmp);
        tmp = Instantiate(movement.GetTile(new Vector3Int(tile.pos.x, tile.pos.y, 0))) as GenericTile;
        if (ground.GetTile(new Vector3Int(tile.pos.x - 1, tile.pos.y, 0)) != null && obstacles.GetTile(new Vector3Int(tile.pos.x - 1, tile.pos.y, 0)) == null && characterLayer.GetTile(new Vector3Int(characterLayerPos.x - 1, characterLayerPos.y, 0)) == null && (tmp = Instantiate(ground.GetTile(new Vector3Int(tile.pos.x - 1, tile.pos.y, 0))) as GenericTile) != null && (tmp.value < movementPoint - tmp.cost || tmp.value == 100000))
        {
            tmp.value = movementPoint - tmp.cost;
            ground.SetTile(tmp.pos, tmp);
            findPath(movementPoint - tmp.cost, tmp, tile);
        }
        if (ground.GetTile(new Vector3Int(tile.pos.x + 1, tile.pos.y, 0)) != null && obstacles.GetTile(new Vector3Int(tile.pos.x + 1, tile.pos.y, 0)) == null && characterLayer.GetTile(new Vector3Int(characterLayerPos.x + 1, characterLayerPos.y, 0)) == null && (tmp = Instantiate(ground.GetTile(new Vector3Int(tile.pos.x + 1, tile.pos.y, 0))) as GenericTile) != null && (tmp.value < movementPoint - tmp.cost || tmp.value == 100000))
        {
            tmp.value = movementPoint - tmp.cost;
            ground.SetTile(tmp.pos, tmp);
            findPath(movementPoint - tmp.cost, tmp, tile);
        }
        if (ground.GetTile(new Vector3Int(tile.pos.x, tile.pos.y - 1, 0)) != null && obstacles.GetTile(new Vector3Int(tile.pos.x, tile.pos.y - 1, 0)) == null && characterLayer.GetTile(new Vector3Int(characterLayerPos.x, characterLayerPos.y - 1, 0)) == null && (tmp = Instantiate(ground.GetTile(new Vector3Int(tile.pos.x, tile.pos.y - 1, 0))) as GenericTile) != null && (tmp.value < movementPoint - tmp.cost || tmp.value == 100000))
        {
            tmp.value = movementPoint - tmp.cost;
            ground.SetTile(tmp.pos, tmp);
            findPath(movementPoint - tmp.cost, tmp, tile);
        }
        if (ground.GetTile(new Vector3Int(tile.pos.x, tile.pos.y + 1, 0)) != null && obstacles.GetTile(new Vector3Int(tile.pos.x, tile.pos.y + 1, 0)) == null && characterLayer.GetTile(new Vector3Int(characterLayerPos.x, characterLayerPos.y + 1, 0)) == null && (tmp = Instantiate(ground.GetTile(new Vector3Int(tile.pos.x, tile.pos.y + 1, 0))) as GenericTile) != null && (tmp.value < movementPoint - tmp.cost || tmp.value == 100000))
        {
            tmp.value = movementPoint - tmp.cost;
            ground.SetTile(tmp.pos, tmp);
            findPath(movementPoint - tmp.cost, tmp, tile);
        }
    }
Beispiel #8
0
    private static void Json2Map()
    {
        GameObject  map         = GameObject.FindGameObjectWithTag("Map");
        MetaTileMap metaTileMap = map.GetComponentInChildren <MetaTileMap>();

        metaTileMap.ClearAllTiles();

        TilemapConverter converter = new TilemapConverter();

        TileMapBuilder builder = new TileMapBuilder(metaTileMap, true);

        Dictionary <string, TilemapLayer> layers = DeserializeJson();

        List <Tuple <Vector3Int, ObjectTile> > objects = new List <Tuple <Vector3Int, ObjectTile> >();

        foreach (KeyValuePair <string, TilemapLayer> layer in layers)
        {
            List <Vector3Int> positions =
                layer.Value.TilePositions.ConvertAll(coord => new Vector3Int(coord.X, coord.Y, 0));

            for (int i = 0; i < positions.Count; i++)
            {
                Vector3Int  position = positions[i];
                GenericTile tile     = converter.DataToTile(layer.Value.Tiles[i]);

                if (tile is ObjectTile)
                {
                    if (!objects.Exists(t => t.Item1.Equals(position) && t.Item2 == tile))
                    {
                        objects.Add(new Tuple <Vector3Int, ObjectTile>(position, (ObjectTile)tile));
                    }
                }
                else
                {
                    builder.PlaceTile(position, tile);
                }
            }
        }

        foreach (Tuple <Vector3Int, ObjectTile> tuple in objects)
        {
            Vector3Int position = tuple.Item1;
            ObjectTile obj      = tuple.Item2;

            Matrix4x4 matrix = obj.Rotatable ? FindObjectPosition(metaTileMap, ref position, obj) : Matrix4x4.identity;

            builder.PlaceTile(position, obj, matrix);
        }

        // mark as dirty, otherwise the scene can't be saved.
        EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
        Logger.Log("Import kinda finished");
    }
Beispiel #9
0
    public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix, Color color)
    {
        ObjectTile objectTile = tile as ObjectTile;

        if (objectTile)
        {
            //hack to expand bounds when placing items in editor
            base.InternalSetTile(position, tile);
            base.InternalSetTile(position, null);

            objectTile.SpawnObject(position, tilemap, transformMatrix);
        }
    }
Beispiel #10
0
 void setBackGroundValues()
 {
     foreach (Vector3Int position in ground.cellBounds.allPositionsWithin)
     {
         TileBase t = ground.GetTile(position);
         if (!Equals(t, null))
         {
             if (t is GenericTile)
             {
                 GenericTile gt = Instantiate(t) as GenericTile;
                 gt.value = 100000;
                 ground.SetTile(position, gt);
             }
         }
     }
 }
Beispiel #11
0
    public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
    {
        var isServer = false;
        if (CustomNetworkManager.Instance != null)
        {
            isServer = CustomNetworkManager.Instance._isServer;
        }
        else
        {
            if (!Application.isPlaying) isServer = true;
        }

        //We do not want to duplicate under floor tiles if they are the same:
        if (TileStore.ContainsKey(position.To2Int()))
        {
            foreach (var l in TileStore[position.To2Int()])
            {
                if (l == tile)
                {
                    //duplicate found aborting
                    return;
                }
            }
        }

        if (isServer)
        {
            Vector2Int position2 = position.To2Int();
            if (!TileStore.ContainsKey(position2))
            {
                TileStore.Add(position2, new List<LayerTile>());
            }

            position.z = 1 - TileStore[position2].Count;
            TileStore[position2].Add((LayerTile)tile);

            if (Application.isPlaying)
            {
                matrix.TileChangeManager.UnderfloorUpdateTile(position, tile as BasicTile);
            }
            base.SetTile(position, tile, transformMatrix);
        }
        else
        {
            base.SetTile(position, tile, transformMatrix);
        }
    }
Beispiel #12
0
    // Start is called before the first frame update
    void Start()
    {
        ground         = GameObject.FindGameObjectWithTag("Ground").GetComponent <Tilemap>();
        obstacles      = GameObject.FindGameObjectWithTag("Obstacles").GetComponent <Tilemap>();
        movement       = GameObject.FindGameObjectWithTag("Movement").GetComponent <Tilemap>();
        characterLayer = GameObject.FindGameObjectWithTag("CharacterLayer").GetComponent <Tilemap>();

        foreach (Vector3Int position in ground.cellBounds.allPositionsWithin)
        {
            TileBase t = ground.GetTile(position);
            if (!Equals(t, null))
            {
                if (t is GenericTile)
                {
                    GenericTile gt = Instantiate(t) as GenericTile;
                    gt.StartUp(position, gt.tilemap, gt.gameObject);
                    ground.SetTile(position, gt);
                }
            }
        }

        foreach (Vector3Int position in obstacles.cellBounds.allPositionsWithin)
        {
            TileBase t = obstacles.GetTile(position);
            if (!Equals(t, null))
            {
                if (t is GenericTile)
                {
                    GenericTile gt = Instantiate(t) as GenericTile;
                    gt.StartUp(position, gt.tilemap, gt.gameObject);
                    obstacles.SetTile(position, gt);
                }
            }
        }
        sizeMap = new Vector2(ground.size.x * ground.cellSize.x, ground.size.y * ground.cellSize.y);

        Vector3 CameraPos = ground.CellToWorld(ground.origin);

        CameraPos.z  -= 1.5f;
        CameraPos.y  += sizeMap.y / 2;
        mapOriginCell = new Vector2(CameraPos.x, CameraPos.y);
        GameObject.FindGameObjectWithTag("MainCamera").transform.position = CameraPos;

        Vector3 pos = ground.GetCellCenterWorld(new Vector3Int(-7, 0, 0));

        pos.z = -1.2f;
    }
Beispiel #13
0
        public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
        {
            ObjectTile objectTile = tile as ObjectTile;

            if (objectTile)
            {
                if (!objectTile.IsItem)
                {
                    tilemap.SetTile(position, null);
                }
                objectTile.SpawnObject(position, tilemap, transformMatrix);
            }
            else
            {
                base.SetTile(position, tile, transformMatrix);
            }
        }
Beispiel #14
0
 void removeTakenMovement()
 {
     foreach (Vector3Int position in movement.cellBounds.allPositionsWithin)
     {
         TileBase t = movement.GetTile(position);
         if (!Equals(t, null))
         {
             if (t is GenericTile)
             {
                 GenericTile gt = Instantiate(t) as GenericTile;
                 if (gt.type == "TakenMovement")
                 {
                     movement.SetTile(position, null);
                 }
             }
         }
     }
 }
Beispiel #15
0
    void showTakenPath(GenericTile tile)
    {
        if (tile.parent != null)
        {
            showTakenPath(tile.parent);
        }
        GenericTile tmp = tile;
        GenericTile gt  = Instantiate(movement.GetTile(tile.pos)) as GenericTile;

        movement.SetTile(tmp.pos, takenMovement);
        TileBase    t    = movement.GetTile(new Vector3Int(tile.pos.x, tile.pos.y, 0));
        GenericTile tmp2 = Instantiate(t) as GenericTile;

        tmp2.pos    = gt.pos;
        tmp2.parent = gt.parent;
        tmp2.value  = gt.value;
        movement.SetTile(tmp2.pos, tmp2);
    }
Beispiel #16
0
    void findAttack(int attackRange, GenericTile tile)
    {
        Vector3Int pos = tile.pos;

        pos = characterLayer.WorldToCell(ground.CellToWorld(pos));

        for (int y2 = -attackRange; y2 <= attackRange; y2++)
        {
            for (int x2 = -attackRange; x2 <= attackRange; x2++)
            {
                if (Mathf.Abs(y2) + Mathf.Abs(x2) <= attackRange && Mathf.Abs(y2) + Mathf.Abs(x2) > 0)
                {
                    GenericTile tmp2;
                    movement.SetTile(new Vector3Int(pos.x - x2, pos.y - y2, 0), possibleAttack);
                    TileBase t = movement.GetTile(new Vector3Int(pos.x - x2, pos.y - y2, 0));
                    tmp2 = Instantiate(t) as GenericTile;
                    possibleMovement.StartUp(new Vector3Int(pos.x - x2, pos.y - y2, 0), tmp2.tilemap, tmp2.gameObject);
                    movement.SetTile(new Vector3Int(pos.x - x2, pos.y - y2, 0), tmp2);
                }
            }
        }
    }
Beispiel #17
0
    public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
    {
        var isServer = false;

        if (CustomNetworkManager.Instance != null)
        {
            isServer = CustomNetworkManager.Instance._isServer;
        }
        else
        {
            if (!Application.isPlaying)
            {
                isServer = true;
            }
        }

        if (isServer)
        {
            Vector2Int position2 = position.To2Int();
            if (!TileStore.ContainsKey(position2))
            {
                TileStore.Add(position2, new List <LayerTile>());
            }

            position.z = 1 - TileStore[position2].Count;
            TileStore[position2].Add((LayerTile)tile);

            if (Application.isPlaying)
            {
                matrix.TileChangeManager.UpdateTile(position, tile as BasicTile, false);
            }
            base.SetTile(position, tile, transformMatrix);
        }
        else
        {
            base.SetTile(position, tile, transformMatrix);
        }
    }
Beispiel #18
0
    List <Vector3> listMoves(Vector3Int destination)
    {
        List <Vector3> res = new List <Vector3>();

        GenericTile gt = Instantiate(movement.GetTile(destination)) as GenericTile;

        while (gt != null)
        {
            Vector3 tmp = movement.GetCellCenterWorld(gt.pos);
            tmp.z = selectedCharacter.transform.position.z;
            Vector3 posCharacter = movement.WorldToCell(selectedCharacter.transform.position);
            if (posCharacter.x == gt.pos.x && posCharacter.y == gt.pos.y)
            {
                movement.SetTile(gt.pos, null);
                selectedCharacter.transform.position = tmp;
            }
            else
            {
                res.Insert(res.Count, tmp);
            }
            gt = gt.parent;
        }
        return(res);
    }
Beispiel #19
0
 void removeTakenPath()
 {
     foreach (Vector3Int position in movement.cellBounds.allPositionsWithin)
     {
         TileBase t = movement.GetTile(position);
         if (!Equals(t, null))
         {
             if (t is GenericTile)
             {
                 GenericTile gt = Instantiate(t) as GenericTile;
                 if (gt.type == "TakenMovement")
                 {
                     movement.SetTile(position, possibleMovement);
                     TileBase    t2   = movement.GetTile(position);
                     GenericTile tmp2 = Instantiate(t2) as GenericTile;
                     tmp2.pos    = gt.pos;
                     tmp2.parent = gt.parent;
                     tmp2.value  = gt.value;
                     movement.SetTile(tmp2.pos, tmp2);
                 }
             }
         }
     }
 }
 // ----------------------------------------------------------------
 //  Initialize
 // ----------------------------------------------------------------
 override public void Initialize(BoardView _myBoardView, Tile bo)
 {
     MyGenericTile = bo as GenericTile;
     base.Initialize(_myBoardView, bo);
     gameObject.name = "Tile_" + bo.MyType;
 }
Beispiel #21
0
 public virtual void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
 {
     tilemap.SetTile(position, tile);
     tilemap.SetTransformMatrix(position, transformMatrix);
     systemManager.UpdateAt(position);
 }
    public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix, Color color)
    {
        var isServer = false;

        if (CustomNetworkManager.Instance != null)
        {
            isServer = CustomNetworkManager.Instance._isServer;
        }
        else
        {
            if (!Application.isPlaying)
            {
                isServer = true;
            }
        }

        //We do not want to duplicate under floor tiles if they are the same:
        if (TileStore.ContainsKey(position.To2Int()))
        {
            foreach (var l in TileStore[position.To2Int()])
            {
                if (l == tile)
                {
                    //duplicate found aborting
                    return;
                }
            }
        }

        if (isServer)
        {
            Vector2Int position2 = position.To2Int();
            if (!TileStore.ContainsKey(position2))
            {
                for (int i = 0; i < 50; i++)
                {
                    var localPlace = position;
                    localPlace.z = -i + 1;
                    var getTile = tilemap.GetTile(localPlace) as LayerTile;
                    if (getTile != null)
                    {
                        if (!TileStore.ContainsKey((Vector2Int)localPlace))
                        {
                            TileStore.Add((Vector2Int)localPlace, new List <LayerTile>());
                        }

                        TileStore[(Vector2Int)localPlace].Add(getTile);
                    }
                }

                if (!TileStore.ContainsKey(position2))
                {
                    TileStore[position2] = new List <LayerTile>();
                }
            }

            int index = FindFirstEmpty(TileStore[position2]);
            if (index < 0)
            {
                position.z = 1 - TileStore[position2].Count;
                TileStore[position2].Add((LayerTile)tile);
            }
            else
            {
                position.z = 1 - index;
                TileStore[position2][index] = (LayerTile)tile;
            }


            if (Application.isPlaying)
            {
                matrix.TileChangeManager.UnderfloorUpdateTile(position, tile as BasicTile, transformMatrix, color);
            }
            else
            {
                if (position.z < -49)
                {
                    Logger.LogError("Tile has reached maximum Meta data system depth This could be from accidental placing of multiple tiles", Category.Editor);
                    return;
                }
            }

            base.SetTile(position, tile, transformMatrix, color);
        }
        else
        {
            base.SetTile(position, tile, transformMatrix, color);
        }
    }
Beispiel #23
0
 void SimulateAttack(GameObject attacker, GenericTile attackerTile, GameObject victim, GenericTile victimTile)
 {
     canInteract = false;
     GameObject.FindGameObjectWithTag("CombatSimulator").GetComponent <CombatSimulator>().launchFight(attacker, attackerTile, victim, victimTile);
 }
 public void PlaceTile(Vector3Int position, GenericTile tile)
 {
     PlaceTile(position, tile, Matrix4x4.identity);
 }
Beispiel #25
0
    // Update is called once per frame

    void Update()
    {
        Vector3    mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2    mousePos2D = new Vector2(mousePos.x, mousePos.y);
        Vector3Int mouseGrid  = movement.WorldToCell(mousePos);

        mouseGrid.z = 0;

        updateCamera();

        // If mouvement is processing continue the movement

        if (listOfMoves.Count > 0 && selectedCharacter != null)
        {
            if (selectedCharacter.transform.position == listOfMoves[listOfMoves.Count - 1])
            {
                listOfMoves.RemoveAt(listOfMoves.Count - 1);
                Vector3Int posOfPlayer = movement.WorldToCell(selectedCharacter.transform.position);
                posOfPlayer.z = 0;
                movement.SetTile(posOfPlayer, null);
                percentageOfMovement = 0;
                Vector3 groundTilePos = selectedCharacter.transform.position;
                groundTilePos.z = 0;
                selectedCharacter.GetComponent <Character>().RemoveMovementPoint((Instantiate(ground.GetTile(ground.WorldToCell(groundTilePos)) as GenericTile)).cost);
                if (listOfMoves.Count == 0)
                {
                    Vector3 characterPos = selectedCharacter.transform.position;
                    characterPos.z = 0;
                    characterLayer.SetTile(characterLayer.WorldToCell(characterPos), characterTile);
                    TileBase      t   = characterLayer.GetTile(characterLayer.WorldToCell(characterPos));
                    CharacterTile tmp = Instantiate(t) as CharacterTile;
                    tmp.character = selectedCharacter.gameObject;
                    characterLayer.SetTile(characterLayer.WorldToCell(characterPos), tmp);
                    canInteract       = true;
                    selectedCharacter = null;
                }
            }
            else
            {
                percentageOfMovement += 0.05f;
                selectedCharacter.transform.position = Vector3.Lerp(selectedCharacter.transform.position, listOfMoves[listOfMoves.Count - 1], percentageOfMovement);
            }
        }

        // Else player can play

        else if (attackAction == false && selectedCharacter != null && movement.GetTile(mouseGrid) != null && (Instantiate(movement.GetTile(mouseGrid)) as GenericTile) != null && (Instantiate(movement.GetTile(mouseGrid)) as GenericTile).pos != lastMovementPos)
        {
            lastMovementPos = (Instantiate(movement.GetTile(mouseGrid)) as GenericTile).pos;
            removeTakenPath();
            showTakenPath(Instantiate(movement.GetTile(mouseGrid)) as GenericTile);
        }
        else if (attackAction == false && selectedCharacter != null && movement.GetTile(mouseGrid) == null)
        {
            lastMovementPos = new Vector3Int(1000000, 1000000, 0);
            removeTakenPath();
        }
        if (Input.GetMouseButtonDown(0) && canInteract)
        {
            if (selectedCharacter != null)
            {
                Vector3Int mousePosGrid = movement.WorldToCell(selectedCharacter.transform.position);
                if (attackAction == false && movement.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null)
                {
                    removePossibleMovement();
                    canInteract = false;
                    listOfMoves = listMoves(mouseGrid);
                    if (listOfMoves.Count <= 0)
                    {
                        canInteract       = true;
                        selectedCharacter = null;
                    }
                    else
                    {
                        Vector3Int characterLayerPos = characterLayer.WorldToCell(selectedCharacter.transform.position);
                        characterLayerPos.z = 0;
                        characterLayer.SetTile(characterLayerPos, null);
                    }
                }
                else if (attackAction && movement.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null && characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0)) != null &&
                         (Instantiate(characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0))) as CharacterTile).character.GetComponent <Character>().ally != selectedCharacter.GetComponent <Character>().ally)
                {
                    Vector3Int characterLayerPos = characterLayer.WorldToCell(selectedCharacter.transform.position);
                    characterLayerPos.z = 0;
                    CharacterTile tmp = Instantiate(characterLayer.GetTile(new Vector3Int(mouseGrid.x, mouseGrid.y, 0))) as CharacterTile;
                    if (tmp.character.GetComponent <Ressuractable>() != null && tmp.character.GetComponent <Ressuractable>().canBeRessurected&& selectedCharacter.GetComponent <Character>().necromancer == true)
                    {
                        tmp.character.GetComponent <Ressuractable>().Ressurect();
                    }
                    else if (tmp.character.GetComponent <Ressuractable>() == null || (tmp.character.GetComponent <Ressuractable>() != null && !tmp.character.GetComponent <Ressuractable>().canBeRessurected))
                    {
                        GenericTile attackerTile = Instantiate(ground.GetTile(ground.WorldToCell(new Vector3(selectedCharacter.transform.position.x, selectedCharacter.transform.position.y, 0)))) as GenericTile;
                        GenericTile opponentTile = Instantiate(ground.GetTile(ground.WorldToCell(new Vector3(mousePos.x, mousePos.y, 0)))) as GenericTile;

                        SimulateAttack(selectedCharacter, attackerTile, tmp.character, opponentTile);
                    }
                    selectedCharacter.GetComponent <Character>().canAttacked = false;
                    removePossibleAttack();
                    removePossibleMovement();
                    removeTakenMovement();
                    selectedCharacter = null;
                }
                else
                {
                    removePossibleMovement();
                    removeTakenMovement();
                    removePossibleAttack();
                    selectedCharacter = null;
                    attackAction      = false;
                }
            }
            else
            {
                RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
                if (hit.collider != null)
                {
                    selectedCharacter = hit.collider.gameObject;
                    if (selectedCharacter.GetComponent <Character>().ally == true && selectedCharacter.GetComponent <Character>().actualMovementPoint > 0)
                    {
                        showMovementOfPlayer();
                    }
                    else
                    {
                        selectedCharacter = null;
                    }
                }
            }
        }
        if (Input.GetMouseButtonDown(1) && canInteract)
        {
            if (selectedCharacter != null)
            {
                removePossibleMovement();
                removeTakenMovement();
                removePossibleAttack();
                selectedCharacter = null;
                attackAction      = false;
            }
            else
            {
                RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
                if (hit.collider != null)
                {
                    selectedCharacter = hit.collider.gameObject;
                    if (selectedCharacter.GetComponent <Character>().ally == true && selectedCharacter.GetComponent <Character>().canAttacked)
                    {
                        showAttackOfPlayer();
                        attackAction = true;
                    }
                    else
                    {
                        selectedCharacter = null;
                    }
                }
            }
        }
    }
Beispiel #26
0
 /// <summary>
 /// Set tile and invoke tile changed event.
 /// </summary>
 protected void InternalSetTile(Vector3Int position, GenericTile tile)
 {
     tilemap.SetTile(position, tile);
     OnTileChanged.Invoke(position, tile);
 }