Example #1
0
    private bool Clean()
    {
        var nonStructureItems = Blueprint.Cell.Items.Where(i => !Blueprint.Cost.Items.ContainsKey(i.Name));

        if (nonStructureItems.Any())
        {
            foreach (var item in nonStructureItems)
            {
                item.Free();
                AddSubTask(new Pickup(item));
                AddSubTask(new Drop(Blueprint.Cell.GetPathableNeighbour()));
            }

            return(false);
        }

        var structuresToClean = Loc.GetIdService()
                                .GetStructuresInCell(Blueprint.Cell)
                                .Where(c => !c.Buildable);

        if (structuresToClean.Any())
        {
            foreach (var structureToClean in structuresToClean)
            {
                AddSubTask(new RemoveStructure(structureToClean));
            }
            return(false);
        }
        return(true);
    }
Example #2
0
    private List <ItemData> GetItemsByCriteria(string criteria)
    {
        List <ItemData> items = DomainCells.GetCells().SelectMany(c => c?.Items.Where(item => item.IsType(criteria) && !item.IsReserved())).ToList();

        items.AddRange(Loc.GetIdService().ItemIdLookup.Values.Where(i => i.FactionName == FactionName && i.IsType(criteria)));
        return(items);
    }
Example #3
0
 internal void DestroyItem(ItemData item)
 {
     if (item != null)
     {
         Loc.GetIdService().RemoveItem(item);
         Loc.GetGameController().AddItemToDestroy(item.Renderer.gameObject);
     }
 }
Example #4
0
 private void DeselectItem()
 {
     foreach (var item in Loc.GetIdService().ItemIdLookup.Values)
     {
         item.HideOutline();
     }
     Loc.GetGameController().DestroyItemInfoPanel();
 }
Example #5
0
 public static Structure GetStructure(this string id)
 {
     if (Loc.GetIdService().StructureIdLookup.TryGetValue(id, out var structure))
     {
         return(structure);
     }
     return(null);
 }
Example #6
0
 public static ItemData GetItem(this string id)
 {
     if (!Loc.GetIdService().ItemIdLookup.TryGetValue(id, out var item))
     {
         return(null);
     }
     return(item);
 }
Example #7
0
 public static CreatureData GetCreature(this string id)
 {
     if (!Loc.GetIdService().CreatureIdLookup.TryGetValue(id, out var creature))
     {
         return(null);
     }
     return(creature);
 }
Example #8
0
 internal IEnumerable <Structure> GetStructuresInCell(Cell cell)
 {
     if (Loc.GetIdService().StructureCellLookup.ContainsKey(cell))
     {
         return(Loc.GetIdService().StructureCellLookup[cell]);
     }
     return(new List <Structure>());
 }
Example #9
0
 private void DeselectStructure()
 {
     foreach (var structure in Loc.GetIdService().StructureIdLookup.Values)
     {
         structure.HideOutline();
     }
     Loc.GetGameController().DestroyStructureInfoPanel();
 }
Example #10
0
    private string Burn()
    {
        var structure = Loc.GetIdService().StructureIdLookup.Values.Where(s => s.Flammable()).GetRandomItem();

        structure.AddBehaviour <Wildfire>();

        return($"Started a fire at {structure.Cell}");
    }
Example #11
0
        private void DeselectCreature()
        {
            foreach (var creature in Loc.GetIdService().CreatureIdLookup.Values.Select(v => v.CreatureRenderer))
            {
                creature.DisableHightlight();
            }

            Loc.GetGameController().DestroyCreaturePanel();
            Loc.GetGameController().DestroyToolTip();
        }
Example #12
0
    private static CreatureData GetCreature(string nameOrId)
    {
        var creature = nameOrId.GetCreature();

        if (creature == null)
        {
            creature = Loc.GetIdService().CreatureIdLookup.Values.ToList().Find(c => c.Name.Equals(nameOrId, StringComparison.OrdinalIgnoreCase));
        }

        return(creature);
    }
Example #13
0
    public CreatureRenderer GetCreatureAtPoint(Vector2 point)
    {
        foreach (var creature in Loc.GetIdService().CreatureIdLookup.Values)
        {
            var rect = new Rect(creature.CreatureRenderer.transform.position.x - 0.5f, creature.CreatureRenderer.transform.position.y - 0.5f, 1f, 1f);
            if (rect.Contains(point))
            {
                return(creature.CreatureRenderer);
            }
        }

        return(null);
    }
Example #14
0
        private void UpdateWorkStructures()
        {
            _lastUpdate += Time.deltaTime;

            if (_lastUpdate > 0.5f)
            {
                foreach (var structure in Loc.GetIdService().StructureIdLookup.Values.OfType <WorkStructureBase>())
                {
                    structure.Process(_lastUpdate);
                }
                _lastUpdate = 0;
            }
        }
Example #15
0
        internal void DestroyStructure(Structure structure)
        {
            if (structure != null)
            {
                if (structure.Cell == null)
                {
                    Debug.Log("Unbound structure");
                }

                structure.OnDestroy();
                Loc.GetIdService().RemoveStructure(structure);
                Loc.GetFactionController().Factions[structure.FactionName].Structures.Remove(structure);
                Loc.GetGameController().AddItemToDestroy(structure.Renderer.gameObject);
            }
        }
Example #16
0
    internal void DestroyCreature(CreatureRenderer creature)
    {
        if (creature != null)
        {
            Debug.Log($"Destroying: {creature.Data.Name}");
            if (creature.Data.Task != null)
            {
                creature.Data.AbandonTask();
            }

            Loc.GetFactionController().Factions[creature.Data.FactionName].Creatures.Remove(creature.Data);
            Loc.GetIdService().RemoveCreature(creature.Data);
            Loc.GetGameController().AddItemToDestroy(creature.gameObject);
        }
    }
Example #17
0
 public static Save MakeSave()
 {
     return(new Save
     {
         MapGenerationData = MapGenerationData.Instance,
         Factions = Loc.GetFactionController().Factions.Values.ToList(),
         Time = Loc.GetTimeManager().Data,
         Items = Loc.GetIdService().ItemIdLookup.Values.ToList(),
         CameraData = new CameraData(Loc.GetCamera()),
         Rooms = Loc.GetZoneController().RoomZones,
         Stores = Loc.GetZoneController().StorageZones,
         Areas = Loc.GetZoneController().AreaZones,
         Chunks = Loc.GetMap().Chunks.Values.Select(s => s.Data).ToList(),
     });
 }
Example #18
0
    public string List(string type)
    {
        var list = "";

        switch (type.ToLower())
        {
        case "items":
            foreach (var item in Loc.GetIdService().ItemIdLookup)
            {
                list += $"{item.Key}: {item.Value.Name}\n";
            }
            break;

        case "creatures":
            foreach (var creature in Loc.GetIdService().CreatureIdLookup)
            {
                list += $"{creature.Key}: {creature.Value.Name}\n";
            }
            break;

        case "structures":
            foreach (var structure in Loc.GetIdService().StructureIdLookup)
            {
                list += $"{structure.Key}: {structure.Value.Name}\n";
            }
            break;

        case "factions":
            foreach (var faction in Loc.GetFactionController().Factions)
            {
                list += $"{faction.Key}\n";
            }
            break;

        case "zones":
            foreach (var zone in Loc.GetZoneController().Zones)
            {
                list += $"{zone.Key.Name}: {zone.Key.FactionName}\n";
            }
            break;

        default:
            list = "Provide type of list:\n-items\n-creatures\n-structures\n-factions\n-zones";
            break;
        }
        return(list);
    }
Example #19
0
 private void IndexItem(ItemData item)
 {
     Loc.GetIdService().EnrollItem(item);
 }
Example #20
0
 private void IndexStructure(Structure structure)
 {
     Loc.GetIdService().EnrollStructure(structure);
 }