Пример #1
0
	def test_filter(self):
		data = pages.get_plaintext(self.cursor, "test", "test", "public")
		self.assertEqual(data, "Summary\nSummary text\n\nDescription\nDescription text and more")
		
		data = pages.get_plaintext(self.cursor, "test", "test", "secret")
		self.assertEqual(data, "Summary\nSummary text\n\nDescription\nDescription text and more\n\n\nSecret info")
		
		data = pages.get_plaintext(self.cursor, "test", "test", "gm")
		self.assertEqual(data, "Summary\nSummary text\n\nDescription\nDescription text and more\n\n\nSecret info\n\nGm_notes\nGM info")
Пример #2
0
def get_lore(options):
	from data_classes import lore_entry
	from lore import pages
	
	if len(sys.argv) < 3:
		print("Usage: $rob lore <cat> <page> <type:html/bbcode/plain>")
		exit()
	
	cursor = database.get_cursor()
	
	try:
		category = sys.argv[2]
		page = sys.argv[3]
		
		if len(sys.argv) > 4:
			formatting = sys.argv[4]
		else:
			formatting = "plaintext"
		
		if len(sys.argv) > 5:
			level = sys.argv[5].lower()
		else:
			level = "public"
	except Exception as e:
		raise
	
	if formatting == "html":
		print(pages.get_html(cursor, category, page, level))
	elif formatting == "bbcode":
		print(pages.get_bbcode(cursor, category, page, level))
	elif formatting == "plain" or formatting == "plaintext":
		print(pages.get_plaintext(cursor, category, page, level))
Пример #3
0
	def interactive_setup(self, cursor):
		map_area, target, men, budget, army = None, None, None, None, None
		temp_lines = self.content.split("\n")
		content = []
		
		monster_lookup	= self.the_world.monsters_lookup(lower=True)
		army_lookup		= self.the_world.armies_lookup_from_team(self.team)
		
		# Block matching
		i = 0
		while i < len(temp_lines):
			found = False
			for g, regex in self.greps.items():
				r = regex.search(temp_lines[i])
				
				if r != None:
					found = True
					
					if g == "map_area":	map_area = (int(r.groups()[0]), int(r.groups()[1]))
					elif g == "target":	target = r.groups()[0]
					elif g == "men":	men = int(r.groups()[0])
					elif g == "budget":	budget = float(r.groups()[0])
					elif g == "army":	army = r.groups()[0]
			
			# Strip this line and look at the next
			if found:
				del(temp_lines[i])
				continue
			
			# No match, must be part of the main content
			content.append(temp_lines[i])
			i += 1
		
		# Show this as an integer if possible
		if budget == int(budget): budget = int(budget)
		
		monster_id = monster_lookup[target.lower()]
		the_monster = self.the_world.monsters()[monster_id]
		
		army_id = army_lookup[army.lower()]
		the_army = self.the_world.armies()[army_id]
		
		# Apply multiplier for man count
		multiplier = 1
		# multiplier = (men - the_monster.min_men)/(the_monster.max_men - the_monster.min_men)
		# multiplier = min(1, max(multiplier, 0))
		
		multiplier *= (budget - the_monster.min_budget)/(the_monster.max_budget - the_monster.min_budget)
		multiplier = min(1, max(multiplier, 0))
		
		self.interactivity['multiplier'] = multiplier
		
		# Make sure they have monsters in this army
		self.try_query(monster_f.check_row_exists(army_id=the_army.id, monster_id=the_monster.id))
		
		# Query producing function
		self.interactivity['query_func'] = """
		amount = parseInt(score/100 * {amount});
		return "UPDATE army_monsters SET amount = amount + " + amount + " WHERE army = {army_id} AND monster = {monster_id};" +
		"\\nUPDATE team_resources SET amount = amount - {budget} WHERE team = {team} AND resource = {materials};";
		""".format(
			army_id = the_army.id,
			monster_id = the_monster.id,
			amount = the_monster.max_amount,
			budget = budget,
			team = self.team,
			materials = resource_list.data_dict_n['Materials'],
		)
		
		self.interactivity['result_func'] = """
		amount = parseInt(score/100 * {amount});
		if (amount < 1)
		{{
			return "[o]{title}[/o]\\nYou captured no {monster}s";
		}}
		else
		{{
			if (amount > 1)
			{{
				return "[o]{title}[/o]\\nYou captured " + amount + " {monster}s";
			}}
			else
			{{
				return "[o]{title}[/o]\\nYou captured 1 {monster}";
			}}
		}}
		""".format(
			army_id = the_army.id,
			monster_id = the_monster.id,
			monster = the_monster.name,
			amount = the_monster.max_amount,
			title = self.title_name,
		)
		
		# General info about the order context
		self.interactivity['pre_calculations'] = """
		Monster: <a href="web.py?mode=lore&amp;cat=monsters&page={monster_l}">{monster}</a>,
		Terrain: {terrain},
		Men: {men},
		Budget: {budget},
		Army: <a href="web.py?mode=edit_army&amp;army={army_id}">{army}</a>
		""".format(
			monster = target,
			monster_l = target.lower(),
			terrain = map_data.terrain[mapper_q.get_terrain(cursor, map_area[0], map_area[1])],
			men = ('<span class="neg" style="font-weight:bold;">%s</span>' % men if men < the_monster.min_men else men),
			budget = ('<span class="neg" style="font-weight:bold;">%s</span>' % budget if budget < the_monster.min_budget else budget),
			army = the_army.name,
			army_id = the_army.id,
		)
		
		self.interactivity['content'] = "<br />".join(content)
		self.interactivity['points'] = pages.get_plaintext(cursor, "monsters", "karithor", "gm", ['capture_points']).split("\n")
Пример #4
0
	def test_plaintext(self):
		data = pages.get_plaintext(self.cursor, "test", "test", "public")
		self.assertEqual(data, "Summary\nSummary text\n\nDescription\nDescription text and more")