Пример #1
0
def ajax_battle_list(request):
    """ Get the current incoming and outgoing attacks. """
    _stop_if_err_request(request, 'GET', True)
    player = _player(request)
    heroes = Hero.objects.filter(player=player)
    # Incoming Player Attacks
    IPAttacks = []
    for pa in player.cur_inc_player_attacks():
        IPAttacks.append({'id': pa.id, 
                          'size': conf.size_name(pa.critts.count()),
                          'attacker_hero': pa.attacker.name,
                          'attacker_player': pa.attacker.player.nick,
                          'end': utils.epoch(pa.real_end())})
    # Incoming Hero Attacks
    IHAttacks = []
    for pa in player.cur_inc_hero_attacks():
        IHAttacks.append({'id': pa.id, 
                          'size': conf.size_name(pa.critts.count()),
                          'attacker_hero': pa.attacker.name,
                          'attacker_player': pa.attacker.player.nick,
                          'target_hero': pa.target.name,
                          'end': utils.epoch(pa.real_end())})
    # Outgoing Player Attacks
    OPAttacks = []
    for pa in PlayerAttack.objects.filter(attacker__in=heroes, battle__isnull=True):
        critts = []
        for c in pa.critts.all():
            critts.append(c.vals())
        OPAttacks.append({'id': pa.id, 
                          'critts': critts, 
                          'target': pa.target.nick,
                          'end': utils.epoch(pa.real_end()),
                          'attacker': pa.attacker.name})
    # Outgoing Hero Attacks
    OHAttacks = []
    heroes = Hero.objects.filter(player=player)
    for pa in HeroAttack.objects.filter(attacker__in=heroes, battle__isnull=True):
        critts = []
        for c in pa.critts.all():
            critts.append(c.vals())
        OHAttacks.append({'id': pa.id, 
                          'critts': critts, 
                          'target_hero': pa.target.name,
                          'target_player': pa.target.player.nick,
                          'end': utils.epoch(pa.real_end()),
                          'attacker': pa.attacker.name})
    data = {'IPAttacks': IPAttacks,
            'IHAttacks': IHAttacks,
            'OPAttacks': OPAttacks,
            'OHAttacks': OHAttacks}
    return HttpResponse(simplejson.dumps(data, cls=DjangoJSONEncoder))
Пример #2
0
def ajax_city(request):
    """ Player loads city data """
    _stop_if_err_request(request, 'GET', True)
    try:
        city_id = int(request.GET.get('city_id', 'crash'))
    except ValueError:
        _miss('ajax_city')
    player = _player(request)
    city = CityZone.objects.get(id=city_id)
    if not city.owner == player:
        print "ajax_city: Haxxor, Attempting to access another players city."
        return HttpResponse("HAX_ATTEMPT")
    # Buildings
    building_ids = []
    buildings = []
    for b in Building.objects.filter(faction=player.faction):
        con = Construction.objects.filter(building=b, player=player, city=city_id)
        if con.exists():
            finished = utils.epoch(con[0].finished)
            building_ids.append(b.id)
        else:
            finished = False
        buildings.append({'build_id': b.id, 'name': b.name, 'time': b.build_time, 'finished': finished, 'cost': b.cost})
    # Creatures city can summon
    can_sum = []
    for c in CrittType.objects.all():
        if c.building.id in building_ids:
            can_sum.append(c.stats())
    workers = {'gold': city.goldwork, 'blood': city.bloodwork, 'gems': city.gemwork, 'wood': city.woodwork, 'ore': city.orework}
    data = {'name': city.name, 'level': city.level(), 'workers': workers, 'buildings': buildings, 'can_sum': can_sum}
    return HttpResponse(simplejson.dumps(data, cls=DjangoJSONEncoder))
Пример #3
0
 def vals(self):
     return {'id': self.id, 
              'finished': utils.epoch(self.finished), 
              'stats': self.ctype.stats()}
Пример #4
0
 def vals(self, full):
     vals = {'id': self.id, 'name': str(self.name), 'pnick': str(self.player.nick),
             'loc': {'x': self.location.x, 'y': self.location.y}}
     if full:
         vals.update({'resting': utils.epoch(self.resting), 'level': self.level()})
     return vals