Skip to content

Commit

Permalink
- Item store define custom prices for gear
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed May 21, 2021
1 parent 37437c9 commit 3af8aed
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 142 deletions.
34 changes: 23 additions & 11 deletions src/BDO_Enhancement_Tool/Core/ItemStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def get_update(self, id: str) -> Tuple[float, Union[None, list]]:
return -1.0, None


def check_in_dict(dic, key, subkey, value):
if key in dic:
gm = dic[key]
else:
gm = {}
dic[key] = gm
gm[subkey] = value


class ItemStore(object):
"""
This may later be re-vamped to get items from database
Expand Down Expand Up @@ -98,17 +107,14 @@ def check_out_item(self, item_id):
item_id = STR_FMT_ITM_ID.format(item_id)
return item_id

def override_gear_price(self, gear, level, price):
if gear in self.custom_prices:
gm = self.custom_prices[gear]
else:
gm = {}
self.custom_prices[gear] = gm
gm[level] = price
def override_gear_price(self, item_id, level, price):
item_id = self.check_out_item(item_id)
check_in_dict(self.custom_prices, item_id, level, price)

def price_is_overridden(self, gear, grade):
if gear in self.custom_prices:
cust_price = self.custom_prices[gear]
def price_is_overridden(self, item_id, grade):
item_id = self.check_out_item(item_id)
if item_id in self.custom_prices:
cust_price = self.custom_prices[item_id]
return grade in cust_price
else:
return False
Expand Down Expand Up @@ -149,6 +155,7 @@ def get_cost(self, item_id, bn_mp=None):
if bn_mp is None: # those cost of just an item id is the base cost
bn_mp = 0

item_id = self.check_out_item(item_id)
if item_id in self.custom_prices:
price_reg = self.custom_prices[item_id]
if bn_mp in price_reg:
Expand All @@ -174,7 +181,12 @@ def set_state_json(self, state):
this_item = ItemStoreItem(None, None)
this_item.set_state_json(_st)
self.store_items[key] = this_item
self.custom_prices = state.pop('custom_prices')
customs = {}
# These items are indexed by integers buy json saves them as strings.. Gross
for k,v in state.pop('custom_prices').items():
v = {int(i):j for i,j in v.items()}
customs[k] = v
self.custom_prices = customs

def __getstate__(self):
return self.get_state_json()
Expand Down
19 changes: 2 additions & 17 deletions src/BDO_Enhancement_Tool/EnhanceModelSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ def get_state_json(self):
self.P_QUEST_FS_INC: self[self.P_QUEST_FS_INC],
self.P_VERSION: self.VERSION
})
item_store = super_state[self.P_ITEM_STORE]
customs = item_store['custom_prices']
gear_customs = {}
gear_entries = [k for k in customs.keys() if isinstance(k, Gear)]
for ge in gear_entries:
vm = customs.pop(ge)
gear_customs[id(ge)] = vm
super_state['gear_customs'] = gear_customs
return super_state

def unwrap_gear_list(self, gl):
Expand Down Expand Up @@ -148,17 +140,10 @@ def set_state_json(self, state):
valks = state.pop(self.P_VALKS)
new_valks = {int(k): v for k,v in valks.items()}
state[self.P_VALKS] = new_valks

item_store = state[self.P_ITEM_STORE]
customs = item_store['custom_prices']
gear_customs = state.pop('gear_customs')

for k, v in gear_customs.items():
gid = int(k)
if gid in self.gear_reg:
customs[self.gear_reg[gid]] = {int(x):y for x,y in v.items()}
custom_gear_prices = state[self.P_ITEM_STORE].pop('custom_gear_prices')

super(EnhanceModelSettings, self).set_state_json(state) # load settings base settings first
self.item_store.set_custom_gear_json(custom_gear_prices, self.gear_reg)
update_r = {
self.P_FAIL_STACKERS: P_FAIL_STACKERS,
self.P_FAIL_STACKER_SECONDARY: P_FAIL_STACKER_SECONDARY,
Expand Down
2 changes: 1 addition & 1 deletion src/BDO_Enhancement_Tool/FrmMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def open_file_dlg(self):
self.ui.statusbar.showMessage('Aborted opening file.')

def backup_model_load(self):
self.model = Enhance_model(settings=FrmSettings(self, item_store=GearItemStore()))
self.model = Enhance_model(settings=FrmSettings(self, item_store=GearItemStore(self.model.settings)))
self.load_ui_common()

def open_file(self, fileName):
Expand Down
111 changes: 38 additions & 73 deletions src/BDO_Enhancement_Tool/Widgets/Abstract_FS_Table.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,16 @@ def cellChanged_callback(self, row, col):
except ValueError:
self.frmMain.sig_show_message.emit(self.frmMain.WARNING, 'Cost must be a number.')

def cmdFSUpdateMP_callback(self, thread: QThread, ret):
model = self.enh_model
frmMain = self.frmMain

idx_NAME = self.HEADERS.index(HEADER_NAME)

def MPThread_sig_done(self, thread: QThread, ret):
if isinstance(ret, Exception):
print(ret)
frmMain.sig_show_message.emit(frmMain.CRITICAL, 'Error contacting central market')
else:
settings = model.settings
item_store: ItemStore = settings[settings.P_ITEM_STORE]
with QBlockSig(self):
for i in range(self.rowCount()):
this_gear: Gear = self.cellWidget(i, idx_NAME).gear
self.fs_gear_set_costs(this_gear, item_store, i)
frmMain.sig_show_message.emit(frmMain.REGULAR, 'Fail stacking prices updated')
thread.wait(2000)
if thread.isRunning():
thread.terminate()
self.mp_threads.remove(thread)

def cmdFSRemove_clicked(self):
return
with QBlockSig(self):
for i in range(self.rowCount()):
self.set_item_data(i)
self.model_invalidate_func()
self.main_invalidate_func()

def action_table_FS_remove_triggered(self):
tmodel = self.enh_model
tsettings = tmodel.settings
idx_NAME = self.HEADERS.index(HEADER_NAME)
Expand All @@ -113,16 +100,7 @@ def cmdFSRemove_clicked(self):
self.removeRow(i)
tsettings.changes_made = True

def cmdFSUpdateMP_clicked(self):
model = self.enh_model
settings = model.settings

thread = MPThread(model.update_costs, settings[self.prop_in_list] + settings[self.prop_out_list])
self.mp_threads.append(thread)
thread.sig_done.connect(self.cmdFSUpdateMP_callback)
thread.start()

def cmdFSAdd_clicked(self, bool_):
def action_table_FS_add_triggered(self, bool_):
model = self.enh_model

gear_type = list(gear_types.items())[0][1]
Expand All @@ -134,22 +112,20 @@ def cmdFSAdd_clicked(self, bool_):

def fs_gear_sig_gear_changed(self, gw: GearWidget, old_gear:Gear):
model = self.enh_model
settings = model.settings
item_store: ItemStore = settings[settings.P_ITEM_STORE]
this_gear:Gear = gw.gear
model.swap_gear(old_gear, this_gear)
with QBlockSig(self):
self.fs_gear_set_costs(this_gear, item_store, gw.row())
self.set_item_data(gw.row())

def table_FS_add_gear(self, this_gear:Gear, check_state=Qt.Checked):
frmMain = self.frmMain
model = self.enh_model
settings = model.settings
rc = self.rowCount()

idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)
idx_HEADER_NAME = self.get_header_index(HEADER_NAME)
idx_HEADER_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE)
idx_HEADER_TARGET = self.get_header_index(HEADER_TARGET)

with SpeedUpTable(self):
with SpeedUpTable(self, blk_sig=True):
self.insertRow(rc)
with QBlockSig(self):
# If the rows are not initialized then the context menus will bug out
Expand All @@ -171,50 +147,53 @@ def table_FS_add_gear(self, this_gear:Gear, check_state=Qt.Checked):
cmb_gt.currentTextChanged.connect(lambda x: set_cell_color_compare(twi_gt, x))
cmb_enh.currentTextChanged.connect(lambda x: set_cell_lvl_compare(twi_lvl, x, this_gear.gear_type))

item_store = model.item_store()
f_two.add_to_table(self, rc, col=idx_HEADER_NAME)
self.setCellWidget(rc, idx_HEADER_GEAR_TYPE, cmb_gt)

with QBlockSig(self):
f_two.add_to_table(self, rc, col=0)
self.setCellWidget(rc, 1, cmb_gt)
twi = monnies_twi_factory(this_gear.base_item_cost)
self.setItem(rc, 2, twi)
if item_store.price_is_overridden(this_gear, -1):
twi.setForeground(COLOR_CUSTOM_PRICE)
self.setCellWidget(rc, 3, cmb_enh)
self.setItem(rc, 1, twi_gt)
self.setItem(rc, 3, twi_lvl)
self.setCellWidget(rc, idx_HEADER_TARGET, cmb_enh)
self.setItem(rc, idx_HEADER_GEAR_TYPE, twi_gt)
self.setItem(rc, idx_HEADER_TARGET, twi_lvl)

set_cell_lvl_compare(twi_lvl, cmb_enh.currentText(), this_gear.gear_type)
set_cell_color_compare(twi_gt, cmb_gt.currentText())

f_two.chkInclude.stateChanged.connect(lambda x: self.gw_check_state_changed(f_two, x))
self.clearSelection()
self.selectRow(rc)


with QBlockSig(self):
self.cellWidget(rc, 1).currentTextChanged.connect(frmMain.invalidate_fs_list)
self.cellWidget(rc, 3).currentTextChanged.connect(frmMain.invalidate_fs_list)
self.resizeColumnToContents(0)
self.cellWidget(rc, idx_HEADER_GEAR_TYPE).currentTextChanged.connect(frmMain.invalidate_fs_list)
self.cellWidget(rc, idx_HEADER_TARGET).currentTextChanged.connect(frmMain.invalidate_fs_list)
self.set_item_data(rc)
self.resizeColumnToContents(idx_HEADER_NAME)
f_two.sig_gear_changed.connect(self.fs_gear_sig_gear_changed)

def set_item_data(self, row):
idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)
idx_HEADER_NAME = self.get_header_index(HEADER_NAME)

item_store = self.enh_model.item_store()
this_gear = self.cellWidget(row, idx_HEADER_NAME).gear
twi = monnies_twi_factory(this_gear.base_item_cost)
with QBlockSig(self):
self.setItem(row, idx_BASE_ITEM_COST, twi)
if item_store.price_is_overridden(this_gear, -1):
twi.setForeground(COLOR_CUSTOM_PRICE)

def gw_check_state_changed(self, gw:GearWidget, state):
raise NotImplementedError()

def fs_gear_set_costs(self, this_gear:Gear, item_store:ItemStore, row):
self.item(row, self.get_header_index(HEADER_BASE_ITEM_COST)).setText(MONNIES_FORMAT.format(this_gear.base_item_cost))

def make_menu(self, menu:QMenu):
super(AbstractTableFS, self).make_menu(menu)
menu.addSeparator()
action_table_FS_add = QAction('Add Item', menu)
action_table_FS_add.setIcon(pix.get_icon(STR_PLUS_PIC))
menu.addAction(action_table_FS_add)
action_table_FS_add.triggered.connect(self.cmdFSAdd_clicked)
action_table_FS_add.triggered.connect(self.action_table_FS_add_triggered)
action_table_FS_remove = QAction('Remove Item', menu)
action_table_FS_remove.setIcon(pix.get_icon(STR_MINUS_PIC))
menu.addAction(action_table_FS_remove)
action_table_FS_remove.triggered.connect(self.cmdFSRemove_clicked)
action_table_FS_remove.triggered.connect(self.action_table_FS_remove_triggered)
action_table_FS_mp_update = QAction('Central Market: Update All', menu)
action_table_FS_mp_update.setIcon(pix.get_icon(STR_GOLD_PIC))
settings = self.enh_model.settings
Expand All @@ -231,20 +210,6 @@ def action_mp_update_triggered(self):
thrd.sig_done.connect(self.MPThread_sig_done)
thrd.start()

def MPThread_sig_done(self, ret):
if isinstance(ret, Exception):
return
idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)
idx_NAME = self.get_header_index(HEADER_NAME)
with QBlockSig(self):
for i in range(0, self.rowCount()):
gw = self.cellWidget(i, idx_NAME)
this_gear = gw.gear
itm = self.item(i, idx_BASE_ITEM_COST)
itm.setText(MONNIES_FORMAT.format(int(round(this_gear.base_item_cost))))
self.model_invalidate_func()
self.main_invalidate_func()

def check_index_widget_menu(self, index:QModelIndex, menu:QMenu):
pass

Expand Down
11 changes: 3 additions & 8 deletions src/BDO_Enhancement_Tool/Widgets/Abstract_Gear_Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,14 @@ def action_mp_update_triggered(self):
def MPThread_sig_done(self, ret):
if isinstance(ret, Exception):
return
idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)
idx_NAME = self.get_header_index(HEADER_NAME)
invalids = []
with QBlockSig(self):
for i in range(0, self.topLevelItemCount()):
t_itm = self.topLevelItem(i)
gw = self.itemWidget(t_itm, idx_NAME)
this_gear = gw.gear
t_itm.setText(idx_BASE_ITEM_COST, MONNIES_FORMAT.format(int(round(this_gear.base_item_cost))))
self.set_item_data(t_itm)
invalids.append(t_itm)
for j in range(0, t_itm.childCount()):
child = t_itm.child(j)
child.setText(idx_BASE_ITEM_COST, MONNIES_FORMAT.format(int(round(this_gear.base_item_cost))))
if len(invalids) > 0:
self.invalidate_items(invalids)
return invalids

def remove_selected_equipment(self):
Expand Down
4 changes: 0 additions & 4 deletions src/BDO_Enhancement_Tool/Widgets/TreeEquipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ def table_itemChanged(self, t_item: QTreeWidgetItem, col):
super(TableEquipment, self).table_itemChanged(t_item, col)
self.invalidate_item(t_item)

def MPThread_sig_done(self, ret):
invalids = super(TableEquipment, self).MPThread_sig_done(ret)
self.invalidate_item(invalids)

def master_gw_sig_gear_changed(self, gw:GearWidget, old_gear:Gear):
if old_gear in self.invalidated_gear:
self.invalidated_gear.remove(old_gear)
Expand Down
4 changes: 0 additions & 4 deletions src/BDO_Enhancement_Tool/Widgets/table_FS_Secondary.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ def table_itemChanged(self, t_item: QTreeWidgetItem, col):
super(TableFSSecondary, self).table_itemChanged(t_item, col)
self.invalidate_item(t_item)

def MPThread_sig_done(self, ret):
invalids = super(TableFSSecondary, self).MPThread_sig_done(ret)
self.invalidate_item(invalids)

def master_gw_sig_gear_changed(self, gw:GearWidget, old_gear:Gear):
super(TableFSSecondary, self).master_gw_sig_gear_changed(gw, old_gear)
twi = gw.parent_widget
Expand Down
2 changes: 0 additions & 2 deletions src/BDO_Enhancement_Tool/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
# TODO: Bug in genome fs when remove multiple items
# TODO: Cannot set max fs in genome list
# TODO: PRI cost via enhance is calculated in the calc_fs method of the model. How does with affect optimizer and other stand alone?
# TODO: Num fails isn't accurate on equ tab when item is cronned
# TODO: Cron blocker
# TODO: MP lock interface
# TODO: Gear widget on enhance for profit items

# TODO: Distinguish items that have a custom price from ones that are manually set (text color, icon)
# TODO: Gears that are freshly loaded ont he for-profit section are still messed up

# TODO: Tooltip
Expand Down
Loading

0 comments on commit 3af8aed

Please sign in to comment.