예제 #1
0
파일: trade_o.py 프로젝트: Teifion/Rob3
def send_spell(the_line, spell_id, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	teams_lookup	= the_line.the_world.teams_lookup(lower=True)
	
	spells_lookup	= the_line.the_world.spells_lookup()
	spell_dict		= the_line.the_world.spells()
	
	team_dict		= the_line.the_world.teams()
	
	the_team		= team_dict[the_line.block.team]
	the_spell		= spell_dict[spell_id]
	
	# Can we find the team?
	if groups['team_name'].lower() not in teams_lookup:
		return order_block.fail(results, "There is no team by the name of '%s'" % groups['team_name'])
	else:
		target_team = team_dict[teams_lookup[groups['team_name'].lower()]]
	
	# Is the item tradable?
	if not the_spell.tradable:
		return order_block.fail(results, "%s could not be sent to %s because it is not tradable" % (the_spell.name, target_team.name))
	
	# Limits of how many you can send a turn
	if the_team.research_sent >= 2:
		return order_block.fail(results, "%s could not be sent to %s because you have already sent the maximum number of spells/techs this turn" % (the_spell.name, target_team.name))
	
	# Do you have a high enough level?
	if the_team.spell_levels.get(spell_id, 0) <= target_team.spell_levels.get(spell_id, 0):
		return order_block.fail(results, "%s could not be sent to %s" % (the_spell.name, target_team.name))
	
	#	EXECUTION
	#------------------------
	# Check that there's an entry in the database for it
	if target_team.spell_levels.get(spell_id, 0) == 0:
		if target_team.spell_points.get(spell_id, 0) == 0:
			the_line.try_query(spell_f.check_row_exists(team_id=target_team.id, spell_id=the_spell.id))
	
	# Queries
	results['foreign_queries'][target_team.id] = spell_f.trade_query(target_team.id, spell_id)
	
	# Apply change to our copy of the world
	target_team.spell_levels[spell_id] = target_team.spell_levels.get(spell_id, 0) + 1
	target_team.spell_points[spell_id] = 0
	
	# Result
	results['results'].append("%s was sent to %s" % (the_spell.name, target_team.name))
	results['foreign_results'][target_team.id] = ["%s was sent from %s" % (the_spell.name, the_team.name)]
	
	# Update sending limits
	the_team.research_sent += 1
	
	return order_block.success(results)
예제 #2
0
파일: research_o.py 프로젝트: Teifion/Rob3
def research_spell(the_line, spell_id, debug=False):
	results = order_block.default_line_results(the_line)
	
	spell_dict		= the_line.the_world.spells()
	the_team		= the_line.the_world.teams()[the_line.block.team]
	the_spell		= spell_dict[spell_id]
	
	lore_name		= spell.categories[the_spell.category]
	current_level	= the_team.spell_levels.get(spell_id, 0)
	current_points	= the_team.spell_points.get(spell_id, 0)
	
	new_level		= current_level + 1
	new_points		= 0
	
	results = order_block.default_line_results(the_line, "%s could not be researched to level %s because" % (the_spell.name, current_level+1))
	
	# Level limit
	if the_spell.max_level > 0:
		if current_level >= the_spell.max_level:
			return order_block.fail(results, "%s is it's maximum level" % the_spell.max_level)
	
	# Cost, it's a bit more complicated here...
	spell_cost = spell_rules.cost_for_next_level(the_line.the_world.cursor, the_spell, current_level, completed=current_points)
	
	# If we've started it then we don't need to worry about materials
	if current_points > 0:
		spell_cost.set("Materials", 0)
	
	# Lets get some stuff here for working out partiality of research
	points_cost = spell_cost.get("%s points" % lore_name) + spell_cost.get("Spell points")
	real_points_cost = points_cost# Used for output later
	points_availiable = the_team.resources.get("%s points" % lore_name) + the_team.resources.get("Spell points")
	
	afford_result = the_team.resources.affordable(spell_cost, overbudget_list=the_team.overbudget)
	
	# We cannot afford it
	if afford_result[0]:
		# We need to apply swappables
		spell_cost = res_dict.Res_dict(afford_result[1])
		
	elif not afford_result[0]:
		# Check materials - Fail outright
		materials_cost = spell_cost.get("Materials")
		if materials_cost > the_team.resources.get("Materials"):
			if "Materials" not in the_team.overbudget:
				return order_block.fail(results, "you do not have enough materials for it")
		
		# Lets try points - Fail outright if 0 points (either spell or lore)
		if points_availiable == 0:
			return order_block.fail(results, "you do not have any more spell points availiable this turn")
		
		# At this point they cannot afford the whole spell, set cost to what's available - Fail partial
		if 0 < points_availiable < points_cost:
			
			spell_cost.set("Spell points", the_team.resources.get("Spell points"))
			spell_cost.set("%s points" % lore_name, the_team.resources.get("%s points" % lore_name))
			
			new_level		= current_level
			new_points		= current_points + points_availiable
	
	#	EXECUTION
	#------------------------
	# Check we've got a DB row ready to update
	if current_level == 0 and current_points == 0:
		the_line.try_query(spell_f.check_row_exists(team_id=the_team.id, spell_id=the_spell.id))
	
	# Tell them it's only being partially completed
	if new_level == current_level:
		result_line = "%s was researched to %s out of %s points towards level %d" % (the_spell.name, new_points, real_points_cost, new_level+1)
	
	# It's complete
	else:
		result_line	= "%s is now level %s" % (the_spell.name, new_level)
	
	# Save cost into results dictionary
	results['cost'] = spell_cost
	
	# Queries
	results['queries'].append("-- Spell research %s to %d.%d for team:%d" % (the_spell.name, new_level, new_points, the_team.id))
	results['queries'].extend(spell_f.research_query(the_team.id, spell_id, new_level, new_points))
	
	# Apply cost
	the_team.resources -= results['cost'].discrete()
	
	# Update team spell level/points
	the_team.spell_levels[the_spell.id] = new_level
	the_team.spell_points[the_spell.id] = new_points
	
	# Result
	results['results'].append(result_line)
	
	return order_block.success(results)