示例#1
0
        internal void ConsumeCostItems()
        {
            foreach (var cost in Option.Cost.Items)
            {
                var totalNeeded = cost.Value;
                foreach (var item in Structure.Cell.Items.Where(i => i.IsType(cost.Key)).ToList())
                {
                    if (totalNeeded <= 0)
                    {
                        break;
                    }

                    if (item.Amount >= totalNeeded)
                    {
                        item.Amount -= totalNeeded;
                        totalNeeded  = 0;
                    }
                    else
                    {
                        totalNeeded -= item.Amount;
                        item.Amount  = 0;
                    }

                    if (item.Amount == 0)
                    {
                        Loc.GetItemController().DestroyItem(item);
                    }
                }
            }
        }
示例#2
0
 public override void UnitComplete(float quality)
 {
     if (!Active())
     {
         return;
     }
     Loc.GetItemController().SpawnItem(Option.Name, Structure.Cell, 1);
 }
示例#3
0
 public void Update()
 {
     if (Data.Amount <= 0)
     {
         Loc.GetItemController().DestroyItem(Data);
     }
     else
     {
         _text.text = Data.Amount.ToString();
         _text.transform.localRotation = Quaternion.Euler(Loc.GetCamera().GetPerpendicularRotation(), -90, -90);
     }
 }
示例#4
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);
    }
示例#5
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);
    }
示例#6
0
    public override bool Done(CreatureData creature)
    {
        if (SubTasksComplete(creature))
        {
            if (string.IsNullOrEmpty(ContainerId))
            {
                FindContainer(creature);
            }

            var container = ContainerId.GetStructure() as LiquidContainer;
            if (!creature.InRangeOf(container))
            {
                AddSubTask(new Move(container.GetWorkCell()));
                return(false);
            }

            var water = Loc.GetItemController().SpawnItem("StoredWater", creature.Cell, 1);
            creature.PickUpItem(water, 1);
            container.FillLevel -= 1;
            return(true);
        }
        return(false);
    }
示例#7
0
    public override bool Done(CreatureData creature)
    {
        try
        {
            if (SubTasksComplete(creature))
            {
                if (MoveToShore(creature))
                {
                    var water = Loc.GetItemController().SpawnItem("FreshWater", creature.Cell, 1);
                    creature.PickUpItem(water, 1);
                    return(true);
                }
            }
        }
        catch (TaskFailedException)
        {
            if (_targetShore != null)
            {
                _targetShore = null;
            }
        }

        return(false);
    }
示例#8
0
    public override bool Done(CreatureData creature)
    {
        if (SubTasksComplete(creature))
        {
            var food = creature.HeldItem;

            if (food == null || !food.IsType(ConsumptionCriteria))
            {
                creature.DropItem(creature.Cell);
                AddSubTask(new FindAndGetItem(ConsumptionCriteria, 1));
                return(false);
            }

            if (!FoundSeating)
            {
                FoundSeating = true;
                var chair = creature.Faction.Structures
                            .Where(s => s.IsType("Chair") && !s.InUseByAnyone)
                            .OrderBy(c => c.Cell.DistanceTo(creature.Cell))
                            .FirstOrDefault();
                if (chair != null)
                {
                    ChairId = chair.Id;
                    chair.Reserve(creature);
                    AddSubTask(new Move(chair.Cell));
                    return(false);
                }
                else
                {
                    creature.Feelings.Add(Feeling.GetAnnoyance("No place to sit and eat"));
                }
            }

            if (!Consuming)
            {
                AddSubTask(new Wait(2, "Eating...", AnimationType.Interact));
                BusyEmote = "*munch, chomp*";
                Consuming = true;
            }
            else if (!Consumed)
            {
                BusyEmote = "";

                if (food.ValueProperties.ContainsKey("Nutrition"))
                {
                    creature.GetNeed <Hunger>().Current += food.ValueProperties["Nutrition"];
                }
                if (food.ValueProperties.ContainsKey("Quench"))
                {
                    creature.GetNeed <Thirst>().Current += food.ValueProperties["Quench"];
                }

                creature.DropItem(creature.Cell);

                if (!string.IsNullOrEmpty(ChairId))
                {
                    ChairId.GetStructure().Free();
                }
                Loc.GetItemController().DestroyItem(food);
                Consumed = true;

                if (creature.GetNeed <Hunger>().Current < 60)
                {
                    AddSubTask(new Consume());
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                Consuming = false;
                Consumed  = false;
                return(true);
            }
        }
        return(false);
    }
示例#9
0
 public void AddAllowed()
 {
     Loc.GetGameController().UIController.ShowFilterView("Choose item to allow:",
                                                         Loc.GetItemController().GetAllItemOptions(),
                                                         (option) => Zone.Filter.AddAllowedItem(option.Name));
 }
示例#10
0
        public override void UnitComplete(float quality)
        {
            ConsumeCostItems();

            Loc.GetItemController().SpawnItem(Option.Name, Structure.GetOutputCell(), Option.Amount);
        }
示例#11
0
 internal void SpawnYield()
 {
     Loc.GetItemController().SpawnItem(PlantName, Cell, (int)Quality);
 }