Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 19-08-14 06:29:03-04 <bound method Rat.get_target of rat>
- 19-08-14 06:29:03-04 [::] Traceback (most recent call last):
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
- 19-08-14 06:29:03-04 [::] ret = cmd.func()
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\commands\default\building.py", line 524, in func
- 19-08-14 06:29:03-04 [::] locks=lockstring, report_to=caller)
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\utils\create.py", line 138, in create_object
- 19-08-14 06:29:03-04 [::] new_object.save()
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\utils\idmapper\models.py", line 396, in save
- 19-08-14 06:29:03-04 [::] super().save(*args, **kwargs)
- 19-08-14 06:29:03-04 [::] File "d:\muddev\myvirtualenv\Lib\site-packages\django\db\models\base.py", line 718, in save
- 19-08-14 06:29:03-04 [::] force_update=force_update, update_fields=update_fields)
- 19-08-14 06:29:03-04 [::] File "d:\muddev\myvirtualenv\Lib\site-packages\django\db\models\base.py", line 758, in save_base
- 19-08-14 06:29:03-04 [::] update_fields=update_fields, raw=raw, using=using,
- 19-08-14 06:29:03-04 [::] File "d:\muddev\myvirtualenv\Lib\site-packages\django\dispatch\dispatcher.py", line 175, in send
- 19-08-14 06:29:03-04 [::] for receiver in self._live_receivers(sender)
- 19-08-14 06:29:03-04 [::] File "d:\muddev\myvirtualenv\Lib\site-packages\django\dispatch\dispatcher.py", line 175, in <listcomp>
- 19-08-14 06:29:03-04 [::] for receiver in self._live_receivers(sender)
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\typeclasses\models.py", line 71, in call_at_first_save
- 19-08-14 06:29:03-04 [::] instance.at_first_save()
- 19-08-14 06:29:03-04 [::] File "d:\muddev\evennia\evennia\objects\objects.py", line 1066, in at_first_save
- 19-08-14 06:29:03-04 [::] self.at_object_creation()
- 19-08-14 06:29:03-04 [::] File "D:\muddev\hecate\typeclasses\mobs.py", line 35, in at_object_creation
- 19-08-14 06:29:03-04 [::] tickerhandler.add(3, self.claw())
- 19-08-14 06:29:03-04 [::] File "D:\muddev\hecate\typeclasses\mobs.py", line 67, in claw
- 19-08-14 06:29:03-04 [::] self.combat.attack(target, damage_type, skillset, skill)
- 19-08-14 06:29:03-04 [::] File "D:\muddev\hecate\world\combat_handler.py", line 94, in attack
- 19-08-14 06:29:03-04 [::] if success < 5 or target.db.ko == True:
- 19-08-14 06:29:03-04 [::] AttributeError: 'function' object has no attribute 'db'
- 19-08-14 06:29:03-04 [EE] User input was: 'create/drop rat:mobs.Rat'.
- """
- '''typeclasses.mobs module'''
- from evennia import DefaultCharacter
- from world import skillsets
- from world.combat_handler import CombatHandler
- from typeclasses.scripts import ScriptMob
- from evennia.utils.utils import lazy_property
- from evennia.utils.search import search_object
- from evennia import utils
- from evennia import TICKER_HANDLER as tickerhandler
- import random
- class DefaultMob(DefaultCharacter):
- def at_object_creation(self):
- self.db.hp = 100
- self.db.ko = False
- self.db.approached = []
- @lazy_property
- def combat(self):
- return CombatHandler(self)
- @lazy_property
- def combat_script(self):
- return ScriptMob(self)
- class Rat(DefaultMob):
- rat_skills = {'claw': {'damage_type': 'slash', 'difficulty': 'easy', 'attack_range': 'melee', 'default_aim': 'mid'},
- 'bite': {'damage_type': 'slash', 'difficulty': 'easy', 'attack_range': 'melee', 'default_aim': 'high'}}
- def at_object_creation(self):
- super().at_object_creation()
- rank = 10
- rb = skillsets.easy_rb
- rb = rb[rank - 1]
- rat_skills = {'claw': {'rank': rank, 'rb': rb}, 'bite': {'rank': rank, 'rb': rb}}
- self.attributes.add('rat', rat_skills)
- tickerhandler.add(3, self.claw())
- def get_target(self):
- # Set target to first approached.
- approached = self.attributes.get('approached')
- app_len = len(approached)
- if app_len >= 1:
- target = approached[0]
- print(target)
- return target
- # If approached is empty, find new target and approach it.
- visible = []
- for targ in self.location.contents:
- if targ.has_account:
- visible.append(targ)
- t_len = len(visible)
- # Pick target from visible targets.
- target = visible[random.randint(0, t_len - 1)]
- combat.approach(self, target)
- print(target)
- return target
- def claw(self):
- target = self.get_target
- print(target)
- damage_type = self.rat_skills['claw']['damage_type']
- skillset = 'rat'
- skill = 'claw'
- self.combat.attack(target, damage_type, skillset, skill)
- utils.delay(3, self.claw)
- def bite(self):
- pass
- '''world.combat_handler module'''
- from evennia import utils
- from world import skillsets
- from world import build_skill_str
- import time
- import random
- class CombatHandler:
- def __init__(self, owner):
- self.owner = owner
- def approach(self, attacker, target):
- a_app = attacker.attributes.get('approached')
- t_app = target.attributes.get('approached')
- a_name = attacker.key
- t_name = target.key
- if target in a_app:
- attacker.msg(f"You are already approached to {t_name}!")
- return
- if len(a_app) >= 1:
- attacker.msg(f"You are already approached to {a_app}!")
- target.msg(f"{a_name} attempts to approach you, but fails.")
- return
- if len(t_app) >= 3:
- attacker.msg(f"{t_app} are already approached to that target!")
- return
- a_app.append(target)
- t_app.append(attacker)
- attacker.msg(f"You approach {t_name}.")
- target.msg(f"{a_name} approaches you.")
- return
- def retreat(self, attacker):
- a_app = attacker.attributes.get('approached')
- a_name = attacker.key
- if len(a_app) == 0:
- attacker.msg(f"You are not approached to anything.")
- return
- for t in a_app:
- t.db.approached.remove(attacker)
- t.msg(f"{a_name} retreats from you.")
- attacker.msg(f"You retreat.")
- a_app.clear()
- def success_calc(self, target, skillset, skill):
- a_skillset = self.owner.attributes.get(skillset)
- a_skill = a_skillset.get(skill)
- a_rb = a_skill.get('rb')
- t_rb = 0
- if a_rb > t_rb:
- bonus = a_rb - t_rb
- success = 50 - bonus
- elif t_rb > a_rb:
- loss = t_rb - a_rb
- success = 50 + loss
- else:
- success = 50
- return success
- def attack(self, target, damage_type, skillset, skill):
- damage = 20
- # Create cooldown attribute if non-existent.
- if not self.owner.attributes.has('attack_cd'):
- self.owner.db.attack_cd = 0
- # Calculate current time, total cooldown, and remaining time.
- now = time.time()
- lastcast = self.owner.attributes.get('attack_cd')
- cooldown = lastcast + 3
- time_remaining = cooldown - now
- # Inform the attacker that they are in cooldown and exit the function.
- 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.owner.msg(message)
- return
- roll = random.randint(1, 100)
- success = self.success_calc(target, skillset, skill)
- if success < 5 or target.db.ko == True:
- success = 5
- elif success > 95:
- success = 95
- #temp values
- damage_tier = 0
- body_part = 'head'
- # a_desc, t_desc = build_skill_str.create_attack_desc(self.owner, target, damage_type, damage_tier, body_part)
- # outcome = a_desc
- # weapon = 'quarterstave'
- if roll > success:
- self.owner.msg(f"[Success: {success} Roll: {roll}] " + " and hit! ")
- self.take_damage(target, damage)
- else:
- self.owner.msg(f"[Success: {success} Roll: {roll}] You miss {target} with your stave!")
- utils.delay(3, self.unbusy)
- self.owner.db.attack_cd = now
- def take_damage(self, target, damage):
- mob = target.key
- location = target.location
- mob_app = target.attributes.get('approached')
- hp = target.db.hp
- hp -= damage
- target.db.hp = 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:
- # Check for
- for a in mob_app:
- ap_list = a.attributes.get('approached')
- ap_list.remove(target)
- 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.owner.msg('|yYou are no longer busy.|n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement