private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component) { if (!TryComp <BatteryComponent>(uid, out var battery)) { return; } UpdateShots(component, battery); }
private void OnAmmoCountUpdate(EntityUid uid, BatteryAmmoProviderComponent component, UpdateAmmoCounterEvent args) { if (args.Control is not BoxesStatusControl boxes) { return; } boxes.Update(component.Shots, component.Capacity); }
private void OnBatteryGetState(EntityUid uid, BatteryAmmoProviderComponent component, ref ComponentGetState args) { args.State = new BatteryAmmoProviderComponentState() { Shots = component.Shots, MaxShots = component.Capacity, FireCost = component.FireCost, }; }
protected void UpdateBatteryAppearance(EntityUid uid, BatteryAmmoProviderComponent component) { if (!TryComp <AppearanceComponent>(uid, out var appearance)) { return; } appearance.SetData(AmmoVisuals.AmmoCount, component.Shots); appearance.SetData(AmmoVisuals.AmmoMax, component.Capacity); }
protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component) { if (!TryComp <BatteryComponent>(uid, out var battery)) { return; } battery.CurrentCharge -= component.FireCost; UpdateShots(component, battery); }
private void OnBatteryHandleState(EntityUid uid, BatteryAmmoProviderComponent component, ref ComponentHandleState args) { if (args.Current is not BatteryAmmoProviderComponentState state) { return; } component.Shots = state.Shots; component.Capacity = state.MaxShots; component.FireCost = state.FireCost; }
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); }
private IShootable GetShootable(BatteryAmmoProviderComponent component, EntityCoordinates coordinates) { switch (component) { case ProjectileBatteryAmmoProviderComponent proj: var ent = Spawn(proj.Prototype, coordinates); return(EnsureComp <AmmoComponent>(ent)); case HitscanBatteryAmmoProviderComponent hitscan: return(ProtoManager.Index <HitscanPrototype>(hitscan.Prototype)); default: throw new ArgumentOutOfRangeException(); } }
private void OnBatteryTakeAmmo(EntityUid uid, BatteryAmmoProviderComponent component, TakeAmmoEvent args) { var shots = Math.Min(args.Shots, component.Shots); // Don't dirty if it's an empty fire. if (shots == 0) { return; } for (var i = 0; i < shots; i++) { args.Ammo.Add(GetShootable(component, args.Coordinates)); component.Shots--; } TakeCharge(uid, component); UpdateBatteryAppearance(uid, component); Dirty(component); }
private void OnControl(EntityUid uid, BatteryAmmoProviderComponent component, AmmoCounterControlEvent args) { args.Control = new BoxesStatusControl(); }
/// <summary> /// Update the battery (server-only) whenever fired. /// </summary> protected virtual void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component) { }
private void OnBatteryAmmoCount(EntityUid uid, BatteryAmmoProviderComponent component, ref GetAmmoCountEvent args) { args.Count = component.Shots; args.Capacity = component.Capacity; }
private void OnBatteryExamine(EntityUid uid, BatteryAmmoProviderComponent component, ExaminedEvent args) { args.PushMarkup(Loc.GetString("gun-battery-examine", ("color", AmmoExamineColor), ("count", component.Shots))); }
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ChargeChangedEvent args) { UpdateShots(uid, component); }
private void OnBatteryStartup(EntityUid uid, BatteryAmmoProviderComponent component, ComponentStartup args) { UpdateShots(uid, component); }