Exemplo n.º 1
0
from rulebuilder.conditions import Condition, Language
from rulebuilder.forms import ConditionForm

from django import forms

from models import Technology

from players.language import PLAYER_LANGUAGE

class TechnologyForm(ConditionForm):
    representation_string = u'Player has the following technology: %(tech)s'
    tech = forms.ModelChoiceField(Technology)

class TechnologyCondition(Condition):
    form = TechnologyForm

    def evaluate(self, context, node):
        races = node['tech']
        return context['player'].technologies.all().filter(pk=tech.pk).count()

PLAYER_LANGUAGE.add('tech', TechnologyCondition)

Exemplo n.º 2
0
                                          ('gt','greater then'),
                                          ('lt','less then')])
    planets = forms.IntegerField()

class PlanetCondition(Condition):
    form = PlanetForm

    operations = {'eq': lambda x, y: x == y,
                  'gt': lambda x, y: x > y,
                  'lt': lambda x, y: x < y}

    def evaluate(self, context, node):
        planets = int(node['planets'])
        return self.operations[node['operator']](node['player'].planets.count(), planets)

PLAYER_LANGUAGE.add('planet', PlanetCondition)

class PlanetPopulationForm(ConditionForm):
    representation_string = u'Planet has %(operator)s %(population)s population'
    operator = forms.ChoiceField(choices=[('eq','equal to'),
                                          ('gt','greater then'),
                                          ('lt','less then')])
    population = forms.IntegerField()

class PlanetPopulationCondition(Condition):
    form = PlanetPopulationForm

    operations = {'eq': lambda x, y: x == y,
                  'gt': lambda x, y: x > y,
                  'lt': lambda x, y: x < y}