Esempio n. 1
0
 def genMissileExplosionMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_MISSILE_EXPLOSION,
         {
             constants.ENTITY_ID: self.entity_id
         }
     )
Esempio n. 2
0
 def genMissileDestoryMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_DESTORY_MISSILE,
         {
             constants.ENTITY_ID: self.entity_id
         }
     )
Esempio n. 3
0
    def handleHostEvent(self, event, client_id, data):

        if event == conf.NET_CONNECTION_NEW:
            print "[new connect] --> {0} client_id: {1}".format(
                data, client_id)
            dict_data = {
                constants.CLIENT_ID: client_id,
                constants.CODE: conf.COMMAND_SEND_CLIENTID,
            }
            # when new connect come, then send client_id to client
            send_msg = MsgHandler.genServerMsgFromDict(
                conf.SERVER_CLIENTID_DATA, dict_data)
            self.addToSingleMsgQueue(client_id, send_msg)

        elif event == conf.NET_CONNECTION_LEAVE:
            print self.entities
            print "[disconnect] --> {0} client_id: {1}".format(data, client_id)
            player_entity = self.getEntityByClientID(
                constants.PLAYER_ENTITY_TYPE, client_id)
            # maybe player is died
            if player_entity is not None:
                self.addToBroadcastMsgQueue(
                    player_entity.genPlayerDisconnectMsg())
                self.deleteEntity(constants.PLAYER_ENTITY_TYPE,
                                  player_entity.entity_id)
            self.deleteDisconnectClient(client_id)

        elif event == conf.NET_CONNECTION_DATA:
            # print "[receive] --> from client_id: {0} data: {1}".format(client_id, data)
            service_msg = ServiceMsg(*MsgHandler.get_service_id(data))
            self.dispatcher.dispatch(self, service_msg, client_id)
Esempio n. 4
0
 def genMissileLocationMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_SYNC_MISSILE,
         {
             constants.LOCATION: self.location.getDict(),
             constants.ENTITY_ID: self.entity_id
         }
     )
Esempio n. 5
0
 def genElephantAttackMsg(self, player_id):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_ELEPHANT_ATTACK,
         {
             constants.MONSTER_ID: self.entity_id,
             constants.PLAYER_ID: player_id
         }
     )
Esempio n. 6
0
 def genOtherPlayerSyncMsg(self):
     player_dict = {
         constants.PLAYER_ID: self.entity_id,
         constants.ROTATION: self.rotation.getDict(),
         constants.LOCATION: self.location.getDict(),
         constants.PLAYER_HEALTH: self.health
     }
     return MsgHandler.genServerMsgFromDict(conf.SERVER_SYNC_OTHER_PLAYER, player_dict)
Esempio n. 7
0
    def genSyncPlayerMsg(self):

        player_dict = {
            constants.PLAYER_ID: self.entity_id,
            constants.SCORE: self.score,
            constants.MONEY: self.money,
            constants.EXP: self.exp,
            constants.PLAYER_HEALTH: self.health,
            constants.USER_LEVEL: self.user_level,
            constants.ICE_TRAP_LEVEL: self.ice_trap_level,
            constants.NEEDLE_TRAP_LEVEL: self.needle_trap_level,
            constants.MISSILE_LEVEL: self.missile_level
        }

        return MsgHandler.genServerMsgFromDict(conf.SERVER_SYNC_PLAYER, player_dict)
Esempio n. 8
0
    def updatePlayerInGameDB(self, player_entity):

        history_score = player_entity.history_score
        if player_entity.score > player_entity.history_score:
            history_score = player_entity.score

        self.game_db.player_entity_table.update_player(
            player_entity.name, history_score, player_entity.user_level,
            player_entity.ice_trap_level, player_entity.needle_trap_level,
            player_entity.missile_level, player_entity.exp)

        # send the highest score to client
        self.addToSingleMsgQueue(
            player_entity.client_id,
            MsgHandler.genServerMsgFromDict(
                conf.SERVER_HIGHEST_SCORE,
                {constants.HIGHEST_SCORE: history_score}))
Esempio n. 9
0
    def startGameLevel(self, level):
        if level < 0:
            level = 0
        if level > len(constants.LEVELS) - 1:
            level = len(constants.LEVELS) - 1

        wait_time = conf.LEVEL_WAIT_TIME

        for monster_type in constants.LEVELS[level]:
            TimerManager.addTimer(wait_time,
                                  self.createMonsterEntity,
                                  monster_type=monster_type)

            wait_time += conf.MONSTER_GEN_INTERVAL

        TimerManager.addTimer(wait_time - conf.MONSTER_GEN_INTERVAL,
                              self.changeDuringGameLevel)

        # send to clients level time
        self.addToBroadcastMsgQueue(
            MsgHandler.genServerMsgFromDict(
                conf.SERVER_NEXT_LEVEL_TIME,
                {constants.NEXT_LEVEL_TIME: conf.LEVEL_WAIT_TIME}))
Esempio n. 10
0
 def genMonsterLocationMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_SYNC_MONSTER,
         {constants.MONSTER_ENTITY: self.getDict()}
     )
Esempio n. 11
0
 def genMonsterCreateMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_CREATE_MONSTER,
         {constants.MONSTER_ENTITY: self.getDict()}
     )
Esempio n. 12
0
 def genServerKillMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_KILL_MONSTER,
         {constants.MONSTER_ID: self.entity_id}
     )
Esempio n. 13
0
 def genAllServerEntitiesMsg(self):
     return MsgHandler.genServerMsgFromDict(conf.SERVER_ALL_ENTITIES,
                                            self.getAllEntityDict())
Esempio n. 14
0
 def genOtherPlayerShootMsg(self, shoot_point_dict):
     player_shoot_dict = {
         constants.PLAYER_ID: self.entity_id,
         constants.SHOOT_POINT: shoot_point_dict
     }
     return MsgHandler.genServerMsgFromDict(conf.SERVER_SYNC_OTHER_PLAYER_SHOOT, player_shoot_dict)
Esempio n. 15
0
 def genPlayerDisconnectMsg(self):
     player_disconnect_dict = {
         constants.PLAYER_ID: self.entity_id
     }
     return MsgHandler.genServerMsgFromDict(conf.SERVER_PLAYER_DISCONNECT, player_disconnect_dict)
Esempio n. 16
0
 def genPlayerKillMsg(monster_id):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_KILL_MONSTER,
         {constants.MONSTER_ID: monster_id}
     )
Esempio n. 17
0
 def genMissileCreateMsg(self):
     return MsgHandler.genServerMsgFromDict(
         conf.SERVER_CREATE_MISSILE,
         {constants.MISSILE_ENTITY: self.getDict()}
     )
Esempio n. 18
0
    def genTrapCreateMsg(self):

        return MsgHandler.genServerMsgFromDict(
            conf.SERVER_CREATE_TRAP, {constants.TRAP_ENTITY: self.getDict()})
Esempio n. 19
0
 def genPlayerDieMsg(self):
     msg_dict = {
         constants.PLAYER_ID: self.entity_id
     }
     return MsgHandler.genServerMsgFromDict(conf.SERVER_PLAYER_DIE, msg_dict)