Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Character import for shadowcraft engine
# -*- coding: utf-8 -*-
from os import path
import sys
import pprint
import shelve
sys.path.append(path.abspath(path.join(path.dirname(__file__), '..')))
from wowapi.api import WoWApi
wowapi = WoWApi()
pp = pprint.PrettyPrinter(indent=4)
class ItemDB:
def __init__(self):
pass
def get_item(self, id):
return None
def add_item(self, id, item):
pass
def close(self):
pass
class SimpleItemDB(ItemDB):
def __init__(self, path):
self.path = path
self.db = shelve.open(path, writeback = True)
def get_item(self, id):
str_id = str(id)
if str_id in self.db:
return self.db[str_id]
else:
return None
def add_item(self, id, item):
str_id = str(id)
self.db[str_id] = item
self.sync() # FIXME it's best to call it once, at the end of script with close()
def close(self):
self.db.close()
def sync(self):
self.db.sync()
item_db = SimpleItemDB('item_db')
def get_item_cached(region, id):
cached_item = item_db.get_item(id)
if cached_item:
return cached_item
else:
item = wowapi.get_item(region, id)
item_db.add_item(id, item)
return item
class CharacterData:
races = {1 : 'human',
2 : 'orc',
3 : 'dwarf',
4 : 'night_elf',
5 : 'undead',
6 : 'tauren',
7 : 'gnome',
8 : 'troll',
9 : 'goblin',
10 : 'blood_elf',
11 : 'draenie',
22 : 'worgen',
24 : 'pandaren'}
enchants = {4441 : 'windsong'}
def __init__(self, region, realm, name):
self.region = region
self.realm = realm
self.name = name
self.raw_data = None
def do_import(self):
self.raw_data = wowapi.get_character(self.region , self.realm, self.name, ['talents', 'items', 'stats'])
def get_race(self):
return CharacterData.races[self.raw_data[u'data'][u'race']]
def get_weapon(self, weapon_data, item_data):
weapon_info = weapon_data['data'][u'weaponInfo']
damage_info = weapon_info[u'damage']
damage = (damage_info[u'max'] + damage_info[u'min']) / 2
speed = weapon_info[u'weaponSpeed']
# FIXME: need better weapon type recognition here, don't know how to tell weapon type using api
if speed <= 1.8:
type = 'dagger'
else:
type = 'axe'
enchant = CharacterData.enchants[item_data[u'tooltipParams'][u'enchant']]
return [damage, speed, type, enchant]
def get_mh(self):
item_data = self.raw_data['data'][u'items'][u'mainHand']
weapon_data = get_item_cached(self.region, item_data[u'id'])
# weapon_data = get_item_cached(self.region, 85924)
ret = self.get_weapon(weapon_data, item_data)
return ret
def get_oh(self):
item_data = self.raw_data['data'][u'items'][u'offHand']
weapon_data = get_item_cached(self.region, item_data[u'id'])
ret = self.get_weapon(weapon_data, item_data)
return ret
def get_procs(self):
# TODO
return ['windswept_pages', 'searing_words']
#return ['relic_of_xuen', 'searing_words']
# return ['relic_of_xuen', 'windswept_pages']
def get_stats(self):
stats_data = self.raw_data['data'][u'stats']
agi = stats_data[u'agi']
str = stats_data[u'str']
ap = stats_data[u'attackPower']
crit = stats_data[u'critRating']
hit = stats_data[u'hitRating']
exp = stats_data[u'expertiseRating']
haste = stats_data[u'hasteRating']
mast = stats_data[u'masteryRating']
ret = [str, agi, ap - 2 * agi, crit, hit, exp, haste, mast]
# ret = [str, agi + 956, 250, crit, hit, exp, haste, mast]
# pp.pprint(ret)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.