Advertisement
Kovitikus

No Such Attribute

Aug 5th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.95 KB | None | 0 0
  1. '''
  2. Traceback (most recent call last):
  3.  File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  4.    ret = cmd.func()
  5.  File ".\commands\combat.py", line 28, in func
  6.    self.caller.combat.attack(target)
  7. AttributeError: 'Player_Character' object has no attribute 'attack'
  8.  
  9. An untrapped error occurred.
  10. (Traceback was logged 19-08-05 12:00:06-04).
  11. '''
  12.  
  13. '''Combat Command Module'''
  14. from evennia import Command as BaseCommand
  15. from evennia import utils
  16. from evennia import create_script
  17. import time
  18. import random
  19.  
  20. class CmdStaveBash(BaseCommand):
  21.     '''
  22.    Use your staff to bash an enemy.
  23.  
  24.    Usage:
  25.        bash <target>
  26.    '''
  27.     key = 'bash'
  28.     help_category = 'combat'
  29.  
  30.     def func(self):
  31.         if not self.args:
  32.             self.caller.msg('Usage: bash <target>')
  33.             return
  34.         target = self.caller.search(self.args)
  35.         if not target:
  36.             self.caller.msg('That target does not exist!')
  37.             return
  38.         if not target.attributes.has('hp'):
  39.             self.caller.msg('You cannot attack that target!')
  40.             return
  41.         self.caller.combat.attack(target)
  42.  
  43. '''Combat Handler'''
  44. from typeclasses.objects import Object
  45. from evennia import utils
  46. import time
  47. import random
  48.  
  49. class CombatHandler(Object):
  50.     def __init__(self, owner):
  51.         self.owner = owner
  52.  
  53.     def attack(self, target):  
  54.         damage = 20
  55.         self.db.stave_bash = 0
  56.         now = time.time()
  57.         lastcast = self.db.stave_bash
  58.         cooldown = lastcast + 3
  59.         time_remaining = cooldown - now
  60.  
  61.         if time_remaining > 0:
  62.             if time_remaining >= 2:
  63.                 message = f"You need to wait {int(time_remaining)} more seconds."
  64.             elif time_remaining >= 1 and time_remaining < 2:
  65.                 message = f"You need to wait {int(time_remaining)} more second."
  66.             elif time_remaining < 1:
  67.                 message = f"You are in the middle of something."
  68.             self.msg(message)
  69.             return
  70.  
  71.         # roll = random.randint(1, 100)
  72.         # success = random.randint(5, 95)
  73.         roll = 100
  74.         success = 0
  75.  
  76.         if roll > success:
  77.             self.msg(f'[Success: {success} Roll: {roll}] You bash {target} with your stave!')
  78.             self.take_damage(target, damage)
  79.         else:
  80.             self.msg(f'[Success: {success} Roll: {roll}] You miss {target} with your stave!')
  81.         utils.delay(3, self.unbusy)
  82.         self.db.stave_bash = now
  83.  
  84.     def take_damage(self, target, damage):
  85.         mob = target.key
  86.         location = target.location
  87.        
  88.         target.db.hp -= damage
  89.         hp = target.db.hp
  90.         location.msg_contents(f'{mob} has {hp} health remaining!')
  91.         if hp >= 1:
  92.             target.db.ko = False
  93.         elif hp <= 0 and target.db.ko != True:
  94.             target.db.ko = True
  95.             location.msg_contents(f'{mob} falls unconscious!')
  96.         if hp <= -100:
  97.             okay = target.delete()
  98.             if not okay:
  99.                 location.msg_contents(f'\nERROR: {mob} not deleted, probably because delete() returned False.')
  100.             else:
  101.                 location.msg_contents(f'{mob} breathes a final breath and expires.')
  102.         return
  103.    
  104.     def unbusy(self):
  105.             self.msg('|yYou are no longer busy.|n')
  106.  
  107. '''Player Character Class'''
  108. from evennia import DefaultCharacter
  109. from collections import defaultdict
  110. from evennia.utils.utils import (list_to_string, inherits_from, lazy_property)
  111. from world.combat_handler import CombatHandler
  112.  
  113.  
  114. class Character(DefaultCharacter):
  115.     pass
  116.  
  117. class Player_Character(DefaultCharacter):
  118.  
  119.     @lazy_property
  120.     def combat(self):
  121.         return CombatHandler(self)
  122.  
  123.     def return_appearance(self, looker, **kwargs):
  124.         if not looker:
  125.             return ""
  126.        
  127.         # get description, build string
  128.         string  = self.create_desc()
  129.         return string
  130.  
  131.     def create_desc(self):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement