Guest User

Wynncraft DPS calculator

a guest
Oct 2nd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # Wynncraft DPS calculator
  2.  
  3. import requests, json
  4.  
  5. print('\n:: ------------------- WYNNCRAFT DPS CALCULATOR ------------------- ::\n:: DPS values for super fast and super slow weapons are approximate ::\n')
  6.  
  7. # Get item name as string
  8. item_name = str(input('Item name   : '))
  9.  
  10. payload = {'action': 'itemDB', 'search': item_name}
  11.  
  12. # Fetch JSON with parameters itemDB and item name
  13. r = requests.get('https://api.wynncraft.com/public_api.php', params = payload)
  14.  
  15. # Get JSON data
  16. json_data = r.json()
  17.  
  18. # Get specific values
  19. official_name = json_data['items'][0]['name']
  20. lore = str(json_data['items'][0]['addedLore'])
  21. attack_speed = json_data['items'][0]['attackSpeed']
  22. damage = json_data['items'][0]['damage']
  23.  
  24. # Map weapon attack speed strings to int values
  25. weapon_time_dict = {
  26.     'SUPER_FAST': 4,   
  27.     'VERY_FAST': 2.5,
  28.     'FAST': 1.9,
  29.     'NORMAL': 1.7,
  30.     'SLOW': 1.3,
  31.     'VERY_SLOW': 0.8,
  32.     'SUPER_SLOW': 0.4
  33. }
  34.  
  35. # Map uppercase attack speed strings to more readable strings
  36. weapon_lower_dict = {
  37.     'SUPER_FAST': 'Super fast',
  38.     'VERY_FAST': 'Very fast',
  39.     'FAST': 'Fast',
  40.     'NORMAL': 'Normal',
  41.     'SLOW': 'Slow',
  42.     'VERY_SLOW': 'Very slow',
  43.     'SUPER_SLOW': 'Super slow'
  44. }
  45.  
  46. # Get average weapon damage
  47. weapon_damages = damage.split('-')
  48. weapon_approx_damage = (int(weapon_damages[1]) + int(weapon_damages[0])) / 2
  49.  
  50. # Calculate dps
  51. dps = weapon_approx_damage * weapon_time_dict.get(attack_speed)
  52.  
  53. # Print everything
  54. print('Lore        : ' + lore)
  55. print('Attack speed: ' + weapon_lower_dict.get(attack_speed))
  56. print('Damage      : ' + damage)
  57. print('Avg damage  : ' + '%.2f' % weapon_approx_damage)
  58. print('\n:: -------------- ::')
  59. print(':: DPS   : ' + '%.2f' % dps + ' ::')
  60. print(':: -------------- ::')
Advertisement
Add Comment
Please, Sign In to add comment