private void OnChamberMagazineTakeAmmo(EntityUid uid, ChamberMagazineAmmoProviderComponent component, TakeAmmoEvent args) { // So chamber logic is kinda sussier than the others // Essentially we want to treat the chamber as a potentially free slot and then the mag as the remaining slots // i.e. if we shoot 3 times, then we use the chamber once (regardless if it's empty or not) and 2 from the mag // We move the n + 1 shot into the chamber as we essentially treat it like a stack. TryComp <AppearanceComponent>(uid, out var appearance); if (TryTakeChamberEntity(uid, out var chamberEnt)) { args.Ammo.Add(EnsureComp <AmmoComponent>(chamberEnt.Value)); } var magEnt = GetMagazineEntity(uid); // Pass an event to the magazine to get more (to refill chamber or for shooting). if (magEnt != null) { // We pass in Shots not Shots - 1 as we'll take the last entity and move it into the chamber. var relayedArgs = new TakeAmmoEvent(args.Shots, new List <IShootable>(), args.Coordinates, args.User); RaiseLocalEvent(magEnt.Value, relayedArgs, false); // Put in the nth slot back into the chamber // Rest of the ammo gets shot if (relayedArgs.Ammo.Count > 0) { var newChamberEnt = ((AmmoComponent)relayedArgs.Ammo[^ 1]).Owner;
protected (int, int) GetChamberMagazineCountCapacity(ChamberMagazineAmmoProviderComponent component) { var count = GetChamberEntity(component.Owner) != null ? 1 : 0; var(magCount, magCapacity) = GetMagazineCountCapacity(component); return(count + magCount, magCapacity); }
private void OnChamberMagazineAmmoUpdate(EntityUid uid, ChamberMagazineAmmoProviderComponent component, UpdateAmmoCounterEvent args) { if (args.Control is not ChamberMagazineStatusControl control) { return; } var chambered = GetChamberEntity(uid); var magEntity = GetMagazineEntity(uid); var ammoCountEv = new GetAmmoCountEvent(); if (magEntity != null) { RaiseLocalEvent(magEntity.Value, ref ammoCountEv, false); } control.Update(chambered != null, magEntity != null, ammoCountEv.Count, ammoCountEv.Capacity); }
private void OnChamberEntRemove(EntityUid uid, ChamberMagazineAmmoProviderComponent component, EntRemovedFromContainerMessage args) { if (args.Container.ID != ChamberSlot) { return; } // This is dirty af. Prediction moment. // We may be predicting spawning entities and the engine just removes them from the container so we'll just delete them. if (args.Entity.IsClientSide()) { QueueDel(args.Entity); } // AFAIK the only main alternative is having some client-specific handling via a bool or otherwise for the state. // which is much larger and I'm not sure how much better it is. It's bad enough we have to do it with revolvers // to avoid 6-7 additional entity spawns. }
private void OnChamberMagazineExamine(EntityUid uid, ChamberMagazineAmmoProviderComponent component, ExaminedEvent args) { var(count, _) = GetChamberMagazineCountCapacity(component); args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", count))); }
private void OnChamberMagazineCounter(EntityUid uid, ChamberMagazineAmmoProviderComponent component, AmmoCounterControlEvent args) { args.Control = new ChamberMagazineStatusControl(); }