示例#1
0
def move(request, coordinate_x, coordinate_y):

    hero = request.hero
    herom = HeroM(hero)
    island = herom.get_island()
    hero_position = herom.get_position_on_island()

    islandm = IslandM(island)
    if not islandm.is_can_make_step(coordinate_x, coordinate_y, hero_position):
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    if not herom.get_combat():
        if not islandm.get_time_left_to_move(hero_position):
            try:
                island.islandpart_set.get(coordinate_x=coordinate_x,
                                          coordinate_y=coordinate_y,
                                          is_move=False)
            except IslandPart.DoesNotExist:
                herom.update_position_on_island(coordinate_x, coordinate_y)
                islandm.update_bots_position(coordinate_x, coordinate_y)
                CombatM(None,
                        hero).update_bots_in_combats(coordinate_x,
                                                     coordinate_y)
    else:
        #
        messages.add_message(request, messages.ERROR, 'Take away your demand.')

    return HttpResponseRedirect(reverse('island'))
示例#2
0
def move(request, coordinate_x, coordinate_y):
    
    hero = request.hero
    herom = HeroM(hero)
    island = herom.get_island()
    hero_position = herom.get_position_on_island()

    islandm = IslandM(island)
    if not islandm.is_can_make_step(coordinate_x, coordinate_y, hero_position):
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    if not herom.get_combat():
        if not islandm.get_time_left_to_move(hero_position):
            try:
                island.islandpart_set.get(coordinate_x=coordinate_x, 
                                          coordinate_y=coordinate_y, 
                                          is_move=False)
            except IslandPart.DoesNotExist:
                herom.update_position_on_island(coordinate_x, coordinate_y)
                islandm.update_bots_position(coordinate_x, coordinate_y)
                CombatM(None, hero).update_bots_in_combats(coordinate_x,
                                                           coordinate_y)
    else:
#
        messages.add_message(request, messages.ERROR, 'Take away your demand.')
    
    return HttpResponseRedirect(reverse('island'))
示例#3
0
def island(request, template_name='island/island.html'):
    
    hero = request.hero
    herom = HeroM(hero)
    island = herom.get_island()
    islandm = IslandM(island)

    if not islandm.is_near_island(hero.location):
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    BuildingM(None, hero).remove_from_location()

    hero_position = herom.get_position_on_island()
    hero_time_left = islandm.get_time_left_to_move(hero_position)

    x, y = hero_position[0], hero_position[1]
    buildings = Building.objects.filter(island=island,
                                        coordinate_x1__lte=x,
                                        coordinate_y1__lte=y,
                                        coordinate_x2__gte=x,
                                        coordinate_y2__gte=y)
    bots = Bot.objects.filter(island=island,
                              current_coordinate_x=x,
                              current_coordinate_y=y,
                              in_combat=False)
    
    variables = RequestContext(request, {'island': island,
                                         'buildings': buildings,
                                         'bots': bots,
                                         'hero_position_x': hero_position[0],
                                         'hero_position_y': hero_position[1],
                                         'hero_time_left': hero_time_left})
    
    return render_to_response(template_name, variables)
示例#4
0
def bot_attack(request, bot_id):
    hero = request.hero
    herom = HeroM(hero)
    hero_position = herom.get_position_on_island()

    try:
        bot = Bot.objects.get(id=bot_id)
    except Bot.DoesNotExist:
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    if bot.current_coordinate_x != hero_position[0] or \
        bot.current_coordinate_y != hero_position[1]:
        #
        messages.add_message(request, messages.ERROR, 'Bot go away.')
        return HttpResponseRedirect(reverse('island'))

    if herom.get_combat():
        #
        messages.add_message(request, messages.ERROR, 'Take away your demand.')
        return HttpResponseRedirect(reverse('island'))

    if not bot.in_combat:
        combat = Combat(type=Combat.TYPE_TERRITORIAL,
                        is_active=Combat.IS_ACTIVE_FIGHT,
                        location=herom.get_location())
        combat.save()
        combat.combatwarrior_set.create(hero=hero, team=Combat.TEAM_FIRST)
        combat.combatwarrior_set.create(bot=bot, team=Combat.TEAM_SECOND)

        bot.in_combat = True
        bot.save()

        CombatM(combat, hero).write_log_message(combat, True)
        return HttpResponseRedirect(reverse('combat'))
    else:
        #
        messages.add_message(request, messages.ERROR, 'Bot in combat.')
        return HttpResponseRedirect(reverse('island'))
示例#5
0
def bot_attack(request, bot_id):
    hero = request.hero
    herom = HeroM(hero)
    hero_position = herom.get_position_on_island()

    try:
        bot = Bot.objects.get(id=bot_id)
    except Bot.DoesNotExist:
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    if bot.current_coordinate_x != hero_position[0] or \
        bot.current_coordinate_y != hero_position[1]:
#
        messages.add_message(request, messages.ERROR, 'Bot go away.')
        return HttpResponseRedirect(reverse('island'))

    if herom.get_combat():
#
        messages.add_message(request, messages.ERROR, 'Take away your demand.')
        return HttpResponseRedirect(reverse('island'))

    if not bot.in_combat:
        combat = Combat(type=Combat.TYPE_TERRITORIAL,
                        is_active=Combat.IS_ACTIVE_FIGHT,
                        location=herom.get_location())
        combat.save()
        combat.combatwarrior_set.create(hero=hero, team=Combat.TEAM_FIRST)
        combat.combatwarrior_set.create(bot=bot, team=Combat.TEAM_SECOND)
        
        bot.in_combat = True
        bot.save()
        
        CombatM(combat, hero).write_log_message(combat, True)
        return HttpResponseRedirect(reverse('combat'))
    else:
#
        messages.add_message(request, messages.ERROR, 'Bot in combat.')
        return HttpResponseRedirect(reverse('island'))
示例#6
0
def island(request, template_name='island/island.html'):

    hero = request.hero
    herom = HeroM(hero)
    island = herom.get_island()
    islandm = IslandM(island)

    if not islandm.is_near_island(hero.location):
        return HttpResponseRedirect(reverse(settings.URL_REVERSE_404))

    BuildingM(None, hero).remove_from_location()

    hero_position = herom.get_position_on_island()
    hero_time_left = islandm.get_time_left_to_move(hero_position)

    x, y = hero_position[0], hero_position[1]
    buildings = Building.objects.filter(island=island,
                                        coordinate_x1__lte=x,
                                        coordinate_y1__lte=y,
                                        coordinate_x2__gte=x,
                                        coordinate_y2__gte=y)
    bots = Bot.objects.filter(island=island,
                              current_coordinate_x=x,
                              current_coordinate_y=y,
                              in_combat=False)

    variables = RequestContext(
        request, {
            'island': island,
            'buildings': buildings,
            'bots': bots,
            'hero_position_x': hero_position[0],
            'hero_position_y': hero_position[1],
            'hero_time_left': hero_time_left
        })

    return render_to_response(template_name, variables)
示例#7
0
    def is_near_building(self, slug):
        slugs = [i.split(':')[1] for i in self.hero.location.split('&')[1:]]

        herom = HeroM(self.hero)
        x, y, time = herom.get_position_on_island()
        island = herom.get_island()

        if not len(slugs):
            if self.building.coordinate_x1 <= x and \
               self.building.coordinate_x2 >= x and \
               self.building.coordinate_y1 <= y and \
               self.building.coordinate_y2 >= y and \
               island == self.building.island:
                return True
        else:
            if (len(slugs) >= 2 and slug == slugs[-2]) or \
               (self.building.parent and \
               self.building.parent.slug == slugs[-1]) or \
               slug == slugs[-1] or \
               (self.building.parent and \
                self.building.parent.default_child == True):
                return True

        return False
示例#8
0
    def is_near_building(self, slug):
        slugs = [ i.split(':')[1] for i in self.hero.location.split('&')[1:] ]

        herom = HeroM(self.hero)
        x, y, time = herom.get_position_on_island()
        island = herom.get_island()
        
        if not len(slugs):
            if self.building.coordinate_x1 <= x and \
               self.building.coordinate_x2 >= x and \
               self.building.coordinate_y1 <= y and \
               self.building.coordinate_y2 >= y and \
               island == self.building.island:
                return True
        else:
            if (len(slugs) >= 2 and slug == slugs[-2]) or \
               (self.building.parent and \
               self.building.parent.slug == slugs[-1]) or \
               slug == slugs[-1] or \
               (self.building.parent and \
                self.building.parent.default_child == True):
                return True

        return False