Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Samalmeida1028 committed Dec 8, 2022
2 parents acaa59f + 061a7f3 commit ff9edd5
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .idea/Dnd_Shop_Manager.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 17 additions & 20 deletions Objects/Shop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from Objects.Item import ItemManager
from Objects.Item import *
import random


Expand Down Expand Up @@ -31,26 +31,24 @@ def __str__(self): # this puts the shop items in JSON format for saving
def str(self):
return self.__str__()

def addItems(self, items): # adds a list of items, given an item list, to the shop
def addItems(self, items: dict): # adds a list of items, given an item list, to the shop
for key in items:
self.items[key] = {"Cost": "", "Amount": "0"}
if items[key]["Base Region"] == self.region:
self.items[key]["Cost"] = str((float(items[key]["Value"]) * 1 / float(items[key]["Rarity"])) // 2)
else:
self.items[key]["Cost"] = str((float(items[key]["Value"]) * 1 / float(items[key]["Rarity"])))

def addNewItem(self, item, amount, cost): # adds a new item to the shop
def addNewItem(self, item: Item, amount: str, cost: float): # adds a new item to the shop
self.items[item.name] = {"Cost": float(cost), "Amount": amount}

def addItem(self, name, amount): # adds a previous item to the shop, increasing the amount
def addItem(self, name: str, amount: float): # adds a previous item to the shop, increasing the amount
temp = int(self.items[name]["Amount"])
temp += amount
self.items[name]["Amount"] = temp

def updateItemPrice(self, item_name, cost): # updates the cost of an item
temp = int(self.items[item_name]["Cost"])
temp = cost
self.items[item_name]["Cost"] = temp
def updateItemPrice(self, item_name: str, cost: float): # updates the cost of an item
self.items[item_name]["Cost"] = cost


#
Expand Down Expand Up @@ -106,30 +104,29 @@ def getShopTypes(self) -> dict: # returns all the different types of shops
types.update({'Shop Types': temp})
return types

def getShopByRegion(self, region) -> dict:
def getShopByRegion(self, region: str) -> dict:
regional_shops = {}
for k in self.shopList:
if self.shopList[k]["Region"] == region:
# print(k)
regional_shops.update({k: self.shopList[k]})
return regional_shops

def getShopByType(self, type_shop) -> dict:
def getShopByType(self, type_shop: str) -> dict:
type_shops = {}
for k in self.shopList:
if self.shopList[k]["Type"] == type_shop:
type_shops.update({k: self.shopList[k]})
return type_shops

def getShopByCity(self, city) -> dict:
def getShopByCity(self, city: str) -> dict:
city_shops = {}
for k in self.shopList:
if self.shopList[k]["City"] == city:
# print(k)
city_shops.update({k: self.shopList[k]})
return city_shops

def getShopByTypeinCity(self, city, shop_type) -> dict:
def getShopByTypeinCity(self, city: str, shop_type) -> dict:
city_shops = {}
for k in self.shopList:
if self.shopList[k]["City"] == city:
Expand All @@ -141,7 +138,7 @@ def getShopByTypeinCity(self, city, shop_type) -> dict:
def getItemAmount(self, shop_name: str, item: str) -> int:
return int(self.shopList[shop_name]["Items"][item]["Amount"])

def removeItem(self, shop_name, item):
def removeItem(self, shop_name:str, item: str):
self.shopList[shop_name]["Items"].pop(item)

def addNewItem(self, shop_name: str, item_name: str):
Expand All @@ -160,29 +157,29 @@ def increaseShopItemAmount(self, shop_name: str, item_name: str):
amount += 1
shop["Items"][item_name]["Amount"] = amount

def decreaseShopItemAmount(self, shop_name, item):
def decreaseShopItemAmount(self, shop_name: str, item):
amount = int(self.shopList[shop_name]["Items"][item]["Amount"])
amount -= 1
self.shopList[shop_name]["Items"][item]["Amount"] = amount

def decreaseShopGoldAmount(self, shop_name, gold):
def decreaseShopGoldAmount(self, shop_name: str, gold):
amount = int(float(self.shopList[shop_name]["GoldAmount"]))
amount -= round(gold)
if amount < 0:
amount = 0
self.shopList[shop_name]["GoldAmount"] = amount

def increaseShopGoldAmount(self, shop_name, gold):
def increaseShopGoldAmount(self, shop_name: str, gold):
amount = int(float(self.shopList[shop_name]["GoldAmount"]))
amount += round(gold)
if amount < 0:
amount = 0
self.shopList[shop_name]["GoldAmount"] = amount

def getShopByName(self, name) -> dict:
def getShopByName(self, name: str) -> dict:
return self.shopList[name]

def printShopItems(self, shop):
def printShopItems(self, shop: str ):
printed_shop = self.shopList[shop]
for k in printed_shop["Items"]:
cost = float(self.shopList[shop]["Items"][k]["Cost"]) / 100
Expand All @@ -197,7 +194,7 @@ def printShopItems(self, shop):
cost = str.format("%.2f" % float(cost)) + " gp"
print("%s : %s, Cost : %s" % (k, str(self.shopList[shop]["Items"][k]["Amount"]), cost))

def printShop(self, shop_name):
def printShop(self, shop_name: str):
shop = self.shopList[shop_name]
print("Shop name is: ", shop["Name"])
print("Shop shop_type is: ", shop["Type"])
Expand Down
Binary file modified Objects/__pycache__/Item.cpython-310.pyc
Binary file not shown.
Binary file modified Objects/__pycache__/Shop.cpython-310.pyc
Binary file not shown.
Binary file modified Objects/__pycache__/TypeAndRegionManager.cpython-310.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ _this also means you can use all save data as JSON objects_

**If you need to add items, then under "Scripts" there is an item adder script that can be used currently**

## TODO (in terminal app)
### Update:
added the ability to add items through the terminal!

- Allow user to add new items to the item list
## TODO (in terminal app)
- Remove shops, remove items from shops, remove regions, and remove items from regions
- Rename Shops
- add update shops to randomly update and change shops
Expand Down
2 changes: 1 addition & 1 deletion Resources/names/nicknames.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Resources/save_data/items.txt
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@
"Base Region": "Magic Lands"
},
"Mithril": {
"Name": "Mithral",
"Name": "Mithril",
"Type": "Material",
"Value": "1000",
"Rarity": ".6",
Expand Down Expand Up @@ -762,8 +762,8 @@
"Rarity": ".6",
"Base Region": "Magic Area"
},
"Mithral Plate Armor": {
"Name": "Mithral Plate Armor",
"Mithril Plate Armor": {
"Name": "Mithril Plate Armor",
"Type": "Armor",
"Value": "2000",
"Rarity": ".6",
Expand Down
3 changes: 1 addition & 2 deletions Resources/save_data/regions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"Polar": "[]",
"Oksandarr": "['Mines','Magic Lands']",
"Crestus": "['Mines','Plains']",
"Pitt": "[]",
"1": "[]"
"Pitt": "[]"
}
Loading

0 comments on commit ff9edd5

Please sign in to comment.