def UnselectNoRedraw (): pc = GemRB.GameGetSelectedPCSingle () LeftCount = Store['StoreItemCount'] for i in range (LeftCount, 0, -1): Flags = GemRB.IsValidStoreItem (pc, i-1, ITEM_STORE)&SHOP_SELECT if Flags: GemRB.ChangeStoreItem (pc, i-1, SHOP_BUY|SHOP_SELECT) RightCount = len (inventory_slots) for Slot in range (RightCount): Flags = GemRB.IsValidStoreItem (pc, inventory_slots[Slot], ITEM_PC) & SHOP_SELECT if Flags: GemRB.ChangeStoreItem (pc, inventory_slots[Slot], SHOP_SELL|SHOP_SELECT)
def IdentifyPressed (): pc = GemRB.GameGetSelectedPCSingle () Count = len(inventory_slots) # get all the selected items toID = [] for Slot in range (0, Count): Flags = GemRB.IsValidStoreItem (pc, inventory_slots[Slot], ITEM_PC) if Flags & SHOP_SELECT and Flags & SHOP_ID: toID.append(Slot) # enough gold? EndGold = GemRB.GameGetPartyGold () - Store['IDPrice'] * len(toID) if EndGold < 0: return # identify Window = StoreIdentifyWindow TextArea = Window.GetControl (23) for i in toID: GemRB.ChangeStoreItem (pc, inventory_slots[i], SHOP_ID) Slot = GemRB.GetSlotItem (pc, inventory_slots[i]) Item = GemRB.GetItem (Slot['ItemResRef']) # FIXME: some items have the title, some don't - figure it out TextArea.Append(Item['ItemNameIdentified']) TextArea.Append("\n\n") TextArea.Append(Item['ItemDescIdentified']) TextArea.Append("\n\n\n") GemRB.GameSetPartyGold (EndGold) UpdateStoreIdentifyWindow () return
def OnDragItem(): """Updates dragging.""" if GemRB.IsDraggingItem() == 2: return #don't call when splitting items if ItemAmountWindow != None: return pc = GemRB.GameGetSelectedPCSingle() slot = GemRB.GetVar("ItemButton") slot_item = GemRB.GetSlotItem(pc, slot) if not GemRB.IsDraggingItem(): item = GemRB.GetItem(slot_item["ItemResRef"]) GemRB.DragItem(pc, slot, item["ItemIcon"], 0, 0) else: SlotType = GemRB.GetSlotType(slot, pc) #special monk check if GemRB.GetPlayerStat(pc, IE_CLASS) == 0x14: #offhand slot mark if SlotType["Effects"] == TYPE_OFFHAND: SlotType["ResRef"] = "" GemRB.DisplayString(61355, 0xffffff) if SlotType["ResRef"] != "": if slot_item: item = GemRB.GetItem(slot_item["ItemResRef"]) #drag items into a bag if item["Function"] & 4: #first swap them GemRB.DropDraggedItem(pc, slot) #enter the store GemRB.EnterStore(slot_item["ItemResRef"]) #if it is possible to add, then do it ret = GemRB.IsValidStoreItem(pc, slot, 0) if ret & SHOP_SELL: GemRB.ChangeStoreItem(pc, slot, SHOP_SELL) else: msg = 9375 if ret & SHOP_FULL: if GUICommon.GameIsIWD1() or GUICommon.GameIsIWD2( ): msg = 24893 elif GUICommon.HasTOB: msg = 54692 GemRB.DisplayString(msg, 0xffffff) #leave (save) store GemRB.LeaveStore() GemRB.DropDraggedItem(pc, slot) # drop item if it caused us to disable the inventory view (example: cursed berserking sword) if GemRB.GetPlayerStat(pc, IE_STATE_ID) & ( STATE_BERSERK) and GemRB.IsDraggingItem(): GemRB.DropDraggedItem(pc, -3) GUIINV.UpdateInventoryWindow() return
def SelectBuy(): Window = StoreShoppingWindow pc = GemRB.GameGetSelectedPCSingle() LeftIndex = GemRB.GetVar("LeftIndex") GemRB.ChangeStoreItem(pc, LeftIndex, SHOP_BUY | SHOP_SELECT) RedrawStoreShoppingWindow() return
def SelectSell (): Window = StoreShoppingWindow pc = GemRB.GameGetSelectedPCSingle () RightIndex = GemRB.GetVar ("RightIndex") GemRB.ChangeStoreItem (pc, inventory_slots[RightIndex], SHOP_SELL|SHOP_SELECT) RedrawStoreShoppingWindow () return
def ToBagPressed(): Window = StoreShoppingWindow pc = GemRB.GameGetSelectedPCSingle() RightCount = len(inventory_slots) #no need to go reverse for Slot in range(RightCount): Flags = GemRB.IsValidStoreItem(pc, inventory_slots[Slot], ITEM_PC) if Flags & SHOP_SELECT: GemRB.ChangeStoreItem(pc, inventory_slots[Slot], SHOP_SELL) UpdateStoreShoppingWindow() return
def ToBackpackPressed(): Window = StoreShoppingWindow pc = GemRB.GameGetSelectedPCSingle() LeftCount = Store['StoreItemCount'] #going backwards because removed items shift the slots for i in range(LeftCount, 0, -1): Flags = GemRB.IsValidStoreItem(pc, i - 1, ITEM_STORE) & SHOP_SELECT if Flags: GemRB.ChangeStoreItem(pc, i - 1, SHOP_BUY) UpdateStoreShoppingWindow() return
def SellPressed (): Window = StoreShoppingWindow pc = GemRB.GameGetSelectedPCSingle () RightCount = len (inventory_slots) #no need to go reverse for Slot in range (RightCount): Flags = GemRB.IsValidStoreItem (pc, inventory_slots[Slot], ITEM_PC) & SHOP_SELECT if Flags: GemRB.ChangeStoreItem (pc, inventory_slots[Slot], SHOP_SELL) GemRB.GameSetPartyGold (GemRB.GameGetPartyGold ()+SellSum) GemRB.PlaySound(DEF_SOLD) UpdateStoreShoppingWindow () return
def OnDragItem (): """Updates dragging.""" if GemRB.IsDraggingItem()==2: return #don't call when splitting items if ItemAmountWindow != None: return pc = GemRB.GameGetSelectedPCSingle () slot = GemRB.GetVar ("ItemButton") slot_item = GemRB.GetSlotItem (pc, slot) if not GemRB.IsDraggingItem (): item = GemRB.GetItem (slot_item["ItemResRef"]) GemRB.DragItem (pc, slot, item["ItemIcon"], 0, 0) else: SlotType = GemRB.GetSlotType (slot, pc) #special monk check if GemRB.GetPlayerStat (pc, IE_CLASS)==0x14: #offhand slot mark if SlotType["Effects"]==TYPE_OFFHAND: SlotType["ResRef"]="" GemRB.DisplayString (61355, 0xffffff) if SlotType["ResRef"]!="": if slot_item: item = GemRB.GetItem (slot_item["ItemResRef"]) #drag items into a bag if item["Function"]&4: #first swap them GemRB.DropDraggedItem (pc, slot) #enter the store GemRB.EnterStore (slot_item["ItemResRef"]) #if it is possible to add, then do it if GemRB.IsValidStoreItem (pc, slot, 0)&SHOP_SELL: GemRB.ChangeStoreItem (pc, slot, SHOP_SELL) else: GemRB.DisplayString( 9375, 0xffffff) #leave (save) store GemRB.LeaveStore() GemRB.DropDraggedItem (pc, slot) GUIINV.UpdateInventoryWindow () return
def StealPressed(): Window = StoreShoppingWindow LeftIndex = GemRB.GetVar("LeftIndex") pc = GemRB.GameGetSelectedPCSingle() #percentage skill check, if fails, trigger StealFailed #if difficulty = 0 and skill=100, automatic success #if difficulty = 0 and skill=50, 50% success #if difficulty = 50 and skill=50, 0% success #if skill>random(100)+difficulty - success if GUICommon.CheckStat100(pc, IE_PICKPOCKET, Store['StealFailure']): GemRB.ChangeStoreItem(pc, LeftIndex, SHOP_STEAL) UpdateStoreStealWindow() else: GemRB.StealFailed() CloseStoreWindow() return
def IdentifyPressed(): IDPrice = Store['IDPrice'] if (GemRB.GameGetPartyGold() < IDPrice): return Index = GemRB.GetVar("Index") if (Index < 0): return pc = GemRB.GameGetSelectedPCSingle() Count = len(inventory_slots) if Index >= Count: return GemRB.ChangeStoreItem(pc, inventory_slots[Index], SHOP_ID) GemRB.GameSetPartyGold(GemRB.GameGetPartyGold() - IDPrice) UpdateStoreIdentifyWindow() return
def BuyPressed(): Window = StoreShoppingWindow if (BuySum > GemRB.GameGetPartyGold()): ErrorWindow(50081) return pc = GemRB.GameGetSelectedPCSingle() LeftCount = Store['StoreItemCount'] #going backwards because removed items shift the slots for i in range(LeftCount, 0, -1): Flags = GemRB.IsValidStoreItem(pc, i - 1, ITEM_STORE) & SHOP_SELECT if Flags: Slot = GemRB.GetStoreItem(i - 1) Item = GemRB.GetItem(Slot['ItemResRef']) Price = Item['Price'] * Store['SellMarkup'] / 100 if Price <= 0: Price = 1 if GemRB.ChangeStoreItem(pc, i - 1, SHOP_BUY): GemRB.GameSetPartyGold(GemRB.GameGetPartyGold() - Price) UpdateStoreShoppingWindow() return
def SelectID (): pc = GemRB.GameGetSelectedPCSingle () Index = GemRB.GetVar ("Index") GemRB.ChangeStoreItem (pc, inventory_slots[Index], SHOP_ID|SHOP_SELECT) RedrawStoreIdentifyWindow () return
def OnDragItem (btn): """Updates dragging.""" #don't call when splitting items if ItemAmountWindow != None: return slot = btn.Value pc = GemRB.GameGetSelectedPCSingle () slot_item = GemRB.GetSlotItem (pc, slot) GemRB.GetView ("MsgSys").SetText ("") if not GemRB.IsDraggingItem (): item = GemRB.GetItem (slot_item["ItemResRef"]) GemRB.DragItem (pc, slot, item["ItemIcon"], 0, 0) if slot == 2: # reset disguise GemRB.SetGlobal ("APPEARANCE", "GLOBAL", 0) else: SlotType = GemRB.GetSlotType (slot, pc) #special monk check if GemRB.GetPlayerStat (pc, IE_CLASS) == 20 and SlotType["Effects"] == TYPE_OFFHAND: SlotType["ResRef"] = "" GemRB.DisplayString (61355, ColorWhite) if SlotType["ResRef"]!="": if slot_item: item = GemRB.GetItem (slot_item["ItemResRef"]) #drag items into a bag if item["Function"] & ITM_F_CONTAINER: #first swap them GemRB.DropDraggedItem (pc, slot) #enter the store GemRB.EnterStore (slot_item["ItemResRef"]) #if it is possible to add, then do it ret = GemRB.IsValidStoreItem (pc, slot, 0) if ret&SHOP_SELL: GemRB.ChangeStoreItem (pc, slot, SHOP_SELL) else: msg = 9375 if ret&SHOP_FULL: if GameCheck.IsIWD1() or GameCheck.IsIWD2(): msg = 24893 elif GameCheck.HasTOB(): msg = 54692 GemRB.DisplayString(msg, ColorWhite) #leave (save) store GemRB.LeaveStore() item = GemRB.GetSlotItem (0, 0) itemData = GemRB.GetItem (item['ItemResRef']) GemRB.DropDraggedItem (pc, slot) # handle pst disguises if slot == 2 and item['ItemResRef'] == 'dustrobe': GemRB.SetGlobal ("APPEARANCE", "GLOBAL", 2) elif slot < 21 and itemData['AnimationType'] != '': GemRB.SetGlobal ("APPEARANCE", "GLOBAL", 0) # drop item if it caused us to disable the inventory view (example: cursed berserking sword) if GemRB.GetPlayerStat (pc, IE_STATE_ID) & (STATE_BERSERK) and GemRB.IsDraggingItem (): GemRB.DropDraggedItem (pc, -3) UpdateInventoryWindow () return