## a vs die roller as used by Exalted games 
#!/usr/bin/env python
# Copyright (C) 2000-2001 The OpenRPG Project
#
#   openrpg-dev@lists.sourceforge.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# --
#
# File: exalt.py
# Author: OpenRPG Dev Team
# Maintainer:
# Version:
#   $Id: exalt.py,v 1.3 2002/06/10 01:12:35 markt1964 Exp $
#
# Description: Exalted die roller 
#
from die import *

__version__ = "$Id: exalt.py,v 1.3 2002/06/10 01:12:35 markt1964 Exp $"

          
class exalt(std):
    def __init__(self,source=[]):
        std.__init__(self,source)
    
    def dmg(self):
        return exaltdmg(self)
        
    def test(self):
        return exalttest(self)
           
        
class exalttest(std):
    def __init__(self,source=[]):
        std.__init__(self,source)
        
    def __str__(self):
        if len(self.data) > 0:
            myStr = "[" + str(self.data[0])
            for a in self.data[1:]:
                myStr += ","
                myStr += str(a)
            r = self.sum()
            if r > 1:
                myStr += "] = <b>" + str(r) + "</b> Successes"
            elif r == 1:
                myStr += "] = <b>" + str(r) + "</b> Success"
            elif r == 0:
                myStr += "] = <b>Failure</b>"
            else:
                myStr += "] = <b>Botch</b>"
        else:
            myStr = "[] = (0)"

        return myStr
        
    def sum(self):
        rolls = []
        s = 0
        f = 0
        for a in self.data:
            rolls.extend(a.gethistory())           
        for r in rolls:
            if r == 10:
                s += 2;
            elif r >= 7:
                s += 1
            elif r == 1:
                f += 1
        if s == 0 and f > 0:
            return -f
        
        return s

class exaltdmg(std):
    def __init__(self,source=[]):
        std.__init__(self,source)
     
    def __str__(self):
        if len(self.data) > 0:
            myStr = "[" + str(self.data[0])
            for a in self.data[1:]:
                myStr += ","
                myStr += str(a)
            r = self.sum()
            if r >= 0:
                myStr += "] = Damage <b>" + str(r) + "</b>"
        else:
            myStr = "[] = (0)"

        return myStr

    def sum(self):
        rolls = []
        s = 0
        for a in self.data:
            rolls.extend(a.gethistory())
        
        for r in rolls:
            if r >= 7:
                s += 1
        
        return s
