Ejemplo n.º 1
0
def rules_class_create (request):
	form_data = h.ignore_request_params_fields(request.POST)
	form = forms.CharacterClass(form_data)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	char_class = models.CharacterClass()
	char_class.rules_id = form.rules_id.data
	char_class.title = form.title.data
	char_class.skills = {}

	if form.skills.data:
		class_skills = {}

		for skill in form.skills.data:
			skill_id = skill['skill_id'] # TODO: Title?
			mod = skill['mod']

			class_skills[skill_id] = mod

		char_class.skills = class_skills

	char_class.add()
	DBSession.flush()

	return {'success': True, 'result': char_class.as_dict()}
Ejemplo n.º 2
0
def rules_race_create (request):
	form_data = h.ignore_request_params_fields(request.POST)
	form = forms.Race(form_data)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	race = models.Race()
	race.rules_id = form.rules_id.data
	race.title = form.title.data
	race.skills = {}

	if form.skills.data:
		race_skills = {}

		for skill in form.skills.data:
			skill_id = skill['skill_id']
			mod = skill['mod']

			race_skills[skill_id] = mod

		race.skills = race_skills

	race.add()
	DBSession.flush()

	return {'success': True, 'result': race.as_dict()}
Ejemplo n.º 3
0
def rules_perk_create (request):
	form_data = h.ignore_request_params_fields(request.POST)
	form = forms.Perk(form_data)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	perk = models.Perk()
	perk.rules_id = form.rules_id.data
	perk.title = form.title.data
	perk.description = form.description.data

	if form.skills.data:
		perk_skills = perk.skills or {}

		for skill in form.skills.data:
			skill_id = skill['skill_id'] # TODO: Title?
			mod = skill['mod']

			perk_skills[skill_id] = mod

		perk.skills = perk_skills

	perk.add()
	DBSession.flush()

	return {'success': True, 'perk_id': perk.id}
Ejemplo n.º 4
0
def create (request):
	form_data = h.update_request_params(request.matchdict)
	form = forms.CreateGameSession(form_data)
	if not form.validate():
		return HTTPBadRequest()

	user = request.user

	session = models.GameSession()
	form.populate_obj(session)
	session.board_image = ""
	session.status = constants.GameSessionStatuses.AVAILABLE

	session.add()

	character = models.SessionCharacter()
	character.user_id = user.id
	character.user_role = constants.SessionCharacterRoles.MASTER
	character.name = user.nickname
	character.game_session = session
	character.token = hashlib.sha256('{0}{1}{2}'.format(user.id, time.time(), random.randint(0, 1000))).hexdigest()
	character.add()

	DBSession.flush()

	return HTTPFound(location = request.route_url('play', game_session_id = session.id))
Ejemplo n.º 5
0
def rules_skills_category_create (request):
	form = forms.SkillCategory(request.POST)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	category = models.SkillCategory()
	form.populate_obj(category)
	category.add()
	DBSession.flush()

	return {'success': True, 'result': category.as_dict()}
Ejemplo n.º 6
0
def rules_item_group_create (request):
	form = forms.ItemGroup(request.POST)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	ig = models.ItemGroup()
	form.populate_obj(ig)
	ig.add()
	DBSession.flush()

	return {'success': True, 'result': ig.as_dict()}
Ejemplo n.º 7
0
def rules_dices_choose (request):
	form = forms.AddDices(request.POST)
	if not form.validate():
		return form.errors

	dices = form.dice_id.data
	rules_id = form.rules_id.data

	rules = models.GameRules.query.get(rules_id)
	if not rules:
		request.response.status = 422
		return {'success': False}

	rules.dices = dices
	rules.add()
	DBSession.flush()

	return {'success': True}
Ejemplo n.º 8
0
def rules_character_levels (request):
	form = forms.CharacterLevels(request.POST)
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	rules = models.GameRules.query.get(rules_id)
	if not rules:
		request.response.status = 422
		return {'success': False}

	levels = []
	for lvl, level_settings in enumerate(form.level_settings.data):
		if level_settings['xp'] is None:
			break

		levels.append({
			'level': lvl + 1,
			'xp': level_settings['xp'],
			# 'perks_formula': level_settings['perks_formula'],
		})

	for skills_category_formula in form.skills_categories_formulas.data:
		level = skills_category_formula['level']
		if len(levels) > level:
			continue

		category_id = skills_category_formula['category_id']
		formula = skills_category_formula['formula']

		level_settings = levels[level - 1]
		level_settings.setdefault('skills_categories_formulas', {})
		level_settings['skills_categories_formulas'][category_id] = formula

		# TODO: Could i-th element of list "levels" sets up a level differs from i-th?
		# For example: [{...}, {...}, {'level': 500, ...}, {...}]
		# The 3rd element is for 500th level

	rules.level_settings = levels
	rules.add()
	DBSession.flush()

	return {'success': True}
Ejemplo n.º 9
0
def rules_skill_create (request):
	form = forms.Skill(request.POST)
	form.category.choices = [(None, 'No category')] + [(category.id, category.title) for category in models.SkillCategory.query.filter_by(rules_id = form.rules_id.data)]

	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	skill = models.Skill()
	skill.is_disabled = False # TODO: Convert skill names to IDs?
	skill.category_id = form.category.data
	form.populate_obj(skill)
	skill.add()
	DBSession.flush()

	return {'success': True, 'result': skill.as_dict()}
Ejemplo n.º 10
0
def rules_item_create (request):
	rules = models.GameRules.query.get(int(request.POST.get('rules_id', -1)))
	if not rules:
		request.response.status = 422
		return {'success': False}

	form = forms.ItemCreate(request.POST)
	form.group_id.choices = [(ig.id, ig.title) for ig in rules.item_groups]
	if not form.validate():
		return form.errors

	rules_id = form.rules_id.data
	if not request.user.owned_rules(rules_id):
		request.response.status = 403
		return {'success': False}

	item = models.Item()
	item.title = form.title.data
	item.rules_id = form.rules_id.data
	item.group_id = form.group_id.data

	attrs = {}
	attrs['slots_consumed'] = form.slots_consumed.data
	item.attrs = attrs

	item.skills = {}
	if form.skills.data:
		item_skills = {}

		for skill in form.skills.data:
			skill_id = skill['skill_id']
			mod = skill['mod']

			item_skills[skill_id] = mod

		item.skills = item_skills

	item.add()
	DBSession.flush()

	return {'success': True, 'result': item.as_dict()}