public static bool Prefix(EnergyMixin __instance, bool __result, ref float amount)
        {
            float num = -__instance.ModifyCharge(-Math.Abs(amount * HCPSettings.Instance.HandToolsPowerDrainMultiplier));

            __result = num > 0f;
            return(false);
        }
        public void OnConsoleCommand_charge()
        {
            EnergyMixin energyMixin = Inventory.main.GetHeldTool().GetComponent <EnergyMixin>();

            energyMixin.ModifyCharge(energyMixin.capacity);
            ErrorMessage.AddMessage("Charged.");
        }
        public override void Process(EnergyMixinValueChanged energyMixinPacket)
        {
            GameObject  target      = NitroxEntity.RequireObjectFrom(energyMixinPacket.Id);
            EnergyMixin energyMixin = target.RequireComponent <EnergyMixin>();

            using (packetSender.Suppress <EnergyMixinValueChanged>())
            {
                energyMixin.ModifyCharge(energyMixinPacket.Value - energyMixin.charge);
            }
        }
        public override void Process(PowerLevelChanged packet)
        {
            GameObject gameObject = GuidHelper.RequireObjectFrom(packet.Guid);

            if (packet.PowerType == PowerType.ENERGY_INTERFACE)
            {
                EnergyInterface energyInterface = gameObject.RequireComponent <EnergyInterface>();

                float amount = packet.Amount;
                float num    = 0f;
                if (GameModeUtils.RequiresPower())
                {
                    int num2 = 0;
                    if (packet.Amount > 0f)
                    {
                        float num3 = energyInterface.TotalCanConsume(out num2);
                        if (num3 > 0f)
                        {
                            float amount2 = amount / (float)num2;
                            for (int i = 0; i < energyInterface.sources.Length; i++)
                            {
                                EnergyMixin energyMixin = energyInterface.sources[i];
                                if (energyMixin != null && energyMixin.charge < energyMixin.capacity)
                                {
                                    num += energyMixin.ModifyCharge(amount2);
                                }
                            }
                        }
                    }
                    else
                    {
                        float num4 = energyInterface.TotalCanProvide(out num2);
                        if (num2 > 0)
                        {
                            amount = ((-amount <= num4) ? amount : (-num4));
                            for (int j = 0; j < energyInterface.sources.Length; j++)
                            {
                                EnergyMixin energyMixin2 = energyInterface.sources[j];
                                if (energyMixin2 != null && energyMixin2.charge > 0f)
                                {
                                    float num5 = energyMixin2.charge / num4;
                                    num += energyMixin2.ModifyCharge(amount * num5);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Log.Error("Unsupported packet power type: " + packet.PowerType);
            }
        }
Exemple #5
0
        public override void Process(EnergyMixinValueChanged energyMixinPacket)
        {
            Optional <GameObject> target = NitroxEntity.GetObjectFrom(energyMixinPacket.Id); // Can't find inventory items for now because they aren't really synced.

            if (target.HasValue)
            {
                EnergyMixin energyMixin = target.Value.RequireComponent <EnergyMixin>();

                using (packetSender.Suppress <EnergyMixinValueChanged>())
                {
                    energyMixin.ModifyCharge(energyMixinPacket.Value - energyMixin.charge);
                }
            }
        }
        public void OnConsoleCommand_chargeto(NotificationCenter.Notification n)
        {
            EnergyMixin energyMixin = Inventory.main.GetHeldTool().GetComponent <EnergyMixin>();

            if (n.data.Count != 1 || n.data == null)
            {
                ErrorMessage.AddMessage("Usage: chargeto [amount]");
                return;
            }

            if (float.TryParse((string)n.data[0], out float newCharge))
            {
                float oldCharge = energyMixin.charge;
                energyMixin.ModifyCharge(newCharge - oldCharge);
                Messenger.AddMessage("Charged to " + ((newCharge > energyMixin.capacity) ? energyMixin.capacity : newCharge) + ".");
            }
            else
            {
                Messenger.AddMessage("Amount must be number.");
            }
        }