view orpg/dieroller/rollers/alternity.py @ 184:dcae32e219f1 beta

Traipse Beta 'OpenRPG' {100117-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Dieroller structure from Core New DieRoller portability for odd Dice Added 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) Fixes: Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Modified ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Sun, 17 Jan 2010 21:37:34 -0600
parents ff48c2741fe7
children 24d59375aac9
line wrap: on
line source

# (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: Alternity.py
# Version:
#   $Id: Alternity.py,v .1 JEC (cchriss@thecastle.com)
#
# Description: Alternity die roller based on Posterboy's D20 Dieroller
#
# Changelog:
#
# v.1 original release JEC
#
# Traipse Release: 
# The changes made in the Traipe release are intended to create a more direct connection
# between the source and the intrepretor. IF, ELIF statements have been replaced with dictionaries,
# unused objects have been replace with re-usable objects, and the code has been condensed.

import re
from std import std
from time import time, clock
from orpg.dieroller.base import di, die_base, die_rollers

__version__ = "$Id: alternity.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"

# Alternity stands for "Alternity system" 20 sided die plus mods

class alternity(std):
    name = "alternity" # ADDED by SEG Nov 2009 ***
    
    def __init__(self,source=[]):
        std.__init__(self,source)

    def sk(self,score,mod):
      return sk(self,score,mod)

    def at(self,score,mod,dmgo,dmgg,dmga):
      return at(self,score,mod,dmgo,dmgg,dmga)

die_rollers.register(alternity)

class sk(std):
    def __init__(self,source=[],sc="10/5/2",mod=0):
        std.__init__(self,source)
        m = re.match( r"\d+", str(sc) )
        self.score = int( m.group(0) )
        self.mod = mod

    def getMod(self,mod=0):
        m=0
        mods = { -4: -di(12), -3: -di(8), -2:  -di(6), -1: -di(4), 1: -di(4),
                2: di(6), 3: di(8), 4: di(12), 5: di(20)}
        if mod in mods.keys(): m = mods[mod].value
        elif mod <= -5: m=-di(20).value
        elif mod == 6:  m=di(20).value + di(20).value
        elif mod >= 7:  m=di(20).value + di(20).value + di(20).value
        return m

    def getRolLStr(self):
        myStr = "[" + str(self.data[0])
        self.d20 = self.sum()
        amod = self.getMod(self.mod)
        self.dieRoll = self.d20 + amod
        for a in self.data[1:]:
            myStr += ","
            myStr += str(a)
        myStr += "," + str(amod) + "] = (" + str(self.dieRoll) + ")"
        if ( self.d20 == 1 ): self.success = 'CS'
        if ( self.dieRoll <= self.score / 4 ): self.success = 'A'
        elif ( self.dieRoll <= self.score / 2 ): self.success = 'G'
        elif ( self.dieRoll <= self.score ): self.success = 'O'
        else: self.success = 'F'
        if ( self.d20 == 20 ): self.success = 'CF'
        return myStr

    def __str__(self):
        myStr = self.getRolLStr()
        successes = {'CS': " <b><font color='#00aa00'>CRITICAL SUCCESS</font></b>",
                    'CF': " <b><font color='#ff0000'>CRITICAL FAILURE</font></b>",
                    'A': " <b>AMAZING Success</b>",
                    'G': " <b>Good Success</b>",
                    'O': " <b>Ordinary Success</b>",
                    'F': " <b>failure</b>"}
        myStr += successes[self.success]
        return myStr

class at(sk):
    ## Traipse Usage: The source I received had the damage rolls like this 1d6s, with the damage type a
    ## letter that could be sliced from the roll. However, the roll is parsed before the letter can be
    ## sliced from it, and with the letter attached it created an error.
    ##
    ## The Traipse method puts the damage type and the damage roll into a Tuple, ie (1d6, 's').
    ## When uing this method you must include single or double quoutes around the damage type or the
    ## software will treat it as an object.
    def __init__(self,source=[],sc=10, mod=0, dmgo="(1d6, 's')",dmgg="(1d6, 'w')",dmga="(1d6, 'm')"):
        sk.__init__(self,source,sc,mod)
        self.dmgo = dmgo
        self.dmgg = dmgg
        self.dmga = dmga

    def getdmg(self,dmgroll):
        astr = "===> Damage "
        droll = str(dmgroll[0])
        dtype = dmgroll[1]
        astr += droll
        if dtype=="s": astr += " stun"
        elif dtype=="w": astr += " wound"
        elif dtype=="m":astr += " mortal"
        return astr

    def __str__(self):
        myStr = self.getRolLStr()
        successes = {'CS': " <b><font color='#00aa00'>CRITICAL SUCCESS</font></b>",
                    'CF': " <b><font color='#ff0000'>CRITICAL FAILURE</font></b>",
                    'A': " <b><font color='#00aa00'>AMAZING HIT</font></b> ",
                    'G': " <b>Good HIT</b> ",
                    'O': " <b>Ordinary HIT</b> ",
                    'F': " <b>miss</b>"}
        myStr += successes[self.success]
        if self.success == 'A': myStr += self.getdmg(self.dmga)
        elif self.success == 'G': myStr += self.getdmg(self.dmgg)
        elif self.success == 'O': myStr += self.getdmg(self.dmgo)
        return myStr