Advertisement
Kovitikus

Mob can't find target?

Aug 14th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.70 KB | None | 0 0
  1. """
  2. 19-08-14 06:29:03-04 <bound method Rat.get_target of rat>
  3. 19-08-14 06:29:03-04 [::] Traceback (most recent call last):
  4. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  5. 19-08-14 06:29:03-04 [::]     ret = cmd.func()
  6. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\commands\default\building.py", line 524, in func
  7. 19-08-14 06:29:03-04 [::]     locks=lockstring, report_to=caller)
  8. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\utils\create.py", line 138, in create_object
  9. 19-08-14 06:29:03-04 [::]     new_object.save()
  10. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\utils\idmapper\models.py", line 396, in save
  11. 19-08-14 06:29:03-04 [::]     super().save(*args, **kwargs)
  12. 19-08-14 06:29:03-04 [::]   File "d:\muddev\myvirtualenv\Lib\site-packages\django\db\models\base.py", line 718, in save
  13. 19-08-14 06:29:03-04 [::]     force_update=force_update, update_fields=update_fields)
  14. 19-08-14 06:29:03-04 [::]   File "d:\muddev\myvirtualenv\Lib\site-packages\django\db\models\base.py", line 758, in save_base
  15. 19-08-14 06:29:03-04 [::]     update_fields=update_fields, raw=raw, using=using,
  16. 19-08-14 06:29:03-04 [::]   File "d:\muddev\myvirtualenv\Lib\site-packages\django\dispatch\dispatcher.py", line 175, in send
  17. 19-08-14 06:29:03-04 [::]     for receiver in self._live_receivers(sender)
  18. 19-08-14 06:29:03-04 [::]   File "d:\muddev\myvirtualenv\Lib\site-packages\django\dispatch\dispatcher.py", line 175, in <listcomp>
  19. 19-08-14 06:29:03-04 [::]     for receiver in self._live_receivers(sender)
  20. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\typeclasses\models.py", line 71, in call_at_first_save
  21. 19-08-14 06:29:03-04 [::]     instance.at_first_save()
  22. 19-08-14 06:29:03-04 [::]   File "d:\muddev\evennia\evennia\objects\objects.py", line 1066, in at_first_save
  23. 19-08-14 06:29:03-04 [::]     self.at_object_creation()
  24. 19-08-14 06:29:03-04 [::]   File "D:\muddev\hecate\typeclasses\mobs.py", line 35, in at_object_creation
  25. 19-08-14 06:29:03-04 [::]     tickerhandler.add(3, self.claw())
  26. 19-08-14 06:29:03-04 [::]   File "D:\muddev\hecate\typeclasses\mobs.py", line 67, in claw
  27. 19-08-14 06:29:03-04 [::]     self.combat.attack(target, damage_type, skillset, skill)
  28. 19-08-14 06:29:03-04 [::]   File "D:\muddev\hecate\world\combat_handler.py", line 94, in attack
  29. 19-08-14 06:29:03-04 [::]     if success < 5 or target.db.ko == True:
  30. 19-08-14 06:29:03-04 [::] AttributeError: 'function' object has no attribute 'db'
  31. 19-08-14 06:29:03-04 [EE] User input was: 'create/drop rat:mobs.Rat'.
  32. """
  33.  
  34. '''typeclasses.mobs module'''
  35.  
  36. from evennia import DefaultCharacter
  37. from world import skillsets
  38. from world.combat_handler import CombatHandler
  39. from typeclasses.scripts import ScriptMob
  40. from evennia.utils.utils import lazy_property
  41. from evennia.utils.search import search_object
  42. from evennia import utils
  43. from evennia import TICKER_HANDLER as tickerhandler
  44. import random
  45.  
  46. class DefaultMob(DefaultCharacter):
  47.     def at_object_creation(self):
  48.         self.db.hp = 100
  49.         self.db.ko = False
  50.         self.db.approached = []
  51.  
  52.     @lazy_property
  53.     def combat(self):
  54.         return CombatHandler(self)
  55.     @lazy_property
  56.     def combat_script(self):
  57.         return ScriptMob(self)
  58.        
  59. class Rat(DefaultMob):
  60.    
  61.     rat_skills = {'claw': {'damage_type': 'slash', 'difficulty': 'easy', 'attack_range': 'melee', 'default_aim': 'mid'},
  62.                     'bite': {'damage_type': 'slash', 'difficulty': 'easy', 'attack_range': 'melee', 'default_aim': 'high'}}
  63.     def at_object_creation(self):
  64.         super().at_object_creation()
  65.         rank = 10
  66.         rb = skillsets.easy_rb
  67.         rb = rb[rank - 1]
  68.         rat_skills = {'claw': {'rank': rank, 'rb': rb}, 'bite': {'rank': rank, 'rb': rb}}
  69.         self.attributes.add('rat', rat_skills)
  70.         tickerhandler.add(3, self.claw())
  71.  
  72.  
  73.     def get_target(self):
  74.         # Set target to first approached.
  75.         approached = self.attributes.get('approached')
  76.         app_len = len(approached)
  77.         if app_len >= 1:
  78.             target = approached[0]
  79.             print(target)
  80.             return target
  81.  
  82.         # If approached is empty, find new target and approach it.
  83.         visible = []
  84.         for targ in self.location.contents:
  85.             if targ.has_account:
  86.                 visible.append(targ)
  87.         t_len = len(visible)
  88.        
  89.         # Pick target from visible targets.
  90.         target = visible[random.randint(0, t_len - 1)]
  91.         combat.approach(self, target)
  92.         print(target)
  93.         return target
  94.  
  95.     def claw(self):
  96.         target = self.get_target
  97.         print(target)
  98.         damage_type = self.rat_skills['claw']['damage_type']
  99.         skillset = 'rat'
  100.         skill = 'claw'
  101.  
  102.         self.combat.attack(target, damage_type, skillset, skill)
  103.         utils.delay(3, self.claw)
  104.  
  105.     def bite(self):
  106.         pass
  107.  
  108. '''world.combat_handler module'''
  109. from evennia import utils
  110. from world import skillsets
  111. from world import build_skill_str
  112. import time
  113. import random
  114.  
  115. class CombatHandler:
  116.     def __init__(self, owner):
  117.         self.owner = owner
  118.  
  119.     def approach(self, attacker, target):
  120.         a_app = attacker.attributes.get('approached')
  121.         t_app = target.attributes.get('approached')
  122.         a_name = attacker.key
  123.         t_name = target.key
  124.  
  125.         if target in a_app:
  126.             attacker.msg(f"You are already approached to {t_name}!")
  127.             return
  128.         if len(a_app) >= 1:
  129.             attacker.msg(f"You are already approached to {a_app}!")
  130.             target.msg(f"{a_name} attempts to approach you, but fails.")
  131.             return
  132.         if len(t_app) >= 3:
  133.             attacker.msg(f"{t_app} are already approached to that target!")
  134.             return
  135.         a_app.append(target)
  136.         t_app.append(attacker)
  137.         attacker.msg(f"You approach {t_name}.")
  138.         target.msg(f"{a_name} approaches you.")
  139.         return
  140.  
  141.     def retreat(self, attacker):
  142.         a_app = attacker.attributes.get('approached')
  143.         a_name = attacker.key
  144.  
  145.         if len(a_app) == 0:
  146.             attacker.msg(f"You are not approached to anything.")
  147.             return
  148.         for t in a_app:
  149.             t.db.approached.remove(attacker)
  150.             t.msg(f"{a_name} retreats from you.")
  151.         attacker.msg(f"You retreat.")
  152.        
  153.         a_app.clear()
  154.    
  155.     def success_calc(self, target, skillset, skill):
  156.         a_skillset = self.owner.attributes.get(skillset)
  157.         a_skill = a_skillset.get(skill)
  158.         a_rb = a_skill.get('rb')
  159.  
  160.         t_rb = 0
  161.  
  162.         if a_rb > t_rb:
  163.             bonus = a_rb - t_rb
  164.             success = 50 - bonus
  165.         elif t_rb > a_rb:
  166.             loss = t_rb - a_rb
  167.             success = 50 + loss
  168.         else:
  169.             success = 50
  170.  
  171.         return success
  172.            
  173.  
  174.  
  175.  
  176.     def attack(self, target, damage_type, skillset, skill):  
  177.         damage = 20
  178.  
  179.         # Create cooldown attribute if non-existent.
  180.         if not self.owner.attributes.has('attack_cd'):
  181.             self.owner.db.attack_cd = 0
  182.  
  183.         # Calculate current time, total cooldown, and remaining time.
  184.         now = time.time()
  185.         lastcast = self.owner.attributes.get('attack_cd')
  186.         cooldown = lastcast + 3
  187.         time_remaining = cooldown - now
  188.  
  189.         # Inform the attacker that they are in cooldown and exit the function.
  190.         if time_remaining > 0:
  191.             if time_remaining >= 2:
  192.                 message = f"You need to wait {int(time_remaining)} more seconds."
  193.             elif time_remaining >= 1 and time_remaining < 2:
  194.                 message = f"You need to wait {int(time_remaining)} more second."
  195.             elif time_remaining < 1:
  196.                 message = f"You are in the middle of something."
  197.             self.owner.msg(message)
  198.             return
  199.  
  200.         roll = random.randint(1, 100)
  201.         success = self.success_calc(target, skillset, skill)
  202.         if success < 5 or target.db.ko == True:
  203.             success = 5
  204.         elif success > 95:
  205.             success = 95
  206.        
  207.        
  208.         #temp values
  209.         damage_tier = 0
  210.         body_part = 'head'
  211.  
  212.         # a_desc, t_desc = build_skill_str.create_attack_desc(self.owner, target, damage_type, damage_tier, body_part)
  213.         # outcome = a_desc
  214.         # weapon = 'quarterstave'
  215.  
  216.         if roll > success:
  217.             self.owner.msg(f"[Success: {success} Roll: {roll}] " + " and hit! ")
  218.             self.take_damage(target, damage)
  219.         else:
  220.             self.owner.msg(f"[Success: {success} Roll: {roll}] You miss {target} with your stave!")
  221.         utils.delay(3, self.unbusy)
  222.         self.owner.db.attack_cd = now
  223.  
  224.     def take_damage(self, target, damage):
  225.         mob = target.key
  226.         location = target.location
  227.         mob_app = target.attributes.get('approached')
  228.        
  229.         hp = target.db.hp
  230.         hp -= damage
  231.         target.db.hp = hp
  232.  
  233.         location.msg_contents(f'{mob} has {hp} health remaining!')
  234.         if hp >= 1:
  235.             target.db.ko = False
  236.         elif hp <= 0 and target.db.ko != True:
  237.             target.db.ko = True
  238.             location.msg_contents(f'{mob} falls unconscious!')
  239.         if hp <= -100:
  240.             # Check for
  241.             for a in mob_app:
  242.                 ap_list = a.attributes.get('approached')
  243.                 ap_list.remove(target)
  244.             okay = target.delete()
  245.             if not okay:
  246.                 location.msg_contents(f'\nERROR: {mob} not deleted, probably because delete() returned False.')
  247.             else:
  248.                 location.msg_contents(f'{mob} breathes a final breath and expires.')
  249.         return
  250.    
  251.     def unbusy(self):
  252.             self.owner.msg('|yYou are no longer busy.|n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement