Advertisement
TorroesPrime

Untitled

Mar 1st, 2022
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.11 KB | None | 0 0
  1. import random
  2. import math
  3. from tools import addSpacing
  4. class ScreenPrinter:
  5.     screenWidth = 100
  6.     printSpace = screenWidth-2
  7.     def printFullCharacterSheet(self,CharacterData):
  8.         '''prints a full character sheet'''
  9.         #coreCharacteristics = self.getCoreCharacteristics(CharacterData)
  10.         self.getReportHeading(CharacterData)
  11.     def getCoreCharacteristics(self,CharacterData):
  12.         '''takes the assembled characterData and extracts the character core characterists.'''
  13.         CoreCharacteristics = {"WS":CharacterData['WS'],"BS":CharacterData['BS'],\
  14.             'Strength':CharacterData['Strength'],'Toughness':CharacterData['Toughness'],\
  15.             'Agility':CharacterData['Agility'],'Intelligence':CharacterData['Intelligence'],\
  16.             'Perception':CharacterData['Perception'],'WP':CharacterData['WP'],'Fell':CharacterData['Fell']
  17.         }
  18.         return CoreCharacteristics
  19.     def getReportHeading(self,CharacterData,title="Torroes Prime's Text Adventure System"):
  20.         report = [self.getBarHead(),
  21.         self.getPageTitle(title),
  22.         self.getTwoColumn(44),
  23.         self.getCharacterNameAndClassLine(CharacterData["name"],CharacterData["class"]),
  24.         self.getTwoColumn(49),
  25.         self.getTotalXpEarned(999999999),
  26.         self.getThreeColumn(49,19),
  27.         self.getCoreCharacteristicsChartHeaderAndWoundsLine(CharacterData["cWounds"],CharacterData["tWounds"]),
  28.         self.getCoreCharacteristisAndCurrentFatique(self.getCoreCharacteristicsLine(CharacterData),CharacterData["fatique"]),
  29.         self.getTwoColumn(55),
  30.         self.getPresentDamageAndCarriedWeightChartHeaders()]
  31.         for item in report:
  32.             print(item)
  33.     def getBarHead(self):
  34.         '''prints a report head line '+----+' number of '-' determined by screenWidth '''
  35.         space = ScreenPrinter.printSpace
  36.         output = "+"+("-"*space)+"+"
  37.         return output
  38.     def getPageTitle(self, title="Torroes Prime's Text Adventure System"):
  39.         '''prints report title'''
  40.         space = ScreenPrinter.printSpace - len(title)
  41.         return "|"+addSpacing(title,ScreenPrinter.printSpace,2)+"|"
  42.     def getTwoColumn(self,firstColumnWidth = 25):
  43.         '''prints a 2 column header. if a firstColumnWidth is not supplied, default width is 25 spaces'''
  44.         rightColumnSpace = ScreenPrinter.printSpace-firstColumnWidth-1
  45.         return "+"+("-"*firstColumnWidth)+"+"+("-"*rightColumnSpace)+"+"
  46.     def getThreeColumn(self,firstColumnWidth = 25,secondColumnWidth=25):
  47.         '''prints a 3 column header. if a firstColumnWidth/secondColumnWidth is not supplied, default width is 25 spaces'''
  48.         output = "+"+("-"*firstColumnWidth)+"+"+("-"*secondColumnWidth)+"+"+\
  49.             ("-"*(ScreenPrinter.printSpace - firstColumnWidth-secondColumnWidth-2))+"+"
  50.         return output
  51.     def getCharacterName(self,name="Test Name"):
  52.         return "| Character Name: "+addSpacing(name,26)+" |"
  53.     def getCharacterClass(self,charClass = "Test Class"):
  54.         return " Class: "+addSpacing(charClass,44)+" |"
  55.     def getCharacterNameAndClassLine(self,name,charClass):
  56.         return self.getCharacterName(name)+self.getCharacterClass(charClass)
  57.     def getCoreCharacteristicsAndTotalXpLine(self):
  58.         '''supplies the '|              Core Characteristics               | Total XP Earned: ' section'''
  59.         return "|              Core Characteristics               | Total XP Earned: "
  60.     def getTotalXpEarned(self,xpEarned):
  61.         if isinstance(xpEarned,int) is True:
  62.             xp = "{:,}".format(int(xpEarned))
  63.         output = self.getCoreCharacteristicsAndTotalXpLine() + addSpacing(xp,29,)+" |"
  64.         return output
  65.     def getCoreCharacteristicsTableHeader(self):
  66.         ''' supplies core characteristics chart header'''
  67.         return "| WS | BS | Str | Tgh | Ag | Int | Per | WP | Chr "
  68.     def getTotalWoundsHeader(self):
  69.         '''supplies '| Total Wounds: \''''
  70.         return "| Total Wounds: "
  71.     def getCurrentWoundsHeader(self):
  72.         '''supplies '| Current Wounds: \''''
  73.         return "| Current Wounds: "
  74.     def getWounds(self,current,total):
  75.         '''constructs total wounds and Current wounds section of character sheet'''
  76.         totalWounds = self.getTotalWoundsHeader()+addSpacing(total,3)+" "
  77.         currentWound = self.getCurrentWoundsHeader()+addSpacing(current,9)+" "
  78.         output = totalWounds+currentWound+" |"
  79.         return output
  80.     def getTotalWounds(self,totalWounds):
  81.         '''constructs the totalWounds section of character sheet'''
  82.         output = self.getTotalWoundsHeader()+addSpacing(totalWounds,3)+" |"
  83.         return output
  84.     def getCurrentWounds(self,CurrentWounds):
  85.         '''constructs the current Wounds section of character sheet'''
  86.         output = self.getCurrentWoundsHeader()+addSpacing(CurrentWounds,9)
  87.         return output
  88.     def getCoreCharacteristicsChartHeaderAndWoundsLine(self,current,total):
  89.         ''' constructs the characteristics chart header and wounds sections as a single line'''
  90.         output = self.getCoreCharacteristicsTableHeader()+\
  91.         self.getWounds(current,total)
  92.         return output
  93.     def getPresentDamageChartHeader(self):
  94.         '''supplies 'Present damage' header for character sheet'''
  95.         return "| "+addSpacing("Present Damage:",53,2)+" "
  96.     def getCurrentCarriesWeightHeader(self):
  97.         ''' suppleis the "Current Carried Weight" chart header for character sheet'''
  98.         return "| "+addSpacing("Current Carried Weight",40,2)+" |"
  99.     def getPresentDamageAndCarriedWeightChartHeaders(self):
  100.         '''supplies the present damage header and current carried weight header as a single line'''
  101.         return self.getPresentDamageChartHeader()+self.getCurrentCarriesWeightHeader()
  102.     def getCoreCharacteristicsLine(self,chars):
  103.         ''' supplies the core characteristics for output'''
  104.         ws = "| "+addSpacing(chars[character.ListOfCharacteristics[0]],3,2)
  105.         bs = "| "+addSpacing(chars[character.ListOfCharacteristics[1]],3,2)
  106.         strength = "| "+addSpacing(chars[character.ListOfCharacteristics[2]],4,2)
  107.         tgh = "| "+addSpacing(chars[character.ListOfCharacteristics[3]],4,2)
  108.         ag = "| "+addSpacing(chars[character.ListOfCharacteristics[4]],3,2)
  109.         intel = "| "+addSpacing(chars[character.ListOfCharacteristics[5]],4,2)
  110.         per = "| "+addSpacing(chars[character.ListOfCharacteristics[6]],4,2)
  111.         wp = "|"+addSpacing(chars[character.ListOfCharacteristics[7]],3,2)
  112.         fel ="| "+addSpacing(chars[character.ListOfCharacteristics[8]],4,2)
  113.         return ws+bs+strength+tgh+ag+intel+per+wp+fel+" |"
  114.     def getCurrentFatigue(self,fatigue):
  115.         ''' supplies the current fatigue for the character sheet'''
  116.         return "             Current Fatigue: "+addSpacing(fatigue,17)+" |"
  117.     def getCoreCharacteristisAndCurrentFatique(self,chars,fatigue):
  118.         '''constructs core characteristis and current fatigue as a single line'''
  119.         return self.getCoreCharacteristicsLine(chars)+self.getCurrentFatigue(999)
  120.     def getPresentDamageHeader(self):
  121.         '''provides the table header for damage'''
  122.         return "|  Head  | Torso | L. Arm | R. Arm | L. Leg | R. Leg |"
  123.    
  124. class character:
  125.     ListOfCharacteristics = ["WS","BS","Strength","Toughness","Agility","Intelligence","Perception","WP","Fell"]
  126.     ListOfCharacteristicNames = ["Weapon Skill","Ballistic SKill","Strength","Toughness","Agility","Intelligence","Perception","Will PowerP","Fellowship"]
  127.     def __init__(self,**kwargs):
  128.         self.fName = kwargs.get("fName","TESTfName")
  129.         self.lName = kwargs.get("lName","")
  130.         self.name = ""
  131.         self.characteristics ={
  132.             character.ListOfCharacteristics[0]:kwargs.get(character.ListOfCharacteristics[0],character.generateCharacteristic(0)),
  133.             character.ListOfCharacteristics[1]:kwargs.get(character.ListOfCharacteristics[1],character.generateCharacteristic(0)),
  134.             character.ListOfCharacteristics[2]:kwargs.get(character.ListOfCharacteristics[2],character.generateCharacteristic(0)),
  135.             character.ListOfCharacteristics[3]:kwargs.get(character.ListOfCharacteristics[3],character.generateCharacteristic(0)),
  136.             character.ListOfCharacteristics[4]:kwargs.get(character.ListOfCharacteristics[4],character.generateCharacteristic(0)),
  137.             character.ListOfCharacteristics[5]:kwargs.get(character.ListOfCharacteristics[5],character.generateCharacteristic(0)),
  138.             character.ListOfCharacteristics[6]:kwargs.get(character.ListOfCharacteristics[6],character.generateCharacteristic(0)),
  139.             character.ListOfCharacteristics[7]:kwargs.get(character.ListOfCharacteristics[7],character.generateCharacteristic(0)),
  140.             character.ListOfCharacteristics[8]:kwargs.get(character.ListOfCharacteristics[8],character.generateCharacteristic(0)),
  141.         }
  142.         self.charClass = "TEST CLASS"
  143.         self.totalWounds = kwargs.get("tWounds",10)
  144.         self.currentWounds = kwargs.get("cWounds",0)
  145.         self.fatique = 0
  146.         self.expierencePoints = 0
  147.         self.experienceToSpend = 0
  148.         self.skills = []
  149.         self.traits = []
  150.         self.talents = []
  151.         self.bonus = []
  152.         self.affinity = {}
  153.         self.bodyParts = {
  154.             "head":"notDamaged",
  155.             "torso":"notDamaged",
  156.             "left arm":"notDamaged",
  157.             "right arm":"notDamaged",
  158.             "left leg":"notDamaged",
  159.             "right leg":"notDamaged"
  160.         }
  161.         self.armor = {
  162.             "head":"notArmored",
  163.             "head":"notArmored",
  164.             "torso":"notArmored",
  165.             "left arm":"notArmored",
  166.             "right arm":"notArmored",
  167.             "left leg":"notArmored",
  168.             "right leg":"notArmored"
  169.         }
  170.         self.armaments = {
  171.             "head":"unArmed",
  172.             "right fore-arm":"unArmed",
  173.             "rigth hand":"unArmed",
  174.             "left fore-arm":"unArmed",
  175.             "left hand":"unArmed",
  176.             "rifle":"unArmed",
  177.             "hold out slot 1":"unArmed",
  178.         }
  179.     def getCharacterData(self):
  180.         '''compiles character data for use in output functions'''
  181.         charData = {"name":self.getFullName(),"class":self.charClass}
  182.         for item in character.ListOfCharacteristics:
  183.             charData.update({item:self.getCharacteristicByName(item)})
  184.         charData.update({"cWounds":self.getCurrentWounds()})
  185.         charData.update({"tWounds":self.getTotalWounds()})
  186.         charData.update({"xp":self.expierencePoints})
  187.         charData.update({"fatique":self.fatique})
  188.         return charData
  189.     def getTotalWounds(self):
  190.         '''returns character's total wounds'''
  191.         return self.totalWounds
  192.     def getCurrentWounds(self):
  193.         '''returns character's current wounds'''
  194.         return self.currentWounds
  195.     def getTotalXP(self):
  196.         '''returns character's expierence.'''
  197.         return self.expierencePoints
  198.     def generateCharacteristic(bonus=0):
  199.         '''generates 1 core characteristic, an int between 0 and 20 and applies any supplied bonus'''
  200.         return random.randint(2,20)+bonus
  201.     def setFullName(self):
  202.         '''sets character's full name by combining first name and lat name'''
  203.         self.name = self.fName+" "+self.lName
  204.     def getFirstName(self):
  205.         '''returns character first name'''
  206.         name = self.name.split()
  207.         return name[0]
  208.     def getFullName(self):
  209.         '''returns a combination of characters first name and last name'''
  210.         return self.fName+" "+self.lName
  211.     def getCharacteristicByName(self,name):
  212.         '''returns characteristic value by supplied name'''
  213.         try:
  214.             return self.characteristics[name]
  215.         except KeyError:
  216.             print(f"no characteristic '{name}' found.")  
  217.     def setCharacteristicByName(self,name,valueToMod):
  218.         '''modifies a selected characteristic by a supplied value. raises KeyError is characteristic name is not found.'''
  219.         try:
  220.             self.characteristics[name] += valueToMod
  221.             print(f"{self.getFullName()}'s {name} has been modded by {valueToMod}.")
  222.         except KeyError:
  223.             print(f"no characteristic '{name}' found.")
  224.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement