def handle_interrupt_target_activity( character_id: int, add_time: int, change_data: game_type.CharacterStatusChange ): """ 打断交互目标活动 Keyword arguments: character_id -- 角色id add_time -- 结算时间 change_data -- 状态变更信息记录对象 """ if not add_time: return character_data: game_type.Character = cache.character_data[character_id] target_data: game_type.Character = cache.character_data[character_data.target_character_id] if target_data.dead: return if target_data.state == constant.CharacterStatus.STATUS_DEAD: return if target_data.behavior.behavior_id: if target_data.behavior.start_time <= character_data.behavior.start_time: target_end_time = game_time.get_sub_date( target_data.behavior.duration, old_date=target_data.behavior.start_time ) if target_end_time >= character_data.behavior.start_time: if target_data.behavior.behavior_id == constant.Behavior.MOVE: target_data.behavior = game_type.Behavior() target_data.state = constant.CharacterStatus.STATUS_ARDER character.init_character_behavior_start_time( target_data.cid, character_data.behavior.start_time ) else: settle_behavior.handle_settle_behavior( target_data.cid, character_data.behavior.start_time )
def judge_character_status(character_id: int) -> bool: """ 校验并结算角色状态 Keyword arguments: character_id -- 角色id Return arguments: bool -- 本次update时间切片内活动是否已完成 """ character_data = cache_contorl.character_data[character_id] start_time = character_data.behavior["StartTime"] end_time = game_time.datetime_to_game_time( game_time.get_sub_date( minute=character_data.behavior["Duration"], old_date=game_time.game_time_to_datetime(start_time), )) now_time = cache_contorl.game_time time_judge = game_time.judge_date_big_or_small(now_time, end_time) if time_judge: settle_behavior.handle_settle_behavior(character_id) character_data.behavior["BehaviorId"] = constant.Behavior.SHARE_BLANKLY character_data.state = constant.CharacterStatus.STATUS_ARDER if time_judge == 1: character_data.behavior["StartTime"] = end_time return 0 elif time_judge == 2: character.init_character_behavior_start_time(character_id) return 0 return 1
def character_target_judge(character_id: int): """ 查询角色可用目标活动并执行 Keyword arguments: character_id -- 角色id """ target, _, judge = search_target( character_id, list(cache_contorl.handle_target_data.keys()), set()) if judge: cache_contorl.handle_target_data[target](character_id) else: start_time = cache_contorl.character_data[character_id].behavior[ "StartTime"] now_judge = game_time.judge_date_big_or_small(start_time, cache_contorl.game_time) if now_judge: cache_contorl.over_behavior_character[character_id] = 1 else: next_time = game_time.datetime_to_game_time( game_time.get_sub_date( minute=1, old_date=game_time.game_time_to_datetime(start_time), )) cache_contorl.character_data[character_id].behavior[ "StartTime"] = next_time
def character_target_judge(character_id: int, now_time: datetime.datetime): """ 查询角色可用目标活动并执行 Keyword arguments: character_id -- 角色id """ premise_data = {} target_weight_data = {} target, _, judge = search_target( character_id, list(game_config.config_target.keys()), set(), premise_data, target_weight_data, ) if judge: target_config = game_config.config_target[target] constant.handle_state_machine_data[target_config.state_machine_id](character_id) else: start_time = cache.character_data[character_id].behavior.start_time now_judge = game_time.judge_date_big_or_small(start_time, now_time) if now_judge: cache.over_behavior_character.add(character_id) else: next_time = game_time.get_sub_date(minute=1, old_date=start_time) cache.character_data[character_id].behavior.start_time = next_time
def get_rand_npc_birthday(age: int): """ 随机生成npc生日 Keyword arguments: age -- 年龄 """ now_year = cache.game_time.year now_month = cache.game_time.month now_day = cache.game_time.day birth_year = now_year - age birthday = game_time.get_rand_day_for_year(birth_year) if now_month < birthday.month or (now_month == birthday.month and now_day < birthday.day): birthday = game_time.get_sub_date(year=-1, old_date=birthday) return birthday
def judge_character_status(character_id: int, now_time: datetime.datetime) -> int: """ 校验并结算角色状态 Keyword arguments: character_id -- 角色id Return arguments: bool -- 本次update时间切片内活动是否已完成 """ character_data: game_type.Character = cache.character_data[character_id] scene_path_str = map_handle.get_map_system_path_str_for_list(character_data.position) scene_data: game_type.Scene = cache.scene_data[scene_path_str] start_time = character_data.behavior.start_time end_time = game_time.get_sub_date(minute=character_data.behavior.duration, old_date=start_time) if ( character_data.target_character_id != character_id and character_data.target_character_id not in scene_data.character_list ): end_time = now_time time_judge = game_time.judge_date_big_or_small(now_time, end_time) add_time = (end_time.timestamp() - start_time.timestamp()) / 60 if not add_time: character_data.behavior = game_type.Behavior() character_data.behavior.start_time = end_time character_data.state = constant.CharacterStatus.STATUS_ARDER return 1 last_hunger_time = start_time if character_data.last_hunger_time is not None: last_hunger_time = character_data.last_hunger_time hunger_time = int((now_time - last_hunger_time).seconds / 60) character_data.status.setdefault(27, 0) character_data.status.setdefault(28, 0) character_data.status[27] += hunger_time * 0.02 character_data.status[28] += hunger_time * 0.02 character_data.last_hunger_time = now_time if time_judge: settle_behavior.handle_settle_behavior(character_id, end_time) talk.handle_talk(character_id) character_data.behavior = game_type.Behavior() character_data.state = constant.CharacterStatus.STATUS_ARDER if time_judge == 1: character_data.behavior.start_time = end_time return 0 elif time_judge == 2: character.init_character_behavior_start_time(character_id, now_time) return 0 return 1
def move_action(character_id: int, target_path: list): """ 移动行为执行 Keyword arguments: character_id -- 角色id target_path -- 目标地点 """ character_data = cache_contorl.character_data["character"][character_id] character_data.behavior[ "BehaviorId"] = constant.CharacterStatus.STATUS_MOVE if character_data.position == target_path: character_data.behavior["StartTime"] = 0 character_data.behavior["Duration"] = 0 character_data.behavior[ "BehaviorId"] = constant.CharacterStatus.STATUS_ARDER else: if character_data.behavior["MoveTarget"] != []: end_time = game_time.get_sub_date( character_data.behavior["Duration"], 0, 0, 0, 0, character_data.behavior["StartTime"], ) if game_time.judge_date_big_or_small(end_time, cache_contorl.game_time): pass ( move_status, _, now_target_position, now_need_time, ) = character_move.character_move(character_id, target_path) if move_status == "Null": pass else: pass
def move_action(character_id: int, target_path: list): """ 移动行为执行 Keyword arguments: character_id -- 角色id target_path -- 目标地点 """ character_data = cache_contorl.character_data["character"][character_id] character_data.behavior[ "BehaviorId"] = constant.CharacterStatus.STATUS_MOVE if character_data.position == target_path: character_data.behavior["StartTime"] = 0 character_data.behavior["Duration"] = 0 character_data.behavior[ "BehaviorId"] = constant.CharacterStatus.STATUS_ARDER else: if character_data.behavior["MoveTarget"] != []: end_time = game_time.get_sub_date( character_data.behavior["Duration"], 0, 0, 0, 0, character_data.behavior["StartTime"], ) time_judge = game_time.judge_date_big_or_small( end_time, cache_contorl.game_time) if time_judge == 0: map_handle.character_move_scene( character_data.position, character_data.behavior["MoveTarget"], character_id, ) character_data.behavior["StartTime"] = end_time elif time_judge == 1: need_time = (game_time.timetuple_to_datetime(end_time) - game_time.game_time_to_time_tuple( cache_contorl.game_time)).minutes character_data.behavior["Duration"] = need_time character_data.behavior[ "BehaviorId"] = constant.Behavior.SHARE_BLANKLY character_data.state = constant.CharacterStatus.STATUS_ARDER else: map_handle.character_move_scene( character_data.position, character_data.behavior["MoveTarget"], character_id, ) character_data.behavior["StartTime"] = end_time else: ( move_status, _, now_target_position, now_need_time, ) = character_move.character_move(character_id, target_path) if move_status != "Null": character_data.behavior["MoveTarget"] = now_target_position character_data.behavior["StartTime"] = cache_contorl.game_time character_data.behavior["Duration"] = now_need_time else: character_data.behavior["StartTime"] = cache_contorl.game_time character_data.state = constant.CharacterStatus.STATUS_ARDER character_data.behavior[ "BehaviorId"] = constant.Behavior.SHARE_BLANKLY cache_contorl.character_data["character"][character_id] = character_data