Skip to content

Commit b1ddef4

Browse files
committed
Suspend physics on vehicle mounting
1 parent 4ba75c9 commit b1ddef4

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

spockbot/plugins/helpers/clientinfo.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(self):
8686
self.eid = 0
8787
self.name = ""
8888
self.uuid = ""
89+
self.mount = None
8990
self.abilities = Abilities()
9091
self.game_info = GameInfo()
9192
self.spawn_position = Position()
@@ -104,6 +105,7 @@ class ClientInfoPlugin(PluginBase):
104105
events = {
105106
'LOGIN<Login Success': 'handle_login_success',
106107
'PLAY<Join Game': 'handle_join_game',
108+
'PLAY<Attach Entity': 'handle_attach_entity',
107109
'PLAY<Spawn Position': 'handle_spawn_position',
108110
'PLAY<Update Health': 'handle_update_health',
109111
'PLAY<Player Position and Look': 'handle_position_update',
@@ -133,6 +135,15 @@ def handle_join_game(self, name, packet):
133135
self.client_info.game_info.set_dict(packet.data)
134136
self.event.emit('client_join_game', self.client_info.game_info)
135137

138+
def handle_attach_entity(self, name, packet):
139+
eid, v_eid = packet.data['eid'], packet.data['v_eid']
140+
if eid == self.client_info.eid:
141+
self.client_info.mount = v_eid
142+
self.event.emit('client_mount', v_eid)
143+
elif v_eid == self.client_info.mount and eid == -1:
144+
self.client_info.mount = None
145+
self.event.emit('client_unmount', v_eid)
146+
136147
# Spawn Position - Update client Spawn Position state
137148
def handle_spawn_position(self, name, packet):
138149
self.client_info.spawn_position.set_dict(packet.data['location'])
@@ -171,9 +182,9 @@ def handle_player_list(self, name, packet):
171182
self.client_info.player_list[pl['uuid']] = item
172183
self.uuids[pl['uuid']] = item
173184
self.event.emit('client_add_player', item)
174-
elif act in [const.PL_UPDATE_GAMEMODE,
185+
elif act in (const.PL_UPDATE_GAMEMODE,
175186
const.PL_UPDATE_LATENCY,
176-
const.PL_UPDATE_DISPLAY]:
187+
const.PL_UPDATE_DISPLAY):
177188
if pl['uuid'] in self.uuids:
178189
item = self.uuids[pl['uuid']]
179190
item.set_dict(pl)

spockbot/plugins/helpers/physics.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class PhysicsPlugin(PluginBase):
7070
events = {
7171
'physics_tick': 'physics_tick',
7272
'client_tick': 'client_tick',
73-
'client_position_update': 'pause_physics',
73+
'client_position_update': 'skip_physics',
74+
'client_mount': 'suspend_physics',
75+
'client_unmount': 'resume_physics',
7476
}
7577

7678
def __init__(self, ploader, settings):
@@ -84,10 +86,17 @@ def __init__(self, ploader, settings):
8486
self.pc = PhysicsCore(self.pos, self.vec, self.clientinfo.abilities)
8587
ploader.provides('Physics', self.pc)
8688

87-
def pause_physics(self, _=None, __=None):
89+
def skip_physics(self, _=None, __=None):
8890
self.vec.zero()
8991
self.skip_tick = True
9092

93+
def suspend_physics(self, _=None, __=None):
94+
self.vec.zero()
95+
self.event.unreg_event_handler('physics_tick', self.physics_tick)
96+
97+
def resume_physics(self, _=None, __=None):
98+
self.event.reg_event_handler('physics_tick', self.physics_tick)
99+
91100
def client_tick(self, name, data):
92101
self.net.push_packet('PLAY>Player Position and Look',
93102
self.clientinfo.position.get_dict())

0 commit comments

Comments
 (0)