Ejemplo n.º 1
0
    private ZoneLabel DrawZone(ZoneBase newZone)
    {
        var sprite = Loc.GetZoneController().ZoneSprite;
        var room   = false;

        if (newZone is RoomZone)
        {
            sprite = Loc.GetZoneController().RoomSprite;
            room   = true;
        }
        else if (newZone is StorageZone)
        {
            sprite = Loc.GetZoneController().StorageSprite;
        }

        foreach (var cell in newZone.ZoneCells.GetCells())
        {
            SetZoneCellTile(newZone, sprite, cell);
            if (room)
            {
                Loc.GetStructureController().CreateRoof(cell);
            }
        }

        var label = Instantiate(ZoneLabelPrefab, transform);

        label.name      = newZone.Name;
        label.Text.text = newZone.Name;
        MoveZoneLabel(newZone, label);
        return(label);
    }
Ejemplo n.º 2
0
        internal bool Place(Cell origin, Faction faction)
        {
            var x = 0;
            var y = 0;

            foreach (var line in FlippedPlan)
            {
                foreach (var character in line)
                {
                    if (character == '.')
                    {
                        x++;
                        continue;
                    }

                    var cell = Loc.GetMap().GetCellAtCoordinate(origin.X + x, origin.Z + y);

                    Loc.GetStructureController().SpawnBlueprint(GetStructure(character), cell, faction);
                    x++;
                }
                x = 0;
                y++;
            }
            return(true);
        }
Ejemplo n.º 3
0
 internal void Clear()
 {
     foreach (var structure in Structures)
     {
         Loc.GetStructureController().DestroyStructure(structure);
     }
 }
Ejemplo n.º 4
0
    public void UpdateStuctureOrder(string structureName)
    {
        var structure = Loc.GetStructureController().StructureDataReference[structureName];

        Loc.GetGameController().OrderInfoPanel.Show($"Build {structureName}",
                                                    "Select a location to place the structure.  A creature with the build skill will gather the required cost of material and then make the structure.",
                                                    structure.Description,
                                                    $"{structure.Cost}");
    }
Ejemplo n.º 5
0
 private void UpdateRemainingFlammability(Structure structure, float delta)
 {
     structure.Flammability -= delta / 2;
     if (structure.Flammability <= 0)
     {
         Loc.GetStructureController().SpawnStructure("Debris", structure.Cell, Loc.GetFactionController().WorldFaction);
         Loc.GetStructureController().DestroyStructure(structure);
     }
 }
Ejemplo n.º 6
0
        public void SetMesh(string name, ValidateMouseDelegate validationFunction)
        {
            Clear();
            _meshName = name;

            var structure = Loc.GetStructureController().InstantiateNewStructureMeshRenderer(name, transform);

            structure.SetAllMaterial(Loc.GetFileController().BlueprintMaterial);

            _meshRenderer = structure;
            Validate      = validationFunction;
        }
Ejemplo n.º 7
0
        internal Texture2D GetTexture()
        {
            if (this._texture != null)
            {
                return(this._texture);
            }
            _texture = new Texture2D(Width * MapController.PixelsPerCell, Height * MapController.PixelsPerCell);

            var z = 0;
            var x = 0;

            foreach (var line in FlippedPlan)
            {
                foreach (var character in line)
                {
                    var startX = x * MapController.PixelsPerCell;
                    var startZ = z * MapController.PixelsPerCell;

                    Texture2D sourceTexture;
                    if (character == '.')
                    {
                        sourceTexture = new Texture2D(1, 1);
                        sourceTexture.SetPixel(0, 0, new Color(0, 0, 0, 0));
                        sourceTexture.Apply();
                    }
                    else
                    {
                        var structure = Loc.GetStructureController().StructureDataReference.Values.First(s => s.Name == GetStructure(character));
                        sourceTexture = Loc.GetSpriteStore().GetSprite(structure.Icon).texture;
                    }
                    var constructTexture = sourceTexture.Clone();
                    constructTexture.ScaleToGridSize(1, 1);

                    for (var subTexX = 0; subTexX < MapController.PixelsPerCell; subTexX++)
                    {
                        for (var subTexY = 0; subTexY < MapController.PixelsPerCell; subTexY++)
                        {
                            var pixel = constructTexture.GetPixel(subTexX, subTexY);
                            _texture.SetPixel(startX + subTexX,
                                              startZ + subTexY,
                                              pixel);
                        }
                    }

                    x++;
                }
                z++;
            }
            _texture.Apply();

            return(_texture);
        }
Ejemplo n.º 8
0
        public void Delete()
        {
            if (_task is Build build)
            {
                Loc.GetStructureController().DestroyBlueprint(build.Blueprint);
            }

            if (Loc.GetFactionController().PlayerFaction.AssignedTasks.ContainsKey(_task))
            {
                Loc.GetFactionController().PlayerFaction.AssignedTasks[_task].CancelTask();
            }
            else
            {
                Loc.GetFactionController().PlayerFaction.AvailableTasks.Remove(_task);
            }
            _task.Destroy();
        }
Ejemplo n.º 9
0
        private void ShowCursorEffects(List <Cell> selectedCells)
        {
            if (!string.IsNullOrEmpty(_meshName))
            {
                if (selectedCells == null || selectedCells.Count == 0)
                {
                    return;
                }

                foreach (var cell in selectedCells)
                {
                    MeshRenderer cellRenderer;
                    if (!_draggedRenderers.ContainsKey(cell))
                    {
                        cellRenderer = Loc.GetStructureController().InstantiateNewStructureMeshRenderer(_meshName, Loc.GetMap().transform);
                        cellRenderer.transform.position = new Vector3(cell.Vector.x, cell.Vector.y, cell.Vector.z);
                        _draggedRenderers.Add(cell, cellRenderer);
                    }
                    else
                    {
                        cellRenderer = _draggedRenderers[cell];
                    }

                    if (Validate?.Invoke(cell) == false)
                    {
                        cellRenderer.SetAllMaterial(Loc.GetFileController().InvalidBlueprintMaterial);
                    }
                    else
                    {
                        cellRenderer.SetAllMaterial(Loc.GetFileController().BlueprintMaterial);
                    }
                }

                foreach (var cell in _draggedRenderers.Keys.ToList())
                {
                    if (!selectedCells.Contains(cell))
                    {
                        Destroy(_draggedRenderers[cell].gameObject);
                        _draggedRenderers.Remove(cell);
                    }
                }
            }
        }
Ejemplo n.º 10
0
    public void FinishStructure()
    {
        Loc.GetStructureController().SpawnStructure(Blueprint.StructureName, Blueprint.Cell, Blueprint.Faction);
        var cellItems = Blueprint.Cell.Items.ToList();

        foreach (var costItem in Blueprint.Cost.Items)
        {
            foreach (var item in cellItems.Where(c => c.Name == costItem.Key))
            {
                item.Amount -= costItem.Value;
                if (item.Amount < 0)
                {
                    Loc.GetItemController().DestroyItem(item);
                }
            }
        }

        Loc.GetStructureController().DestroyBlueprint(Blueprint);
    }
Ejemplo n.º 11
0
    public void BuildClicked(string structureName)
    {
        var structure = Loc.GetStructureController().StructureDataReference[structureName];

        Loc.Current.Get <CursorController>().SetSelectionPreference(SelectionPreference.Cell);

        Loc.Current.Get <CursorController>().SetMesh(structureName, (cell) => structure.ValidateCellLocationForStructure(cell));
        UpdateStuctureOrder(structureName);

        CellClickOrder = cells =>
        {
            foreach (var cell in cells)
            {
                if (structure.ValidateCellLocationForStructure(cell))
                {
                    Loc.GetStructureController().SpawnBlueprint(structureName, cell, Loc.GetFactionController().PlayerFaction);
                }
            }
        };
    }
Ejemplo n.º 12
0
    public override bool Done(CreatureData creature)
    {
        if (SubTasksComplete(creature))
        {
            if (!creature.Cell.Neighbors.Contains(StructureToRemove.Cell))
            {
                var pathable = Loc.GetMap().TryGetPathableNeighbour(StructureToRemove.Cell);

                if (pathable != null)
                {
                    AddSubTask(new Move(pathable));
                }
                else
                {
                    creature.SuspendTask(true);
                    return(false);
                }
            }

            if (!Decontructed)
            {
                creature.Face(StructureToRemove.Cell);
                AddSubTask(new Wait(StructureToRemove.Cost.Items.Sum(c => c.Value) + 1, "Deconstructing...", AnimationType.Interact));
                Decontructed = true;
                return(false);
            }

            foreach (var item in StructureToRemove.Cost.Items)
            {
                var spawnedItem = Loc.GetItemController().SpawnItem(item.Key, StructureToRemove.Cell);
                spawnedItem.Amount      = item.Value;
                spawnedItem.FactionName = creature.FactionName;
            }

            Loc.GetStructureController().DestroyStructure(StructureToRemove);
            StructureToRemove = null;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 13
0
    public void BuildTypeClicked()
    {
        if (Loc.GetGameController().OrderTrayController.gameObject.activeInHierarchy)
        {
            DisableAndReset();
        }
        else
        {
            EnableAndClear();

            foreach (var structureData in Loc.GetStructureController().StructureDataReference.Values)
            {
                if (!structureData.Buildable)
                {
                    continue;
                }

                var button = CreateOrderButton(() => BuildClicked(structureData.Name), () => UpdateStuctureOrder(structureData.Name), structureData.Icon, structureData.ColorHex);
            }
        }
    }
Ejemplo n.º 14
0
 public override void FinalizeTask()
 {
     Loc.GetStructureController().DestroyBlueprint(Blueprint);
 }
Ejemplo n.º 15
0
    internal Structure CreateStructure(string structureName, string faction = FactionConstants.World)
    {
        var structure = Loc.GetStructureController().SpawnStructure(structureName, this, Loc.GetFactionController().Factions[faction]);

        return(structure);
    }