private TaskState FindDepot(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                List<BuildingRequest> depoesCandidates = new List<BuildingRequest>();

                    List<Building> depos = WorldMap.Instance.GetDepos(d.GetActionMapElementType(), d.GetActionLevel());
                    foreach (Building b in depos)
                    {
                        depoesCandidates.Add(new BuildingRequest() { Building = b, TypeToGet = d.GetActionMapElementType(), Level = d.GetActionLevel() });
                    }

                // If no depot exist that has the required materials, the behavier fails
                if (depoesCandidates.Count == 0)
                {
                    if (_buildBuilding.HasRequestedNeededResourcesForCrafting== true)
                        return TaskState.Fail;

                    if (CraftRules.IsMapElementTypeCraftable(d.GetActionMapElementType()) == true)
                    {
                        TaskManager.AddTask(new CraftingOfResourceTask(d.GetActionMapElementType(), d.GetActionLevel()));
                        _buildBuilding.HasRequestedNeededResourcesForCrafting = true;
                    }

                    return TaskState.Fail;
                }

                foreach (BuildingRequest b in depoesCandidates)
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.Building.GetActivationPoint(), b);
                    _numerOfPaths++;
                }
            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d));

            if (_paths.Count > _numerOfPaths)
            {

            }

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            PathfindingResult shortestPath = Path.ShortestPath(_paths);
            BuildingRequest br = (BuildingRequest)shortestPath.Data;

            d.SetActionBuilding(br.Building);
            d.SetActionMapElementType(br.TypeToGet);
            d.SetActionLevel(br.Level);
            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
 private TaskState Pickup(Dwarf d, float dt)
 {
     WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel());
     if (m == null)
         return TaskState.Fail;
     d.CarryWorldObject(m);
     d.SetActionBuilding(d.GetPrevActionBuilding());
     return TaskState.Success;
 }
 private TaskState Check(Dwarf d, float dt)
 {
     if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel())) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
Ejemplo n.º 4
0
        private TaskState CraftItem(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                if (d.GetActionbuilding().GetCraftSlot() != null && d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType())
                    throw new Exception("Can't craft, workshop allready in use");
                // If an item is already being crafted of the same kind
                if (d.GetActionbuilding().GetCraftSlot() != null && d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType())
                {
                    DwarfConsole.WriteLine("Continues crafting, after it was aborted", ConsoleColor.Green);
                    // Do thothing
                }
                else
                    d.GetActionbuilding().SetCraftSlot((WorldObject)WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel()));
            }

            if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()) == false)
            {
                d.GetActionbuilding().ReleaseDwarfFromCrafting();
                return TaskState.Fail;
            }

            d.GetActionbuilding().CraftOnItemInCraftSlot(CraftRules.CraftOnItem(d.GetActionbuilding().BuildingType, d), dt);

            // The item was crafted :)
            if (d.GetActionbuilding().GetCraftSlot().IsCrafted() == true)
            {
                RemoveUsedResources(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot());
                DwarfConsole.WriteLine("Crafted: " + d.GetActionbuilding().GetCraftSlot().ElementType + " " + d.GetActionbuilding().GetCraftSlot().Level, ConsoleColor.Yellow);
                //d.CarryWorldObject(d.GetActionbuilding().TakeCraftSlot());
                d.GetActionbuilding().ReleaseForCrafting();
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }