Exemple #1
0
        /*
         * public override bool clicked(Farmer who)
         * {
         *  if(who.CurrentTool == null)
         *  {
         *      DataAccess DataAccess = DataAccess.GetDataAccess();
         *      if (DataAccess.IOPipeNames.Contains(this.Name))
         *      {
         *          List<Node> nodes = DataAccess.LocationNodes[Game1.currentLocation];
         *          Node node = nodes.Find(n => n.Position.Equals(this.TileLocation));
         *          if(node is IOPipeNode)
         *          {
         *              IOPipeNode pipe = (IOPipeNode)node;
         *              if (pipe != null)
         *              {
         *                  Printer.Info($"{Name} is {pipe.Signal}");
         *
         *              }
         *          }
         *      }
         *  }
         *  return false;
         * }
         */

        public void ChangeSignal()
        {
            DataAccess  DataAccess = DataAccess.GetDataAccess();
            List <Node> nodes      = DataAccess.LocationNodes[Game1.currentLocation];
            IOPipeNode  pipe       = (IOPipeNode)nodes.Find(n => n.Position.Equals(this.TileLocation));

            pipe.ChangeSignal();
            UpdateSignal(pipe.Signal);
        }
Exemple #2
0
        public PipeNode SendItem(Item item, IOPipeNode input)
        {
            List <PipeNode> path = GetPath(input);

            /*
             * Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}] PATH---------------");
             * foreach (Node node in path)
             * {
             *  Printer.Info(node.Print());
             * }
             * Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}] PATH---------------");
             */
            return(MoveItemRecursive(item, input, path, 0));
        }
Exemple #3
0
        public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
        {
            base.draw(spriteBatch, x, y);
            DataAccess DataAccess = DataAccess.GetDataAccess();

            if (DataAccess.LocationNodes.ContainsKey(Game1.currentLocation))
            {
                List <Node> nodes = DataAccess.LocationNodes[Game1.currentLocation];
                Node        node  = nodes.Find(n => n.Position.Equals(TileLocation));
                if (node != null && node is IOPipeNode)
                {
                    IOPipeNode IONode = (IOPipeNode)node;
                    if (IONode.Signal != null && !IONode.PassingItem)
                    {
                        UpdateSignal(IONode.Signal);
                        float transparency = 1f;
                        if (IONode.Passable)
                        {
                            Passable     = true;
                            transparency = 0.5f;
                        }
                        else
                        {
                            Passable     = false;
                            transparency = 1f;
                        }
                        Rectangle srcRect = new Rectangle(0, 0, 16, 16);
                        spriteBatch.Draw(SignalTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64)), srcRect, Color.White * transparency, 0f, Vector2.Zero, 4f, SpriteEffects.None, ((float)(y * 64 + 32) / 10000f) + 0.002f);
                    }
                    if (Globals.IOPipeStatePopup && IONode.Signal != null)
                    {
                        if (IONode.Signal.Equals("nochest"))
                        {
                            Texture2D sprite;
                            if (((int)Game1.currentGameTime.TotalGameTime.TotalSeconds) % 2 == 0)
                            {
                                sprite = DataAccess.Sprites["nochest_state"];
                            }
                            else
                            {
                                sprite = DataAccess.Sprites["nochest1_state"];
                            }
                            Popup.Draw(spriteBatch, sprite, x, y);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public bool FlushPipe(Item item, IOPipeNode input)
        {
            bool flushed = false;

            if (input.ConnectedContainer != null)
            {
                StoredItem  = item;
                PassingItem = true;
                bool interrupted = false;
                while (input.ConnectedContainer != null && !input.ConnectedContainer.InsertItem(item) && !interrupted)
                {
                    try
                    {
                        StoredItem  = item;
                        PassingItem = true;
                    }
                    catch (ThreadInterruptedException exception)
                    {
                        interrupted = true;
                    }
                }
            }
            return(flushed);
        }
Exemple #5
0
        public PipeNode MoveItemRecursive(Item item, IOPipeNode input, List <PipeNode> path, int index)
        {
            //Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}]Current node: {Print()}");
            if (this.Equals(input))
            {
                if (input.ConnectedContainer != null)
                {
                    StoredItem  = item;
                    PassingItem = true;
                    bool interrupted = false;

                    //Printer.Info((!input.ConnectedContainer.InsertItem(item)).ToString());
                    //Printer.Info(interrupted.ToString());
                    while (input.ConnectedContainer != null && !input.ConnectedContainer.InsertItem(item) && !interrupted)
                    {
                        try
                        {
                            StoredItem  = item;
                            PassingItem = true;
                            System.Threading.Thread.Sleep(ItemTimer);
                        }
                        catch (ThreadInterruptedException exception)
                        {
                            /*
                             * if (Globals.Debug) { Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}]Waiting for {Print()} clogged item to return to output..."); }
                             * int i = 0;
                             * bool sent = false;
                             * while (i < ParentNetwork.Outputs.Count && !sent)
                             * {
                             *  if (ParentNetwork.Outputs[i].ConnectedContainer.InsertItem(StoredItem))
                             *  {
                             *      //Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}]ITEM RETURNED");
                             *      sent = true;
                             *      interrupted = true;
                             *      try
                             *      {
                             *          if (DataAccess.GetDataAccess().Threads.Contains(Thread.CurrentThread))
                             *          {
                             *              //Printer.Info("Removing T" + Thread.CurrentThread.ManagedThreadId);
                             *              DataAccess.GetDataAccess().Threads.Remove(Thread.CurrentThread);
                             *          }
                             *      }
                             *      catch (Exception e)
                             *      {
                             *          DataAccess.GetDataAccess().Threads.Clear();
                             *      }
                             *  }
                             *  i++;
                             * }
                             */
                            interrupted = true;
                        }
                    }
                    try
                    {
                        System.Threading.Thread.Sleep(ItemTimer);
                    }
                    catch (ThreadInterruptedException exception)
                    {
                    }
                    if (interrupted)
                    {
                        StoredItem  = item;
                        PassingItem = true;
                    }
                    else
                    {
                        StoredItem  = null;
                        PassingItem = false;
                    }
                    return(this);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (index < path.Count - 1 && path[index + 1] != null)
                {
                    StoredItem  = item;
                    PassingItem = true;
                    while (path[index + 1] != null && path[index + 1].StoredItem != null)
                    {
                        StoredItem  = item;
                        PassingItem = true;
                    }
                    try
                    {
                        System.Threading.Thread.Sleep(ItemTimer);
                    }
                    catch (ThreadInterruptedException exception) { }
                    StoredItem  = null;
                    PassingItem = false;
                    index++;
                    return(path[index].MoveItemRecursive(item, input, path, index));
                }
            }
            return(this);
        }