private void OnMicrowaved(EntityUid uid, BatteryComponent component, BeingMicrowavedEvent args)
    {
        args.Handled = true;

        // What the f**k are you doing???
        Explode(uid, component);
    }
        private void PreSync(EntityUid uid, BatteryComponent component, NetworkBatteryPreSync args)
        {
            var networkBattery = ComponentManager.GetComponent <PowerNetworkBatteryComponent>(uid);

            networkBattery.NetworkBattery.Capacity       = component.MaxCharge;
            networkBattery.NetworkBattery.CurrentStorage = component.CurrentCharge;
        }
Beispiel #3
0
    private void TryWhackAstronaut()
    {
        for (int i = 0; i < AstronautController.Instances.Count; ++i)
        {
            AstronautController astro = AstronautController.Instances[i];
            if (astro != this)
            {
                Vector3 toAstro = (astro.transform.position - transform.position).WithY(0);
                if (toAstro.magnitude < 2.5f)
                {
                    if (_hitSound)
                    {
                        AudioManager.Instance.PlaySound(gameObject, _hitSound);
                    }

                    astro.GetWhacked(transform.position);

                    BatteryComponent battery = GetComponent <BatteryComponent>();
                    if (battery != null && battery.HasCharge)
                    {
                        astro.RoomInhabitant.NotifySuckedIntoSpace();
                        battery.DrainCharge();
                    }

                    return;
                }
            }
        }
    }
Beispiel #4
0
    //protected SpringJoint2D joint;

    // Use this for initialization
    protected virtual void Start()
    {
        rigidbody2D = GetComponent <Rigidbody2D>();
        battery     = GetComponent <BatteryComponent>();
        animator    = gameObject.GetComponent <Animator>();
        audio       = GetComponent <AudioSource>();
    }
Beispiel #5
0
    protected override void OnInteractionPressed(GameObject gameObject)
    {
        BatteryComponent battery = gameObject.GetComponentInChildren <BatteryComponent>();

        if (battery != null && !battery.HasCharge)
        {
            battery.AddCharge(ChargePerInteraction);
            StartCooldownTimer();
        }
    }
    protected override void OnInteractionPressed(GameObject gameObject)
    {
        BatteryComponent battery = gameObject.GetComponentInChildren <BatteryComponent>();

        if (battery != null && battery.HasCharge)
        {
            battery.DrainCharge();
            OpenNextDoor();
        }
    }
Beispiel #7
0
    private void OnMicrowaved(EntityUid uid, BatteryComponent component, BeingMicrowavedEvent args)
    {
        if (component.CurrentCharge == 0)
        {
            return;
        }

        args.Handled = true;

        // What the f**k are you doing???
        Explode(uid, component);
    }
Beispiel #8
0
 private bool TryInsertItem(IEntity entity)
 {
     if (!IsEntityCompatible(entity) || _container.ContainedEntity != null)
     {
         return(false);
     }
     if (!_container.Insert(entity))
     {
         return(false);
     }
     _heldBattery = GetBatteryFrom(entity);
     UpdateStatus();
     return(true);
 }
    private void UpdateShots(BatteryAmmoProviderComponent component, BatteryComponent battery)
    {
        var shots    = (int)(battery.CurrentCharge / component.FireCost);
        var maxShots = (int)(battery.MaxCharge / component.FireCost);

        if (component.Shots != shots || component.Capacity != maxShots)
        {
            Dirty(component);
        }

        component.Shots    = shots;
        component.Capacity = maxShots;
        UpdateBatteryAppearance(component.Owner, component);
    }
Beispiel #10
0
        public async Task ApcChargingTest()
        {
            var options = new ServerIntegrationOptions {
                ExtraPrototypes = Prototypes
            };
            var server = StartServerDummyTicker(options);

            BatteryComponent       apcBattery         = null;
            PowerSupplierComponent substationSupplier = null;

            server.Assert(() =>
            {
                var mapMan    = IoCManager.Resolve <IMapManager>();
                var entityMan = IoCManager.Resolve <IEntityManager>();
                mapMan.CreateMap(new MapId(1));
                var grid = mapMan.CreateGrid(new MapId(1));

                var generatorEnt  = entityMan.SpawnEntity("GeneratorDummy", grid.ToCoordinates());
                var substationEnt = entityMan.SpawnEntity("SubstationDummy", grid.ToCoordinates(0, 1));
                var apcEnt        = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 2));

                Assert.That(generatorEnt.TryGetComponent <PowerSupplierComponent>(out var generatorSupplier));

                Assert.That(substationEnt.TryGetComponent(out substationSupplier));
                Assert.That(substationEnt.TryGetComponent <BatteryStorageComponent>(out var substationStorage));
                Assert.That(substationEnt.TryGetComponent <BatteryDischargerComponent>(out var substationDischarger));

                Assert.That(apcEnt.TryGetComponent(out apcBattery));
                Assert.That(apcEnt.TryGetComponent <BatteryStorageComponent>(out var apcStorage));

                generatorSupplier.SupplyRate          = 1000; //arbitrary nonzero amount of power
                substationStorage.ActiveDrawRate      = 1000; //arbitrary nonzero power draw
                substationDischarger.ActiveSupplyRate = 500;  //arbitirary nonzero power supply less than substation storage draw
                apcStorage.ActiveDrawRate             = 500;  //arbitrary nonzero power draw
                apcBattery.MaxCharge     = 100;               //abbitrary nonzero amount of charge
                apcBattery.CurrentCharge = 0;                 //no charge
            });

            server.RunTicks(5); //let run a few ticks for PowerNets to reevaluate and start charging apc

            server.Assert(() =>
            {
                Assert.That(substationSupplier.SupplyRate, Is.Not.EqualTo(0)); //substation should be providing power
                Assert.That(apcBattery.CurrentCharge, Is.Not.EqualTo(0));      //apc battery should have gained charge
            });

            await server.WaitIdleAsync();
        }
Beispiel #11
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var chunkTranslations = chunk.GetNativeArray(translationType);
            var chunkBatteries    = chunk.GetNativeArray(batteryComponentType);
            var chunkFactions     = chunk.GetNativeArray(factionComponentType);

            for (int i = 0; i < chunk.Count; i++)
            {
                var countDown = chunkBatteries[i].countDown - deltaTime;
                if (countDown < 0)
                {
                    int selected;
                    do
                    {
                        selected = random.NextInt(entities.Length);
                    } while (factions[entities[selected]].faction == chunkFactions[i].faction);

                    var vec = translations[entities[selected]].Value - chunkTranslations[i].Value;
                    var d   = math.length(vec);
                    var g   = 9.8f;
                    var v   = chunkBatteries[i].speed;

                    if ((d * g) / (v * v) <= 1)
                    {
                        var instance = commandBuffer.Instantiate(chunkIndex, prefab);
                        var theta    = math.asin((d * g) / (v * v)) / 2;

                        var vxz      = math.normalize(new float3(vec.x, 0, vec.z));
                        var velocity = math.up() * math.sin(theta) * v + vxz * math.cos(theta) * v;
                        commandBuffer.AddComponent(chunkIndex, instance, new BulletComponent {
                            vec = velocity
                        });
                        commandBuffer.SetComponent(chunkIndex, instance, new Translation {
                            Value = chunkTranslations[i].Value
                        });
                    }
                }

                chunkBatteries[i] = new BatteryComponent
                {
                    interval  = chunkBatteries[i].interval,
                    speed     = chunkBatteries[i].speed,
                    countDown = countDown + (countDown > 0 ? 0 : chunkBatteries[i].interval),
                };
            }
        }
Beispiel #12
0
    // Update is called once per frame
    void Update()
    {
        //Hide the display if no robot is selected
        if (robot == null)
        {
            canvasGroup.alpha = 0.0f;
            return;
        }
        else
        {
            canvasGroup.alpha = 1.0f;
        }

        //Get the battery of the current robot
        //BatteryComponent battery = robot.GetBattery ();
        BatteryComponent battery = robot.GetTopComponent(typeof(BatteryComponent)) as BatteryComponent;

        //incase the current robot has changed
        maxBattery = battery.max;

        //Get level
        CurrentBattery = battery.level;
    }
Beispiel #13
0
        /// <summary>
        /// This will remove the item directly into the user's hand / floor
        /// </summary>
        /// <param name="user"></param>
        private void RemoveItem(IEntity user)
        {
            var heldItem = _container.ContainedEntity;

            if (heldItem == null)
            {
                return;
            }

            _container.Remove(heldItem);
            _heldBattery = null;
            if (user.TryGetComponent(out HandsComponent handsComponent))
            {
                handsComponent.PutInHandOrDrop(heldItem.GetComponent <ItemComponent>());
            }

            if (heldItem.TryGetComponent(out ServerBatteryBarrelComponent batteryBarrelComponent))
            {
                batteryBarrelComponent.UpdateAppearance();
            }

            UpdateStatus();
        }
        private void PostSync(EntityUid uid, BatteryComponent component, NetworkBatteryPostSync args)
        {
            var networkBattery = ComponentManager.GetComponent <PowerNetworkBatteryComponent>(uid);

            component.CurrentCharge = networkBattery.NetworkBattery.CurrentStorage;
        }