Exemple #1
0
    def get(self):
        county = current_user.county
        infrastructure = county.infrastructure

        # overwrite and vueify form, probably should be a method.
        form = EconomyForm(tax=county.tax_rate)
        form.tax.choices = tax_options

        return jsonify(
            status='success',
            debugMessage='You called on the gold api.',
            tax=county.tax_rate,
            gold=county.gold,
            rations=county.rations,
            goldChange=county.gold_income,
            form=vue_safe_form(form),
            income_mod=vue_safe_metadata_mod(income_modifier, county),
            race=county.race,
            background=county.background,
            taxIncome=county.get_tax_income(),
            bankIncome=county.bank_income,
            hasBanks=infrastructure.buildings['bank'].total > 0,
            isOverworking=county.production_choice == 0,
            excessProduction=county.get_excess_production_value(0),
            militaryExpenses=county.get_upkeep_costs(),
        )
Exemple #2
0
    def get(self):
        forms = get_forms()
        county = current_user.county

        known_technologies = [
            generic_vue_safe(tech, ['name', 'description', 'source'])
            for tech in county.completed_technologies
        ]
        available_technologies = [
            generic_vue_safe(
                tech,
                ['name', 'description', 'tier', 'current', 'cost', 'source'])
            for tech in county.available_technologies
        ]

        locked_technologies = [
            generic_vue_safe(
                tech,
                ['name', 'description', 'tier', 'current', 'cost', 'source'])
            for tech in county.unavailable_technologies
        ]

        form = forms.TechnologyForm()
        form.technology.choices = [(tech.id, tech.name)
                                   for tech in county.available_technologies]

        county_data = dict(research=county.research, )

        current_tech = county.research_choice
        try:
            current_tech_data = dict(
                currentTech=current_tech.name,
                description=current_tech.description,
                selectedResearch=current_tech.id,
                progressCurrent=current_tech.current,
                progressRequired=current_tech.cost,
            )
        except AttributeError:
            current_tech_data = dict(
                currentTech="N/A",
                description="You have researched everything!",
                selectedResearch="N/A",
                progressCurrent=0,
                progressRequired=0,
            )
            form.technology.choices.append((
                current_tech_data['selectedResearch'],
                current_tech_data['currentTech'],
            ))
        return jsonify(debugMessage=f"You called on {__name__}",
                       form=vue_safe_form(form),
                       county=county_data,
                       knownTechnologies=known_technologies,
                       availableTechnologies=available_technologies,
                       researchChange=county.research_change,
                       lockedTechnologies=locked_technologies,
                       **current_tech_data)
Exemple #3
0
    def get(self):
        county = current_user.county

        form = EconomyForm(tax=county.tax_rate, rations=county.rations)
        form.tax.choices = tax_options
        form.rations.choices = rations_terminology

        return jsonify(status="success",
                       message="You have accessed the update api.",
                       form=vue_safe_form(form))
Exemple #4
0
    def get(self):
        county = current_user.county
        infrastructure = county.infrastructure
        form = MilitaryForm()

        armies = county.armies
        besiegers = armies['besieger']
        lair = infrastructure.buildings['lair']

        military_strength = dict(
            offensiveStrength=county.get_offensive_strength(),
            defensiveStrength=county.get_defensive_strength(),
            availableWorkers=county.get_available_workers(),
            besiegerStrength=besiegers.total * besiegers.attack,
        )

        vue_safe_county = dict(
            population=county.population,
            gold=county.gold,
            wood=county.wood,
            iron=county.iron,
            happiness=county.happiness,
            background=county.background,
            unitsAvailable=county.get_available_army_size(),
            unitsUnavailable=county.get_unavailable_army_size(),
            unitsInTraining=county.get_training_army_size(),
            upkeepCosts=county.get_upkeep_costs(),
            **military_strength
        )

        vue_safe_armies = {
            army.key: vue_safe_army(county, army)
            for army in armies.values()
        }
        vue_safe_armies['monster']['building'] = dict(
            name=lair.class_name_plural.title(),
            total=lair.total,
        )

        vue_safe_metadata = generic_vue_safe(
            SimpleNamespace(id='metadata'),
            [],
            **game_descriptions
        )

        return jsonify(
            debugMessage=f"You called on {__name__}",
            form=vue_safe_form(form),
            county=vue_safe_county,
            metadata=vue_safe_metadata,
            armies=vue_safe_armies,
            armyOrdering=all_armies,
        )
Exemple #5
0
    def get(self):
        forms = get_forms()
        county = current_user.county

        excess_worker_form = forms.ExcessProductionForm(
            goal=county.production_choice)
        excess_worker_form.goal.choices = excess_worker_choices

        return jsonify(
            status="success",
            debugMessage="You called on the idle workers api.",
            allocateWorkersUrl=url_for('api.infrastructure_allocate_api'),
            form=vue_safe_form(excess_worker_form),
            overworking=county.get_excess_production_value(0),
            landProduced=county.preferences.produce_land,
            landToClear=county.land * land_to_clear_ratio,
            reclaiming=county.get_excess_production_value(1),
            foraging=county.get_excess_production_value(2),
            relaxing=county.get_excess_production_value(3),
            goal=county.production_choice)
Exemple #6
0
    def post(self):
        models = get_models()
        forms = get_forms()
        county = current_user.county
        form = forms.TechnologyForm()

        form.technology.choices = [(tech.id, tech.name)
                                   for tech in county.available_technologies]

        if form.validate_on_submit():
            tech = models.Technology.query.get(form.technology.data)
            # update choice.
            county.research_choice = tech
            return jsonify(
                debugMessage='You have updated your current research choice.',
                researchChange=county.research_change,
                description=tech.description,
                progressCurrent=tech.current,
                progressRequired=tech.cost,
                form=vue_safe_form(form)), 201
        return jsonify(
            debugMessage='Your research form did not pass validation.'), 403
Exemple #7
0
    def get(self):
        county = current_user.county

        # probably should move to a function.
        form = EconomyForm(rations=current_user.county.rations)
        form.rations.choices = rations_terminology

        return jsonify(
            status='success',
            debugMessage='You called the food api.',
            grain_stores=county.grain_stores,
            grainStorageChange=county.grain_storage_change(),
            foodEaten=county.get_food_to_be_eaten(),
            rations=county.rations,
            form=vue_safe_form(form),
            race=county.race,
            background=county.background,
            food_consumed_mod=vue_safe_metadata_mod(food_consumed_modifier,
                                                    county),
            producedGrain=county.get_produced_grain(),
            producedDairy=county.get_produced_dairy(),
            isForaging=county.production_choice == 2,
            excessProduction=county.get_excess_production_value(2),
        )