Advertisement
Kovitikus

CombatHandler Descriptor

Aug 9th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.00 KB | None | 0 0
  1. '''
  2. [Success: 0 Roll: 100] You bash dum with your stave! It suffers a small bruise to its head.
  3. dum has 80 health remaining!
  4. You are no longer busy.
  5. [Success: 0 Roll: 100] You bash dum with your stave! It suffers a small bruise to its head.
  6. dum has 80 health remaining!
  7. You need to wait 1 more second.
  8. You are in the middle of something.
  9. You are no longer busy.
  10. [Success: 0 Roll: 100] You bash dum with your stave! It suffers a small bruise to its head.
  11. dum has 80 health remaining!
  12. You need to wait 1 more second.
  13. You are in the middle of something.
  14. You are no longer busy.
  15. [Success: 0 Roll: 100] You bash dum with your stave! It suffers a small bruise to its head.
  16. dum has 80 health remaining!
  17. You need to wait 1 more second.
  18. You are in the middle of something.
  19. You are no longer busy.
  20. [Success: 0 Roll: 100] You bash dum with your stave! It suffers a small bruise to its head.
  21. dum has 80 health remaining!
  22. You are no longer busy.
  23. '''
  24.  
  25. from evennia import utils
  26. import time
  27. import random
  28.  
  29. class CombatHandler:
  30.     def __init__(self, owner):
  31.         self.owner = owner
  32.  
  33.     wound_tier = {'slash': ['shallow cut', 'cut', 'deep cut', 'severe cut', 'devastating cut'],
  34.     'pierce': ['faint wound', 'puncture', 'deep puncture', 'severe puncture', 'gaping wound'],
  35.     'bruise': ['small bruise', 'bruise', 'ugly bruise', 'major bruise', 'fracture']}
  36.  
  37.  
  38.     def create_attack_desc(self, attacker, target, damage_type, damage_tier, body_part):
  39.         attack_wound = self.wound_tier[damage_type][damage_tier]
  40.         determiner = 'an' if attack_wound[0] in ['a', 'e', 'i', 'o', 'u'] else 'a'
  41.  
  42.         if not attacker.attributes.has('figure'):
  43.             a_gender_pos = 'its'
  44.             a_gender_sin = 'It'
  45.         elif attacker.db.figure['gender'] == 'male':
  46.             a_gender_pos = 'his'
  47.             a_gender_sin = 'He'
  48.         elif attacker.db.figure['gender'] == 'female':
  49.             a_gender_pos = 'her'
  50.             a_gender_sin = 'She'
  51.  
  52.         if not target.attributes.has('figure'):
  53.             t_gender_pos = 'its'
  54.             t_gender_sin = 'It'
  55.         elif target.db.figure['gender'] == 'male':
  56.             t_gender_pos = 'his'
  57.             t_gender_sin = 'He'
  58.         elif target.db.figure['gender'] == 'female':
  59.             t_gender_pos = 'her'
  60.             t_gender_sin = 'She'
  61.  
  62.  
  63.         attacker_desc = f"{t_gender_sin} suffers {determiner} {attack_wound} to {t_gender_pos} {body_part}."
  64.         target_desc = f"You suffer {determiner} {attack_wound} to your {body_part}."
  65.  
  66.         return attacker_desc, target_desc
  67.  
  68.     def attack(self, target, damage_type):  
  69.         damage = 20
  70.  
  71.         # Create cooldown attribute if non-existent.
  72.         if not self.owner.attributes.has('attack_cd'):
  73.             self.owner.db.attack_cd = 0
  74.  
  75.         # Calculate current time, total cooldown, and remaining time.
  76.         now = time.time()
  77.         lastcast = self.owner.attributes.get('attack_cd')
  78.         cooldown = lastcast + 3
  79.         time_remaining = cooldown - now
  80.  
  81.         # Inform the attacker that they are in cooldown and exit the function.
  82.         if time_remaining > 0:
  83.             if time_remaining >= 2:
  84.                 message = f"You need to wait {int(time_remaining)} more seconds."
  85.             elif time_remaining >= 1 and time_remaining < 2:
  86.                 message = f"You need to wait {int(time_remaining)} more second."
  87.             elif time_remaining < 1:
  88.                 message = f"You are in the middle of something."
  89.             self.owner.msg(message)
  90.             return
  91.  
  92.         # roll = random.randint(1, 100)
  93.         # success = random.randint(5, 95)
  94.         roll = 100
  95.         success = 0
  96.  
  97.         #temp values
  98.         damage_tier = 0
  99.         body_part = 'head'
  100.  
  101.         a_desc, t_desc = self.create_attack_desc(self.owner, target, damage_type, damage_tier, body_part)
  102.  
  103.         if roll > success:
  104.             self.owner.msg(f"[Success: {success} Roll: {roll}] You bash {target} with your stave! " + a_desc)
  105.             self.take_damage(target, damage)
  106.         else:
  107.             self.owner.msg(f"[Success: {success} Roll: {roll}] You miss {target} with your stave!")
  108.         utils.delay(3, self.unbusy)
  109.         self.owner.db.attack_cd = now
  110.  
  111.     def take_damage(self, target, damage):
  112.         mob = target.key
  113.         location = target.location
  114.        
  115.         hp = target.db.hp
  116.         hp -= damage
  117.         location.msg_contents(f'{mob} has {hp} health remaining!')
  118.         if hp >= 1:
  119.             target.db.ko = False
  120.         elif hp <= 0 and target.db.ko != True:
  121.             target.db.ko = True
  122.             location.msg_contents(f'{mob} falls unconscious!')
  123.         if hp <= -100:
  124.             okay = target.delete()
  125.             if not okay:
  126.                 location.msg_contents(f'\nERROR: {mob} not deleted, probably because delete() returned False.')
  127.             else:
  128.                 location.msg_contents(f'{mob} breathes a final breath and expires.')
  129.         return
  130.    
  131.     def unbusy(self):
  132.             self.owner.msg('|yYou are no longer busy.|n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement