Advertisement
Kovitikus

F-Strings inside Dictionaries Erroring

Aug 15th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.88 KB | None | 0 0
  1. # GAME'S OUTPUT WITH TRACEBACKS
  2. https://i.imgur.com/rBSpTAj.png
  3. '''
  4. Server restart initiated ...
  5. ... Server restarted.
  6. [Success: 16 Roll: 21] Using the center of a quarterstave as a fulcrum, you swat at dum with one end
  7. of the weapon, It suffers a small bruise to its head.
  8. dum has 80 health remaining!
  9. You are no longer busy.
  10. Traceback (most recent call last):
  11.  File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  12.    ret = cmd.func()
  13.  File ".\commands\combat_cmds.py", line 71, in func
  14.    self.caller.combat.attack(target, damage_type, 'staves', 'swat')
  15.  File "d:\muddev\hecate\world\combat_handler.py", line 131, in attack
  16.    attacker_desc, target_desc, others_desc = build_skill_str.create_attack_desc(attacker, target,
  17. skillset, skill, damage_type, damage_tier, body_part, hit)
  18.  File "d:\muddev\hecate\world\build_skill_str.py", line 29, in create_attack_desc
  19.    skillsets = {'staves': {'leg sweep': {'attack_desc': {'attacker': f"You sweep your {weapon} at
  20. {t_name}\'s legs, {a_outcome}.",
  21. UnboundLocalError: local variable 'a_outcome' referenced before assignment
  22.  
  23. An untrapped error occurred.
  24. (Traceback was logged 19-08-15 07:53:47-04).
  25. [Success: 16 Roll: 78] Using the center of a quarterstave as a fulcrum, you swat at dum with one end
  26. of the weapon, It suffers a small bruise to its head.
  27. dum has 60 health remaining!
  28. You are no longer busy.
  29. [Success: 16 Roll: 18] Using the center of a quarterstave as a fulcrum, you swat at dum with one end
  30. of the weapon, It suffers a small bruise to its head.
  31. dum has 40 health remaining!
  32. You are no longer busy.
  33. Traceback (most recent call last):
  34.  File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  35.    ret = cmd.func()
  36.  File ".\commands\combat_cmds.py", line 71, in func
  37.    self.caller.combat.attack(target, damage_type, 'staves', 'swat')
  38.  File "d:\muddev\hecate\world\combat_handler.py", line 131, in attack
  39.    attacker_desc, target_desc, others_desc = build_skill_str.create_attack_desc(attacker, target,
  40. skillset, skill, damage_type, damage_tier, body_part, hit)
  41.  File "d:\muddev\hecate\world\build_skill_str.py", line 29, in create_attack_desc
  42.    skillsets = {'staves': {'leg sweep': {'attack_desc': {'attacker': f"You sweep your {weapon} at
  43. {t_name}\'s legs, {a_outcome}.",
  44. UnboundLocalError: local variable 'a_outcome' referenced before assignment
  45.  
  46. An untrapped error occurred.
  47. (Traceback was logged 19-08-15 07:55:20-04).
  48. '''
  49.  
  50. # CREATE ATTACK DESCRIPTION MODULE
  51. from world import generic_str
  52.  
  53. article = generic_str.article
  54. pronoun = generic_str.pronoun
  55.  
  56. def create_attack_desc(attacker, target, skillset, skill, damage_type, damage_tier, body_part, hit):
  57.     # Temp Values
  58.     weapon = 'quarterstave'
  59.  
  60.     wound_tier = {'slash': ['shallow cut', 'cut', 'deep cut', 'severe cut', 'devastating cut'],
  61.         'pierce': ['faint wound', 'puncture', 'deep puncture', 'severe puncture', 'gaping wound'],
  62.         'bruise': ['small bruise', 'bruise', 'ugly bruise', 'major bruise', 'fracture']}
  63.     attack_wound = wound_tier[damage_type][damage_tier]
  64.  
  65.     # Attacker and target pronouns. Possessive (its, his, her), Singular Subject (it, he, she), Singular Object (it, him, her)
  66.     a_poss, a_sin_sub, a_sin_obj = pronoun(attacker)
  67.     t_poss, t_sin_sub, t_sin_obj = pronoun(target)
  68.  
  69.     a_name = attacker.key
  70.     t_name = target.key
  71.  
  72.     # Weapon's article. 'a' or 'an'
  73.     art_weap = article(weapon)
  74.     if hit:
  75.         a_outcome = str.capitalize(f"{t_sin_sub} suffers {article(attack_wound)} {attack_wound} to {t_poss} {body_part}.")
  76.         t_outcome = f"you suffer {article(attack_wound)} {attack_wound} to your {body_part}."
  77.         o_outcome = f"{t_name} suffers {article(attack_wound)} {attack_wound} to {t_poss} {body_part}."
  78.  
  79.     skillsets = {'staves': {'leg sweep': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  80.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  81.  
  82.             'feint': {'attack_desc': {'attacker': f"You sweep your {weapon} at {target}\'s legs, {a_outcome}.",
  83.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  84.  
  85.             'end jab': {'attack_desc': {'attacker': f"You sweep your {weapon} at {target}\'s legs, {a_outcome}.",
  86.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  87.  
  88.             'swat': {'attack_desc': {'attacker': f"Using the center of a {weapon} as a fulcrum, you swat at {t_name} with one end of the weapon, {a_outcome}",
  89.                                             'target': f"Using the center of a {weapon} as a fulcrum, {attacker} swats at you with one end of the weapon, {t_outcome}",
  90.                                             'others': f"Using the center of a {weapon} as a fulcrum, {attacker} swats at {t_name} with one end of the weapon, {o_outcome}"}},
  91.  
  92.             'simple strike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  93.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  94.  
  95.             'side strike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  96.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  97.  
  98.             'pivot smash': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  99.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  100.  
  101.             'longarm strike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  102.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  103.  
  104.             'simple block': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  105.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  106.  
  107.             'cross block': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  108.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  109.  
  110.             'overhead block': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  111.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  112.  
  113.             'parting jab': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  114.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  115.  
  116.             'parting swat': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  117.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  118.  
  119.             'parting smash': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  120.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  121.  
  122.             'defensive sweep': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  123.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  124.  
  125.             'stepping spin': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  126.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  127.  
  128.             'snapstrike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  129.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  130.  
  131.             'sweep strike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  132.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  133.  
  134.             'spinstrike': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  135.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  136.  
  137.             'tbash': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  138.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  139.  
  140.             'whirling block': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  141.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}},
  142.  
  143.             'pivoting longarm': {'attack_desc': {'attacker': f"You sweep your {weapon} at {t_name}\'s legs, {a_outcome}.",
  144.                                             'others': f"{a_name} sweeps {art_weap} {weapon} at {t_name}\'s legs, {o_outcome}."}}}}
  145.  
  146.     attacker_desc = skillsets[skillset][skill]['attack_desc']['attacker']
  147.     target_desc = skillsets[skillset][skill]['attack_desc']['target']
  148.     others_desc = skillsets[skillset][skill]['attack_desc']['others']
  149.  
  150.     return attacker_desc, target_desc, others_desc
  151.  
  152.  
  153.  
  154. # GENERIC STRING HANDLER FOR PRONOUNS AND SUCH (NOT REALLY NEEDED, BUT JUST IN CASE)
  155. vowels = ['a', 'e', 'i', 'o', 'u']
  156.  
  157. consonant_vowels = ['amazigh', 'euboean', 'eucharist', 'eumenides', 'eurasian', 'euro-american', 'europe',
  158. 'european', 'eusebius', 'oaxaca', 'ouija', 'ucalegon', 'uclaf', 'udale',
  159. 'udall', 'udy', 'ueberroth', 'uganda', 'uinita', 'ukase', 'ukie', 'ukraine', 'ukrainian', 'ullyses', 'unakas',
  160. 'uniate', 'unix', 'uranus', 'usanian', 'usonian', 'utah', 'utahn', 'utonian', 'esclop', 'eucalyptus', 'eucatastrophe',
  161. 'euchologion', 'euchre', 'euclidianness', 'eudaemon', 'eudemonia', 'eugarie', 'eugenesis', 'eugenics', 'eugenist',
  162. 'eugeny', 'euglena', 'eukaryote', 'eulachon', 'eulogy', 'eunoia', 'eunuch', 'euouae', 'euphemism', 'euphoria',
  163. 'euphoriant', 'eureka', 'euro', 'eustasy', 'eustress', 'eutectic', 'euth', 'euthanasia', 'eutripsia', 'ewe', 'ewer',
  164. 'latmul', 'once', 'oncer', 'one', 'onesie', 'ouabain', 'ubac', 'uberty', 'ubication', 'ubicity', 'ubiety', 'ubiquity',
  165. 'udometer', 'uey', 'ufo', 'ufologist', 'ufology', 'uke', 'ukelele', 'ukulele', 'ululate', 'ululation', 'unanimity',
  166. 'unanimous', 'unary', 'uni', 'unicameral', 'unicorn', 'unicycle', 'unidirection', 'unidirectional', 'unidirectionality',
  167. 'uniform', 'uniformitarianism', 'unify', 'unigeniture', 'union', 'unique', 'uniquity', 'unisex', 'unison', 'unit', 'unite',
  168. 'unity', 'univalence', 'univalent', 'universalism', 'universe', 'university', 'univocal', 'upas', 'upsilon', 'uraeus',
  169. 'ural', 'uranism', 'uranist', 'uranium', 'uranophobia', 'urea', 'ureter', 'ureteroureterostomy', 'urethra', 'uridine',
  170. 'urinal', 'urinalysis', 'urine', 'urology', 'uropygium', 'urus', 'usability', 'usage', 'use', 'user', 'using', 'usual',
  171. 'usufruct', 'usufruction', 'usufructuary', 'usurer', 'usuress', 'usurp', 'usurper', 'usurping', 'usury', 'ute', 'utensil',
  172. 'uterus', 'utile', 'utilitarian', 'utility', 'utopia', 'utopographer', 'utricle', 'uvarovite', 'uvas', 'uvea', 'uvula',
  173. 'uvular', 'zzxjoanw']
  174.  
  175. def article(word):
  176.     word.lower()
  177.  
  178.     if word[0] in vowels:
  179.         article = 'an'
  180.     elif word in consonant_vowels:
  181.         article = 'a'
  182.     else:
  183.         article = 'a'
  184.     return article
  185.  
  186. def pronoun(char):
  187.     if not char.attributes.has('figure'):
  188.         possessive = 'its'
  189.         singular_subject = 'it'
  190.         singular_object = 'it'
  191.     elif char.db.figure['gender'] == 'male':
  192.         possessive = 'his'
  193.         singular_subject = 'he'
  194.         singular_object = 'him'
  195.     elif char.db.figure['gender'] == 'female':
  196.         possessive = 'hers'
  197.         singular_subject = 'she'
  198.         singular_object = 'her'
  199.     return possessive, singular_subject, singular_object
  200.  
  201.  
  202.  
  203. # COMBAT HANDLER MODULE (NOT NEEDED REALLY, BUT JUST IN CASE)
  204. from evennia import utils
  205. from world import skillsets
  206. from world import build_skill_str
  207. import time
  208. import random
  209.  
  210. class CombatHandler:
  211.     def __init__(self, owner):
  212.         self.owner = owner
  213.  
  214.     def approach(self, attacker, target):
  215.         a_app = attacker.attributes.get('approached')
  216.         t_app = target.attributes.get('approached')
  217.         a_name = attacker.key
  218.         t_name = target.key
  219.  
  220.         if target in a_app:
  221.             attacker.msg(f"You are already approached to {t_name}!")
  222.             return
  223.         if len(a_app) >= 1:
  224.             attacker.msg(f"You are already approached to {a_app}!")
  225.             target.msg(f"{a_name} attempts to approach you, but fails.")
  226.             return
  227.         if len(t_app) >= 3:
  228.             attacker.msg(f"{t_app} are already approached to that target!")
  229.             return
  230.         a_app.append(target)
  231.         t_app.append(attacker)
  232.         attacker.msg(f"You approach {t_name}.")
  233.         target.msg(f"{a_name} approaches you.")
  234.         return
  235.  
  236.     def retreat(self, attacker):
  237.         a_app = attacker.attributes.get('approached')
  238.         a_name = attacker.key
  239.  
  240.         if len(a_app) == 0:
  241.             attacker.msg(f"You are not approached to anything.")
  242.             return
  243.         for t in a_app:
  244.             t.db.approached.remove(attacker)
  245.             t.msg(f"{a_name} retreats from you.")
  246.         attacker.msg(f"You retreat.")
  247.        
  248.         a_app.clear()
  249.    
  250.     def success_calc(self, target, skillset, skill):
  251.         a_skillset = self.owner.attributes.get(skillset)
  252.         a_skill = a_skillset.get(skill)
  253.         a_rb = a_skill.get('rb')
  254.  
  255.         t_rb = 0
  256.  
  257.         if a_rb > t_rb:
  258.             bonus = a_rb - t_rb
  259.             success = 50 - bonus
  260.         elif t_rb > a_rb:
  261.             loss = t_rb - a_rb
  262.             success = 50 + loss
  263.         else:
  264.             success = 50
  265.  
  266.         return success
  267.            
  268.  
  269.  
  270.  
  271.     def attack(self, target, damage_type, skillset, skill):
  272.         attacker = self.owner
  273.  
  274.         if self.owner.db.ko == True:
  275.             self.owner.msg("You can't do that while unconscious!")
  276.             return
  277.  
  278.         damage = 20
  279.  
  280.         # Create cooldown attribute if non-existent.
  281.         if not self.owner.attributes.has('attack_cd'):
  282.             self.owner.db.attack_cd = 0
  283.  
  284.         # Calculate current time, total cooldown, and remaining time.
  285.         now = time.time()
  286.         lastcast = self.owner.attributes.get('attack_cd')
  287.         cooldown = lastcast + 3
  288.         time_remaining = cooldown - now
  289.  
  290.         # Inform the attacker that they are in cooldown and exit the function.
  291.         if time_remaining > 0:
  292.             if time_remaining >= 2:
  293.                 message = f"You need to wait {int(time_remaining)} more seconds."
  294.             elif time_remaining >= 1 and time_remaining < 2:
  295.                 message = f"You need to wait {int(time_remaining)} more second."
  296.             elif time_remaining < 1:
  297.                 message = f"You are in the middle of something."
  298.             self.owner.msg(message)
  299.             return
  300.  
  301.         roll = random.randint(1, 100)
  302.         success = self.success_calc(target, skillset, skill)
  303.  
  304.         # Make sure that the success is never below 5 or above 95 and always 5 if the target is unconscious.
  305.         if success < 5 or target.db.ko == True:
  306.             success = 5
  307.         elif success > 95:
  308.             success = 95
  309.        
  310.        
  311.         #temp values
  312.         damage_tier = 0
  313.         body_part = 'head'
  314.  
  315.         # a_desc, t_desc = build_skill_str.create_attack_desc(self.owner, target, damage_type, damage_tier, body_part)
  316.         # outcome = a_desc
  317.         # weapon = 'quarterstave'
  318.  
  319.         if roll > success:
  320.             hit = True
  321.  
  322.             # create_attack_desc(attacker, target, skillset, skill, damage_type, damage_tier, body_part, hit)
  323.             attacker_desc, target_desc, others_desc = build_skill_str.create_attack_desc(attacker, target, skillset, skill, damage_type, damage_tier, body_part, hit)
  324.  
  325.             self.owner.msg(f"|430[Success: {success} Roll: {roll}] {attacker_desc}|n")
  326.             target.msg(f"|r[Success: {success} Roll: {roll}] {target_desc}|n")
  327.             self.owner.location.msg_contents(f"{others_desc}", exclude=(self.owner, target))
  328.             self.take_damage(target, damage)
  329.  
  330.         else:
  331.             hit = False
  332.  
  333.             # create_attack_desc(attacker, target, skillset, skill, damage_type, damage_tier, body_part, hit)
  334.             attacker_desc, target_desc, others_desc = build_skill_str.create_attack_desc(attacker, target, skillset, skill, damage_type, damage_tier, body_part, hit)
  335.  
  336.             self.owner.msg(f"|430[Success: {success} Roll: {roll}] {attacker_desc}|n")
  337.             target.msg(f"|r[Success: {success} Roll: {roll}] {target_desc}|n")
  338.             self.owner.location.msg_contents(f"{others_desc}", exclude=(self.owner, target))
  339.  
  340.         utils.delay(3, self.unbusy)
  341.         self.owner.db.attack_cd = now
  342.  
  343.     def take_damage(self, target, damage):
  344.         t_name = target.key
  345.         location = target.location
  346.         targ_app = target.attributes.get('approached')
  347.        
  348.         hp = target.attributes.get('hp')
  349.         current_hp = hp['current_hp']
  350.         current_hp -= damage
  351.         target.db.hp['current_hp'] = current_hp
  352.  
  353.         location.msg_contents(f'{t_name} has {current_hp} health remaining!')
  354.         if current_hp >= 1:
  355.             target.db.ko = False
  356.         elif current_hp <= 0 and target.db.ko != True:
  357.             target.db.ko = True
  358.             location.msg_contents(f'{t_name} falls unconscious!')
  359.         if current_hp <= -100:
  360.             # Check for
  361.             for a in targ_app:
  362.                 ap_list = a.attributes.get('approached')
  363.                 ap_list.remove(target)
  364.             if not target.has_account:
  365.                 okay = target.delete()
  366.                 if not okay:
  367.                     location.msg_contents(f'\nERROR: {t_name} not deleted, probably because delete() returned False.')
  368.                 else:
  369.                     location.msg_contents(f'{t_name} breathes a final breath and expires.')
  370.             else:
  371.                 target.db.hp['current_hp'] = target.db.hp['max_hp']
  372.                 location.msg_contents(f"{t_name} dies and is resurrected to max HP.", exclude=target)
  373.                 target.msg("You die and are resurrected to full HP.")
  374.                 target.db.ko = False
  375.    
  376.     def unbusy(self):
  377.             self.owner.msg('|yYou are no longer busy.|n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement