# -*- coding: utf8 -*-

# Copyright (c) 2006, Jonathan R. Woodworth
# Distributed under the BSD license. See LICENSE for details.

"""
Commands for playing Shadowrun, 3rd Edition.

"""

from random import randint

def roll(dice = 6, sides = 6, sort = 1, tn = None, exploding = True):
	"""
	A simple dieroller with support for TNs/success counting, result sorting 
	(use sorted = 0 for unsorted, <0 for ascending, >1 for descending (default))
	
	TN support currently broken, being restored soon.
	
	"""
	successes = None
	
	dice = (dice if dice < 250000 else 250000) # ensure Banana can handle
	
	rolls = [randint(1,sides) for die in range(dice)]
	
	if exploding and sides > 1: # avoid denial of service
		while max(rolls) % sides == 0:
			rolls = [(roll + randint(1, sides) if roll % sides == 0 else roll) 
				for roll in rolls]
	
	if sort:
		rolls.sort(reverse=(sort > 0))
	
	return rolls, dice, sides
	


exporting = {"roll" : roll,}