-
Notifications
You must be signed in to change notification settings - Fork 89
/
hostage.go
65 lines (54 loc) · 1.94 KB
/
hostage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package common
import (
"github.com/golang/geo/r3"
st "github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/sendtables"
)
// HostageState is the type for the various HostageStateXYZ constants.
type HostageState byte
// HostageState constants give information about hostages state.
// e.g. being untied, picked up, rescued etc.
const (
HostageStateIdle HostageState = 0
HostageStateBeingUntied HostageState = 1
HostageStateGettingPickedUp HostageState = 2
HostageStateBeingCarried HostageState = 3
HostageStateFollowingPlayer HostageState = 4
HostageStateGettingDropped HostageState = 5
HostageStateRescued HostageState = 6
HostageStateDead HostageState = 7
)
// Hostage represents a hostage.
type Hostage struct {
Entity st.Entity
demoInfoProvider demoInfoProvider
}
// Position returns the current position of the hostage.
func (hostage *Hostage) Position() r3.Vector {
if hostage.Entity == nil {
return r3.Vector{}
}
return hostage.Entity.Position()
}
// State returns the current hostage's state.
// e.g. being untied, picked up, rescued etc.
// See HostageState for all possible values.
func (hostage *Hostage) State() HostageState {
return HostageState(getInt(hostage.Entity, "m_nHostageState"))
}
// Health returns the hostage's health points.
// ! On Valve MM matches hostages are invulnerable, it will always return 100 unless "mp_hostages_takedamage" is set to 1
func (hostage *Hostage) Health() int {
return getInt(hostage.Entity, "m_iHealth")
}
// Leader returns the possible player leading the hostage.
// Returns nil if the hostage is not following a player.
func (hostage *Hostage) Leader() *Player {
return hostage.demoInfoProvider.FindPlayerByHandle(getInt(hostage.Entity, "m_leader"))
}
// NewHostage creates a hostage.
func NewHostage(demoInfoProvider demoInfoProvider, entity st.Entity) *Hostage {
return &Hostage{
demoInfoProvider: demoInfoProvider,
Entity: entity,
}
}