Exemplo n.º 1
0
        private string GetTextForState(FurnaceState state)
        {
            string str;

            switch (state)
            {
            case FurnaceState.Waiting:
                // we found replacement string in MyTexts.
                str = VRage.MyTexts.Get(MyStringId.TryGet("FurnaceStateWaiting")).ToString();
                str = str.Replace("\\n", "\n");
                return(str);

            //return @"      Drop\n     unwanted\n  vehicles and\n   large items\n  into furnace";
            case FurnaceState.LoadedUp:
                // we found replacement string in MyTexts.
                str = VRage.MyTexts.Get(MyStringId.TryGet("FurnaceStateLoadedUp")).ToString();
                str = str.Replace("\\n", "\n");
                return(str);

            //return @"\n   Close doors\n    to activate\n      furnace";
            case FurnaceState.Working:
                // we found replacement string in MyTexts.
                str = VRage.MyTexts.Get(MyStringId.TryGet("FurnaceStateWorking")).ToString();
                str = str.Replace("\\n", "\n");
                return(str);

            //return @"  ! Caution !\n   Furnace is\n      active\n\n      Extreme\n  temperatures";
            case FurnaceState.Off:
                throw new ArgumentException("Furnace should never change to state: " + state);

            default:
                throw new ArgumentException("Uncoped for state: " + state);
            }
        }
Exemplo n.º 2
0
        private string GetTextForState(FurnaceState state)
        {
            switch (state)
            {
            case FurnaceState.Waiting:
                return(@"      Drop
     unwanted
  vehicles and
   large items
  into furnace");

            case FurnaceState.LoadedUp:
                return(@"
   Close doors
    to activate
      furnace");

            case FurnaceState.Working:
                return(@"  ! Caution !
   Furnace is
      active

      Extreme
  temperatures");

            case FurnaceState.Off:
                throw new ArgumentException("Furnace should never change to state: " + state);

            default:
                throw new ArgumentException("Uncoped for state: " + state);
            }
        }
Exemplo n.º 3
0
        private FurnaceState GetState(IWorld world, Coordinates3D coords)
        {
            var tileEntity = world.GetTileEntity(coords);

            if (tileEntity == null)
            {
                tileEntity = CreateTileEntity();
            }
            var burnTime  = tileEntity.Get <NbtShort>("BurnTime");
            var burnTotal = tileEntity.Get <NbtShort>("BurnTotal");
            var cookTime  = tileEntity.Get <NbtShort>("CookTime");
            var state     = new FurnaceState
            {
                BurnTimeTotal     = burnTotal == null ? (short)0 : burnTotal.Value,
                BurnTimeRemaining = burnTime == null ? (short)0 : burnTime.Value,
                CookTime          = cookTime == null ? (short)200 : cookTime.Value
            };
            var items = tileEntity.Get <NbtList>("Items");

            if (items != null)
            {
                var i = 0;
                foreach (var item in items)
                {
                    state.Items[i++] = ItemStack.FromNbt((NbtCompound)item);
                }
            }

            return(state);
        }
Exemplo n.º 4
0
        private void ChangeFurnaceState(FurnaceState newState)
        {
            if (newState == furnaceState)
            {
                return;
            }

            furnaceState = newState;
            SetFurnaceLcdsText(GetTextForState(newState));
        }
Exemplo n.º 5
0
        private void TryInitializeFurnace(FurnaceState state, EventScheduler scheduler, IWorld world,
                                          Coordinates3D coords, IItemRepository itemRepository)
        {
            if (TrackedFurnaces.ContainsKey(coords))
            {
                return;
            }

            var inputStack  = state.Items[FurnaceWindow.IngredientIndex];
            var fuelStack   = state.Items[FurnaceWindow.FuelIndex];
            var outputStack = state.Items[FurnaceWindow.OutputIndex];

            var input = itemRepository.GetItemProvider(inputStack.Id) as ISmeltableItem;
            var fuel  = itemRepository.GetItemProvider(fuelStack.Id) as IBurnableItem;

            if (state.BurnTimeRemaining > 0)
            {
                if (state.CookTime == -1 && input != null &&
                    (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput)))
                {
                    state.CookTime = 0;
                    SetState(world, coords, state);
                }

                var subject = new FurnaceEventSubject();
                TrackedFurnaces[coords] = subject;
                scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                                        server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                return;
            }

            if (fuel != null && input != null)             // We can maybe start
            {
                if (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput))
                {
                    // We can definitely start
                    state.BurnTimeRemaining = state.BurnTimeTotal = (short)(fuel.BurnTime.TotalSeconds * 20);
                    state.CookTime          = 0;
                    state.Items[FurnaceWindow.FuelIndex].Count--;
                    SetState(world, coords, state);
                    world.SetBlockId(coords, LitFurnaceBlock.BlockId);
                    var subject = new FurnaceEventSubject();
                    TrackedFurnaces[coords] = subject;
                    scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                                            server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                }
            }
        }
Exemplo n.º 6
0
 private void SetState(IWorld world, Coordinates3D coords, FurnaceState state)
 {
     world.SetTileEntity(coords, new NbtCompound(new NbtTag[]
     {
         new NbtShort("BurnTime", state.BurnTimeRemaining),
         new NbtShort("BurnTotal", state.BurnTimeTotal),
         new NbtShort("CookTime", state.CookTime),
         new NbtList("Items", new[]
         {
             state.Items[0].ToNbt(),
             state.Items[1].ToNbt(),
             state.Items[2].ToNbt()
         }, NbtTagType.Compound)
     }));
     UpdateWindows(coords, state);
 }
Exemplo n.º 7
0
        private void UpdateWindows(Coordinates3D coords, FurnaceState state)
        {
            if (TrackedFurnaceWindows.ContainsKey(coords))
            {
                Handling = true;
                foreach (var window in TrackedFurnaceWindows[coords])
                {
                    window[0] = state.Items[0];
                    window[1] = state.Items[1];
                    window[2] = state.Items[2];

                    window.Client.QueuePacket(new UpdateProgressPacket(
                                                  window.ID, UpdateProgressPacket.ProgressTarget.ItemCompletion, state.CookTime));
                    var burnProgress = state.BurnTimeRemaining / (double)state.BurnTimeTotal;
                    var burn         = (short)(burnProgress * 250);
                    window.Client.QueuePacket(new UpdateProgressPacket(
                                                  window.ID, UpdateProgressPacket.ProgressTarget.AvailableHeat, burn));
                }
                Handling = false;
            }
        }
 // Update is called once per frame
 void Update()
 {
     if (isServer)
     {
         if (state == FurnaceState.CONSUMING)
         {
             currentConsume += Time.deltaTime;
             if (currentConsume >= consumeTime)
             {
                 Destroy(consuming);
                 state = FurnaceState.OPEN;
                 doorAnim.SetBool("Open", true);
             }
         }
         if (transitionDelay > 0)
         {
             transitionDelay -= Time.deltaTime;
         }
     }
     else
     {
         currentConsume = 0;
     }
 }
Exemplo n.º 9
0
 private FurnaceState GetState(IWorld world, Coordinates3D coords)
 {
     var tileEntity = world.GetTileEntity(coords);
     if (tileEntity == null)
         tileEntity = CreateTileEntity();
     var burnTime = tileEntity.Get<NbtShort>("BurnTime");
     var burnTotal = tileEntity.Get<NbtShort>("BurnTotal");
     var cookTime = tileEntity.Get<NbtShort>("CookTime");
     var state = new FurnaceState
     {
         BurnTimeTotal = burnTotal == null ? (short)0 : burnTotal.Value,
         BurnTimeRemaining = burnTime == null ? (short)0 : burnTime.Value,
         CookTime = cookTime == null ? (short)200 : cookTime.Value
     };
     var items = tileEntity.Get<NbtList>("Items");
     if (items != null)
     {
         int i = 0;
         foreach (var item in items)
             state.Items[i++] = ItemStack.FromNbt((NbtCompound)item);
     }
     return state;
 }
Exemplo n.º 10
0
        private void TryInitializeFurnace(FurnaceState state, IEventScheduler scheduler, IWorld world,
                                          Coordinates3D coords, IItemRepository itemRepository)
        {
            if (TrackedFurnaces.ContainsKey(coords))
                return;

            var inputStack = state.Items[FurnaceWindow.IngredientIndex];
            var fuelStack = state.Items[FurnaceWindow.FuelIndex];
            var outputStack = state.Items[FurnaceWindow.OutputIndex];

            var input = itemRepository.GetItemProvider(inputStack.ID) as ISmeltableItem;
            var fuel = itemRepository.GetItemProvider(fuelStack.ID) as IBurnableItem;

            if (state.BurnTimeRemaining > 0)
            {
                if (state.CookTime == -1 && input != null && (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput)))
                {
                    state.CookTime = 0;
                    SetState(world, coords, state);
                }
                var subject = new FurnaceEventSubject();
                TrackedFurnaces[coords] = subject;
                scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                    server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                return;
            }

            if (fuel != null && input != null) // We can maybe start
            {
                if (outputStack.Empty || outputStack.CanMerge(input.SmeltingOutput))
                {
                    // We can definitely start
                    state.BurnTimeRemaining = state.BurnTimeTotal = (short)(fuel.BurnTime.TotalSeconds * 20);
                    state.CookTime = 0;
                    state.Items[FurnaceWindow.FuelIndex].Count--;
                    SetState(world, coords, state);
                    world.SetBlockID(coords, LitFurnaceBlock.BlockID);
                    var subject = new FurnaceEventSubject();
                    TrackedFurnaces[coords] = subject;
                    scheduler.ScheduleEvent("smelting", subject, TimeSpan.FromSeconds(1),
                        server => UpdateFurnace(server.Scheduler, world, coords, itemRepository));
                }
            }
        }
Exemplo n.º 11
0
 private void SetState(IWorld world, Coordinates3D coords, FurnaceState state)
 {
     world.SetTileEntity(coords, new NbtCompound(new NbtTag[]
     {
         new NbtShort("BurnTime", state.BurnTimeRemaining),
         new NbtShort("BurnTotal", state.BurnTimeTotal),
         new NbtShort("CookTime", state.CookTime),
         new NbtList("Items", new[]
         {
             state.Items[0].ToNbt(),
             state.Items[1].ToNbt(),
             state.Items[2].ToNbt()
         }, NbtTagType.Compound)
     }));
     UpdateWindows(coords, state);
 }
Exemplo n.º 12
0
        private void UpdateWindows(Coordinates3D coords, FurnaceState state)
        {
            if (TrackedFurnaceWindows.ContainsKey(coords))
            {
                Handling = true;
                foreach (var window in TrackedFurnaceWindows[coords])
                {
                    window[0] = state.Items[0];
                    window[1] = state.Items[1];
                    window[2] = state.Items[2];

                    window.Client.QueuePacket(new UpdateProgressPacket(
                        window.ID, UpdateProgressPacket.ProgressTarget.ItemCompletion, state.CookTime));
                    var burnProgress = state.BurnTimeRemaining / (double)state.BurnTimeTotal;
                    var burn = (short)(burnProgress * 250);
                    window.Client.QueuePacket(new UpdateProgressPacket(
                        window.ID, UpdateProgressPacket.ProgressTarget.AvailableHeat, burn));
                }
                Handling = false;
            }
        }
Exemplo n.º 13
0
 internal void RestoreSavedData(MikiScrapSaveData saveData)
 {
     furnaceState            = saveData.FurnaceState;
     furnaceWorkingCountdown = saveData.FurnaceWorkingCountdown;
     timeSinceSpoken         = saveData.TimeSinceSpoken;
 }
Exemplo n.º 14
0
 void Interact(GameObject actor)
 {
     if (transitionDelay <= 0)
     {
         if (state == FurnaceState.CLOSED)
         {
             doorAnim.SetBool("Open", true);
             state           = FurnaceState.OPEN;
             transitionDelay = 2f;
         }
         else if (state == FurnaceState.OPEN)
         {
             GamePlayer player = actor.GetComponent <GamePlayer> ();
             if (player != null)
             {
                 Inventory  inv  = player.GetComponent <Inventory> ();
                 GameObject held = inv.held;
                 if (held != null)
                 {
                     if (inv.held.GetComponent <Item> ().canDrop)
                     {
                         inv.ServerDropItem(inv.selected);
                         consuming = held;
                         consuming.transform.position = coal.position;
                         player.EndAction(1.75f, "You put the " + consuming.GetComponent <Item>().itemName + " into the furnace");
                         consuming.GetComponent <Item> ().DisablePhysics();
                         state = FurnaceState.CONSUMING;
                         doorAnim.SetBool("Open", false);
                         transitionDelay = 1f;
                     }
                     else
                     {
                         player.EndAction(1.5f, "Can't put that into the furnace");
                     }
                 }
                 else
                 {
                     player.AddTimedMessage("You must hold an item to put into the furnace", 1.5f);
                     state = FurnaceState.CLOSED;
                     doorAnim.SetBool("Open", false);
                 }
             }
             else
             {
                 state = FurnaceState.CLOSED;
                 doorAnim.SetBool("Open", false);
             }
         }
         else if (state == FurnaceState.CONSUMING)
         {
             GamePlayer player = actor.GetComponent <GamePlayer> ();
             if (player != null)
             {
                 Inventory inv = player.GetComponent <Inventory> ();
                 if (inv.HasOpenSpace())
                 {
                     state           = FurnaceState.OPEN;
                     transitionDelay = 2f;
                     doorAnim.SetBool("Open", true);
                     inv.AttemptPickup(consuming.GetComponent <Item> ());
                     player.EndAction(2.5f, "You pull the " + consuming.GetComponent <Item>().itemName + " from the burning furnace");
                     consuming = null;
                 }
                 else
                 {
                     player.AddTimedMessage("Open space to pick up the item quick", 1.5f);
                 }
             }
         }
     }
 }