Basic commands for deeptown optimizer
This commit is contained in:
parent
6f09002720
commit
47e8d156c8
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
69
modules/deeptown.py
Normal file
69
modules/deeptown.py
Normal file
@ -0,0 +1,69 @@
|
||||
import datetime
|
||||
|
||||
import discord
|
||||
import traductions as tr
|
||||
import modules.deeptownOptimizer.optimizer as optimizer
|
||||
|
||||
|
||||
class MainClass:
|
||||
name = "deeptown"
|
||||
|
||||
def __init__(self, guild):
|
||||
self.guild = guild
|
||||
self.optimizer = optimizer.Optimizer()
|
||||
|
||||
async def best_place_mine(self, msg, command, args):
|
||||
if args[0] not in self.optimizer.mines["0"].keys():
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["error"]["OreNotFoundError"].format(ore=args[0]))
|
||||
return
|
||||
else:
|
||||
text = tr.tr[self.guild.config["lang"]]["modules"]["deeptown"].format(ore=args[0])
|
||||
i = 0
|
||||
for mine in self.optimizer.best_mines(args[0]):
|
||||
if i >= 10:
|
||||
break
|
||||
if mine[0] == "0":
|
||||
continue
|
||||
text += mine[0].center(3, " ")
|
||||
text += ": "
|
||||
text += str(mine[1][args[0]] * 100)
|
||||
text += "%\n"
|
||||
i += 1
|
||||
text += "```"
|
||||
await msg.channel.send(text)
|
||||
return
|
||||
return
|
||||
|
||||
async def reload_optimizer(self, msg, command, args):
|
||||
if msg.author.id not in self.guild.config["master_admins"]:
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
|
||||
return
|
||||
else:
|
||||
self.optimizer = optimizer.Optimizer()
|
||||
|
||||
async def to_make(self, msg, command, args):
|
||||
if args[0] not in self.optimizer.items.keys():
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["ItemNotFound"].format(item=args[0]))
|
||||
try:
|
||||
quantity = int(args[1])
|
||||
except ValueError:
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotIntError"].format(number=args[1]))
|
||||
return
|
||||
result = self.optimizer.to_make(args[0], quantity)
|
||||
time = datetime.timedelta(seconds=int(result["time"]))
|
||||
needed = ", ".join([str(quantity) + " " + name for name, quantity in result["needed"].items()])
|
||||
await msg.channel.send(
|
||||
tr.tr[self.guild.config["lang"]]["modules"]["deeptown"]["to_make"].format(time=time, quantity=quantity,
|
||||
item=args[0], needed=needed,
|
||||
value=result["value"]))
|
||||
|
||||
async def on_message(self, msg):
|
||||
if msg.content.startswith(self.guild.config["prefix"]):
|
||||
command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ")
|
||||
if command == "best_place_mine":
|
||||
await self.best_place_mine(msg, command, args)
|
||||
elif command == "reload_optimizer":
|
||||
await self.reload_optimizer(msg, command, args)
|
||||
elif command == "to_make":
|
||||
await self.to_make(msg, command, args)
|
||||
return
|
0
modules/deeptownOptimizer/__init__.py
Normal file
0
modules/deeptownOptimizer/__init__.py
Normal file
65
modules/deeptownOptimizer/items.json
Normal file
65
modules/deeptownOptimizer/items.json
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"graphite": {
|
||||
"value": 15,
|
||||
"time": 5,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"coal": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"copperBar": {
|
||||
"value": 25,
|
||||
"time": 10,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"copper": 5
|
||||
},
|
||||
"building": "smelting"
|
||||
},
|
||||
"ironBar": {
|
||||
"value": 40,
|
||||
"time": 15,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"iron": 5
|
||||
},
|
||||
"building": "smelting"
|
||||
},
|
||||
"amberCharger": {
|
||||
"value": 4,
|
||||
"time": 5,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"amber": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"polishedAmber": {
|
||||
"value": 70,
|
||||
"time": 30,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"amber": 5
|
||||
},
|
||||
"bullding": "jewel"
|
||||
},
|
||||
"goldBar": {
|
||||
"value": 40,
|
||||
"time": 15,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"gold": 5
|
||||
},
|
||||
"building": "smelting"
|
||||
},
|
||||
"copperNail": {
|
||||
"value": 7,
|
||||
"time": 20,
|
||||
"quantity": 10,
|
||||
"required": {
|
||||
"copperBar": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
}
|
||||
}
|
54
modules/deeptownOptimizer/mines.json
Normal file
54
modules/deeptownOptimizer/mines.json
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"0": {
|
||||
"coal": 0,
|
||||
"copper": 0,
|
||||
"iron": 0,
|
||||
"amber": 0,
|
||||
"gold": 0,
|
||||
"aluminium": 0,
|
||||
"silver": 0,
|
||||
"emerald": 0,
|
||||
"ruby": 0,
|
||||
"diamond": 0,
|
||||
"topaz": 0,
|
||||
"sapphire": 0,
|
||||
"amethyst": 0,
|
||||
"alexandrite": 0,
|
||||
"titanium": 0,
|
||||
"uranium": 0,
|
||||
"platinum": 0,
|
||||
"helium3": 0,
|
||||
"obsidian": 0
|
||||
},
|
||||
"1": {
|
||||
"coal": 1
|
||||
},
|
||||
"2": {
|
||||
"coal": 0.70,
|
||||
"copper": 0.30
|
||||
},
|
||||
"3": {
|
||||
"coal": 0.595,
|
||||
"copper": 0.2833,
|
||||
"iron": 0.0917,
|
||||
"amber": 0.025,
|
||||
"gold": 0.005
|
||||
},
|
||||
"4": {
|
||||
"coal": 0.5425,
|
||||
"copper": 0.325,
|
||||
"iron": 0.1025,
|
||||
"amber": 0.0225,
|
||||
"gold": 0.0075
|
||||
},
|
||||
"5": {
|
||||
"coal": 0.4900,
|
||||
"copper": 0.3667,
|
||||
"iron": 0.1133,
|
||||
"amber": 0.0200,
|
||||
"gold": 0.0100
|
||||
},
|
||||
"13": {
|
||||
"copper": 1
|
||||
}
|
||||
}
|
55
modules/deeptownOptimizer/optimizer.py
Normal file
55
modules/deeptownOptimizer/optimizer.py
Normal file
@ -0,0 +1,55 @@
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class Optimizer():
|
||||
def __init__(self):
|
||||
self.mines = {}
|
||||
self.items = {}
|
||||
# get mine stats
|
||||
with open(os.path.join("modules", "deeptownOptimizer", "mines.json")) as mines:
|
||||
self.mines = json.load(mines)
|
||||
# get items stats
|
||||
with open(os.path.join("modules", "deeptownOptimizer", "items.json")) as items:
|
||||
self.items = json.load(items)
|
||||
# Add zero values to mine stat
|
||||
ores = self.mines["0"].keys()
|
||||
for area, stats in self.mines.items():
|
||||
for ore in ores:
|
||||
if self.mines[area].get(ore) is None:
|
||||
self.mines[area].update({ore: 0})
|
||||
print(self.mines)
|
||||
|
||||
def best_mines(self, ore):
|
||||
if ore not in self.mines["0"].keys():
|
||||
raise ValueError("{ore} is not a correct ore.".format(ore=ore))
|
||||
ordered_mines = [(k, v) for k, v in self.mines.items()]
|
||||
ordered_mines.sort(key=lambda x: x[1][ore], reverse = True)
|
||||
return ordered_mines
|
||||
|
||||
def to_make(self, item, quantity=1):
|
||||
if item not in self.items.keys():
|
||||
raise ValueError("{item} is not a correct item.".format(item=item))
|
||||
number_of_craft = quantity/self.items[item]["quantity"]
|
||||
if number_of_craft % 1 != 0:
|
||||
number_of_craft = (number_of_craft // 1)+1
|
||||
time = self.items[item]["time"]*number_of_craft
|
||||
value = self.items[item]["value"]*number_of_craft*self.items[item]["quantity"]
|
||||
needed = {}
|
||||
for resource, quantity in self.items[item]["required"].items():
|
||||
needed.update({resource: quantity*number_of_craft})
|
||||
return {"time": time, "value": value, "needed": needed}
|
||||
|
||||
def recursive_to_make(self, item, quantity=1):
|
||||
# Compute needed time and resource for craft item
|
||||
result = self.to_make(item, quantity)
|
||||
# For each needed resource try to craft it
|
||||
for i, q in result["needed"].keys():
|
||||
try:
|
||||
temp_result = self.recursive_to_make(i, g)
|
||||
result["time"] = result["time"] + temp_result["time"]
|
||||
for
|
||||
|
||||
return result
|
Loading…
Reference in New Issue
Block a user