def playing_idol_on_event_playing_actor_enter(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorEnter() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家杀死NPC事件、角色被杀死事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_kill_npc") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_killed") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_idol_on_event_playing_actor_request_complete") # 获取副本对象 playing = idol_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("idol副本 获取 playing(%d) 失败" % message.playing_) return None now = time.time() # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: # 玩家不存在时,创建并加入副本管理器中 actor = idol_types.Actor(message.actor_, now) playing.add_actor(actor) # 副本管理器中加入一个玩家ID到副本ID的对应关系 idol_types.PlayingManager.add_actor(message.actor_, message.playing_) # 请求初始化玩家 request = ccrequest.playing.ttypes.RequestPlayingInitializeActor() request.actor_ = message.actor_ request.spend_time_ = now - actor.get_start_time() request.scores_ = [] request.datas_ = [] # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \ request_data, len(request_data)) log.log_debug("玩家(%d) 进入 idol副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def playing_idol_on_event_playing_actor_enter(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorEnter() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家杀死NPC事件、角色被杀死事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_kill_npc") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_killed") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_idol_on_event_playing_actor_request_complete") # 获取副本对象 playing = idol_types.PlayingManager.get(message.playing_) if playing == None: log.log_error("idol副本 获取 playing(%d) 失败" % message.playing_) return None now = time.time() # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: # 玩家不存在时,创建并加入副本管理器中 actor = idol_types.Actor(message.actor_, now) playing.add_actor(actor) # 副本管理器中加入一个玩家ID到副本ID的对应关系 idol_types.PlayingManager.add_actor(message.actor_, message.playing_) # 请求初始化玩家 request = ccrequest.playing.ttypes.RequestPlayingInitializeActor() request.actor_ = message.actor_ request.spend_time_ = now - actor.get_start_time() request.scores_ = [] request.datas_ = [] # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \ request_data, len(request_data)) log.log_debug("玩家(%d) 进入 idol副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def playing_idol_on_event_playing_actor_leave(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorLeave() # 反序列化 TSerialization.deserialize(message, serialize) # 取消关注玩家杀死NPC事件、角色被杀死事件 communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_killed") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_idol_on_event_actor_kill_npc") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_idol_on_event_playing_actor_request_complete") # 副本管理器中删除玩家对象 idol_types.PlayingManager.remove_actor(message.actor_) log.log_debug("玩家(%d) 离开 idol副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def add_award(actor, template): log.log_debug("idol.add_award(%d, %d)" % (actor, template)) request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 获取副本配置 playing_config = idol_types.Config.get(template) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % template) return None # 请求增加副本奖励 request = ccrequest.playing.ttypes.RequestPlayingAddAward() request.actor_ = actor request.playing_template_ = template # 奖励 request.awards_ = playing_config.get_awards() # 抽奖 draw_awards = playing_config.get_draw_awards() draw_awards_size = len(draw_awards) if draw_awards_size > 0: request.draw_award_ = draw_awards[random.randint(0, draw_awards_size - 1)] else: request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(\ ccentity.resource.ttypes.ResourceType.MIN, 0, 0) # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_ADD_AWARD,\ request_data, len(request_data))
def playing_plot_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_plot_on_event_playing_actor_enter") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_plot_on_event_playing_actor_leave") # 创建副本对象并加入管理器中 playing = plot_types.Playing(message.playing_, message.template_, message.scene_) plot_types.PlayingManager.add(playing) log.log_debug("副本(id=%d,template=%d) 创建成功" % (message.playing_, message.template_))
def playing_plot_on_event_playing_actor_leave(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorLeave() # 反序列化 TSerialization.deserialize(message, serialize) # 取消关注玩家杀死NPC事件、请求完成副本事件、角色被杀死事件 communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_killed") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_plot_on_event_playing_actor_request_complete") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_kill_npc") # 副本1需要关注玩家血量改变的事件 if message.template_ == 1: proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_HP, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_role_change_hp") # 副本管理器中删除玩家对象 plot_types.PlayingManager.remove_actor(message.actor_) log.log_debug("玩家(%d)离开副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def initialize(): # 日常副本配置 for i in range(1, 7): playing_config = plot_types.PlayingConfig(i) if playing_config.initialize() == False: proxy.Logging.error("[plot] init PlayingConfig(%d) failed." % i) return False playing_config.set_hide_npc(200106) plot_types.Config.add(playing_config) # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注增加副本奖励事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_REQUEST_ADD_AWARD, 1, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_request_add_award") # 关注副本创建/销毁事件(副本1~6) for pos in range(1, 7): communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_create") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_destory") proxy.Logging.debug("[plot] initialize") return True
def initialize(): for pos in range(7, 15): playing_config = idol_types.PlayingConfig(pos, 60, 10) if playing_config.initialize() == False: proxy.Logging.error("[idol] init PlayingConfig(%d) failed." % pos) return False idol_types.Config.add(playing_config) # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注增加副本奖励事件 communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_REQUEST_ADD_AWARD, 1, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_request_add_award", ) # 关注副本创建/销毁事件(副本7~14) for pos in range(7, 15): communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_create", ) communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_destory", ) proxy.Logging.debug("[idol] initialize")
def add_award(actor, template): log.log_debug("idol.add_award(%d, %d)" % (actor, template)) request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 获取副本配置 playing_config = idol_types.Config.get(template) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % template) return None # 请求增加副本奖励 request = ccrequest.playing.ttypes.RequestPlayingAddAward() request.actor_ = actor request.playing_template_ = template # 奖励 request.awards_ = playing_config.get_awards() # 抽奖 draw_awards = playing_config.get_draw_awards() draw_awards_size = len(draw_awards) if draw_awards_size > 0: request.draw_award_ = draw_awards[random.randint(0, draw_awards_size - 1)] else: request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(ccentity.resource.ttypes.ResourceType.MIN, 0, 0) # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_ADD_AWARD, request_data, len(request_data))
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 test_initialize(): variable_table.initialize() #__main__.CC_COMMUNICATOR_PROXY.follow(ccevent.ttypes.EventType.EVENT_ACTOR_LOGIN, 0, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, "test_on_actor_login") communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_LOGIN, 0, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, "test_on_actor_login")
def playing_idol_on_event_actor_killed(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.role.ttypes.EventRoleKilled() # 消息反序列化 TSerialization.deserialize(message, serialize) # 主角类型只能是玩家 if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR: return None # 根据玩家ID获取所在副本ID playing_id = idol_types.PlayingManager.get_actor_playing(message.id_) if playing_id == None or playing_id == 0: return None # 获取副本对象 playing = idol_types.PlayingManager.get(playing_id) if playing == None: return None # 获取玩家对象 actor = playing.get_actor(message.id_) if actor == None: return None # 玩家死亡次数增加 actor.inc_dead_count() log.log_debug("idol副本 玩家(%d) 死亡次数(%d)" % (message.id_, actor.get_dead_count())) # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 先复活玩家 request = ccrequest.scene.ttypes.RequestSceneRevive() request.actor_ = message.id_ request.stay_revive_ = True # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \ request_data, len(request_data)) # 请求失败消息 request = ccrequest.playing.ttypes.RequestPlayingFailure() request.playing_ = playing_id # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, \ request_data, len(request_data)) log.log_debug("idol副本 玩家(%d) 失败" % message.id_)
def playing_idol_on_event_actor_killed(message_type, channel, channel_type, serialize): # 事件消息 message = ccevent.role.ttypes.EventRoleKilled() # 消息反序列化 TSerialization.deserialize(message, serialize) # 主角类型只能是玩家 if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR: return None # 根据玩家ID获取所在副本ID playing_id = idol_types.PlayingManager.get_actor_playing(message.id_) if playing_id == None or playing_id == 0: return None # 获取副本对象 playing = idol_types.PlayingManager.get(playing_id) if playing == None: return None # 获取玩家对象 actor = playing.get_actor(message.id_) if actor == None: return None # 玩家死亡次数增加 actor.inc_dead_count() log.log_debug("idol副本 玩家(%d) 死亡次数(%d)" % (message.id_, actor.get_dead_count())) # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 先复活玩家 request = ccrequest.scene.ttypes.RequestSceneRevive() request.actor_ = message.id_ request.stay_revive_ = True # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \ request_data, len(request_data)) # 请求失败消息 request = ccrequest.playing.ttypes.RequestPlayingFailure() request.playing_ = playing_id # 序列化 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, \ request_data, len(request_data)) log.log_debug("idol副本 玩家(%d) 失败" % message.id_)
def finalize(): communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注副本创建/销毁事件(副本7~14) for pos in range(7, 15): communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_create") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_destory") proxy.Logging.debug("[idol] finalize")
def playing_idol_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = idol_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: return None # 获取副本对象 playing = idol_types.PlayingManager.get(playing_id) if playing == None: return None # 获取副本配置 playing_config = idol_types.Config.get(playing.get_template_id()) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % playing.get_template_id()) return None # 获取玩家通关需要杀死的NPC pass_kill_npc = playing_config.get_pass_kill_npc() if message.npc_template_ != pass_kill_npc: log.log_error("玩家(%d) 杀死npc(%d) 不是通关npc(%d)" % \ (message.actor_, message.npc_template_, pass_kill_npc)) return None # 获取副本玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("idol副本 获取actor(%d) 失败" % message.actor_) return None if actor.get_finish() == 0 and actor.get_dead_count() <= 0: actor.set_finish() # 请求同步玩家得分 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) # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, \ request_data, len(request_data))
def playing_plot_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = plot_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: proxy.Logging.error( "plot_types.PlayingManager.get_actor_playing(%d) failed." % message.actor_) 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 # 获取副本玩家对象 actor = playing.get_actor(message.actor_) if actor == None: proxy.Logging.error("playing.get_actor(%d) failed." % message.actor_) return None # 增加杀死NPC个数 actor.inc_kill_npc(message.npc_template_) # 请求消息 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() # 玩家ID request.actor_ = message.actor_ # 分数对象(得分类型=杀死NPC, key=NPC模板ID, value=当前杀死的个数) score_field = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC, \ message.npc_template_, actor.get_kill_npc(message.npc_template_)) request.score_ = score_field # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, \ request_data, len(request_data)) log.log_debug("玩家(%d) 杀死 NPC(%d) 个数(%d)" % (message.actor_, score_field.key_, \ score_field.value_))
def playing_idol_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = idol_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: return None # 获取副本对象 playing = idol_types.PlayingManager.get(playing_id) if playing == None: return None # 获取副本配置 playing_config = idol_types.Config.get(playing.get_template_id()) if playing_config == None: log.log_error("获取 副本配置失败(%d)" % playing.get_template_id()) return None # 获取玩家通关需要杀死的NPC pass_kill_npc = playing_config.get_pass_kill_npc() if message.npc_template_ != pass_kill_npc: log.log_error("玩家(%d) 杀死npc(%d) 不是通关npc(%d)" % \ (message.actor_, message.npc_template_, pass_kill_npc)) return None # 获取副本玩家对象 actor = playing.get_actor(message.actor_) if actor == None: log.log_error("idol副本 获取actor(%d) 失败" % message.actor_) return None if actor.get_finish() == 0 and actor.get_dead_count() <= 0: actor.set_finish() # 请求同步玩家得分 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) # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, \ request_data, len(request_data))
def playing_plot_on_event_actor_kill_npc(message_type, channel, channel_type, serialize): # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.actor.ttypes.EventActorKillNpc() # 反序列化 TSerialization.deserialize(message, serialize) # 获取玩家所在副本ID playing_id = plot_types.PlayingManager.get_actor_playing(message.actor_) if playing_id == None or playing_id == 0: proxy.Logging.error("plot_types.PlayingManager.get_actor_playing(%d) failed." % message.actor_) 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 # 获取副本玩家对象 actor = playing.get_actor(message.actor_) if actor == None: proxy.Logging.error("playing.get_actor(%d) failed." % message.actor_) return None # 增加杀死NPC个数 actor.inc_kill_npc(message.npc_template_) # 请求消息 request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore() # 玩家ID request.actor_ = message.actor_ # 分数对象(得分类型=杀死NPC, key=NPC模板ID, value=当前杀死的个数) score_field = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC, \ message.npc_template_, actor.get_kill_npc(message.npc_template_)) request.score_ = score_field # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, \ request_data, len(request_data)) log.log_debug("玩家(%d) 杀死 NPC(%d) 个数(%d)" % (message.actor_, score_field.key_, \ score_field.value_))
def finalize(): communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注副本创建/销毁事件(副本7~14) for pos in range(7, 15): communicator_proxy.unfollow( ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_create", ) communicator_proxy.unfollow( ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_destory", ) proxy.Logging.debug("[idol] finalize")
def playing_idol_on_event_playing_destory(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingDestory() # 反序列化 TSerialization.deserialize(message, serialize) # 取消关注玩家进入/退出副本 communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_enter") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_idol_on_event_playing_actor_leave") # 从管理器中删除副本对象 idol_types.PlayingManager.remove(message.playing_) log.log_debug("副本(%d) 销毁成功" % message.playing_)
def playing_plot_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_plot_on_event_playing_actor_enter") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_plot_on_event_playing_actor_leave") # 创建副本对象并加入管理器中 playing = plot_types.Playing(message.playing_, message.template_, message.scene_) plot_types.PlayingManager.add(playing) log.log_debug("副本(id=%d,template=%d) 创建成功" % (message.playing_, message.template_))
def initialize(): # 日常副本配置 for i in range(1, 7): playing_config = plot_types.PlayingConfig(i) if playing_config.initialize() == False: proxy.Logging.error("[plot] init PlayingConfig(%d) failed." % i) return False playing_config.set_hide_npc(200106) plot_types.Config.add(playing_config) # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注增加副本奖励事件 communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_REQUEST_ADD_AWARD, 1, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_request_add_award", ) # 关注副本创建/销毁事件(副本1~6) for pos in range(1, 7): communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_create", ) communicator_proxy.follow( ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_plot_on_event_playing_destory", ) proxy.Logging.debug("[plot] initialize") return True
def initialize(): for pos in range(7, 15): playing_config = idol_types.PlayingConfig(pos, 60, 10) if playing_config.initialize() == False: proxy.Logging.error("[idol] init PlayingConfig(%d) failed." % pos) return False idol_types.Config.add(playing_config) # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 关注增加副本奖励事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_REQUEST_ADD_AWARD, 1, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_request_add_award") # 关注副本创建/销毁事件(副本7~14) for pos in range(7, 15): communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_CREATE, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_create") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_DESTORY, pos, \ ccevent.ttypes.ChannelType.CHANNEL_PLAYING, "playing_idol_on_event_playing_destory") proxy.Logging.debug("[idol] initialize")
def playing_plot_on_event_playing_destory(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingDestory() # 反序列化 TSerialization.deserialize(message, serialize) # 取消关注玩家进入/退出副本 communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_plot_on_event_playing_actor_enter") communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \ message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \ "playing_plot_on_event_playing_actor_leave") # 从管理器中删除副本对象 plot_types.PlayingManager.remove(message.playing_) log.log_debug("副本(%d) 销毁成功" % message.playing_)
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(): Communicator.COMMUNICATOR_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)
def initialize(): Request.REQUEST_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)
def log_error(log): log_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.LOG_PROXY) log_proxy.log_info("[Python] %s" % log)
def playing_plot_on_event_playing_actor_enter(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 获取请求代理 request_proxy = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorEnter() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家杀死NPC事件、请求完成副本事件、角色被杀死事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_kill_npc") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_plot_on_event_playing_actor_request_complete") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_killed") # 副本1需要关注玩家血量改变的事件 if message.template_ == 1: proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_HP, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_role_change_hp") # 获取副本对象 playing = plot_types.PlayingManager.get(message.playing_) if playing == None: proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % message.playing_) return None now = time.time() # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: # 玩家不存在时,创建并加入副本中 actor = plot_types.Actor(message.actor_, now) playing.add_actor(actor) # 消耗玩家副本次数 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)) # 副本管理器中加入一个玩家ID到副本ID的对应关系 plot_types.PlayingManager.add_actor(message.actor_, message.playing_) # 请求初始化玩家 request = ccrequest.playing.ttypes.RequestPlayingInitializeActor() request.actor_ = message.actor_ request.spend_time_ = now - actor.get_start_time() request.scores_ = [] request.datas_ = [] # 循环获取玩家杀死的每个NPC for (k, v) in actor.get_kill_npcs().items(): score_field = ccentity.playing.ttypes.PlayingScoreField() score_field.type_ = ccentity.playing.ttypes.PlayingScoreType.KILL_NPC score_field.key_ = k score_field.value_ = v request.scores_.append(score_field) # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \ request_data, len(request_data)) log.log_debug("玩家(%d)进入副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def get_npc(id): if EntityManager.ENTITY_PROXY.get_npc(id) == False: return None return variable_table.get_variable(ccvariable.ttypes.Variable.CURRENT_NPC)
def test_initialize(): variable_table.initialize(); #__main__.CC_COMMUNICATOR_PROXY.follow(ccevent.ttypes.EventType.EVENT_ACTOR_LOGIN, 0, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, "test_on_actor_login") communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_LOGIN, 0, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, "test_on_actor_login")
def playing_plot_on_event_playing_actor_enter(message_type, channel, channel_type, serialize): # 获取事件交互代理 communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY) # 获取请求代理 request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY) # 事件消息 message = ccevent.playing.ttypes.EventPlayingActorEnter() # 反序列化 TSerialization.deserialize(message, serialize) # 关注玩家杀死NPC事件、请求完成副本事件、角色被杀死事件 communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_kill_npc") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\ "playing_plot_on_event_playing_actor_request_complete") communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_actor_killed") # 副本1需要关注玩家血量改变的事件 if message.template_ == 1: proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_HP, \ message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \ "playing_plot_on_event_role_change_hp"); # 获取副本对象 playing = plot_types.PlayingManager.get(message.playing_) if playing == None: proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % message.playing_) return None now = time.time() # 获取玩家对象 actor = playing.get_actor(message.actor_) if actor == None: # 玩家不存在时,创建并加入副本中 actor = plot_types.Actor(message.actor_, now) playing.add_actor(actor) # 消耗玩家副本次数 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)) # 副本管理器中加入一个玩家ID到副本ID的对应关系 plot_types.PlayingManager.add_actor(message.actor_, message.playing_) # 请求初始化玩家 request = ccrequest.playing.ttypes.RequestPlayingInitializeActor() request.actor_ = message.actor_ request.spend_time_ = now - actor.get_start_time() request.scores_ = [] request.datas_ = [] # 循环获取玩家杀死的每个NPC for (k,v) in actor.get_kill_npcs().items(): score_field = ccentity.playing.ttypes.PlayingScoreField() score_field.type_ = ccentity.playing.ttypes.PlayingScoreType.KILL_NPC score_field.key_ = k; score_field.value_ = v; request.scores_.append(score_field); # 序列化消息 request_data = TSerialization.serialize(request) # 发送请求 request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \ request_data, len(request_data)) log.log_debug("玩家(%d)进入副本(id=%d,template=%d)" % \ (message.actor_, message.playing_, message.template_))
def get_npc(id): if EntityManager.ENTITY_PROXY.get_npc(id) == False: return None return variable_table.get_variable( ccvariable.ttypes.Variable.CURRENT_NPC)
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 initialize(): Communicator.COMMUNICATOR_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)
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 initialize(): Function.FUNCTION_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.FUNCTION_PROXY)
def initialize(): Logging.LOG_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.LOG_PROXY)
def initialize(): EntityManager.ENTITY_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.ENTITY_MANAGER)
def initialize(): Logging.LOG_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.LOG_PROXY)
def initialize(): Function.FUNCTION_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.FUNCTION_PROXY)
def initialize(): Timer.TIMER_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.TIMER_PROXY)
def initialize(): Request.REQUEST_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.REQUEST_PROXY)
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 initialize(): Timer.TIMER_PROXY = variable_table.get_variable( ccvariable.ttypes.Variable.TIMER_PROXY)
def initialize(): EntityManager.ENTITY_PROXY = variable_table.get_variable(ccvariable.ttypes.Variable.ENTITY_MANAGER)