//EnergyReleased = 200000000 eV * (PresentNeutrons*NeutronAbsorptionProbability())
        //0.000000000032 = Wsec
        //1 eV = 0.00000000000000000016 Wsec

        public bool TryInsertRod(HandApply interaction)
        {
            if (Validations.HasItemTrait(interaction.UsedObject, CommonTraits.Instance.ReactorRod))
            {
                var Rod = interaction.UsedObject.gameObject.GetComponent <ReactorChamberRod>();
                int pos = Array.IndexOf(ReactorRods, null);
                if (pos > -1)
                {
                    ReactorRods[pos] = Rod;
                    var EmptySlot = RodStorage.GetIndexedItemSlot(pos);
                    Inventory.ServerTransfer(interaction.HandSlot, EmptySlot);
                    var fuelRod = Rod as FuelRod;
                    if (fuelRod != null)
                    {
                        ReactorFuelRods.Add(fuelRod);
                    }

                    var engineStarter = Rod as EngineStarter;
                    if (engineStarter != null)
                    {
                        ReactorEngineStarters.Add(engineStarter);
                    }
                }

                return(true);
            }

            return(false);
        }
        public void PowerOutput()
        {
            EnergyReleased       = ProcessRodsHits(PresentNeutrons);
            EditorEnergyReleased = (float)EnergyReleased;

            uint rods = 0;

            foreach (var rod in ReactorRods)
            {
                if (rod != null)
                {
                    rods++;
                }
            }

            var ExtraEnergyGained = (float)EnergyReleased;

            if (ReactorPipe.pipeData.mixAndVolume.WholeHeatCapacity != 0)
            {
                ReactorPipe.pipeData.mixAndVolume.InternalEnergy =
                    ReactorPipe.pipeData.mixAndVolume.InternalEnergy + ExtraEnergyGained;
            }

            CurrentPressure = (decimal)Mathf.Clamp(((ReactorPipe.pipeData.mixAndVolume.Temperature - 293.15f) *
                                                    ReactorPipe.pipeData.mixAndVolume.Total.x),
                                                   (float)decimal.MinValue, (float)decimal.MaxValue);

            if (CurrentPressure > MaxPressure)
            {
                PoppedPipes = true;
                var EmptySlot = PipeStorage.GetIndexedItemSlot(0);
                Inventory.ServerDrop(EmptySlot);
            }
        }
Example #3
0
        private void Start()
        {
            ItemStorage itemStorage = GetComponent <ItemStorage>();

            containerSlot = itemStorage.GetIndexedItemSlot(0);
            bufferItemOne = itemStorage.GetIndexedItemSlot(1);
            bufferItemTwo = itemStorage.GetIndexedItemSlot(2);
        }
Example #4
0
 private void Awake()
 {
     itemStorage = GetComponent <ItemStorage>();
     AccessSlot  = itemStorage.GetIndexedItemSlot(0);
     TargetSlot  = itemStorage.GetIndexedItemSlot(1);
     AccessSlot.OnSlotContentsChangeServer.AddListener(OnServerSlotContentsChange);
     TargetSlot.OnSlotContentsChangeServer.AddListener(OnServerSlotContentsChange);
 }
Example #5
0
        private void Start()
        {
            SetRingtone(defaultRingtone);

            IDSlot        = storage.GetIndexedItemSlot(0);
            CartridgeSlot = storage.GetIndexedItemSlot(1);

            IDSlot.OnSlotContentsChangeServer.AddListener(OnIDSlotChanged);
            //messengerSystem = GameObject.Find("MessengerManager").GetComponent<MessengerManager>();
            //AddSelf();
        }
Example #6
0
 private void Awake()
 {
     //init weapon with missing settings
     GetComponent <ItemAttributesV2>().AddTrait(CommonTraits.Instance.Gun);
     itemStorage    = GetComponent <ItemStorage>();
     magSlot        = itemStorage.GetIndexedItemSlot(0);
     pinSlot        = itemStorage.GetIndexedItemSlot(1);
     suppressorSlot = itemStorage.GetIndexedItemSlot(2);
     registerTile   = GetComponent <RegisterTile>();
     queuedShots    = new Queue <QueuedShot>();
     if (pinSlot == null || magSlot == null || itemStorage == null)
     {
         Logger.LogWarning($"{gameObject.name} missing components, may cause issues", Category.Firearms);
     }
 }
Example #7
0
        private void Start()
        {
            SetRingtone(defaultRingtone);

            IDSlot        = storage.GetIndexedItemSlot(0);
            CartridgeSlot = storage.GetIndexedItemSlot(1);

            IDSlot.OnSlotContentsChangeServer.AddListener(OnIDSlotChanged);

            if (CustomNetworkManager.IsServer && cartridgePrefab != null)
            {
                var cartridge = Spawn.ServerPrefab(cartridgePrefab).GameObject;
                Inventory.ServerAdd(cartridge, CartridgeSlot);
            }
        }
Example #8
0
    public void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context)
    {
        foreach (var gameObject in DeprecatedContents)
        {
            var ItemSlot = ItemStorage.GetNextFreeIndexedSlot();
            var spawn    = Spawn.ServerPrefab(gameObject, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints:  true);
        }

        if (SlotContents.Count == 0)
        {
            return;
        }

        foreach (var namedSlotPopulatorEntry in SlotContents)
        {
            ItemSlot ItemSlot;
            if (namedSlotPopulatorEntry.UesIndex)
            {
                ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot);
            }
            else
            {
                ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot);
            }
            if (ItemSlot == null)
            {
                continue;
            }

            var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true);
            Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys);
        }
    }
Example #9
0
 private void Awake()
 {
     //we have an item storage with only 1 slot.
     storageObject = GetComponent <ItemStorage>();
     slot          = storageObject.GetIndexedItemSlot(0);
     //TODO: Can probably refactor this component to rely more on ItemStorage and do less of its own logic.
 }
Example #10
0
		private void EnsureInit()
		{
			if (storageObject != null) return;
			//we have an item storage with only 1 slot.
			storageObject = GetComponent<ItemStorage>();
			slot = storageObject.GetIndexedItemSlot(0);
		}
    public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context)
    {
        //if appending, start at first free slot index
        var start = 0;

        if (MergeMode == IndexedMergeMode.Append)
        {
            var freeSlot = toPopulate.GetNextFreeIndexedSlot();
            if (freeSlot == null)
            {
                Logger.LogTraceFormat("Can't populate {0}, no more free slots.", Category.Inventory, toPopulate);
                return;
            }

            start = freeSlot.SlotIdentifier.SlotIndex;
        }
        for (var i = start; i < SlotPopulators.Length; i++)
        {
            var slot = toPopulate.GetIndexedItemSlot(i);
            if (slot == null)
            {
                Logger.LogErrorFormat("Storage {0} does not have a slot with index {1}. Please ensure" +
                                      " the Contents don't exceed the number of slots in the ItemStorage.", Category.Inventory,
                                      toPopulate, i);
                return;
            }

            if (slot.Item != null && MergeMode == IndexedMergeMode.Overwrite)
            {
                Inventory.ServerDespawn(slot);
            }
            SlotPopulators[i].PopulateSlot(slot, context);
        }
    }
Example #12
0
 private void Awake()
 {
     //we can just store a single card.
     itemStorage = GetComponent <ItemStorage>();
     itemSlot    = itemStorage.GetIndexedItemSlot(0);
     itemSlot.OnSlotContentsChangeServer.AddListener(OnServerSlotContentsChange);
 }
Example #13
0
        public void AddItem(ItemSlot fromSlot)
        {
            if (fromSlot == null || fromSlot.IsEmpty || ((fromSlot.ItemObject.GetComponent <Grindable>() == null && fromSlot.ItemObject.GetComponent <Juiceable>() == null) && !fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker)))
            {
                return;
            }


            if (fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker))
            {
                if (itemSlot.IsEmpty)
                {
                    Inventory.ServerTransfer(fromSlot, itemStorage.GetIndexedItemSlot(0));
                }
                return;
            }

            // If there's a stackable component, add one at a time.
            Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>();

            if (stack == null || stack.Amount == 1)
            {
                Inventory.ServerTransfer(fromSlot, itemStorage.GetNextFreeIndexedSlot());
            }
            else
            {
                var item = stack.ServerRemoveOne();
                Inventory.ServerAdd(item, itemStorage.GetNextFreeIndexedSlot());
            }
        }
Example #14
0
        public void Awake()
        {
            ItemStorage itemStorage = GetComponent <ItemStorage>();

            if (itemStorage != null && hasBattery)
            {
                batterySlot = itemStorage.GetIndexedItemSlot(0);
            }
        }
Example #15
0
        private void Awake()
        {
            //init weapon with missing settings
            GetComponent <ItemAttributesV2>().AddTrait(CommonTraits.Instance.Gun);
            itemStorage  = GetComponent <ItemStorage>();
            magSlot      = itemStorage.GetIndexedItemSlot(0);
            registerTile = GetComponent <RegisterTile>();

            queuedShots = new Queue <QueuedShot>();
        }
    public void PowerOutput()
    {
        EnergyReleased       = ProcessRodsHits(PresentNeutrons);
        EditorEnergyReleased = (float)EnergyReleased;

        uint rods = 0;

        foreach (var rod in ReactorRods)
        {
            if (rod != null)
            {
                rods++;
            }
        }

        var ExtraEnergyGained = (float)EnergyReleased /
                                ((RodDensityPer1 * rods) +
                                 (WaterEnergyDensityPer1 *
                                  ReactorPipe.pipeData.mixAndVolume.Mix.Total));         //when add cool

        if (ReactorPipe.pipeData.mixAndVolume.Mix.WholeHeatCapacity == 0)
        {
            ReactorPipe.pipeData.mixAndVolume.Mix.Temperature += ExtraEnergyGained / 90000;
        }
        else
        {
            ReactorPipe.pipeData.mixAndVolume.Mix.InternalEnergy =
                ReactorPipe.pipeData.mixAndVolume.Mix.InternalEnergy + ExtraEnergyGained;
        }



        CurrentPressure = (decimal)((ReactorPipe.pipeData.mixAndVolume.Mix.Temperature - 293.15f) *
                                    ReactorPipe.pipeData.mixAndVolume.Mix.Total);
        if (CurrentPressure > MaxPressure)
        {
            PoppedPipes = true;
            var EmptySlot = PipeStorage.GetIndexedItemSlot(0);
            Inventory.ServerDrop(EmptySlot);
        }
    }
Example #17
0
        /// Checks to see what the new ID is and will register the PDA with the ID if this is its first ID
        private void SlotChange()
        {
            //Checks the slots again and will update the variables
            var slot = storage.GetIndexedItemSlot(0);

            IdCard = null;
            if (slot.IsEmpty != true && isServer)
            {
                IdCard = slot.Item.GetComponent <IDCard>();
                onServerIdCardChanged.Invoke(IdCard);
            }

            //Will register the PDA to the ID card if firstRegister is true
            if (!(firstRegister & (IdCard != null)))
            {
                return;
            }
            PdaRegisteredName = IdCard.RegisteredName;
            firstRegister     = false;
            ReplaceName(pdaId, PdaRegisteredName);
        }
Example #18
0
 private void Awake()
 {
     //init weapon with missing settings
     GetComponent <ItemAttributesV2>().AddTrait(CommonTraits.Instance.Gun);
     itemStorage  = GetComponent <ItemStorage>();
     magSlot      = itemStorage.GetIndexedItemSlot(0);
     registerTile = GetComponent <RegisterTile>();
     gunTrigger   = GetComponent <GunTrigger>();
     queuedShots  = new Queue <QueuedShot>();
     if (gunTrigger == null || magSlot == null || itemStorage == null)
     {
         Debug.LogWarning($"{gameObject.name} missing components, may cause issues");
     }
 }
Example #19
0
        //private MessengerManager messengerSystem;

        /// <summary>
        /// Grabs the components on the game objects and readies itself for slot changes
        /// </summary>
        private void Start()
        {
            storage         = gameObject.GetComponent <ItemStorage>();
            TabOnGameObject = gameObject.GetComponent <HasNetworkTabItem>();
            pdaId           = gameObject.GetComponent <NetworkIdentity>();
            var slot = storage.GetIndexedItemSlot(0);

            if (slot.IsEmpty != true)
            {
                IdCard = slot.Item.GetComponent <IDCard>();
            }
            slot.OnSlotContentsChangeServer.AddListener(SlotChange);
            passlist = UplinkPasswordList.Instance;
            //messengerSystem = GameObject.Find("MessengerManager").GetComponent<MessengerManager>();
            //AddSelf();
        }
Example #20
0
    public void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context)
    {
        //if appending, start at first free slot index
        var start = 0;

        if (MergeMode == IndexedStoragePopulator.IndexedMergeMode.Append)
        {
            var freeSlot = toPopulate.GetNextFreeIndexedSlot();
            if (freeSlot == null)
            {
                Logger.LogTraceFormat("Can't populate {0}, no more free slots.", Category.Inventory, toPopulate);
                return;
            }

            start = freeSlot.SlotIdentifier.SlotIndex;
        }

        for (var i = start; i < Contents.Count; i++)
        {
            // General protection against missing items
            if (Contents[i] == null)
            {
                continue;                 // Will skip the missing item
            }

            var slot = toPopulate.GetIndexedItemSlot(i);
            if (slot == null)
            {
                Logger.LogErrorFormat("Storage {0} does not have a slot with index {1}. Please ensure" +
                                      " the Contents don't exceed the number of slots in the ItemStorage.",
                                      Category.Inventory,
                                      toPopulate, i);
                return;
            }

            if (slot.Item != null && MergeMode == IndexedStoragePopulator.IndexedMergeMode.Overwrite)
            {
                Inventory.ServerDespawn(slot);
            }

            var spawned = Spawn.ServerPrefab(Contents[i]).GameObject;
            Inventory.ServerAdd(spawned, slot);
        }
    }
    //This is all client only interaction:
    public bool Interact(HandActivate interaction)
    {
        if (canQuickEmpty)
        {
            // Drop all items that are inside this storage
            var slots = itemStorage.GetItemSlots();

            if (slots == null)
            {
                if (!CustomNetworkManager.Instance._isServer)
                {
                    Chat.AddExamineMsgToClient("It's already empty!");
                }

                return(false);
            }

            if (PlayerManager.PlayerScript == null)
            {
                return(false);
            }

            PlayerManager.PlayerScript.playerNetworkActions.CmdDropAllItems(itemStorage.GetIndexedItemSlot(0).ItemStorageNetID);

            if (!CustomNetworkManager.Instance._isServer)
            {
                Chat.AddExamineMsgToClient($"You start dumping out the {gameObject.ExpensiveName()}.");
            }

            return(true);
        }

        //open / close the backpack on activate
        if (UIManager.StorageHandler.CurrentOpenStorage != itemStorage)
        {
            UIManager.StorageHandler.OpenStorageUI(itemStorage);
        }
        else
        {
            UIManager.StorageHandler.CloseStorageUI();
        }

        return(true);
    }
Example #22
0
    private void Awake()
    {
        GetComponent <ItemAttributesV2>().AddTrait(CommonTraits.Instance.Gun);
        itemStorage  = GetComponent <ItemStorage>();
        magSlot      = itemStorage.GetIndexedItemSlot(0);
        registerTile = GetComponent <RegisterTile>();
        //init weapon with missing settings
        if (AmmoType == null)
        {
            AmmoType = "12mm";
        }

        if (Projectile == null)
        {
            Projectile = Resources.Load("Bullet_12mm") as GameObject;
        }

        queuedShots = new Queue <QueuedShot>();
    }
Example #23
0
    public override void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context)
    {
        //Uses the old contents for now
        foreach (var gameObject in DeprecatedContents)
        {
            var ItemSlot = ItemStorage.GetNextFreeIndexedSlot();
            var spawn    = Spawn.ServerPrefab(gameObject, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints:  true);
        }

        if (SlotContents.Count == 0)
        {
            return;
        }

        //Look through the specified slots, and tries to find it on the storage and populates if so,
        //and then attempts recursion
        foreach (var namedSlotPopulatorEntry in SlotContents)
        {
            ItemSlot ItemSlot;
            if (namedSlotPopulatorEntry.UesIndex)
            {
                ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot);
            }
            else
            {
                ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot);
            }
            if (ItemSlot == null)
            {
                continue;
            }

            var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true);
            Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true);
            Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys);
        }
    }
Example #24
0
        private void Awake()
        {
            ItemStorage itemStorage = GetComponent <ItemStorage>();

            itemSlot = itemStorage.GetIndexedItemSlot(0);
        }
Example #25
0
    /// <summary>
    /// Server:
    /// Allow items to be stored by clicking on bags with item in hand
    /// and clicking items with bag in hand if CanClickPickup is enabled
    /// </summary>
    public void ServerPerformInteraction(PositionalHandApply interaction)
    {
        if (allowedToInteract == false)
        {
            return;
        }
        // See which item needs to be stored
        if (Validations.IsTarget(gameObject, interaction))
        {
            // Add hand item to this storage
            Inventory.ServerTransfer(interaction.HandSlot, itemStorage.GetBestSlotFor(interaction.HandObject));
        }
        // See if this item can click pickup
        else if (canClickPickup)
        {
            bool       pickedUpSomething = false;
            Pickupable pickup;
            switch (pickupMode)
            {
            case PickupMode.Single:

                // Don't pick up items which aren't set as CanPickup
                pickup = interaction.TargetObject.GetComponent <Pickupable>();
                if (pickup == null || pickup.CanPickup == false)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "There's nothing to pickup!");
                    return;
                }

                // Store the clicked item
                var slot = itemStorage.GetBestSlotFor(interaction.TargetObject);
                if (slot == null)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer,
                                                 $"The {interaction.TargetObject.ExpensiveName()} doesn't fit!");
                    return;
                }

                Inventory.ServerAdd(interaction.TargetObject, slot);
                break;

            case PickupMode.Same:
                if (interaction.TargetObject == null ||
                    interaction.TargetObject.Item() == null)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "There's nothing to pickup!");
                    return;
                }

                // Get all items of the same type on the tile and try to store them
                var itemsOnTileSame =
                    MatrixManager.GetAt <ItemAttributesV2>(interaction.WorldPositionTarget.To2Int().To3Int(), true);

                if (itemsOnTileSame.Count == 0)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "There's nothing to pickup!");
                    return;
                }

                foreach (var item in itemsOnTileSame)
                {
                    // Don't pick up items which aren't set as CanPickup
                    pickup = item.gameObject.GetComponent <Pickupable>();
                    if (pickup == null || pickup.CanPickup == false)
                    {
                        continue;
                    }

                    // Only try to add it if it matches the target object's traits
                    if (item.HasAllTraits(interaction.TargetObject.Item().GetTraits()))
                    {
                        // Try to add each item to the storage
                        // Can't break this loop when it fails because some items might not fit and
                        // there might be stacks with space still
                        if (Inventory.ServerAdd(item.gameObject, itemStorage.GetBestSlotFor(item.gameObject)))
                        {
                            pickedUpSomething = true;
                        }
                    }
                }

                Chat.AddExamineMsgFromServer(interaction.Performer,
                                             $"You put everything you could in the {gameObject.ExpensiveName()}.");
                break;

            case PickupMode.All:
                // Get all items on the tile and try to store them
                var itemsOnTileAll =
                    MatrixManager.GetAt <ItemAttributesV2>(interaction.WorldPositionTarget.To2Int().To3Int(), true);

                if (itemsOnTileAll.Count == 0)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "There's nothing to pickup!");
                    return;
                }

                foreach (var item in itemsOnTileAll)
                {
                    // Don't pick up items which aren't set as CanPickup
                    pickup = item.gameObject.GetComponent <Pickupable>();
                    if (pickup == null || pickup.CanPickup == false)
                    {
                        continue;
                    }

                    // Try to add each item to the storage
                    // Can't break this loop when it fails because some items might not fit and
                    // there might be stacks with space still
                    if (Inventory.ServerAdd(item.gameObject, itemStorage.GetBestSlotFor(item.gameObject)))
                    {
                        pickedUpSomething = true;
                    }
                }

                if (pickedUpSomething)
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer,
                                                 $"You put everything you could in the {gameObject.ExpensiveName()}.");
                }
                else
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "There's nothing to pickup!");
                }

                break;

            case PickupMode.DropClick:
                if (canQuickEmpty)
                {
                    // Drop all items that are inside this storage
                    var slots = itemStorage.GetItemSlots();
                    if (slots == null)
                    {
                        Chat.AddExamineMsgFromServer(interaction.Performer, "It's already empty!");


                        return;
                    }
                    if (PlayerManager.PlayerScript == null)
                    {
                        return;
                    }
                    if (Validations.IsInReachDistanceByPositions(PlayerManager.PlayerScript.registerTile.WorldPosition, interaction.WorldPositionTarget) == false)
                    {
                        return;
                    }
                    if (MatrixManager.IsPassableAtAllMatricesOneTile(interaction.WorldPositionTarget.RoundToInt(), CustomNetworkManager.Instance._isServer) == false)
                    {
                        return;
                    }

                    PlayerManager.PlayerScript.playerNetworkActions.CmdDropAllItems(itemStorage.GetIndexedItemSlot(0)
                                                                                    .ItemStorageNetID, interaction.WorldPositionTarget);


                    Chat.AddExamineMsgFromServer(interaction.Performer, $"You start dumping out the {gameObject.ExpensiveName()}.");
                }

                break;
            }
        }
    }
Example #26
0
 private void Awake()
 {
     spriteHandler = GetComponentInChildren <SpriteHandler>();
     itemStorage   = GetComponent <ItemStorage>();
     ChargingSlot  = itemStorage.GetIndexedItemSlot(0);
 }
Example #27
0
 private void Awake()
 {
     itemStorage  = GetComponent <ItemStorage>();
     ChargingSlot = itemStorage.GetIndexedItemSlot(0);
 }
Example #28
0
 // Start is called before the first frame update
 private void Awake()
 {
     InternalBatterySlot = BatteryitemStorage.GetIndexedItemSlot(0);
 }
 public override void OnStartServer()
 {
     itemSlot = itemStorage.GetIndexedItemSlot(0);
     securable.OnAnchoredChange.AddListener(OnSecuredChanged);
     registerTile.WaitForMatrixInit(CheckStartingPlasma);
 }
Example #30
0
        // Start is called before the first frame update
        private void Awake()
        {
            ItemStorage BatteryitemStorage = GetComponent <ItemStorage>();

            InternalBatterySlot = BatteryitemStorage.GetIndexedItemSlot(0);
        }