예제 #1
0
def main(cursor):
	team			= int(common.get_val("team", -1))
	uname			= common.get_val("name", "")
	total_string	= common.get_val("equipment_string", "")
	
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	if uname == "":
		uname = re.search(r"^([A-Za-z' ]*)", total_string.strip()).groups()[0].strip()
		total_string = total_string.replace(uname, "")
	
	# Get the size
	size_match = re.search(r'(size: ?([0-9]*))', total_string, re.IGNORECASE)
	if size_match != None:
		size = int(size_match.groups()[1])
		temp_string = total_string.replace(size_match.groups()[0], '')
	else:
		size = 100
		temp_string = total_string
	
	# Description
	desc_match = re.search(r'(description: ?(.*))$', temp_string, re.IGNORECASE)
	if desc_match != None:
		description = desc_match.groups()[1]
		temp_string = total_string.replace(desc_match.groups()[0], '')
	else:
		description = ""
	
	# And now equipment
	e_list = equipment_f.match_equipment_from_string(cursor, temp_string)
	
	# print("")
	# print("Team: %d<br />" % team)
	# print("Unit name: %s<br />" % uname)
	# print("Equ: %s<br />" % [equipment_dict[e].name for e in e_list])
	# print("Size: %s<br />" % size)
	# print("Desc: %s<br />" % description)
	# exit()
	
	unit_f.new_unit(cursor, team, uname, description, size, e_list)
	
	# Redirect
	page_data['Redirect'] = 'list_units&team={0:d}'.format(team)
	return ""
예제 #2
0
파일: military_o.py 프로젝트: Teifion/Rob3
def new_unit_order(the_line, groups, debug=False, confirm=False):
	from checks import military_check
	
	results = order_block.default_line_results(the_line)
	
	# Handles
	unit_dict			= the_line.the_world.units()
	units_lookup		= the_line.the_world.units_lookup_from_team(the_line.block.team)
	squad_dict			= the_line.the_world.squads_from_team(the_line.block.team)
	
	equipment_dict		= the_line.the_world.equipment()
	equipment_lookup	= the_line.the_world.equipment_lookup(lower=True)
	
	the_team			= the_line.the_world.teams()[the_line.block.team]
	
	# Make sure unit does not already exist
	# _check_exists
	if groups['unit_name'].lower() in units_lookup:
		if debug:
			results['debug'].append("Failed at _check_exists")
			results['debug'].append("Exists with unit id: %d" % units_lookup[groups['unit_name'].lower()])
		return order_block.fail(results, "you already have a unit type by the name %s" % (groups['unit_name']))
	
	# Now get equipment
	equipment_list = []
	equipment_list_s = groups['item_list'].split(",")
	for e in equipment_list_s:
		els = e.lower().strip()
		if els in equipment_lookup:
			new_equipment = equipment_lookup[els]
			if equipment_dict[new_equipment].public:
				equipment_list.append(new_equipment)
	
	# Make sure we actually have equipment
	# _empty_equipment_list
	if len(equipment_list) < 1:
		if debug:
			results['debug'].append("Failed at _empty_equipment_list")
		return order_block.fail(results, "none of the equipment listed was able to be found")
	
	# Add unit info to the dictionary, only if confirming it
	if confirm:
		temp_unit = unit.Unit()
		temp_unit.name = groups['unit_name']
		temp_unit.equipment.extend(equipment_list)
		c = temp_unit.get_cost(cursor=None, the_world=the_line.the_world, equipment_dict=None, breakdown_mode=False, force_requery=False)
		
		# We need to actually add the unit + equipment
		unit_id = unit_f.new_unit(the_line.the_world.cursor, the_line.block.team, groups['unit_name'], "", 0, equipment_list)
		
		# Now to add it to the dictionaries
		unit_dict[unit_id] = unit_q.get_one_unit(the_line.the_world.cursor, unit_id)
		the_unit = unit_dict[unit_id]
		the_unit.id = unit_id
		
		units_lookup[the_unit.name.lower()] = unit_id
		
		military_check.check_available(the_line.the_world.cursor, verbose=False)
		
		equip_string = [equipment_dict[e].name for e in temp_unit.equipment]
		results['results'].append("Created new unit: %s" % temp_unit.name)
		results['results'].append("Equipment list: %s" % ", ".join(equip_string))
		results['results'].append("Cost: (%s/%s) (%s/%s)" % (
			c['material_cost'].get('Materials'),
			c['iron_cost'].get('Materials'),
			c['material_upkeep'].get('Materials'),
			c['iron_upkeep'].get('Materials'),
		))
		results['results'].append("This unit has been added successfully, even if in a Rob request")
		results['results'].append("")
		
		# Queries
		# results['queries'].append("-- Changing equipment: %s, %s: %s" % (the_unit.name, otype, groups['item_list']))
		# results['queries'].extend(unit_f.replace_equipment(the_unit.id, the_unit.equipment))
		
		return order_block.success(results)
		
	else:
		temp_unit = unit.Unit()
		temp_unit.name = groups['unit_name']
		temp_unit.equipment.extend(equipment_list)
		
		c = temp_unit.get_cost(cursor=None, the_world=the_line.the_world, equipment_dict=None, breakdown_mode=False, force_requery=False)
		
		equip_string = [equipment_dict[e].name for e in temp_unit.equipment]
		results['results'].append("Template for new unit: %s" % temp_unit.name)
		results['results'].append("Equipment list: %s" % ", ".join(equip_string))
		results['results'].append("Cost: (%s/%s) (%s/%s)" % (
			c['material_cost'].get('Materials'),
			c['iron_cost'].get('Materials'),
			c['material_upkeep'].get('Materials'),
			c['iron_upkeep'].get('Materials'),
		))
		results['results'].append("This unit has not yet been added, you must repeat this order with 'New unit' switched with 'Confirm new unit'")
		results['results'].append("")
		
		return order_block.success(results)