コード例 #1
0
ファイル: operative_t.py プロジェクト: Teifion/Rob3
	def test_get_cost(self):
		vals = (
			({"Stealth":1, "Integration":1, "Sedition":1, "Sabotage":1, "Assassination":1, "Observation":1, "Size":1}, 5),
			({"Stealth":5, "Integration":1, "Sedition":1, "Sabotage":1, "Assassination":1, "Observation":1, "Size":1}, 9),
			({"Stealth":5, "Integration":1, "Sedition":1, "Sabotage":1, "Assassination":1, "Observation":1, "Size":2}, 18),
		)
		
		for data, expected in vals:
			r = operative_rules.get_cost(data).get("Materials")
			r2 = operative_rules.get_cost(**data).get("Materials")
			
			self.assertEqual(r, r2)
			self.assertEqual(expected, r)
コード例 #2
0
ファイル: operative_o.py プロジェクト: Teifion/Rob3
def operative_order(the_line, groups, debug=False):
    results = order_block.default_line_results(the_line)

    city_dict = the_line.the_world.cities()
    cities_lookup = the_line.the_world.cities_lookup(lower=True)

    operative_dict = the_line.the_world.operatives()
    operative_lookup = the_line.the_world.operatives_lookup(lower=True)

    the_team = the_line.the_world.teams()[the_line.block.team]

    # Stats
    # Stealth: 3, Observation: 4, Integration: 5, Sedition: 9, Sabotage: 8, Assassination: 3
    stats = {}
    lower_content = the_line.content.lower()
    for key, reg in stat_grep.items():
        m = reg.search(lower_content)
        if m:
            try:
                stats[key] = int(m.groups()[0])
            except Exception as e:
                print(m.groups)
                raise
        else:
            stats[key] = 0

            # DB checks
            # ------------------------
            # Can we find the building?
    if groups["name"].lower() in operative_lookup:
        # If it's ours then we can reinforce it
        if operative_dict[operative_lookup[groups["name"].lower()]].team == the_team.id:
            return reinforce_cell(the_line, {"name": groups["name"], "size": stats["Size"]})
        else:
            return order_block.fail(results, "there is already a cell by the name of '%s'" % groups["name"])

            # Can we find the city?
    if groups["city"].lower() not in cities_lookup:
        return order_block.fail(results, "there is no city by the name of '%s'" % groups["city"])
    else:
        the_city = city_dict[cities_lookup[groups["city"].lower()]]

        # Is this a dead city?
    if the_city.dead > 0:
        return order_block.fail(results, "there is no living city by the name of '%s'" % groups["city"])

        # Rule checks
        # ------------------------
    results = order_block.default_line_results(
        the_line, "%s could not be recruited at %s because" % (groups["name"], the_city.name)
    )

    # Get cost
    try:
        results["cost"] = operative_rules.get_cost(stats)
    except Exception as e:
        return order_block.fail(results, e.args[0])

        # Check affordability
    affordability = the_team.resources.affordable(results["cost"])[0]

    if not affordability:
        return order_block.fail_cost(results)

        # 	EXECUTION
        # ------------------------
        # Queries
    results["queries"].append("-- Operatives %s at %s for team:%d" % (groups["name"], the_city.name, the_team.id))
    results["queries"].extend(operative_f.recruitment_query(groups["name"], the_city.id, the_team.id, stats))

    # Apply cost
    the_team.resources -= results["cost"].discrete()

    # Result
    pstats = []
    for k, v in stats.items():
        if v > 0:
            pstats.append("%s: %s" % (k, v))
    results["results"].append(
        "%s recruited to %s with the stats of: %s" % (groups["name"], the_city.name, ", ".join(pstats))
    )

    return order_block.success(results)