Advertisement
Kovitikus

Time Difference

Aug 3rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. '''
  2. [Success: 65 Roll: 41] You miss Bobby with your stave!
  3. Current time is 1564882188.8737004 and last command was 1564882188.5313141
  4. You need to wait 2 more seconds.
  5. Current time is 1564882189.2390356 and last command was 1564882188.5313141
  6. You need to wait 2 more seconds.
  7. Current time is 1564882189.6005547 and last command was 1564882188.5313141
  8. You need to wait 1 more seconds.
  9. Current time is 1564882189.9060621 and last command was 1564882188.5313141
  10. You need to wait 1 more seconds.
  11. Current time is 1564882190.20256 and last command was 1564882188.5313141
  12. You need to wait 1 more seconds.
  13. Current time is 1564882190.5381482 and last command was 1564882188.5313141
  14. You need to wait 0 more seconds.
  15. Current time is 1564882190.879274 and last command was 1564882188.5313141
  16. You need to wait 0 more seconds.
  17. Current time is 1564882191.2101352 and last command was 1564882188.5313141
  18. You need to wait 0 more seconds.
  19. Current time is 1564882191.517049 and last command was 1564882188.5313141
  20. You need to wait 0 more seconds.
  21. Current time is 1564882191.8005927 and last command was 1564882188.5313141
  22. [Success: 80 Roll: 17] You miss Bobby with your stave!
  23. '''
  24. class CmdStaveBash(BaseCommand):
  25.     '''
  26.    Use your staff to bash an enemy.
  27.  
  28.    Usage:
  29.        bash <target>
  30.    '''
  31.     key = 'bash'
  32.     help_category = 'combat'
  33.  
  34.     def func(self):
  35.         if not self.args:
  36.             self.caller.msg('Usage: bash <target>')
  37.             return
  38.        
  39.         attacker = self.caller
  40.         target = self.caller.search(self.args)
  41.         if not target:
  42.             self.caller.msg('That target does not exist.')
  43.             return
  44.        
  45.         now = time.time()
  46.        
  47.         lastcast = self.caller.db.stave_bash
  48.  
  49.         cooldown = lastcast + 3
  50.  
  51.         time_remaining = cooldown - now
  52.  
  53.         self.caller.msg(f'Current time is {now} and last command was {lastcast}')
  54.  
  55.         if lastcast and now - lastcast < 3:
  56.             message = f"You need to wait {int(time_remaining)} more seconds."
  57.             self.caller.msg(message)
  58.             return
  59.  
  60.         roll = random.randint(1, 100)
  61.         success = random.randint(5, 95)
  62.         if roll > success:
  63.             self.caller.msg(f'[Success: {success} Roll: {roll}] You bash {target} with your stave!')
  64.         else:
  65.             self.caller.msg(f'[Success: {success} Roll: {roll}] You miss {target} with your stave!')
  66.  
  67.         self.caller.db.stave_bash = now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement