Ejemplo n.º 1
0
        ActionState ProcessAction(HaulAction action)
        {
            var dir = action.Direction;

            if (this.ActionTicksUsed == 1)
            {
                var obs = this.Environment.GetContents(this.Location + dir);

                this.ActionTotalTicks = obs.OfType <LivingObject>().Count() + 2;
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
            {
                return(ActionState.Ok);
            }

            var itemID = action.ItemID;
            var item   = this.World.FindObject <ItemObject>(itemID);

            var report = new HaulActionReport(this, dir, item);

            if (item == null)
            {
                SendFailReport(report, "object doesn't exist");
                return(ActionState.Fail);
            }

            if (this.CarriedItem == null)
            {
                SendFailReport(report, "not carrying anything");
                return(ActionState.Fail);
            }

            Debug.Assert(this.CarriedItem.Container == this);

            if (this.CarriedItem != item)
            {
                SendFailReport(report, "already carrying another item");
                return(ActionState.Fail);
            }

            var ok = MoveDir(dir);

            if (!ok)
            {
                SendFailReport(new HaulActionReport(this, action.Direction, item), "could not move (blocked?)");
                return(ActionState.Fail);
            }

            SendReport(report);

            return(ActionState.Done);
        }
Ejemplo n.º 2
0
        ActionState ProcessAction(HaulAction action)
        {
            var dir = action.Direction;

            if (this.ActionTicksUsed == 1)
            {
                var obs = this.Environment.GetContents(this.Location + dir);

                this.ActionTotalTicks = obs.OfType<LivingObject>().Count() + 2;
            }

            if (this.ActionTicksUsed < this.ActionTotalTicks)
                return ActionState.Ok;

            var itemID = action.ItemID;
            var item = this.World.FindObject<ItemObject>(itemID);

            var report = new HaulActionReport(this, dir, item);

            if (item == null)
            {
                SendFailReport(report, "object doesn't exist");
                return ActionState.Fail;
            }

            if (this.CarriedItem == null)
            {
                SendFailReport(report, "not carrying anything");
                return ActionState.Fail;
            }

            Debug.Assert(this.CarriedItem.Parent == this);

            if (this.CarriedItem != item)
            {
                SendFailReport(report, "already carrying another item");
                return ActionState.Fail;
            }

            var ok = MoveDir(dir);

            if (!ok)
            {
                SendFailReport(new HaulActionReport(this, action.Direction, item), "could not move (blocked?)");
                return ActionState.Fail;
            }

            SendReport(report);

            return ActionState.Done;
        }
Ejemplo n.º 3
0
        protected override GameAction PrepareNextActionOverride(out JobStatus progress)
        {
            if (m_pathDirs == null || m_supposedLocation != this.Worker.Location)
            {
                var res = PreparePath(this.Worker);

                if (res != JobStatus.Ok)
                {
                    progress = res;
                    return(null);
                }
            }

            Direction dir = m_pathDirs.Dequeue();

            if (m_pathDirs.Count == 0)
            {
                m_pathDirs = null;
            }

            m_supposedLocation += dir;

            GameAction action;

            if (this.HauledItem == null)
            {
                action = new MoveAction(dir);
            }
            else
            {
                action = new HaulAction(dir, this.HauledItem);
            }

            progress = JobStatus.Ok;
            return(action);
        }
Ejemplo n.º 4
0
        public override void Update(float deltaTime)
        {
            List <Tile> path       = null;
            HaulAction  nextAction = NextAction();

            DebugLog(" - next action: {0}", nextAction);

            switch (nextAction)
            {
            case HaulAction.DumpMaterial:
                character.SetState(new DumpState(character, this));
                break;

            case HaulAction.FindMaterial:
                // Find material somewhere
                string[] inventoryTypes = character.Inventory != null ?
                                          new string[] { character.Inventory.Type } :
                Job.RequestedItems.Keys.ToArray();
                path = World.Current.InventoryManager.GetPathToClosestInventoryOfType(inventoryTypes, character.Tile, Job.canTakeFromStockpile);
                if (path != null && path.Count > 0)
                {
                    GameInventory inv = path.Last().Inventory;
                    inv.Claim(character, (inv.AvailableInventory < Job.RequestedItems[inv.Type].AmountDesired()) ? inv.AvailableInventory : Job.RequestedItems[inv.Type].AmountDesired());
                    character.SetState(new MoveState(character, Pathfinder.GoalTileEvaluator(path.Last(), false), path, this));
                }
                else if (character.Inventory == null)
                {
                    // The character has no inventory and can't find anything to haul.
                    Interrupt();
                    DebugLog(" - Nothing to haul");
                    Finished();
                }
                else
                {
                    noMoreMaterialFound = true;
                }

                break;

            case HaulAction.PickupMaterial:
                GameInventory tileInventory = character.Tile.Inventory;
                int           amountCarried = character.Inventory != null ? character.Inventory.StackSize : 0;
                int           amount        = Mathf.Min(Job.AmountDesiredOfInventoryType(tileInventory.Type) - amountCarried, tileInventory.StackSize);
                DebugLog(" - Picked up {0} {1}", amount, tileInventory.Type);
                World.Current.InventoryManager.PlaceInventory(character, tileInventory, amount);
                break;

            case HaulAction.DeliverMaterial:
                path = Pathfinder.FindPath(character.Tile, Job.IsTileAtJobSite, Pathfinder.DefaultDistanceHeuristic(Job.tile));
                if (path != null && path.Count > 0)
                {
                    character.SetState(new MoveState(character, Pathfinder.GoalTileEvaluator(path.Last(), false), path, this));
                }
                else
                {
                    Job.AddCharCantReach(character);
                    character.InterruptState();
                }

                break;

            case HaulAction.DropOffmaterial:
                DebugLog(" - Delivering {0} {1}", character.Inventory.StackSize, character.Inventory.Type);
                World.Current.InventoryManager.PlaceInventory(Job, character);

                // Ping the Job system
                Job.DoWork(0);
                Finished();
                break;
            }
        }
Ejemplo n.º 5
0
        protected override GameAction PrepareNextActionOverride(out JobStatus progress)
        {
            if (m_pathDirs == null || m_supposedLocation != this.Worker.Location)
            {
                var res = PreparePath(this.Worker);

                if (res != JobStatus.Ok)
                {
                    progress = res;
                    return null;
                }
            }

            Direction dir = m_pathDirs.Dequeue();

            if (m_pathDirs.Count == 0)
                m_pathDirs = null;

            m_supposedLocation += new IntVector3(dir);

            GameAction action;

            if (this.HauledItem == null)
                action = new MoveAction(dir);
            else
                action = new HaulAction(dir, this.HauledItem);

            progress = JobStatus.Ok;
            return action;
        }