示例#1
0
def playing_slime_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorEnter()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 关注玩家杀死NPC事件、请求完成副本事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slime_on_event_actor_kill_npc")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slime_on_event_playing_actor_request_complete")

  playing = slime_types.PlayingManager.get(message.playing_)
  if playing == None:
    return None

  now = time.time()

  actor = playing.get_actor()
  if actor == 0:
    playing.set_start_time(now)
    playing.set_actor(message.actor_)
    # 消耗玩家副本次数
    request = ccrequest.playing.ttypes.RequestPlayingIncreaseComplete()
    # request.actor_ = message.actor_
    # request.playing_template_ = message.template_
    request.playing_ = message.playing_
    # 发送请求
    proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INCREASE_COMPLETE,\
        request)
    proxy.Timer.add(message.playing_, slime_types.Config.get_slime_time() * 1000, 1, "playing_slime_on_timer_slime")

  # 副本管理器中建立一个玩家ID和副本ID的映射关系
  slime_types.PlayingManager.add_actor(message.actor_, message.playing_)

  # 请求初始化玩家
  request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
  request.actor_ = message.actor_
  request.spend_time_ = now - playing.get_start_time()
  # datas = [剩余体力, 阶段, 当前阶段剩余时间]
  request.datas_ = []
  request.datas_.append(slime_types.Config.get_max_power() - playing.get_spend_power())
  if playing.get_section_boss() == True:
    request.datas_.append(2)
    request.datas_.append(now - playing.get_boss_summon_time())
  else:
    request.datas_.append(1)
    # 第一阶段剩下的时间
    elapse_time = now - playing.get_start_time()
    if elapse_time <= slime_types.Config.get_slime_time():
      request.datas_.append(slime_types.Config.get_slime_time() - elapse_time)
    else:
      request.datas_.append(0)
  request.scores_ = []
  request.scores_.append(ccentity.playing.ttypes.PlayingScoreField(\
    ccentity.playing.ttypes.PlayingScoreType.KILL_NPC, 0, playing.get_score()))
  request.scores_.append(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_INITIALIZE_ACTOR,\
      request)

  # 转为临时技能形态
  facade_request.change_skill_form(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, ccentity.skill.ttypes.SkillFormType.TEMP)
  # 增加临时技能
  facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 100, 1)
  facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 200, 1)
  facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 300, 1)

  proxy.Logging.debug("[slime] actor(%d) enter into playing" % message.actor_)
示例#2
0
def playing_slime_on_event_playing_actor_enter(message_type, channel,
                                               channel_type, serialize):
    # 事件消息
    message = ccevent.playing.ttypes.EventPlayingActorEnter()
    # 反序列化
    TSerialization.deserialize(message, serialize)

    # 关注玩家杀死NPC事件、请求完成副本事件
    proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
        message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
        "playing_slime_on_event_actor_kill_npc")
    proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
        message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
        "playing_slime_on_event_playing_actor_request_complete")

    playing = slime_types.PlayingManager.get(message.playing_)
    if playing == None:
        return None

    now = time.time()

    actor = playing.get_actor()
    if actor == 0:
        playing.set_start_time(now)
        playing.set_actor(message.actor_)
        # 消耗玩家副本次数
        request = ccrequest.playing.ttypes.RequestPlayingIncreaseComplete()
        # request.actor_ = message.actor_
        # request.playing_template_ = message.template_
        request.playing_ = message.playing_
        # 发送请求
        proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INCREASE_COMPLETE,\
            request)
        proxy.Timer.add(message.playing_,
                        slime_types.Config.get_slime_time() * 1000, 1,
                        "playing_slime_on_timer_slime")

    # 副本管理器中建立一个玩家ID和副本ID的映射关系
    slime_types.PlayingManager.add_actor(message.actor_, message.playing_)

    # 请求初始化玩家
    request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
    request.actor_ = message.actor_
    request.spend_time_ = now - playing.get_start_time()
    # datas = [剩余体力, 阶段, 当前阶段剩余时间]
    request.datas_ = []
    request.datas_.append(slime_types.Config.get_max_power() -
                          playing.get_spend_power())
    if playing.get_section_boss() == True:
        request.datas_.append(2)
        request.datas_.append(now - playing.get_boss_summon_time())
    else:
        request.datas_.append(1)
        # 第一阶段剩下的时间
        elapse_time = now - playing.get_start_time()
        if elapse_time <= slime_types.Config.get_slime_time():
            request.datas_.append(slime_types.Config.get_slime_time() -
                                  elapse_time)
        else:
            request.datas_.append(0)
    request.scores_ = []
    request.scores_.append(ccentity.playing.ttypes.PlayingScoreField(\
      ccentity.playing.ttypes.PlayingScoreType.KILL_NPC, 0, playing.get_score()))
    request.scores_.append(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_INITIALIZE_ACTOR,\
        request)

    # 转为临时技能形态
    facade_request.change_skill_form(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
        message.actor_, ccentity.skill.ttypes.SkillFormType.TEMP)
    # 增加临时技能
    facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
        message.actor_, 100, 1)
    facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
        message.actor_, 200, 1)
    facade_request.add_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
        message.actor_, 300, 1)

    proxy.Logging.debug("[slime] actor(%d) enter into playing" %
                        message.actor_)
示例#3
0
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()))
示例#4
0
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()))