예제 #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 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)
예제 #5
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
예제 #6
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