Skip to content

Commit

Permalink
Add basic speech backend system. To be polished later. By Lechen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrq619 committed Jul 19, 2023
1 parent 82d6092 commit 7919b95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ws/battlefiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,28 @@ def add_player(self, username, websocket):
async def parse_gestures(self, username:str, gesture_type:str):
player = self.get_player(username)
enemy = self.get_enemy(username)

# By Lechen: Add buffer behavior
player.gesture_buffer.append(gesture_type)
add_buffer_task = asyncio.create_task(self.add_gesture_buffer(player,gesture_type))

if gesture_type == "ILoveYou":
await self.attack(player, enemy, gesture_type)
elif gesture_type == "Thumb_Up":
await self.light_shield(player, gesture_type)
pass

# By Lechen: parse speech
async def parse_speech(self, username:str, speech_type:str):
player = self.get_player(username)
enemy = self.get_enemy(username)

if speech_type == "ILoveYou":
await self.attack(player, enemy, speech_type)
#elif gesture_type == "Thumb_Up":
# await self.light_shield(player, gesture_type)
#pass



async def game_start(self):
Expand All @@ -74,12 +90,12 @@ async def game_start(self):
await self.broadcast_delay(message=str(game_start_message))

async def attack(self, player:Player, enemy:Player, gesture_type:str):
add_buffer_task = asyncio.create_task(self.add_gesture_buffer(player,gesture_type))
#add_buffer_task = asyncio.create_task(self.add_gesture_buffer(player,gesture_type))
light_attack_task = asyncio.create_task(self.light_attack(player))
results_check_task = asyncio.create_task(self.attack_result_check(player,enemy,ATTACK_CHECK_INTERVAL))

async def light_shield(self, player:Player, gesture_type:str):
add_buffer_task = asyncio.create_task(self.add_gesture_buffer(player,gesture_type))
#add_buffer_task = asyncio.create_task(self.add_gesture_buffer(player,gesture_type))
change_status_task = asyncio.create_task(self.change_player_status(player=player, status=PStatus.LIGHT_SHIELD.value))


Expand Down
15 changes: 15 additions & 0 deletions ws/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ async def post_gesture(username:str, message_args:dict) -> str:
debug("Cannot find user %s's room"%username)
return NULL_RESPONSE

# By Lechen: Post speech
async def post_speech(username:str, message_args:dict) -> str:
room = GAME_HALL.find_room_with_user(username)
battlefiled = room.battlefiled
speech_type = message_args['speech_type']
if room != None:
# broadcast_args = {'gesture_source':username,'gesture_type':gesture_type}
# broadcast_response = WS_response(source="ws_server",action='post_gesture',code=0,args=broadcast_args)
await battlefiled.parse_speech(username, speech_type=speech_type)

# await room.broadcast(str(broadcast_response))
else:
debug("Cannot find user %s's room"%username)
return NULL_RESPONSE

async def quit_room(username:str, message_args:dict) -> str:
room_id = message_args['room_id']
room = GAME_HALL.find_room(room_id)
Expand Down

0 comments on commit 7919b95

Please sign in to comment.