# IWeaponHolder interface

> The body holding a weapon, as one tick's command left it. Every vector is a MapVector in meters on Godot's axes. A number or vector it's given that isn't finite, or is past a float's range, throws ArgumentOutOfRangeException naming it, so one bad sum can't spoil the holder's aim or the world, and so does a projectile's mass of 0 or less or a size or damping below 0.

Namespace `EvilEngine.Api.Weapons`, assembly `EvilEngine.Api`. Engine commit 4ff877b1.

```csharp
public interface IWeaponHolder
```

The body holding a weapon, as one tick's command left it. Every vector is a [MapVector](/docs/api/mapvector) in meters on Godot's axes. A number or vector it's given that isn't finite, or is past a float's range, throws `ArgumentOutOfRangeException` naming it, so one bad sum can't spoil the holder's aim or the world, and so does a projectile's mass of 0 or less or a size or damping below 0.

## Members

### Eye (property)

```csharp
MapVector Eye { get; }
```

Where the holder's eye is.

### Aim (property)

```csharp
MapVector Aim { get; }
```

The unit direction the command aims along, from its pitch and yaw. In third person it aims at what the crosshair shows.

### Yaw (property)

```csharp
double Yaw { get; }
```

The command's yaw in degrees.

### Velocity (property)

```csharp
MapVector Velocity { get; }
```

How fast the holder is moving, in meters a second, so what it throws carries its speed.

### Held (property)

```csharp
WeaponButtons Held { get; }
```

The [buttons](/docs/api/weaponbuttons) held on this command.

### Pressed (property)

```csharp
WeaponButtons Pressed { get; }
```

The buttons held now that weren't on the command before.

### Released (property)

```csharp
WeaponButtons Released { get; }
```

The buttons held on the command before that aren't now.

### Mode (property)

```csharp
int Mode { get; }
```

The weapon's mode, as its record's `modes` list it, 0 for the first.

### Interval (property)

```csharp
double Interval { get; }
```

The tick's length in seconds.

### Wheel (property)

```csharp
int Wheel { get; }
```

The mouse wheel's notches since the last command while the weapon [captures](#captures) the wheel, up positive, or 0 when it doesn't.

### Steer (property)

```csharp
WeaponSteer Steer { get; }
```

The [mouse's movement](/docs/api/weaponsteer) since the last command while the weapon [captures](#captures) steering and use is held, which the view doesn't turn by meanwhile.

### Captures (property)

```csharp
WeaponCaptures Captures { get; set; }
```

What the weapon [takes from the player](/docs/api/weaponcaptures) in place of the selector and the view, none by default. It holds until the weapon sets it again or is put away. The physics gun takes both while it holds a prop.

### Time (property)

```csharp
double Time { get; }
```

The session's clock in seconds.

### Beam (property)

```csharp
WeaponBeam? Beam { get; set; }
```

The beam to draw this tick, or `null` for none. Set it every tick it should show; a holder starts each tick with none.

### Dot (property)

```csharp
MapVector? Dot { get; set; }
```

A laser dot to show where the weapon points this tick, like the RPG's, or `null` for none.

### Record (property)

```csharp
WeaponRecord? Record { get; }
```

The weapon's `weapon` record resolved down its bases, with the simulation keys its game's adapter writes: clip size, default clip, ammo, damage and named sounds. `null` when the weapon has none.

### Clip (property)

```csharp
int Clip { get; set; }
```

The rounds in this item's clip, -1 for a weapon without one. Setting it changes the clip the owner's HUD and wheel show.

### Speed (property)

```csharp
double Speed { get; set; }
```

A scale on how fast the holder walks, runs and swims while this weapon is held, 1 for their own speed: 0.8 for a heavy gun, 0.5 while a scope is up. It lasts until it's set again or the weapon is put away, and noclip flies at full speed whatever it is. Below 0 or not a number, it throws.

### Zoomed (property)

```csharp
double? Zoomed { get; }
```

The field of view in degrees the weapon has zoomed to, or `null` when it hasn't.

### ViewModel (property)

```csharp
IWeaponViewModel ViewModel { get; }
```

The owner's [view model](/docs/api/iweaponviewmodel) for this weapon: its skin, body groups, pose parameters, a stack swapped in for its own, and whether it shows.

### Hold (property)

```csharp
string? Hold { get; set; }
```

The hold type the holder's body stands, walks and runs in while this weapon is held: `pistol`, `smg`, `ar2`, `shotgun`, `melee`, `passive` or any name a person has `holds` for. It reads the weapon record's `hold` for the held mode until it's set, and setting it holds another until it's set back with `null` or the weapon is put away, as a weapon lowered while sprinting does. A body with no clips for the hold walks on its own. A name is lower-case letters, digits and `_`; another throws.

```csharp
holder.Hold = sprinting ? "passive" : null;
```

### Ammo (method)

```csharp
int Ammo(ContentId type)
```

How many rounds of an ammo type the body carries.

### SetAmmo (method)

```csharp
void SetAmmo(ContentId type, int count)
```

Sets how many rounds of an ammo type the body carries, never below 0.

### Trace (method)

```csharp
WeaponTrace Trace(MapVector from, MapVector to)
```

```csharp
WeaponTrace Trace(MapVector from, MapVector to, double size)
```

A line from one point to another through the world, its props and its people, as a [WeaponTrace](/docs/api/weapontrace) that names the physics body it hit. With a size it sweeps a box that far out from the line on every side, in metres, as a melee swing does when a line misses.

### Animate (method)

```csharp
void Animate(string activity, double rate = 1, WeaponEase ease = WeaponEase.Linear)
```

Plays an activity (`@ACT_VM_RELOAD`) or a sequence by name on the owner's view model from its start, at a rate and with an ease over the same length, then back to its idle when it ends, or to the idle's last frame when the idle doesn't loop.

### Duration (method)

```csharp
double Duration(string activity)
```

How long an activity or sequence lasts on this weapon's view model at rate 1, in seconds, or 0 when it has none, so a weapon times its next shot or reload by its animation.

### Sound (method)

```csharp
void Sound(ContentId sound)
```

Plays a sound record from the holder's eye, heard by everyone.

### Punch (method)

```csharp
void Punch(double pitch, double yaw)
```

Adds to the view punch's speed, in degrees a second of pitch (up) and yaw (left). The engine's spring brings it back; while it lasts it turns the owner's camera and the [Aim](#aim) bullets fire along.

### Fire (method)

```csharp
IReadOnlyList<WeaponTrace> Fire(WeaponBullets bullets)
```

Fires [bullets](/docs/api/weaponbullets) from the eye along the aim: the engine traces each pellet within the cone, pushes the props it hits, plays each surface's bullet sound and shows the muzzle flash, impacts and tracers in the looks the weapon's record names, or the bullets' own. It hands back what each pellet hit, in order, so a weapon can chain off its hits.

```csharp
foreach (var hit in holder.Fire(new WeaponBullets(1, 0, 20, 0)))
    if (hit.Person)
        holder.Effect(ContentId.Parse("mygun:effect/zap"), WeaponEffectAt.At(hit.End, hit.Normal));
```

### Effect (method)

```csharp
void Effect(ContentId effect, WeaponEffectAt at = default)
```

Plays an `effect` record for every player: at a point facing a normal, or on an attachment of the weapon's own model, which its owner sees on their view model and everyone else at the body's hand. With no place it plays on the weapon's muzzle (see [WeaponEffectAt](/docs/api/weaponeffectat)).

### Impact (method)

```csharp
void Impact(WeaponTrace hit, ContentId? effect = null, ContentId? decal = null)
```

Marks a hit the way a bullet's is marked: plays an `effect` record there, the given one or the struck surface's impact, and leaves a `decal` record, the given one or the surface's `decals.melee`, then its `decals.bullet`. A melee weapon calls it with what its [Trace](#trace) struck.

### Eject (method)

```csharp
void Eject(ContentId? casing = null)
```

Ejects a `casing` record from the weapon's eject attachment, the weapon's own casing when none is named. A weapon whose model has no brass events of its own ejects its casings this way.

### Strike (method)

```csharp
void Strike(WeaponTrace hit, double damage, MapVector impulse, DamageKind kind = DamageKind.Club)
```

Hurts the person a [Trace](#trace) this tick just hit, or pushes the prop it hit, with the damage, the impulse in kg·m/s and the [kind](/docs/api/damagekind) of damage, a club's by default. A melee weapon strikes with it.

### Launch (method)

```csharp
IProjectile Launch(MapVector from, WeaponProjectile projectile, IProjectileBehaviour behaviour)
```

Launches a [projectile](/docs/api/weaponprojectile) from a point and hands back the [IProjectile](/docs/api/iprojectile) that flies. Its [behaviour](/docs/api/iprojectilebehaviour) thinks every tick and decides what happens when it touches something; the weapon can keep the projectile to steer it.

### Zoom (method)

```csharp
void Zoom(double? fov, double seconds = 0)
```

Eases the owner's field of view to a number of degrees over some seconds, or back to their own with `null`, as a scope or a binocular does. The mouse turns more slowly the further in it is, so a zoomed aim moves as far across the screen as an unzoomed one. It lasts until the weapon zooms again or is put away, which snaps the view back at once. A field of view is kept between 1° and 170°.

```csharp
if (holder.Pressed.HasFlag(WeaponButtons.Attack2))
    holder.Zoom(holder.Zoomed is null ? 20 : null, 0.2);
```

### Reading (method)

```csharp
void Reading(string name, double? value)
```

Sets a number the HUD and the power bar can show by name, or clears it with `null`: a charge, a heat, a second clip. A `hudfield` record shows it with `value = "weapon.<name>"`, and a bar segment with `{weapon.<name>}`. Readings last until they're set again or the weapon is put away. A name is lower-case letters, digits and `_`; another throws.

```csharp
holder.Reading("heat", _heat);
```

### Gesture (method)

```csharp
void Gesture(string? name, double seconds = 0)
```

Plays a gesture on the holder's body for everyone to see, over its legs and in its hold type: [WeaponGestures.Attack](/docs/api/weapongestures) as a shot goes off, [WeaponGestures.Reload](/docs/api/weapongestures) stretched to last as long as the reload does, or any name a person has a `gesture.<name>` slot for. A new gesture replaces the last, and `null` stops it, as an interrupted reload does. A name is lower-case letters, digits and `_`; another throws, and so do seconds below 0.

```csharp
holder.Animate("reload");
holder.Gesture(WeaponGestures.Reload, holder.Duration("reload"));
```
