Skip to content

Commit 905ddfc

Browse files
authored
Merge pull request #432 from Falderebet/silenced-weapon
Silenced weapon
2 parents 28a80ab + 2db09f0 commit 905ddfc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/demoinfocs/common/equipment.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,18 @@ func (e *Equipment) RecoilIndex() float32 {
444444
return val.Float()
445445
}
446446

447+
// Silenced returns true if weapon is silenced.
448+
func (e *Equipment) Silenced() bool {
449+
// If entity is nil returns false.
450+
if e.Entity == nil {
451+
return false
452+
}
453+
454+
prop := e.Entity.Property("m_bSilencerOn")
455+
456+
return prop.Value().BoolVal()
457+
}
458+
447459
// NewEquipment creates a new Equipment and sets the UniqueID.
448460
//
449461
// Intended for internal use only.

pkg/demoinfocs/common/equipment_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ func TestEquipment_ZoomLevel_EntityNil(t *testing.T) {
156156
assert.Equal(t, ZoomLevel(0), wep.ZoomLevel())
157157
}
158158

159+
func TestEquipment_Not_Silenced(t *testing.T) {
160+
wep := &Equipment{
161+
Type: EqAK47,
162+
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0}),
163+
}
164+
165+
assert.Equal(t, false, wep.Silenced())
166+
}
167+
168+
func TestEquipment_Silenced_On_Off(t *testing.T) {
169+
wep := &Equipment{
170+
Type: EqUSP,
171+
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 1}),
172+
}
173+
assert.Equal(t, true, wep.Silenced(), "Weapon should be silenced after the property value has been set to 1.")
174+
175+
wep.Entity = entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0})
176+
assert.Equal(t, false, wep.Silenced(), "Weapon should not be silenced after the property value has been set to 0.")
177+
}
178+
159179
func TestEquipmentAlternative(t *testing.T) {
160180
assert.Equal(t, EqUSP, EquipmentAlternative(EqP2000))
161181
assert.Equal(t, EqCZ, EquipmentAlternative(EqP250))

0 commit comments

Comments
 (0)