def playing_idol_on_event_playing_create(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingCreate() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家进入/退出副本事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_enter") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_leave") # 创建副本对象并加入管理器中 playing = idol_types.Playing(message.playing_, message.template_, message.scene_) idol_types.PlayingManager.add(playing) # 获取副本配置 playing_config = idol_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 召唤一个BOSS facade_request.summon_npc(message.scene_, playing_config.get_pass_kill_npc(),\ playing_config.get_pass_npc_x(), playing_config.get_pass_npc_y()); log.log_debug("idol副本(id=%d,template=%d) 创建成功" % (message.playing_, message.template_))
def summon_boss(self): if self.boss_summoned_: return cell = Config.get_boss() facade_request.summon_npc(self.scene_, cell.template_id_, cell.x_, cell.y_) self.boss_summoned_ = True # 同步当前阶段 self.synchronize_current_stage()
def summon_next_group(playing_id): playing = slaughter_house_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error( "[slaughter_house] PlayingManager.get(%d) failed." % playing_id) return None playing.boss_time_ = False facade_request.clear_scene_npcs(playing.get_scene(), 0, True) playing_config = slaughter_house_types.Config.get(playing.get_template()) if playing_config == None: proxy.Logging.error("[slaughter_house] slaughter_house_types.Config.get(%d) failed."\ % playing.get_template()) return None playing.group_ += 1 # 同步阶段给所有玩家 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.score_ = ccentity.playing.ttypes.PlayingScoreField( ccentity.playing.ttypes.PlayingScoreType.STAGE, 0, playing.group_) for actor_id in playing.get_actors(): request.actor_ = actor_id proxy.Request.request( ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) proxy.Timer.remove(playing_id, "playing_slaughter_house_on_timer_boss") if playing.group_ == 8: # 最终BOSS rand_int = random.randint(0, len(playing_config.pos_) - 1) pos = playing_config.pos_[rand_int] facade_request.summon_npc(playing.get_scene(), playing_config.last_boss_id_,\ playing_config.boss_pos_[0], playing_config.boss_pos_[1]) elif playing.group_ > 8: end_playing(playing_id) return None else: monster_group = playing_config.monster_groups_[playing.group_ - 1] if monster_group == None: proxy.Logging.error("[slaughter_house] playing_config.monster_groups_[%d] is none."\ % (playing.group_ - 1)) return None # 招出各种普通怪 for pos in playing_config.pos_: facade_request.summon_npcs(playing.get_scene(), monster_group.monster1_id_,\ monster_group.monster1_num_, pos[0], pos[1], 10, 10) facade_request.summon_npcs(playing.get_scene(), monster_group.monster2_id_,\ monster_group.monster2_num_, pos[0], pos[1], 10, 10) proxy.Timer.add(playing_id, boss_interval_sec * 1000, 1, "playing_slaughter_house_on_timer_boss")
def playing_plot_on_event_role_change_hp(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.role.ttypes.EventRoleChangeHp() # 消息反序列化 TSerialization.deserialize(message, serialize) # 主角类型只能是玩家 if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR: return None # 根据玩家ID获取所在副本ID playing_id = plot_types.PlayingManager.get_actor_playing(message.id_) if playing_id == None or playing_id == 0: proxy.Logging.error("plot_types.PlayingManager.get_actor_playing(%d) failed." % message.id_) return None # 获取副本对象 playing = plot_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % playing_id) return None # 获取玩家对象 playing_actor = playing.get_actor(message.id_) if playing_actor == None: proxy.Logging.error("plot_types.PlayingManager.get_actor(%d) failed." % message.id_) return None # 隐藏NPC是否已召唤 if playing_actor.get_hide_npc() > 0: return None # 获得玩家交互对象 actor = proxy.EntityManager.get_actor(message.id_) if actor == None: proxy.Logging.error("proxy.EntityManager.get_actor(%d) failed." % message.id_) return None max_hp = actor.get_attr_role_aoi(ccentity.role.ttypes.RoleAoiFields.MAX_HP) current_hp = actor.get_attr_role_aoi(ccentity.role.ttypes.RoleAoiFields.CURRENT_HP) if current_hp > (max_hp * 20 / 100): return None playing_config = plot_types.Config.get(playing.get_template()) if playing_config == None: proxy.Logging.error("获取 副本配置失败(%d)" % playing.get_template()) return None playing_actor.inc_hide_npc(1) facade_request.summon_npc(playing.get_scene(), playing_config.get_hide_npc(),\ actor.get_pos_x(), actor.get_pos_y(), 5, 5) proxy.Logging.debug("玩家血量改变,触发隐藏BOSS");
def summon_boss(self): if self.boss_summoned_: return cell = Config.get_boss() facade_request.summon_npc(self.scene_, cell.template_id_, cell.x_, cell.y_) self.boss_summoned_ = True # 同步当前阶段 self.synchronize_current_stage()
def summon_next_group(playing_id): playing = slaughter_house_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("[slaughter_house] PlayingManager.get(%d) failed." % playing_id) return None playing.boss_time_ = False facade_request.clear_scene_npcs(playing.get_scene(), 0, True) playing_config = slaughter_house_types.Config.get(playing.get_template()) if playing_config == None: proxy.Logging.error("[slaughter_house] slaughter_house_types.Config.get(%d) failed."\ % playing.get_template()) return None playing.group_ += 1 # 同步阶段给所有玩家 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.score_ = ccentity.playing.ttypes.PlayingScoreField( ccentity.playing.ttypes.PlayingScoreType.STAGE, 0, playing.group_) for actor_id in playing.get_actors(): request.actor_ = actor_id proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) proxy.Timer.remove(playing_id, "playing_slaughter_house_on_timer_boss") if playing.group_ == 8: # 最终BOSS rand_int = random.randint(0, len(playing_config.pos_) - 1) pos = playing_config.pos_[rand_int] facade_request.summon_npc(playing.get_scene(), playing_config.last_boss_id_,\ playing_config.boss_pos_[0], playing_config.boss_pos_[1]) elif playing.group_ > 8: end_playing(playing_id) return None else: monster_group = playing_config.monster_groups_[playing.group_ - 1] if monster_group == None: proxy.Logging.error("[slaughter_house] playing_config.monster_groups_[%d] is none."\ % (playing.group_ - 1)) return None # 招出各种普通怪 for pos in playing_config.pos_: facade_request.summon_npcs(playing.get_scene(), monster_group.monster1_id_,\ monster_group.monster1_num_, pos[0], pos[1], 10, 10) facade_request.summon_npcs(playing.get_scene(), monster_group.monster2_id_,\ monster_group.monster2_num_, pos[0], pos[1], 10, 10) proxy.Timer.add(playing_id, boss_interval_sec * 1000, 1, "playing_slaughter_house_on_timer_boss")
def summon_boss(self): if self.boss_npc_id_ != 0: return cell = self.config_.get_boss() self.boss_npc_id_ = facade_request.summon_npc(self.scene_, cell.template_id_, cell.x_, cell.y_)
def summon_next_wave(self): if self.current_circle_ < 0: return False if self.is_end_wave(): return False self.current_wave_ += 1 # 刷新怪物 cell = Config.get_circle(self.circle_seq_[self.current_circle_]) for i in range(cell.monster_number_): facade_request.summon_npc(self.scene_, cell.monster_template_id_, cell.x_, cell.y_, cell.width_, cell.height_) self.required_kill_npc_number_ += cell.monster_number_ return True
def transfer_unreal_soul(self): if self.current_unreal_soul_id_ != 0: facade_request.remove_npc(self.current_unreal_soul_id_) self.current_unreal_soul_id_ = facade_request.summon_npc( self.scene_, self.unreal_monster_order_[self.current_unreal_wave_] * 10 + 1, Config.UNREAL_SOUL_X_, Config.UNREAL_SOUL_Y_)
def initialize(self, id, template, scene): self.id_ = id self.template_ = template self.scene_ = scene self.start_time_ = 0 self.actors_ = {} self.monsters_ = {} self.monster_numbers_ = {} self.unreal_monster_order_ = [] self.current_unreal_wave_ = -1 self.current_unreal_soul_id_ = 0 self.draw_award_ = None self.kill_wrong_num_ = 0 self.kill_right_num_ = 0 self.boss_stage_ = False for monster_cell in Config.MONSTERS_: self.unreal_monster_order_.append(monster_cell.template_) self.monster_numbers_[monster_cell.template_] = 0 for pos in range(0, monster_cell.number_): monster_id = facade_request.summon_npc(scene, monster_cell.template_, monster_cell.x_, monster_cell.y_, monster_cell.width_, monster_cell.height_) if monster_id != 0: monster = Monster(monster_id, monster_cell.template_) self.monsters_[monster.id_] = monster self.monster_numbers_[monster.template_] += 1 PlayingManager.add_monster(monster.id_, self.id_) proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_ENTER_FIGHTING_STATUS, monster.id_, ccevent.ttypes.ChannelType.CHANNEL_NPC, "playing_unreal_soul_on_event_role_enter_fighting_status") proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_LEAVE_FIGHTING_STATUS, monster.id_, ccevent.ttypes.ChannelType.CHANNEL_NPC, "playing_unreal_soul_on_event_role_leave_fighting_status") random.shuffle(self.unreal_monster_order_)
def summon_rune(self): if self.current_circle_ < 0: return cell = Config.get_circle(self.circle_seq_[self.current_circle_]) npc_id = facade_request.summon_npc(self.scene_, cell.rune_template_id_, cell.x_, cell.y_) self.runes_[npc_id] = time.time() + Config.get_rune_exist_time()
def summon_rune(self): if self.current_circle_ < 0: return cell = Config.get_circle(self.circle_seq_[self.current_circle_]) npc_id = facade_request.summon_npc(self.scene_, cell.rune_template_id_, cell.x_, cell.y_) self.runes_[npc_id] = time.time() + Config.get_rune_exist_time()
def summon_next_wave(self): if self.current_circle_ < 0: return False if self.is_end_wave(): return False self.current_wave_ += 1 # 刷新怪物 cell = Config.get_circle(self.circle_seq_[self.current_circle_]) for i in range(cell.monster_number_): facade_request.summon_npc(self.scene_, cell.monster_template_id_, cell.x_, cell.y_, cell.width_, cell.height_) self.required_kill_npc_number_ += cell.monster_number_ return True
def playing_slime_on_timer_slime(id): # 获取副本对象 playing = slime_types.PlayingManager.get(id) if playing == None: proxy.Logging.error("[slime] PlayingManager.get(%d) failed" % id) return None chessboard = playing.get_chessboard() if chessboard == None: proxy.Logging.error("[slime] playing.get_chessboard() failed") return None chessboard.erase_all() x, y = slime_types.Config.get_boss_position() facade_request.summon_npc(playing.get_scene(), slime_types.Config.get_boss(), x, y) proxy.Timer.add(id, slime_types.Config.get_boss_time() * 1000, 1, "playing_slime_on_timer_boss") # 设置为Boss阶段 playing.set_section_boss() playing.set_boss_summon_time(time.time()) proxy.Logging.debug("[slime] actor(%d) slime time expired." % playing.get_actor())
def refresh_by_pos(self, x, y): if x < 0 or x >= Chessboard.WIDTH: return False if y < 0 or y >= Chessboard.HEIGHT: return False template = Config.random_get() id = facade_request.summon_npc(self.playing_.get_scene(),\ template, x*5+16, y*7+17, 0, 0, 0, ccentity.direction.ttypes.DirectionType.SOUTH) self.board_[x][y].set_template(template) self.board_[x][y].set_id(id) proxy.Logging.debug("[slime] summon npc(%d, %d)" % (template, id))
def refresh_all(self): proxy.Logging.debug("[slime] refresh_all") for x in range(Chessboard.WIDTH): for y in range(Chessboard.HEIGHT): if self.board_[x][y].get_id() == 0: template = Config.random_get() id = facade_request.summon_npc(self.playing_.get_scene(),\ template, x*5+16, y*7+17, 0, 0, 0, ccentity.direction.ttypes.DirectionType.SOUTH) self.board_[x][y].set_template(template) self.board_[x][y].set_id(id) proxy.Logging.debug("[slime] summon npc(%d, %d)" % (template, id))
def playing_slime_on_timer_slime(id): # 获取副本对象 playing = slime_types.PlayingManager.get(id) if playing == None: proxy.Logging.error("[slime] PlayingManager.get(%d) failed" % id) return None chessboard = playing.get_chessboard() if chessboard == None: proxy.Logging.error("[slime] playing.get_chessboard() failed") return None chessboard.erase_all() x, y = slime_types.Config.get_boss_position() facade_request.summon_npc(playing.get_scene(), slime_types.Config.get_boss(), x, y) proxy.Timer.add(id, slime_types.Config.get_boss_time() * 1000, 1, "playing_slime_on_timer_boss") # 设置为Boss阶段 playing.set_section_boss() playing.set_boss_summon_time(time.time()) proxy.Logging.debug("[slime] actor(%d) slime time expired." % playing.get_actor())
def playing_idol_on_event_playing_create(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingCreate() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家进入/退出副本事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_enter") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_leave") # 创建副本对象并加入管理器中 playing = idol_types.Playing(message.playing_, message.template_, message.scene_) idol_types.PlayingManager.add(playing) # 获取副本配置 playing_config = idol_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 召唤一个BOSS facade_request.summon_npc(message.scene_, playing_config.get_pass_kill_npc(),\ playing_config.get_pass_npc_x(), playing_config.get_pass_npc_y()) log.log_debug("idol副本(id=%d,template=%d) 创建成功" % (message.playing_, message.template_))
def initialize(self, id, template, scene): self.id_ = id self.template_ = template self.scene_ = scene self.start_time_ = 0 self.actors_ = {} self.monsters_ = {} self.monster_numbers_ = {} self.unreal_monster_order_ = [] self.current_unreal_wave_ = -1 self.current_unreal_soul_id_ = 0 self.draw_award_ = None self.kill_wrong_num_ = 0 self.kill_right_num_ = 0 self.boss_stage_ = False for monster_cell in Config.MONSTERS_: self.unreal_monster_order_.append(monster_cell.template_) self.monster_numbers_[monster_cell.template_] = 0 for pos in range(0, monster_cell.number_): monster_id = facade_request.summon_npc( scene, monster_cell.template_, monster_cell.x_, monster_cell.y_, monster_cell.width_, monster_cell.height_) if monster_id != 0: monster = Monster(monster_id, monster_cell.template_) self.monsters_[monster.id_] = monster self.monster_numbers_[monster.template_] += 1 PlayingManager.add_monster(monster.id_, self.id_) proxy.Communicator.follow( ccevent.ttypes.EventType. EVENT_ROLE_ENTER_FIGHTING_STATUS, monster.id_, ccevent.ttypes.ChannelType.CHANNEL_NPC, "playing_unreal_soul_on_event_role_enter_fighting_status" ) proxy.Communicator.follow( ccevent.ttypes.EventType. EVENT_ROLE_LEAVE_FIGHTING_STATUS, monster.id_, ccevent.ttypes.ChannelType.CHANNEL_NPC, "playing_unreal_soul_on_event_role_leave_fighting_status" ) random.shuffle(self.unreal_monster_order_)
def summon_next_npc(self, scene, pos): if pos >= len(self.npcs_pos_): return False npc_info = self.npcs_pos_[pos] facade_request.summon_npc(scene, npc_info[0], npc_info[1], npc_info[2]) return True
def summon_boss(self): if self.boss_stage_ == False: facade_request.summon_npc(self.scene_, Config.BOSS_.template_, Config.BOSS_.x_, Config.BOSS_.y_) self.boss_stage_ = True
def summon_boss(self): if self.boss_stage_ == False: facade_request.summon_npc(self.scene_, Config.BOSS_.template_, Config.BOSS_.x_, Config.BOSS_.y_) self.boss_stage_ = True
def transfer_unreal_soul(self): if self.current_unreal_soul_id_ != 0: facade_request.remove_npc(self.current_unreal_soul_id_) self.current_unreal_soul_id_ = facade_request.summon_npc(self.scene_, self.unreal_monster_order_[self.current_unreal_wave_] * 10 + 1, Config.UNREAL_SOUL_X_, Config.UNREAL_SOUL_Y_)
def playing_slime_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = slime_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: proxy.Logging.error("[slime] PlayingManager.get_actor_playing(%d) failed" % message.actor_) return None # 获取副本对象 playing = slime_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("[slime] PlayingManager.get(%d) failed" % playing_id) return None if message.npc_template_ != slime_types.Config.get_boss(): # 获取副本棋盘 chessboard = playing.get_chessboard() if chessboard == None: proxy.Logging.error("[slime] playing.get_chessboard() failed") return None # 获取当前NPC的坐标 x, y = chessboard.get_pos(message.npc_) if x < 0 or y < 0: proxy.Logging.error("[slime] chessboard.get_pos(%d) failed" % message.npc_) return None # 删除当前NPC if chessboard.erase_by_pos(x, y) == False: proxy.Logging.error("[slime] chessboard.erase_by_pos(%d, %d) failed" % (x, y)) return None score = chessboard.erase_associated_by_pos(message.npc_template_, x, y) + 1 # 增加分数 playing.add_score(score) # 通知客户端得分 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC,\ 0, playing.get_score()) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) # 增加消耗的体力值 playing.add_spend_power(1); # 同步体力值 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.POWER,\ 0, slime_types.Config.get_max_power() - playing.get_spend_power()) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) # 计算经验 exp = 0 if score >= slime_types.Config.get_multi_kill_num(): exp = score * slime_types.Config.get_multi_kill_exp() else: exp = score * slime_types.Config.get_kill_exp() playing.add_exp(exp) # 获取玩家对象 actor = proxy.EntityManager.get_actor(message.actor_) if actor == None: proxy.Logging.error("[slime] get actor(%d) failed" % message.actor_) return None # 增加资源 actor.add_resource(ccentity.resource.ttypes.ResourceID.EXP, exp) # 通知客户端经验增加 request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.EXP,\ 0, playing.get_exp()) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) if playing.get_spend_power() == slime_types.Config.get_max_power(): # 删除所有水晶NPC chessboard.erase_all() x, y = slime_types.Config.get_boss_position() facade_request.summon_npc(playing.get_scene(), slime_types.Config.get_boss(), x, y) proxy.Timer.add(playing_id, slime_types.Config.get_boss_time() * 1000, 1, "playing_slime_on_timer_boss") # 设置为Boss阶段 playing.set_section_boss() playing.set_boss_summon_time(time.time()) else: # 刷新当前NPC # refresh_by_pos(x, y) chessboard.refresh_all() else: playing.set_kill_boss() # 通知客户端得分 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC,\ message.npc_template_, 1) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) proxy.Timer.remove(playing_id, "playing_slime_on_timer_boss") proxy.Logging.debug("[slime] actor kill boss") proxy.Logging.debug("[slime] actor(%d) kill npc, score=%d" % (message.actor_, playing.get_score()))
def playing_plot_on_event_role_change_hp(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.role.ttypes.EventRoleChangeHp() # 消息反序列化 TSerialization.deserialize(message, serialize) # 主角类型只能是玩家 if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR: return None # 根据玩家ID获取所在副本ID playing_id = plot_types.PlayingManager.get_actor_playing(message.id_) if playing_id == None or playing_id == 0: proxy.Logging.error( "plot_types.PlayingManager.get_actor_playing(%d) failed." % message.id_) return None # 获取副本对象 playing = plot_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % playing_id) return None # 获取玩家对象 playing_actor = playing.get_actor(message.id_) if playing_actor == None: proxy.Logging.error("plot_types.PlayingManager.get_actor(%d) failed." % message.id_) return None # 隐藏NPC是否已召唤 if playing_actor.get_hide_npc() > 0: return None # 获得玩家交互对象 actor = proxy.EntityManager.get_actor(message.id_) if actor == None: proxy.Logging.error("proxy.EntityManager.get_actor(%d) failed." % message.id_) return None max_hp = actor.get_attr_role_aoi(ccentity.role.ttypes.RoleAoiFields.MAX_HP) current_hp = actor.get_attr_role_aoi( ccentity.role.ttypes.RoleAoiFields.CURRENT_HP) if current_hp > (max_hp * 20 / 100): return None playing_config = plot_types.Config.get(playing.get_template()) if playing_config == None: proxy.Logging.error("获取 副本配置失败(%d)" % playing.get_template()) return None playing_actor.inc_hide_npc(1) facade_request.summon_npc(playing.get_scene(), playing_config.get_hide_npc(),\ actor.get_pos_x(), actor.get_pos_y(), 5, 5) proxy.Logging.debug("玩家血量改变,触发隐藏BOSS")
def playing_slime_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = slime_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: proxy.Logging.error( "[slime] PlayingManager.get_actor_playing(%d) failed" % message.actor_) return None # 获取副本对象 playing = slime_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("[slime] PlayingManager.get(%d) failed" % playing_id) return None if message.npc_template_ != slime_types.Config.get_boss(): # 获取副本棋盘 chessboard = playing.get_chessboard() if chessboard == None: proxy.Logging.error("[slime] playing.get_chessboard() failed") return None # 获取当前NPC的坐标 x, y = chessboard.get_pos(message.npc_) if x < 0 or y < 0: proxy.Logging.error("[slime] chessboard.get_pos(%d) failed" % message.npc_) return None # 删除当前NPC if chessboard.erase_by_pos(x, y) == False: proxy.Logging.error( "[slime] chessboard.erase_by_pos(%d, %d) failed" % (x, y)) return None score = chessboard.erase_associated_by_pos(message.npc_template_, x, y) + 1 # 增加分数 playing.add_score(score) # 通知客户端得分 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC,\ 0, playing.get_score()) proxy.Request.request( ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) # 增加消耗的体力值 playing.add_spend_power(1) # 同步体力值 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.POWER,\ 0, slime_types.Config.get_max_power() - playing.get_spend_power()) proxy.Request.request( ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) # 计算经验 exp = 0 if score >= slime_types.Config.get_multi_kill_num(): exp = score * slime_types.Config.get_multi_kill_exp() else: exp = score * slime_types.Config.get_kill_exp() playing.add_exp(exp) # 获取玩家对象 actor = proxy.EntityManager.get_actor(message.actor_) if actor == None: proxy.Logging.error("[slime] get actor(%d) failed" % message.actor_) return None # 增加资源 actor.add_resource(ccentity.resource.ttypes.ResourceID.EXP, exp) # 通知客户端经验增加 request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.EXP,\ 0, playing.get_exp()) proxy.Request.request( ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) if playing.get_spend_power() == slime_types.Config.get_max_power(): # 删除所有水晶NPC chessboard.erase_all() x, y = slime_types.Config.get_boss_position() facade_request.summon_npc(playing.get_scene(), slime_types.Config.get_boss(), x, y) proxy.Timer.add(playing_id, slime_types.Config.get_boss_time() * 1000, 1, "playing_slime_on_timer_boss") # 设置为Boss阶段 playing.set_section_boss() playing.set_boss_summon_time(time.time()) else: # 刷新当前NPC # refresh_by_pos(x, y) chessboard.refresh_all() else: playing.set_kill_boss() # 通知客户端得分 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = message.actor_ request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC,\ message.npc_template_, 1) proxy.Request.request( ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, request) proxy.Timer.remove(playing_id, "playing_slime_on_timer_boss") proxy.Logging.debug("[slime] actor kill boss") proxy.Logging.debug("[slime] actor(%d) kill npc, score=%d" % (message.actor_, playing.get_score()))