def playing_slaughter_house_on_timer_boss(id): playing = slaughter_house_types.PlayingManager.get(id) if playing == None: proxy.Logging.error("[slaughter_house] PlayingManager.get(%d) failed." % id) return None 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.boss_time_ = True 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 rand_int = random.randint(0, len(playing_config.pos_) - 1) pos = playing_config.pos_[rand_int] facade_request.summon_npcs(playing.get_scene(), monster_group.boss_id_, monster_group.boss_num_,\ playing_config.boss_pos_[0], playing_config.boss_pos_[1])
def summon_award_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 if playing.boss_time_ == False: return None 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 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 facade_request.summon_npcs(playing.get_scene(), monster_group.award_monster1_id_,\ monster_group.award_monster1_num_, playing_config.award_pos_[0],\ playing_config.award_pos_[1], playing_config.award_pos_range_, playing_config.award_pos_range_) facade_request.summon_npcs(playing.get_scene(), monster_group.award_monster2_id_,\ monster_group.award_monster2_num_, playing_config.award_pos_[0],\ playing_config.award_pos_[1], playing_config.award_pos_range_, playing_config.award_pos_range_)
def playing_slaughter_house_on_timer_boss(id): playing = slaughter_house_types.PlayingManager.get(id) if playing == None: proxy.Logging.error( "[slaughter_house] PlayingManager.get(%d) failed." % id) return None 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.boss_time_ = True 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 rand_int = random.randint(0, len(playing_config.pos_) - 1) pos = playing_config.pos_[rand_int] facade_request.summon_npcs(playing.get_scene(), monster_group.boss_id_, monster_group.boss_num_,\ playing_config.boss_pos_[0], playing_config.boss_pos_[1])
def summon_award_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 if playing.boss_time_ == False: return None 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 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 facade_request.summon_npcs(playing.get_scene(), monster_group.award_monster1_id_,\ monster_group.award_monster1_num_, playing_config.award_pos_[0],\ playing_config.award_pos_[1], playing_config.award_pos_range_, playing_config.award_pos_range_) facade_request.summon_npcs(playing.get_scene(), monster_group.award_monster2_id_,\ monster_group.award_monster2_num_, playing_config.award_pos_[0],\ playing_config.award_pos_[1], playing_config.award_pos_range_, playing_config.award_pos_range_)
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_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 end_playing(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 facade_request.clear_scene_npcs(playing.get_scene(), 0, True) proxy.Timer.remove(playing_id, "playing_slaughter_house_on_timer_next_group") ranking = 1 for actor_rank in playing.ranking_.get_ranking(): actor = playing.get_actor(actor_rank.id_) if actor != None and actor.leaving_ == False: request = ccrequest.playing.ttypes.RequestPlayingActorComplete() request.playing_ = playing_id request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(\ ccentity.resource.ttypes.ResourceType.MIN, 0, 0) request.actor_ = actor_rank.id_ result = ccentity.playing.ttypes.PlayingResultField() result.award_count_ = 1 result.paid_award_count_ = 0 result.awarded_ = False # TODO: values_[0]中放入玩家名次 result.values_ = [] result.values_.append(ranking) ranking += 1 request.awards_ = [] request.result_ = result proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_ACTOR_COMPLETE,\ request) # 副本完成 request = ccrequest.playing.ttypes.RequestPlayingComplete() request.playing_ = playing_id result = ccentity.playing.ttypes.PlayingResultField() result.values_ = [] result.award_count_ = 1 result.paid_award_count_ = 0 result.awarded_ = False request.result_ = result request.awards_ = [] request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(\ ccentity.resource.ttypes.ResourceType.MIN, 0, 0) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE,\ request) proxy.Logging.debug("[slaughter_house] end playing(%d)." % playing_id)
def end_playing(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 facade_request.clear_scene_npcs(playing.get_scene(), 0, True) proxy.Timer.remove(playing_id, "playing_slaughter_house_on_timer_next_group") ranking = 1 for actor_rank in playing.ranking_.get_ranking(): actor = playing.get_actor(actor_rank.id_) if actor != None and actor.leaving_ == False: request = ccrequest.playing.ttypes.RequestPlayingActorComplete() request.playing_ = playing_id request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(\ ccentity.resource.ttypes.ResourceType.MIN, 0, 0) request.actor_ = actor_rank.id_ result = ccentity.playing.ttypes.PlayingResultField() result.award_count_ = 1 result.paid_award_count_ = 0; result.awarded_ = False # TODO: values_[0]中放入玩家名次 result.values_ = [] result.values_.append(ranking); ranking += 1 request.awards_ = [] request.result_ = result proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_ACTOR_COMPLETE,\ request) # 副本完成 request = ccrequest.playing.ttypes.RequestPlayingComplete() request.playing_ = playing_id result = ccentity.playing.ttypes.PlayingResultField() result.values_ = [] result.award_count_ = 1 result.paid_award_count_ = 0; result.awarded_ = False request.result_ = result request.awards_ = [] request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(\ ccentity.resource.ttypes.ResourceType.MIN, 0, 0) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE,\ request) proxy.Logging.debug("[slaughter_house] end playing(%d)." % playing_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_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_idol_on_event_playing_actor_request_complete(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorRequestComplete() # 消息反序列化 TSerialization.deserialize(message, serialize) # 获取副本对象 playing = idol_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("获取 副本对象(%d) 失败" % message.playing_) return None # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("获取 玩家对象(%d) 失败" % message.actor_) return None # 玩家是否完成副本 if actor.get_finish() == 0: log.log_error("玩家(%d) 未成完成idol副本" % message.actor_) return None # 获取副本配置 playing_config = idol_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 消耗玩家副本次数 request = ccrequest.playing.ttypes.RequestPlayingIncreaseComplete() # request.actor_ = message.actor_ # request.playing_template_ = message.template_ request.playing_ = message.playing_ # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INCREASE_COMPLETE, \ request_data, len(request_data)) # 请求完成消息 request = ccrequest.playing.ttypes.RequestPlayingComplete() # request.actor_ = message.actor_ request.playing_ = message.playing_ # 抽奖 actor.draw_award_item(playing_config.get_draw_awards()) request.draw_award_ = actor.get_draw_award_item() # 奖励 request.awards_ = playing_config.get_awards() # 副本耗时 playing_result = ccentity.playing.ttypes.PlayingResultField() playing_result.awarded_ = False playing_result.award_count_ = 1 playing_result.paid_award_count_ = 0; playing_result.values_ = [] # result.value1: 花费时间 playing_result.values_.append(int(time.time() - actor.get_start_time())) # 副本结果 request.result_ = playing_result # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE, \ request_data, len(request_data)) log.log_debug("玩家完成idol副本(%d)" % message.template_) # 请求清除场景中的NPC request_clear_npc = ccrequest.scene.ttypes.RequestSceneClearAllNpc() request_clear_npc.scene_ = playing.get_scene() request_clear_npc.delay_secs_ = 5 # 序列化 request_clear_npc_data = TSerialization.serialize(request_clear_npc) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_CLEAR_ALL_NPC, \ request_clear_npc_data, len(request_clear_npc_data)) log.log_debug("请求清除 场景(%d) npc" % request_clear_npc.scene_);
def playing_plot_on_event_playing_actor_request_complete(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorRequestComplete() # 消息反序列化 TSerialization.deserialize(message, serialize) # 获取副本对象 playing = plot_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("获取 副本对象(%d) 失败" % message.playing_) return None # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("获取 玩家对象(%d) 失败" % message.actor_) return None # 玩家得分(星数) 应该为0 if actor.get_score() != 0: log.log_error("玩家 得分(%d) 错误" % actor.get_score()) return None # 获取副本配置 playing_config = plot_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 获取玩家通关需要杀死的NPC pass_kill_npc = playing_config.get_pass_kill_npc() if actor.get_kill_npc(pass_kill_npc) <= 0: log.log_error("玩家 未能杀死NPC(%d) 不能通关" % pass_kill_npc) return None # 随机抽取一个道具 actor.draw_award_item(playing_config.get_draw_items()) # 统计副本花费时间 spend_time = time.time() - actor.get_start_time() # 请求消息 request = ccrequest.playing.ttypes.RequestPlayingComplete() # 玩家星数加1 actor.inc_score(1); # 死亡次数低于配置次数星数加1 if actor.get_dead_count() <= playing_config.get_dead_count(): actor.inc_score(1) # 花费时间低于配置时间星数加1 if spend_time <= playing_config.get_spend_time(): actor.inc_score(1) # 杀死NPC个数大于配置个数星数加1 if actor.get_kill_npc_num() >= playing_config.get_npc_number(): actor.inc_score(1) # 杀死隐藏NPC星数加1 if actor.get_kill_npc(playing_config.get_hide_npc()): actor.inc_score(1) # request.actor_ = message.actor_ request.playing_ = message.playing_ request.score_ = actor.get_score() request.awards_ = [] award_field = ccentity.playing.ttypes.PlayingAwardField() award_field.type_ = ccentity.resource.ttypes.ResourceType.RESOURCE score = actor.get_score() # 道具 for award in playing_config.get_awards(): if award.type_ == ccentity.resource.ttypes.ResourceType.RESOURCE: award.number_ = award.number_ * score * 20 / 100 request.awards_.append(award) # 抽奖奖励 request.draw_award_ = actor.get_draw_award_item() # 副本耗时, 分数 playing_result = ccentity.playing.ttypes.PlayingResultField() playing_result.awarded_ = False playing_result.award_count_ = 1 playing_result.paid_award_count_ = 0; playing_result.values_ = [] # result.value1: 花费时间 playing_result.values_.append(int(spend_time)) # result.value2: 分数 playing_result.values_.append(score) log.log_debug("[plot] spend_time=%d" % spend_time) # 副本结果 request.result_ = playing_result # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE,\ request_data, len(request_data)) # 请求清除场景中的NPC request_clear_npc = ccrequest.scene.ttypes.RequestSceneClearAllNpc() request_clear_npc.scene_ = playing.get_scene() request_clear_npc.delay_secs_ = 5 # 序列化 request_clear_npc_data = TSerialization.serialize(request_clear_npc) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_CLEAR_ALL_NPC, \ request_clear_npc_data, len(request_clear_npc_data)) log.log_debug("请求清除 场景(%d) npc" % request_clear_npc.scene_)
def playing_plot_on_event_playing_actor_request_complete( message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorRequestComplete() # 消息反序列化 TSerialization.deserialize(message, serialize) # 获取副本对象 playing = plot_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("获取 副本对象(%d) 失败" % message.playing_) return None # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("获取 玩家对象(%d) 失败" % message.actor_) return None # 玩家得分(星数) 应该为0 if actor.get_score() != 0: log.log_error("玩家 得分(%d) 错误" % actor.get_score()) return None # 获取副本配置 playing_config = plot_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 获取玩家通关需要杀死的NPC pass_kill_npc = playing_config.get_pass_kill_npc() if actor.get_kill_npc(pass_kill_npc) <= 0: log.log_error("玩家 未能杀死NPC(%d) 不能通关" % pass_kill_npc) return None # 随机抽取一个道具 actor.draw_award_item(playing_config.get_draw_items()) # 统计副本花费时间 spend_time = time.time() - actor.get_start_time() # 请求消息 request = ccrequest.playing.ttypes.RequestPlayingComplete() # 玩家星数加1 actor.inc_score(1) # 死亡次数低于配置次数星数加1 if actor.get_dead_count() <= playing_config.get_dead_count(): actor.inc_score(1) # 花费时间低于配置时间星数加1 if spend_time <= playing_config.get_spend_time(): actor.inc_score(1) # 杀死NPC个数大于配置个数星数加1 if actor.get_kill_npc_num() >= playing_config.get_npc_number(): actor.inc_score(1) # 杀死隐藏NPC星数加1 if actor.get_kill_npc(playing_config.get_hide_npc()): actor.inc_score(1) # request.actor_ = message.actor_ request.playing_ = message.playing_ request.score_ = actor.get_score() request.awards_ = [] award_field = ccentity.playing.ttypes.PlayingAwardField() award_field.type_ = ccentity.resource.ttypes.ResourceType.RESOURCE score = actor.get_score() # 道具 for award in playing_config.get_awards(): if award.type_ == ccentity.resource.ttypes.ResourceType.RESOURCE: award.number_ = award.number_ * score * 20 / 100 request.awards_.append(award) # 抽奖奖励 request.draw_award_ = actor.get_draw_award_item() # 副本耗时, 分数 playing_result = ccentity.playing.ttypes.PlayingResultField() playing_result.awarded_ = False playing_result.award_count_ = 1 playing_result.paid_award_count_ = 0 playing_result.values_ = [] # result.value1: 花费时间 playing_result.values_.append(int(spend_time)) # result.value2: 分数 playing_result.values_.append(score) log.log_debug("[plot] spend_time=%d" % spend_time) # 副本结果 request.result_ = playing_result # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE,\ request_data, len(request_data)) # 请求清除场景中的NPC request_clear_npc = ccrequest.scene.ttypes.RequestSceneClearAllNpc() request_clear_npc.scene_ = playing.get_scene() request_clear_npc.delay_secs_ = 5 # 序列化 request_clear_npc_data = TSerialization.serialize(request_clear_npc) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_CLEAR_ALL_NPC, \ request_clear_npc_data, len(request_clear_npc_data)) log.log_debug("请求清除 场景(%d) npc" % request_clear_npc.scene_)
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_team_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = team_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: proxy.Logging.error("[team] PlayingManager.get_actor_playing(%d) failed" % message.actor_) return None playing = team_types.PlayingManager.get(playing_id) if playing == None: proxy.Logging.error("[team] PlayingManager.get(%d) failed" % playing_id) return None playing_config = team_types.Config.get(playing.get_template()) if playing_config == None: proxy.Logging.error("[team] team_types.Config.get(%d) failed." % playing.get_template()) return None playing_cell = playing_types.Config.get(playing.get_template()) if playing_cell == None: proxy.Logging.debug("[team] playing_types.Config.get(%d) failed." % playing.get_template()) return None actor = playing.get_actor(message.actor_) if actor == None: proxy.Logging.error("[team] playing.get_actor(%d) failed" % message.actor_) return None playing.inc_kill_npc(message.npc_template_) actors = playing.get_actors() if actors == None: proxy.Logging.error("[team] playing.get_actors() failed") return None if playing_config.summon_next_npc(playing.get_scene(), playing.get_next_pos()) == False: playing_team_sync_ranking(playing_id) request = ccrequest.playing.ttypes.RequestPlayingComplete() request.playing_ = playing_id result = ccentity.playing.ttypes.PlayingResultField() result.values_ = [] result.award_count_ = 1 result.paid_award_count_ = 0; result.awarded_ = False # result.value1: 花费时间 request.result_ = result request.awards_ = [] for award in playing_cell.awards_: request.awards_.append(award) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE,\ request) # 设置副本已完成 playing.set_complete() # 取消定时器 proxy.Timer.remove(playing_id, "playing_team_on_timer_playing") proxy.Timer.remove(playing_id, "playing_team_on_timer_sync_ranking") # 同步一次排行 proxy.Logging.debug("[team] complete playing") # 同步得分 for (k,v) in actors.items(): request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() request.actor_ = k # 分数对象(得分类型=杀死NPC, key=NPC模板ID, value=当前杀死的个数) score_field = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC,\ message.npc_template_, playing.get_kill_npc(message.npc_template_)) request.score_ = score_field # 发送请求 proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE,\ request) if playing.get_complete() == True: award_actor = playing.get_actor(k) if award_actor == None: proxy.Logging.debug("[team] playing.get_actor(%d) failed." % k) return None # 不在副本内不给奖励 if award_actor.get_leave() == False: # 直接给奖励 request_award = ccrequest.playing.ttypes.RequestPlayingAwardActor() request_award.actor_ = k request_award.playing_template_ = playing.get_template() request_award.awards_ = [] for award in playing_cell.awards_: request_award.awards_.append(award) proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_AWARD_ACTOR, request_award) proxy.Logging.debug("[team] add_award award") playing.next_pos() proxy.Logging.debug("[team] actor(%d) kill npc(%d)" % (message.actor_, message.npc_template_))
def playing_idol_on_event_playing_actor_request_complete( message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorRequestComplete() # 消息反序列化 TSerialization.deserialize(message, serialize) # 获取副本对象 playing = idol_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("获取 副本对象(%d) 失败" % message.playing_) return None # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("获取 玩家对象(%d) 失败" % message.actor_) return None # 玩家是否完成副本 if actor.get_finish() == 0: log.log_error("玩家(%d) 未成完成idol副本" % message.actor_) return None # 获取副本配置 playing_config = idol_types.Config.get(message.template_) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % message.template_) return None # 消耗玩家副本次数 request = ccrequest.playing.ttypes.RequestPlayingIncreaseComplete() # request.actor_ = message.actor_ # request.playing_template_ = message.template_ request.playing_ = message.playing_ # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INCREASE_COMPLETE, \ request_data, len(request_data)) # 请求完成消息 request = ccrequest.playing.ttypes.RequestPlayingComplete() # request.actor_ = message.actor_ request.playing_ = message.playing_ # 抽奖 actor.draw_award_item(playing_config.get_draw_awards()) request.draw_award_ = actor.get_draw_award_item() # 奖励 request.awards_ = playing_config.get_awards() # 副本耗时 playing_result = ccentity.playing.ttypes.PlayingResultField() playing_result.awarded_ = False playing_result.award_count_ = 1 playing_result.paid_award_count_ = 0 playing_result.values_ = [] # result.value1: 花费时间 playing_result.values_.append(int(time.time() - actor.get_start_time())) # 副本结果 request.result_ = playing_result # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_COMPLETE, \ request_data, len(request_data)) log.log_debug("玩家完成idol副本(%d)" % message.template_) # 请求清除场景中的NPC request_clear_npc = ccrequest.scene.ttypes.RequestSceneClearAllNpc() request_clear_npc.scene_ = playing.get_scene() request_clear_npc.delay_secs_ = 5 # 序列化 request_clear_npc_data = TSerialization.serialize(request_clear_npc) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_CLEAR_ALL_NPC, \ request_clear_npc_data, len(request_clear_npc_data)) log.log_debug("请求清除 场景(%d) npc" % request_clear_npc.scene_)