Add a tomake recursive function and some items
This commit is contained in:
parent
47e8d156c8
commit
9644cc5619
2
main.py
2
main.py
@ -132,7 +132,7 @@ class FoBot(discord.Client):
|
||||
|
||||
def load_modules(self):
|
||||
for module in os.listdir('modules'):
|
||||
if module != "__pycache__":
|
||||
if module[0] != "_" and module.endswith(".py"):
|
||||
imported = importlib.import_module('modules.' + module[:-3])
|
||||
self.modules.update({module[:-3]: imported.MainClass})
|
||||
|
||||
|
@ -17,7 +17,7 @@ class MainClass:
|
||||
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])
|
||||
text = tr.tr[self.guild.config["lang"]]["modules"]["deeptown"]["best_place_mine"].format(ore=args[0])
|
||||
i = 0
|
||||
for mine in self.optimizer.best_mines(args[0]):
|
||||
if i >= 10:
|
||||
@ -43,7 +43,8 @@ class MainClass:
|
||||
|
||||
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]))
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["ItemNotFoundError"].format(item=args[0]))
|
||||
return
|
||||
try:
|
||||
quantity = int(args[1])
|
||||
except ValueError:
|
||||
@ -57,6 +58,25 @@ class MainClass:
|
||||
item=args[0], needed=needed,
|
||||
value=result["value"]))
|
||||
|
||||
async def to_make_recursive(self, msg, command, args):
|
||||
if args[0] not in self.optimizer.items.keys():
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["ItemNotFoundError"].format(item=args[0]))
|
||||
return
|
||||
try:
|
||||
quantity = int(args[1])
|
||||
except ValueError:
|
||||
await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotIntError"].format(number=args[1]))
|
||||
return
|
||||
needed = self.optimizer.recursive_to_make(args[0], quantity)
|
||||
texte = tr.tr[self.guild.config["lang"]]["modules"]["deeptown"]["recursive_to_make"]["header"] \
|
||||
.format(item=args[0], quantity=quantity)
|
||||
for item in needed[1:]:
|
||||
texte += "\n"
|
||||
texte += tr.tr[self.guild.config["lang"]]["modules"]["deeptown"]["recursive_to_make"]["line"] \
|
||||
.format(item=item[0], quantity=item[1], time=datetime.timedelta(seconds=int(item[2])))
|
||||
texte += "```"
|
||||
await msg.channel.send(texte)
|
||||
|
||||
async def on_message(self, msg):
|
||||
if msg.content.startswith(self.guild.config["prefix"]):
|
||||
command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ")
|
||||
@ -66,4 +86,6 @@ class MainClass:
|
||||
await self.reload_optimizer(msg, command, args)
|
||||
elif command == "to_make":
|
||||
await self.to_make(msg, command, args)
|
||||
elif command == "to_make_recursive":
|
||||
await self.to_make_recursive(msg, command, args)
|
||||
return
|
||||
|
@ -61,5 +61,106 @@
|
||||
"copperBar": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"battery": {
|
||||
"value": 200,
|
||||
"time": 120,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"copperBar": 5,
|
||||
"ironBar": 1,
|
||||
"amber": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"wire": {
|
||||
"value": 15,
|
||||
"time": 30,
|
||||
"quantity": 5,
|
||||
"required": {
|
||||
"copperBar": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"lamp": {
|
||||
"value": 760,
|
||||
"time": 80,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"copperBar": 5,
|
||||
"wire": 10,
|
||||
"graphite": 20
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"circuit": {
|
||||
"value": 800,
|
||||
"time": 180,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"copperBar": 20,
|
||||
"graphite": 50,
|
||||
"ironBar": 10
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"node": {
|
||||
"value": 0,
|
||||
"time": 10800,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"lamp": 1900,
|
||||
"glass": 1600,
|
||||
"copperBar": 9555
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"glass": {
|
||||
"value": 450,
|
||||
"time": 60,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"silicon": 2
|
||||
},
|
||||
"building": "smelting"
|
||||
},
|
||||
"solarPanel": {
|
||||
"value": 69000,
|
||||
"time": 60,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"glass": 50,
|
||||
"silicon": 10,
|
||||
"rubber": 1
|
||||
},
|
||||
"building": "crafting"
|
||||
},
|
||||
"rubber": {
|
||||
"value": 4000,
|
||||
"time": 1800,
|
||||
"quantity": 2,
|
||||
"required": {
|
||||
"liana":1
|
||||
},
|
||||
"building": "chemistery"
|
||||
},
|
||||
"liana": {
|
||||
"value": 1700,
|
||||
"time": 1800,
|
||||
"quantity": 1,
|
||||
"required": {
|
||||
"lianaSeed": 1,
|
||||
"water": 20
|
||||
},
|
||||
"building": "greenhouse"
|
||||
},
|
||||
"water": {
|
||||
"value": 5,
|
||||
"time":120,
|
||||
"quantity":10,
|
||||
"required":{
|
||||
"amberCharger":20,
|
||||
"cosmicIce":10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ class Optimizer():
|
||||
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():
|
||||
@ -32,9 +31,9 @@ class Optimizer():
|
||||
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"]
|
||||
number_of_craft = int(quantity / self.items[item]["quantity"])
|
||||
if number_of_craft % 1 != 0:
|
||||
number_of_craft = (number_of_craft // 1)+1
|
||||
number_of_craft = int((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 = {}
|
||||
@ -43,13 +42,24 @@ class Optimizer():
|
||||
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
|
||||
if item in self.items.keys():
|
||||
needed = self.to_make(item, quantity)
|
||||
results = [(item, quantity, needed["time"])]
|
||||
for needed_item, needed_quantity in needed["needed"].items():
|
||||
needed_result = self.recursive_to_make(needed_item, needed_quantity)
|
||||
already_crafted = [result[0] for result in results]
|
||||
index = 0
|
||||
for i, q, t in needed_result:
|
||||
print(i, q, t)
|
||||
if i in already_crafted:
|
||||
results[already_crafted.index(i)] = (
|
||||
results[already_crafted.index(i)][0],
|
||||
results[already_crafted.index(i)][1] + q,
|
||||
results[already_crafted.index(i)][2] + t
|
||||
)
|
||||
else:
|
||||
results.append((i, q, t))
|
||||
index += 1
|
||||
return results
|
||||
else:
|
||||
return [(item, quantity, 0)]
|
||||
|
@ -3,7 +3,7 @@ tr = {
|
||||
"description": "Français",
|
||||
"modules": {
|
||||
"modules": {
|
||||
"description": "Permet de gérer les modules.",
|
||||
"description": "Gestion des modules.",
|
||||
"aide": {
|
||||
"list_modules": {
|
||||
"description": "Liste tous les modules. Les modules en gras sont activés.",
|
||||
@ -75,6 +75,18 @@ tr = {
|
||||
"add_master_admin": "L'utilisateur {user} est maintenant un administrateur du bot.",
|
||||
"del_master_admin": "L'utilisateur {user} n'est plus un administrateur du bot.",
|
||||
},
|
||||
"deeptown": {
|
||||
"description": "Commandes relatives au jeu deeptown.",
|
||||
"aide":{
|
||||
|
||||
},
|
||||
"best_place_mine":"Voici les meilleurs emplacements pour le minerais {ore}\n```\n",
|
||||
"to_make":"Pour faire {quantity} {item} il faudra {time}. Il vous faudra {needed}. La valeur totale de la production est {value}.",
|
||||
"recursive_to_make":{
|
||||
"header":"Pour faire {quantity} {item} il vous faudra:\n```",
|
||||
"line":"{item:20} | {quantity} | {time}"
|
||||
}
|
||||
},
|
||||
},
|
||||
"errors": {
|
||||
"LangNotFoundError": "La langue {lang} est introuvable, tapez {prefix}list_lang pour voir les langues "
|
||||
@ -97,7 +109,10 @@ tr = {
|
||||
"modifiables.",
|
||||
"NotEnoughParamError": "Il manque un ou plusieurs parametres à la commande.",
|
||||
"NoMentionsError": "Vous devez mentioner un utilisateur pour le rajouter à la liste des administrateurs "
|
||||
"du bot."
|
||||
"du bot.",
|
||||
"OreNotFoundError": "{ore} n'est pas un minerais valide.",
|
||||
"NotIntError":"{number} n'est pas un nombre entier valide.",
|
||||
"ItemNotFoundError":"{item} n'extiste pas dans deeptown",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user