async def update_fields(): fields = utils.get_fields() for field in fields: filename = f"data/fields/{field}.ini" data = iniparser2.INI(convert_property=True) data.read_file(filename) for plot in data.sections(): if data[plot]["progress"] > 0 and data[plot][ "plant"] in statics.items: data[plot]["progress"] -= 1 data.write(filename)
async def _field_buy(): assigned_ids = utils.get_assigned_user_ids() if _field_buy.message.author.id not in assigned_ids: await _field_buy.message.channel.send( ":warning: Your id is not assigned") else: fields = utils.get_fields() if _field_buy.message.author.id in fields: await _field_buy.message.channel.send( f":x: You already have a field") else: filename = f"data/fields/{_field_buy.message.author.id}.ini" user_filename = f"data/users/{_field_buy.message.author.id}.ini" user_data = iniparser2.INI(convert_property=True) user_data.read_file(user_filename) if user_data["stats"]["balance"] >= 1000: open(filename, "w").close() data = iniparser2.INI(convert_property=True) data.read_file(filename) # free plot woo data.set_section("plot0") data["plot0"]["plant"] = True data["plot0"]["progress"] = 0 user_data.set("balance", user_data["stats"]["balance"] - 1000, section="stats") data.write(filename) user_data.write(user_filename) await _field_buy.message.channel.send( ":white_check_mark: You bought a field") else: await _field_buy.message.channel.send( ":x: You need 1000 coins to buy a new field")
async def _field(): assigned_ids = utils.get_assigned_user_ids() if _field.message.author.id not in assigned_ids: await _field.message.channel.send(":warning: Your id is not assigned") else: fields = utils.get_fields() if _field.message.author.id not in fields: await _field.message.channel.send(f":x: You don't have a field") else: filename = f"data/fields/{_field.message.author.id}.ini" data = iniparser2.INI(convert_property=True) data.read_file(filename) embed = discord.Embed( title=f"{_field.message.author.display_name}'s Field", color=0xFF00FF) for pid, plot in enumerate(data.sections()): if data[plot]["progress"] > 0 and data[plot][ "plant"] in statics.items: embed.add_field( name=f"Plot {pid}", value=f"Growing {data[plot]['plant']}...", inline=False, ) elif (data[plot]["progress"] == 0 and data[plot]["plant"] in statics.items): embed.add_field( name=f"Plot {pid}", value=f"{data[plot]['plant']} is ready to be harvested", inline=False, ) else: embed.add_field(name=f"Plot {pid}", value="Empty", inline=False) await _field.message.channel.send(embed=embed)
async def _field_buyplot(): assigned_ids = utils.get_assigned_user_ids() if _field_buyplot.message.author.id not in assigned_ids: await _field_buyplot.message.channel.send( ":warning: Your id is not assigned") else: fields = utils.get_fields() if _field_buyplot.message.author.id not in fields: await _field_buyplot.message.channel.send( f":x: You don't have a field") else: filename = f"data/fields/{_field_buyplot.message.author.id}.ini" user_filename = f"data/users/{_field_buyplot.message.author.id}.ini" data = iniparser2.INI(convert_property=True) user_data = iniparser2.INI(convert_property=True) data.read_file(filename) user_data.read_file(user_filename) if len(data.sections()) == 10: await _field_buyplot.message.channel.send( ":x: You cannot buy more plots") else: price = 1000 * len(data.sections()) if user_data["stats"]["balance"] >= price: await _field_buyplot.message.channel.send( f":white_check_mark: You bought a new field plot with id `{len(data.sections())}`" ) data.set_section(f"plot{len(data.sections())}") data[f"plot{len(data.sections()) - 1}"]["plant"] = True data[f"plot{len(data.sections()) - 1}"]["progress"] = 0 user_data["stats"]["balance"] -= price data.write(filename) user_data.write(user_filename)
async def _field_harvest(plot): try: plot = int(plot) except Exception: await _field_harvest.message.channel.send( ":x: use number to select a plot") else: assigned_ids = utils.get_assigned_user_ids() if _field_harvest.message.author.id not in assigned_ids: await _field_harvest.message.channel.send( ":warning: Your id is not assigned") else: fields = utils.get_fields() if _field_harvest.message.author.id not in fields: await _field_harvest.message.channel.send( f":x: You don't have a field") else: filename = f"data/fields/{_field_harvest.message.author.id}.ini" user_filename = f"data/users/{_field_harvest.message.author.id}.ini" data = iniparser2.INI(convert_property=True) user_data = iniparser2.INI(convert_property=True) data.read_file(filename) user_data.read_file(user_filename) if "plot" + str(plot) not in data.sections(): await _field_harvest.message.channel.send( f":x: Plot id `{plot}` did not exists") else: _plot = "plot" + str(plot) if data[_plot]["plant"] in statics.items: if data[_plot]["progress"] == 0: user_data["inventory"][data[_plot]["plant"]] += 1 user_data["stats"]["current_exp"] += 10.0 await _field_harvest.message.channel.send( f":white_check_mark: {_field_harvest.message.author.mention}, You've harvested item `{data[_plot]['plant']}` from plot id `{plot}`" ) data[_plot]["plant"] = True data.write(filename) user_data.write(user_filename) else: await _field_harvest.message.channel.send( f":warning: crop on plot id `{plot}` is not yet mature, will mature in {utils.fsec(data[_plot]['progress'])}" ) else: await _field_harvest.message.channel.send( f":x: Plot id {plot} is empty")
async def _field_plant(seed, plot): try: plot = int(plot) except Exception: await _field_plant.message.channel.send( ":x: use number to select a plot") else: assigned_ids = utils.get_assigned_user_ids() if _field_plant.message.author.id not in assigned_ids: await _field_plant.message.channel.send( ":warning: Your id is not assigned") else: fields = utils.get_fields() if _field_plant.message.author.id not in fields: await _field_plant.message.channel.send( f":x: You don't have a field") else: if seed not in statics.items: await _field_plant.message.channel.send( f":x: Item `{seed}` did not exists") return if not seed.endswith("_seed"): await _field_plant.message.channel.send( f":x: You cannot plant this item: `{seed}`") return filename = f"data/fields/{_field_plant.message.author.id}.ini" seedfor = seed.split("_seed")[0] data = iniparser2.INI(convert_property=True) data.read_file(filename) if "plot" + str(plot) not in data.sections(): await _field_plant.message.channel.send( f":x: Plot id `{plot}` did not exists") else: _plot = "plot" + str(plot) if (data[_plot]["progress"] > 0 or data[_plot]["plant"] in statics.items): await _field_plant.message.channel.send( f":x: Plot id `{plot}` is not empty") else: data[_plot]["progress"] = statics.farm[seedfor] data[_plot]["plant"] = seedfor data.write(filename) await _field_plant.message.channel.send( f":white_check_mark: {_field_plant.message.author.mention}, You have planted `{seed}`, takes {utils.fsec(statics.farm[seedfor])} to mature." )