Ejemplo n.º 1
0
 public override InteractResult OnActRight(InteractionContext context)
 {
     if (context.HasBlock && context.Block is WoodenTransportPipeBlock)
     {
         TransportPipeInfo info = null;
         if (TransportPipeManager.pipesInfo.TryGetValue(context.BlockPosition.Value, out info))
         {
             if (context.Player.User.Inventory.TryRemoveItems(GetType(), 1))
             {
                 info.type = PIPETYPE.Electric;
                 info.beltLinker.UpdateInfo(info);
                 World.SetBlock(typeof(ElectricTransportPipeBlock), context.BlockPosition.Value);
                 return(InteractResult.Success);
             }
         }
     }
     else if (context.HasTarget && context.Target is ConnectorObject)
     {
         TransportPipeInfo info = null;
         if (TransportPipeManager.pipesInfo.TryGetValue((context.Target as ConnectorObject).Position3i, out info))
         {
             if (context.Player.User.Inventory.TryRemoveItems(GetType(), 1))
             {
                 info.type = PIPETYPE.Electric;
                 info.beltLinker.UpdateInfo(info);
                 return(InteractResult.Success);
             }
         }
     }
     return(InteractResult.NoOp);
 }
Ejemplo n.º 2
0
        public TransportPipeLinker GetLinker()
        {
            TransportPipeInfo info = null;

            if (TransportPipeManager.pipesInfo.TryGetValue(pos, out info))
            {
                return(info.beltLinker);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public void Destroy()
        {
            TransportPipeInfo info = null;

            if (TransportPipeManager.pipesInfo.TryGetValue(pos, out info))
            {
                info.beltLinker.RemoveConveyor(info);
                TransportPipeManager.pipesInfo.TryRemove(pos, out info);
                info.beltLinker.RebuildLinker();
            }
        }
Ejemplo n.º 4
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            TransportPipeInfo info = null;

            if (context.HasBlock && context.Block is BaseTransportPipeBlock)
            {
                info = TransportPipeManager.pipesInfo[Utils.MakeWorldMod(context.BlockPosition.Value)];
            }
            if (context.HasTarget && context.Target is ConnectorObject)
            {
                info = TransportPipeManager.pipesInfo[Utils.MakeWorldMod((context.Target as ConnectorObject).Position3i)];
            }
            ChatManager.ServerMessageToAll($"{info}", false);
            return(InteractResult.Success);
        }
Ejemplo n.º 5
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // if I target a pipe with the wrench, I transform it to a connector set to input
            if (context.HasBlock && context.Block is BaseTransportPipeBlock && Utils.SearchForConnectedInventory(context.BlockPosition.Value) != null)
            {
                //Removing the block and add the connector
                World.DeleteBlock(context.BlockPosition.Value);
                ConnectorObject connector = WorldObjectManager.TryToAdd <ConnectorObject>(context.Player.User, context.BlockPosition.Value, Quaternion.Identity);
                // If the conenctor can't be added just reset the action
                if (connector == null)
                {
                    World.SetBlock(context.Block.GetType(), context.BlockPosition.Value);
                    return(InteractResult.NoOp);
                }
                // I instanciate the connector info with the info from the pipe
                TransportPipeInfo info = null;
                if (TransportPipeManager.pipesInfo.TryGetValue(context.BlockPosition.Value, out info))
                {
                    connector.info = info;
                    context.Player.SendTemporaryMessage($"Set to input");
                    connector.mode = CONNECTOR_MODE.Input;

                    BurnCalories(context.Player);
                    UseDurability(1.0f, context.Player);

                    return(InteractResult.Success);
                }
                else
                {
                    // If the pipe don't contains any info I recreate the linker from the pipe and reset the action
                    connector.Destroy();
                    World.SetBlock(context.Block.GetType(), context.BlockPosition.Value);
                    Utils.RecreateLinker(context.BlockPosition.Value, new TransportPipeLinker());
                }
            }
            // If I use the wrench on a connector
            if (context.HasTarget && context.Target is ConnectorObject)
            {
                // I process the config inside the connector class
                (context.Target as ConnectorObject).ProcessConfig(context);
                BurnCalories(context.Player);
                UseDurability(1.0f, context.Player);
                return(InteractResult.Success);
            }
            return(InteractResult.NoOp);
        }
Ejemplo n.º 6
0
        private void Init()
        {
            doInit = false;

            if (info == null)
            {
                info            = new TransportPipeInfo();
                info.beltLinker = null;
            }

            List <TransportPipeInfo> neighbourgs = Utils.GetNeighbourgPipesInfo(this.Position3i);

            if (neighbourgs.Count > 0)
            {
                foreach (TransportPipeInfo neighbourg in neighbourgs)
                {
                    if (info.beltLinker == null)
                    {
                        info.beltLinker = neighbourg.beltLinker;
                    }
                    else if (neighbourg.beltLinker != null && info.beltLinker != neighbourg.beltLinker)
                    {
                        info.beltLinker.AbsorbLinker(neighbourg.beltLinker);
                    }
                }
                if (info.beltLinker == null)
                {
                    info.beltLinker = new TransportPipeLinker();
                }
            }
            else
            {
                info.beltLinker = new TransportPipeLinker();
            }
            if (TransportPipeManager.pipesInfo.ContainsKey(Utils.MakeWorldMod(Position3i)) == false)
            {
                TransportPipeManager.pipesInfo.TryAdd(Utils.MakeWorldMod(Position3i), info);
            }
            Utils.RecreateLinker(Utils.MakeWorldMod(Position3i), info.beltLinker);
            InitInputOutput();
        }
Ejemplo n.º 7
0
        public PipeEntry(Vector3i offset, WorldObject obj)
        {
            TransportPipeInfo info = new TransportPipeInfo();

            info.beltLinker = null;
            info.type       = PIPETYPE.Electric;
            pos             = Utils.MakeWorldMod(obj.Position3i + offset);
            List <TransportPipeInfo> neighbourgs = Utils.GetNeighbourgPipesInfo(pos);

            if (neighbourgs.Count > 0)
            {
                foreach (TransportPipeInfo neighbourg in neighbourgs)
                {
                    if (info.beltLinker == null)
                    {
                        info.beltLinker = neighbourg.beltLinker;
                    }
                    else if (neighbourg.beltLinker != null && info.beltLinker != neighbourg.beltLinker)
                    {
                        info.beltLinker.AbsorbLinker(neighbourg.beltLinker);
                    }
                }
                if (info.beltLinker == null)
                {
                    info.beltLinker = new TransportPipeLinker();
                }
                info.beltLinker.AddConveyor(info);
            }
            else
            {
                info.beltLinker = new TransportPipeLinker();
                info.beltLinker.AddConveyor(info);
            }
            info.pos = pos;
            TransportPipeManager.pipesInfo[pos] = info;
        }
Ejemplo n.º 8
0
 public void InitInputOutput()
 {
     info.beltLinker.RemoveConnector(this);
     if (TransportPipeManager.pipesInfo.ContainsKey(Utils.MakeWorldMod(Position3i)))
     {
         info = TransportPipeManager.pipesInfo[Utils.MakeWorldMod(Position3i)];
     }
     if (mode == CONNECTOR_MODE.Input)
     {
         WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i));
         if (obj != null)
         {
             Input    = obj;
             InvInput = Utils.SearchInventoryFromObject(obj);
             info.beltLinker.AddConnector(true, this);
             SetAnimatedState("SetModeInput", true);
         }
         if (Input == null || InvInput == null)
         {
             mode = CONNECTOR_MODE.None;
         }
     }
     if (mode == CONNECTOR_MODE.Output)
     {
         WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i));
         if (obj != null)
         {
             Output    = obj;
             InvOutput = Utils.SearchInventoryFromObject(obj);
             info.beltLinker.AddConnector(false, this);
             SetAnimatedState("SetModeOutput", true);
         }
         if (Output == null || InvOutput == null)
         {
             mode = CONNECTOR_MODE.None;
         }
     }
     if (mode == CONNECTOR_MODE.InOut)
     {
         WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i));
         if (obj != null)
         {
             Input     = obj;
             Output    = obj;
             InvOutput = Utils.SearchInventoryFromObject(obj);
             InvInput  = InvOutput;
             info.beltLinker.AddConnector(false, this);
             info.beltLinker.AddConnector(true, this);
             SetAnimatedState("SetModeIOput", true);
         }
         if (Input == null || InvOutput == null)
         {
             mode = CONNECTOR_MODE.None;
         }
     }
     // If it's in an unknow state - remove the connector
     if (mode == CONNECTOR_MODE.None)
     {
         CleanDestroy();
         return;
     }
     if (info != null && info.beltLinker != null)
     {
         info.beltLinker.UpdateElectricityType();
     }
     if (info != null)
     {
         SetAnimatedState("SetWood", info.type == PIPETYPE.Wooden);
         previousType = info.type;
     }
 }