Exemplo n.º 1
0
    public void PlaceBuilding(Building building, Coordinates coords)
    {
        building.transform.position = new Vector3(coords.x, 0, coords.z);
        GridCell cell = gridManager.GetCell(coords);

        if (cell.Building != null)
        {
            throw new CellOccupiedException(cell, "");
        }

        List <GridCell> neighborCells = new List <GridCell>();

        foreach (Vector3 routeDelta in building.RouteDeltas)
        {
            Vector3 delta = Quaternion.Euler(0, building.transform.eulerAngles.y, 0) * routeDelta;
            neighborCells.Add(gridManager.GetCell(coords + delta));
        }

        cell.Building          = building;
        building.Cell          = cell;
        building.NeighborCells = neighborCells;

        //Benachrichtigung an den EventService, der das Signal an den SoundService weitergibt
        EventServices.Instance.OnBuildingPlaced(building.PrefabId);
    }
Exemplo n.º 2
0
        public override bool Paint(float dt, IPaintable canvas, IGridManager gridManager, Painter.InputState inputState, float minVal, float maxVal, Rect rect, Matrix4x4 TRS)
        {
            bool dirty      = false;
            var  pos        = inputState.GridPosition;
            var  baseCell   = gridManager.GetCell(pos);
            int  stealCells = 2;

            float stolenValue = 0;

            for (var i = -stealCells; i <= stealCells; i += 1)
            {
                for (var j = -stealCells; j <= stealCells; j += 1)
                {
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    var offset = gridManager.GetOffset(i, j);
                    var value  = canvas.GetValue(baseCell + offset);

                    if (value <= 0)
                    {
                        continue;
                    }

                    var stealAmount = Mathf.Min(value, Strength);

                    stolenValue += stealAmount;
                    canvas.SetValue(baseCell + offset, value - stealAmount);
                    dirty = true;
                }
            }

            canvas.SetValue(baseCell, canvas.GetValue(baseCell) + stolenValue);
            return(dirty);
        }