def playing_team_on_event_playing_create(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingCreate()
  TSerialization.deserialize(message, serialize)

  playing_config = team_types.Config.get(message.template_)
  if playing_config == None:
    proxy.Logging.error("[team] team_types.Config.get(%d) failed." % message.template_)
    return None

  playing = team_types.Playing(message.playing_, message.template_, message.scene_)
  team_types.PlayingManager.add(playing)

  if playing_config.summon_next_npc(message.scene_, playing.get_next_pos()) == False:
    proxy.Logging.error("[team] playing_config.summon_next_npc(%d) failed." % message.scene_)
    return None

  playing.next_pos()

  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_team_on_event_playing_actor_enter")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_team_on_event_playing_actor_leave")

  # 定时器,副本时间
  proxy.Timer.add(message.playing_, playing_config.get_playing_time() * 1000, 1,\
      "playing_team_on_timer_playing")

  proxy.Timer.add(message.playing_, 2000, -1, "playing_team_on_timer_sync_ranking")

  proxy.Logging.debug("[team] playing(%d,%d,%d) create"\
      % (message.playing_, message.template_, message.scene_))
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_))