def setUp(self):
     time_step = 0.005
     self.arena = Arena(10, 10)
     self.biased_grid = BiasedGrid(self.arena.get_dimensions())
     self.agents = [Agent(0, 0, time_step), Agent(1, 1, time_step)]
     self.algorithm = SingleAgentAlgorithmMock(self.arena, self.agents,
                                               self.biased_grid)
 def setUp(self):
     time_step = 0.05
     self.agents = [Agent(0, 0, time_step)]
     self.arena = Arena(10, 20)
     self.biased_grid = BiasedGrid(self.arena.get_dimensions())
     self.algorithm = AStar(self.arena, self.agents, self.biased_grid)
     self.cli = CommandLine(self.arena, self.agents)
Esempio n. 3
0
    def check_exist(self, server_id, char_id):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            Club(server_id, char_id).check_money(**money_text)
        if self.bag:
            Bag(server_id, char_id).check_items(self.bag)
        if self.staff:
            StaffManger(server_id,
                        char_id).check_original_staff_is_initial_state(
                            self.staff)
        if self.territory_product:
            Territory(server_id, char_id).check_product(self.territory_product)
        if self.work_card:
            Territory(server_id, char_id).check_work_card(self.work_card)
        if self.arena_point:
            Arena(server_id, char_id).check_point(self.arena_point)
        if self.energy:
            Energy(server_id, char_id).check(self.energy)
        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).check_score(self.staff_recruit_score)
        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.check_exists(server_id, char_id)
Esempio n. 4
0
def arena_panel(request):
    arena = Arena(request._char_id)
    response = ArenaPanelResponse()
    response.ret = 0

    arena.fill_up_panel_msg(response.panel)
    return pack_msg(response)
Esempio n. 5
0
    def add(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.talent import TalentManager
        from core.territory import Territory
        from core.vip import VIP
        from core.arena import Arena
        from core.energy import Energy
        from core.plunder import Plunder

        club_property = self.money_as_text_dict()
        if self.club_exp:
            club_property['exp'] = self.club_exp
        if club_property:
            club_property['message'] = message
            Club(server_id, char_id).update(**club_property)

        if self.vip_exp:
            VIP(server_id, char_id).add_exp(self.vip_exp)

        if self.bag:
            bag = Bag(server_id, char_id)
            bag.batch_add(self.bag)

        sm = StaffManger(server_id, char_id)
        if self.staff:
            sm.batch_add(self.staff)

        if self.staff_exp_pool:
            sm.add_exp_pool(self.staff_exp_pool)

        if self.talent_point:
            TalentManager(server_id,
                          char_id).add_talent_points(self.talent_point)

        if self.arena_point:
            Arena(server_id, char_id).add_point(self.arena_point)

        if self.territory_product:
            Territory(server_id, char_id).add_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).add_work_card(self.work_card)

        if self.energy:
            Energy(server_id, char_id).add(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).add_score(self.staff_recruit_score)

        if self.station_exp:
            Plunder(server_id, char_id).add_station_exp(self.station_exp)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.add(server_id, char_id)
Esempio n. 6
0
def refresh(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    Arena(server_id, char_id).refresh()

    response = ArenaRefreshResponse()
    response.ret = 0
    return ProtobufResponse(response)
Esempio n. 7
0
def buy_times(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    Arena(server_id, char_id).buy_times()

    response = ArenaBuyTimesResponse()
    response.ret = 0
    return ProtobufResponse(response)
Esempio n. 8
0
def arena_battle(request):
    char_id = request._char_id

    arena = Arena(char_id)
    msg = arena.battle()

    response = ArenaResponse()
    response.ret = 0
    response.battle.MergeFrom(msg)

    return pack_msg(response)
Esempio n. 9
0
def arena_battle(request):
    char_id = request._char_id

    arena = Arena(char_id)
    msg, drop = arena.battle()

    response = ArenaResponse()
    response.ret = 0
    response.battle.MergeFrom(msg)
    response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop))
    return pack_msg(response)
Esempio n. 10
0
def login_notify(char_id):
    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    hang = Hang(char_id)
    hang.send_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    Arena(char_id).send_notify()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    m = Mail(char_id)
    m.send_mail_notify()

    CheckIn(char_id).send_notify()


    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    FunctionOpen(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()
Esempio n. 11
0
def get_honor_reward(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    honor = request._proto.honor

    a = Arena(server_id, char_id)
    resource_classified = a.get_honor_reward(honor)

    response = ArenaHonorGetRewardResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
Esempio n. 12
0
def match_start(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    formation_slots = parse_protocol_sync_formation_slots(request._proto.slots)

    a = Arena(server_id, char_id)
    msg = a.match(formation_slots)

    response = ArenaMatchStartResponse()
    response.ret = 0
    response.match.MergeFrom(msg)

    return ProtobufResponse(response)
Esempio n. 13
0
 def parse_arena(self) -> None:
     """
     Creates the simulation arena
     :return:
     """
     arena = self.config['arena_properties']
     arena_size = arena['size']
     sim_arena = Arena(arena_size[0], arena_size[1])
     blockages = arena['blockages']
     for blockage in blockages:
         sim_arena.set_blockage([blockage[0]], [blockage[1]])
     self.arena = sim_arena
     self.biased_grid = BiasedGrid(self.arena.get_dimensions())
     biased_squares = arena['biases']
     self._event_squares = arena['event_squares']
     for bias in biased_squares:
         self.biased_grid[bias[0], bias[1]] = bias[2]
Esempio n. 14
0
def _func_opened(char_id, func_ids, **kwargs):
    need_task_notify = False
    task_related_func_ids = [t.func for t in TASKS.values() if t.func]
    for _id in func_ids:
        if _id in task_related_func_ids:
            need_task_notify = True
            break

    if need_task_notify:
        Task(char_id).send_notify()

    # dirty fix...
    # 比武功能没开放的时候,没有初始化
    # 所以在这里要初始化以便自动进入竞技场
    from core.arena import Arena
    for _id in func_ids:
        if _id == Arena.FUNC_ID:
            Arena(char_id).send_notify()
Esempio n. 15
0
    def remove(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            money_text = {k: -v for k, v in money_text.iteritems()}
            money_text['message'] = message
            Club(server_id, char_id).update(**money_text)

        if self.bag:
            bag = Bag(server_id, char_id)
            for _id, _amount in self.bag:
                bag.remove_by_item_id(_id, _amount)

        if self.staff:
            StaffManger(server_id, char_id).internal_remove_by_oid(self.staff)

        if self.territory_product:
            Territory(server_id,
                      char_id).remove_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).remove_work_card(self.work_card)

        if self.arena_point:
            Arena(server_id, char_id).remove_point(self.arena_point)

        if self.energy:
            Energy(server_id, char_id).remove(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).remove_score(self.staff_recruit_score)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.remove(server_id, char_id)
Esempio n. 16
0
def match_report(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    key = request._proto.key
    win = request._proto.win

    a = Arena(server_id, char_id)
    resource_classified, score_changed, rank_changed, max_rank, my_rank, my_score = a.report(
        key, win)

    response = ArenaMatchReportResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())
    response.score_changed = score_changed
    response.rank_changed = rank_changed
    response.max_rank = max_rank
    response.my_rank = my_rank
    response.my_score = my_score
    return ProtobufResponse(response)
Esempio n. 17
0
def login_notify(char_id):
    message_clean(char_id)
    function_open = FunctionOpen(char_id)
    function_open.send_notify()

    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    if Arena.FUNC_ID not in function_open.mf.freeze:
        arena = Arena(char_id)
        arena.send_notify()
        arena.login_process()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    CheckIn(char_id).send_notify()

    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()

    PurchaseAction(char_id).send_notify()

    SystemBroadcast(char_id).send_global_broadcast()

    affairs = Affairs(char_id)
    affairs.send_city_notify()
    affairs.send_hang_notify()

    # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件
    Mail(char_id).send_notify()
 def setUp(self):
     # note: this means coordinates go from x = [0-4], y = [0-9]
     self.arena = Arena(5, 10)
Esempio n. 19
0
def game_start_handler(server_id, char_id, **kwargs):
    MessagePipe(char_id).clean()

    msg = UTCNotify()
    msg.timestamp = arrow.utcnow().timestamp
    MessagePipe(char_id).put(msg=msg)

    msg = SocketServerNotify()
    ss = random.choice(settings.SOCKET_SERVERS)
    msg.ip = ss['host']
    msg.port = ss['tcp']
    MessagePipe(char_id).put(msg=msg)

    _Resource.send_notify(server_id, char_id)

    UnitManager(server_id, char_id).send_notify()

    Bag(server_id, char_id).send_notify()

    StaffManger(server_id, char_id).send_notify()
    StaffRecruit(server_id, char_id).send_notify()

    f = Formation(server_id, char_id)
    f.send_formation_notify()
    f.send_slot_notify()

    club = Club(server_id, char_id)
    club.set_login()
    club.send_notify()

    msg = CreateDaysNotify()
    msg.days = days_passed(club.create_at)
    msg.create_at = club.create_at
    MessagePipe(char_id).put(msg=msg)

    chall = Challenge(server_id, char_id)
    chall.send_chapter_notify()
    chall.send_challenge_notify()

    FriendManager(server_id, char_id).send_notify()
    MailManager(server_id, char_id).send_notify()

    TaskMain(server_id, char_id).send_notify()
    TaskDaily(server_id, char_id).send_notify()

    Chat(server_id, char_id).send_notify()

    Notification(server_id, char_id).send_notify()

    FinanceStatistics(server_id, char_id).send_notify()

    TalentManager(server_id, char_id).send_notify()

    Dungeon(server_id, char_id).send_notify()

    a = Arena(server_id, char_id)
    a.send_notify()
    a.send_honor_notify()

    t = Tower(server_id, char_id)
    t.send_notify()
    t.send_goods_notify()

    Territory(server_id, char_id).send_notify()
    TerritoryStore(server_id, char_id).send_notify()
    TerritoryFriend(server_id, char_id).send_remained_times_notify()

    Store(server_id, char_id).send_notify()
    VIP(server_id, char_id).send_notify()
    Collection(server_id, char_id).send_notify()

    Energy(server_id, char_id).send_notify()

    w = Welfare(server_id, char_id)
    w.send_signin_notify()
    w.send_new_player_notify()
    w.send_level_reward_notify()
    w.send_energy_reward_notify()

    Union(server_id, char_id).send_all_notify()

    Purchase(server_id, char_id).send_notify()

    ac = ActivityNewPlayer(server_id, char_id)
    ac.send_notify()
    ac.send_daily_buy_notify()

    ActivityOnlineTime(server_id, char_id).send_notify()
    ActivityChallenge(server_id, char_id).send_notify()
    ActivityPurchaseDaily(server_id, char_id).send_notify()
    ActivityPurchaseContinues(server_id, char_id).send_notify()
    ActivityLevelGrowing(server_id, char_id).send_notify()

    p = Plunder(server_id, char_id)

    p.send_search_notify()
    p.send_result_notify()
    p.send_revenge_notify()
    p.send_station_notify()
    p.send_formation_notify()
    p.send_plunder_times_notify()
    p.send_plunder_daily_reward_notify()

    SpecialEquipmentGenerator(server_id, char_id).send_notify()

    Party(server_id, char_id).send_notify()

    ins = Inspire(server_id, char_id)
    ins.try_open_slots(send_notify=False)
    ins.send_notify()

    cs = Championship(server_id, char_id)
    cs.try_initialize(send_notify=False)
    cs.send_notify()

    WinningPlunder(server_id, char_id).send_notify()
    WinningArena(server_id, char_id).send_notify()
    WinningChampionship(server_id, char_id).send_notify()
    Worship(server_id, char_id).send_notify()
    CommonArenaWinningChat(server_id, char_id).send_notify()
    CommonPlunderWinningChat(server_id, char_id).send_notify()
    CommonChampionshipChat(server_id, char_id).send_notify()

    send_system_notify(server_id, char_id)
    BroadCast(server_id, char_id).try_cast_login_notify()
Esempio n. 20
0
 def get_current_value(self, char_id):
     from core.arena import Arena
     return Arena(char_id).rank
Esempio n. 21
0
    def buy(self, tp, goods_id):
        if tp not in ALL_TYPES:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        config = ConfigStore.get(goods_id)
        if not config:
            raise GameException(
                ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST"))

        try:
            data = self.doc['tp'][str(tp)]['goods'][str(goods_id)]
        except KeyError:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if data['times'] >= config.times_limit:
            raise GameException(
                ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES"))

        if config.condition_id == 1:
            # VIP 等级
            VIP(self.server_id, self.char_id).check(config.condition_value)
        elif config.condition_id == 2:
            # 爬塔历史最高星
            Tower(self.server_id,
                  self.char_id).check_history_max_star(config.condition_value)
        elif config.condition_id == 3:
            # 竞技场当前排名
            Arena(self.server_id,
                  self.char_id).check_current_rank(config.condition_value)
        elif config.condition_id == 4:
            # 当前公会等级
            Union(self.server_id,
                  self.char_id).check_level(config.condition_value)

        item_id, item_amount, need_id, need_amount = config.content[
            data['index']]
        resource_classify = ResourceClassification.classify([(need_id,
                                                              need_amount)])
        resource_classify.check_exist(self.server_id, self.char_id)
        resource_classify.remove(self.server_id,
                                 self.char_id,
                                 message="Store.buy:{0}".format(goods_id))

        resource_classify = ResourceClassification.classify([(item_id,
                                                              item_amount)])
        resource_classify.add(self.server_id,
                              self.char_id,
                              message="Store.buy:{0}".format(goods_id))

        data['times'] += 1

        MongoStore.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times']
            }
        })

        self.send_notify(tp=tp)
        return resource_classify
Esempio n. 22
0
from core.agent import *
from core.arena import Arena

BASE_TIME_STEP = 0.05
BASE_DPI = 40


# CLI thread
def cli_thread_func(arena: Arena, agents: list) -> None:
    cli = CommandLine(arena, agents)
    while True:
        cli.get_input()


# setup an arena
sim_arena = Arena(40, 40)

# create some agents and add them to the agents list
sim_agent = Agent(0, 0, BASE_TIME_STEP)
sim_agent_1 = Agent(5, 5, BASE_TIME_STEP)
sim_agent_1.set_kinematic_parameters(4, 4, 4)
sim_agent.set_kinematic_parameters(6, 6, 6)
sim_agents = list()
sim_agents.append(sim_agent)
sim_agents.append(sim_agent_1)

# setup the routing algorithm
algorithm = AStar(sim_arena, sim_agents)
algorithm.turn_factor = 2

# create the pathing algorithm
 def setUp(self):
     time_step = 0.005
     self.arena = Arena(10, 10)
     self.biased_grid = BiasedGrid(self.arena.get_dimensions())
     self.agents = [Agent(0, 0, time_step), Agent(1, 1, time_step)]
     self.a_star = AStar(self.arena, self.agents, self.biased_grid)
Esempio n. 24
0
def login_notify(char_id):
    message_clean(char_id)
    function_open = FunctionOpen(char_id)
    function_open.send_notify()

    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()
    VIP(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    a = Arena(char_id)
    a.send_notify()
    a.login_process()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    CheckIn(char_id).send_notify()

    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.check(send_notify=False)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()

    BasePurchaseAction(char_id).send_notify()

    SystemBroadcast(char_id).send_global_broadcast()
    ChatMessagePublish(char_id).send_notify()

    affairs = Affairs(char_id)
    affairs.send_city_notify()
    affairs.send_hang_notify()

    HorseFreeTimesManager(char_id).send_notify()
    Horse(char_id).send_notify()

    union.send_notify(char_id)

    ae = ActivityEntry(char_id, 50006)
    if ae and ae.is_valid():
        ae.enable(ae.get_current_value(char_id))

    ActivityStatic(char_id).send_notify()

    # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件
    Mail(char_id).send_notify()
Esempio n. 25
0
def arena_panel(request):
    response = Arena(request._char_id).make_panel_response()
    return pack_msg(response)