Пример #1
0
	def test_get_reinforce(self):
		vals = (
			(operative.Operative({"stealth":1, "integration":1, "sedition":1, "sabotage":1, "assassination":1, "observation":1, "size":1}), 1, 5),
			(operative.Operative({"stealth":1, "integration":1, "sedition":1, "sabotage":1, "assassination":1, "observation":1, "size":1}), 5, 25),
			(operative.Operative({"stealth":5, "integration":1, "sedition":1, "sabotage":1, "assassination":1, "observation":1, "size":1}), 1, 9),
		)
		
		for the_op, amount, expected in vals:
			r = operative_rules.get_reinforce_cost(the_op, amount).get("Materials")
			self.assertEqual(expected, r)
Пример #2
0
def reinforce_cell(the_line, groups, debug=False):
    results = order_block.default_line_results(the_line)

    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]

    # DB checks
    # ------------------------
    # Can we find the building?
    if groups["name"].lower() not in operative_lookup:
        return order_block.fail(results, "there is no cell by the name of '%s'" % groups["name"])

    the_op = operative_dict[operative_lookup[groups["name"].lower()]]

    # If it's ours then we can reinforce it
    if the_op.team != the_team.id:
        return order_block.fail(results, "the cell named '%s' is not yours" % groups["name"])

    amount = int(groups["size"])

    # Get cost
    try:
        results["cost"] = operative_rules.get_reinforce_cost(the_op, amount)
    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 reinforce by %s for team:%d" % (groups["name"], amount, the_team.id))
    results["queries"].extend(operative_f.reinforce_query(the_op.id, amount))

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

    # Results
    results["results"].append("%s reinforced by %d" % (groups["name"], amount))

    return order_block.success(results)