Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Traceback (most recent call last):
- File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
- ret = cmd.func()
- File ".\commands\combat.py", line 28, in func
- self.caller.combat.attack(target)
- AttributeError: 'Player_Character' object has no attribute 'attack'
- An untrapped error occurred.
- (Traceback was logged 19-08-05 12:00:06-04).
- '''
- '''Combat Command Module'''
- from evennia import Command as BaseCommand
- from evennia import utils
- from evennia import create_script
- import time
- import random
- class CmdStaveBash(BaseCommand):
- '''
- Use your staff to bash an enemy.
- Usage:
- bash <target>
- '''
- key = 'bash'
- help_category = 'combat'
- def func(self):
- if not self.args:
- self.caller.msg('Usage: bash <target>')
- return
- target = self.caller.search(self.args)
- if not target:
- self.caller.msg('That target does not exist!')
- return
- if not target.attributes.has('hp'):
- self.caller.msg('You cannot attack that target!')
- return
- self.caller.combat.attack(target)
- '''Combat Handler'''
- from typeclasses.objects import Object
- from evennia import utils
- import time
- import random
- class CombatHandler(Object):
- def __init__(self, owner):
- self.owner = owner
- def attack(self, target):
- damage = 20
- self.db.stave_bash = 0
- now = time.time()
- lastcast = self.db.stave_bash
- cooldown = lastcast + 3
- time_remaining = cooldown - now
- if time_remaining > 0:
- if time_remaining >= 2:
- message = f"You need to wait {int(time_remaining)} more seconds."
- elif time_remaining >= 1 and time_remaining < 2:
- message = f"You need to wait {int(time_remaining)} more second."
- elif time_remaining < 1:
- message = f"You are in the middle of something."
- self.msg(message)
- return
- # roll = random.randint(1, 100)
- # success = random.randint(5, 95)
- roll = 100
- success = 0
- if roll > success:
- self.msg(f'[Success: {success} Roll: {roll}] You bash {target} with your stave!')
- self.take_damage(target, damage)
- else:
- self.msg(f'[Success: {success} Roll: {roll}] You miss {target} with your stave!')
- utils.delay(3, self.unbusy)
- self.db.stave_bash = now
- def take_damage(self, target, damage):
- mob = target.key
- location = target.location
- target.db.hp -= damage
- hp = target.db.hp
- location.msg_contents(f'{mob} has {hp} health remaining!')
- if hp >= 1:
- target.db.ko = False
- elif hp <= 0 and target.db.ko != True:
- target.db.ko = True
- location.msg_contents(f'{mob} falls unconscious!')
- if hp <= -100:
- okay = target.delete()
- if not okay:
- location.msg_contents(f'\nERROR: {mob} not deleted, probably because delete() returned False.')
- else:
- location.msg_contents(f'{mob} breathes a final breath and expires.')
- return
- def unbusy(self):
- self.msg('|yYou are no longer busy.|n')
- '''Player Character Class'''
- from evennia import DefaultCharacter
- from collections import defaultdict
- from evennia.utils.utils import (list_to_string, inherits_from, lazy_property)
- from world.combat_handler import CombatHandler
- class Character(DefaultCharacter):
- pass
- class Player_Character(DefaultCharacter):
- @lazy_property
- def combat(self):
- return CombatHandler(self)
- def return_appearance(self, looker, **kwargs):
- if not looker:
- return ""
- # get description, build string
- string = self.create_desc()
- return string
- def create_desc(self):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement