Skip to content

Commit

Permalink
Merge pull request #432 from Falderebet/silenced-weapon
Browse files Browse the repository at this point in the history
Silenced weapon
  • Loading branch information
markus-wa authored Oct 9, 2023
2 parents 28a80ab + 2db09f0 commit 905ddfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/demoinfocs/common/equipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ func (e *Equipment) RecoilIndex() float32 {
return val.Float()
}

// Silenced returns true if weapon is silenced.
func (e *Equipment) Silenced() bool {
// If entity is nil returns false.
if e.Entity == nil {
return false
}

prop := e.Entity.Property("m_bSilencerOn")

return prop.Value().BoolVal()
}

// NewEquipment creates a new Equipment and sets the UniqueID.
//
// Intended for internal use only.
Expand Down
20 changes: 20 additions & 0 deletions pkg/demoinfocs/common/equipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ func TestEquipment_ZoomLevel_EntityNil(t *testing.T) {
assert.Equal(t, ZoomLevel(0), wep.ZoomLevel())
}

func TestEquipment_Not_Silenced(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0}),
}

assert.Equal(t, false, wep.Silenced())
}

func TestEquipment_Silenced_On_Off(t *testing.T) {
wep := &Equipment{
Type: EqUSP,
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 1}),
}
assert.Equal(t, true, wep.Silenced(), "Weapon should be silenced after the property value has been set to 1.")

wep.Entity = entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0})
assert.Equal(t, false, wep.Silenced(), "Weapon should not be silenced after the property value has been set to 0.")
}

func TestEquipmentAlternative(t *testing.T) {
assert.Equal(t, EqUSP, EquipmentAlternative(EqP2000))
assert.Equal(t, EqCZ, EquipmentAlternative(EqP250))
Expand Down

0 comments on commit 905ddfc

Please sign in to comment.