コード例 #1
0
    def unit_view(self):
        unit = DiceTemplate.get_by_id(self.request.matchdict.get('id', 0))
        if (len(unit.elements) > 0):
            info = '%s ' % '/'.join([element.name for element in unit.elements])
        else:
            info = ''
        if (unit.type.health < 4):
            #We reverse the type_name string, we remove the first element (it's alway "unit" or "items" and we neither need nor want it), and we reverse again
            info += '%s ' % unit.type_name[::-1].split(' ', 1)[1][::-1]


        info += '%s' % unit.role_name
        return {'name': unit.name, 'info': info, 'faces': [{'name': face.name, 'picture': face.picture} for face in unit.faces]}
コード例 #2
0
    def do_army_edition(self, army=None, special_message=''):
        army = Army.get_by_id(self.request.matchdict.get('id'))

        if 'unit_to_remove[]' in self.request.POST:
            for dice_id in self.request.POST.getall('unit_to_remove[]'):
                Dice.get_by_id(int(dice_id)).delete()
        #Ugly, but how to do otherwise ?
        regexp = re.compile('unit_amount_([1-9][0-9]{0,2})')
        for element, amount in self.request.POST.items():
            m = regexp.search(element)
            if ((m != None) and (int(amount) > 0)):
                for i in range(int(amount)):
                    dice = Dice(DiceTemplate.get_by_id(m.group(1)), army)
                    dice.save()

        return self.army_edition(army, ('army %s succesfully modified !' % army.name))
コード例 #3
0
dice2 = UnitFactory.create('Dispatcher')
dice3 = UnitFactory.create('Magi')
dice4 = UnitFactory.create('Defender')

dice5 = UnitFactory.create('Defender')
dice6 = UnitFactory.create('Wolf Master')
dice7 = UnitFactory.create('Wolf Master')

from business.dice.dice_template import DiceTemplate
import json
dice_template = DiceTemplate('Remorhaz', 'fw', json.dumps([
            {'name': 'ID', 'amount': 4},
            {'name': 'Swallow', 'amount': 4},
            {'name': 'Swallow', 'amount': 4},
            {'name': 'Maneuver', 'amount': 4},
            {'name': 'Maneuver', 'amount': 4},
            {'name': 'Save', 'amount': 4},
            {'name': 'Save', 'amount': 4},
            {'name': 'Save', 'amount': 4},
            {'name': 'Melee', 'amount': 4},
            {'name': 'Melee', 'amount': 4}
        ]))

dice8 = dice_template.get_instance()
dice9 = dice_template.get_instance()
dice10 = dice_template.get_instance()

army1 = Army()
army1.add(dice1)
army1.add(dice2)
army1.add(dice3)
army1.add(dice4)
コード例 #4
0
        for icon, value in category_value.items():
            string += str(icon)+': '+str(value)+'%; '
        print string

print 'CSV Consistency :'
for race_id in sorted(result_consistency.iterkeys()):
    race = Race.get_by_id(race_id).name
    race_value = result_consistency[race_id]
    string = '%s,%s,%s,%s,%s,%s,' % (race, race_value['UC']['Melee'], race_value['UC']['Missile'],race_value['UC']['Maneuver'],race_value['UC']['Save'],race_value['UC']['Magic'])
    string += '%s,%s,%s,%s,%s,' % (race_value['R ']['Melee'], race_value['R ']['Missile'],race_value['R ']['Maneuver'],race_value['R ']['Save'],race_value['R ']['Magic'])
    string += '%s,%s,%s,%s,%s' % (race_value['M ']['Melee'], race_value['M ']['Missile'],race_value['M ']['Maneuver'],race_value['M ']['Save'],race_value['M ']['Magic'])
    print string

print 'Unit report :'
for race_id in sorted(result_concentration_by_unit.iterkeys()):
    print '========================================================='
    race = Race.get_by_id(race_id).name
    print race+':'
    race_value = result_concentration_by_unit[race_id]
    for dice_id in sorted(race_value.iterkeys()):
        dice_value = race_value[dice_id]
        dice_name = DiceTemplate.get_by_id(dice_id).name
        
        string = dice_name.ljust(30)+': '
        total = 0
        for icon, value in dice_value.items():
            total += value
            string += (str(icon)+': '+str(value)+'; ').ljust(12)
        string = dice_name.ljust(30)+': '+str(round(total * 6.0, 2))
        print string