Get resource trading for moon bucks

This commit is contained in:
Joseph Ferano 2023-02-25 13:59:55 +07:00
parent dd42a9880e
commit 3996f54663

54
mm.py
View File

@ -85,6 +85,21 @@ def get_wells(source_id):
cursor.close()
return wells
def get_all_wells():
cursor = conn.cursor()
cursor.execute("""
SELECT resource_well.id,name,supply FROM resource_well
INNER JOIN resource ON resource.id = resource_well.resource_id
INNER JOIN staking_source ON staking_source.id = resource_well.source_id
WHERE staking_source.user_id = ?;
""", (world.current_user_id,))
wells = {w[0]:w[1:] for w in cursor.fetchall()}
cursor.close()
return wells
def get_moons():
cursor = conn.cursor()
@ -264,6 +279,22 @@ def sell_all():
cursor.close()
world.inventory = get_inventory()
def trade():
cursor = conn.cursor()
cursor.execute("""
UPDATE resource_account SET balance = balance - ? WHERE resource_account.user_id = ?
""", (10, world.current_user_id))
cursor.execute("""
UPDATE bank_account SET balance = balance + ? WHERE bank_account.user_id = ?
""", (1, world.current_user_id))
conn.commit()
cursor.close()
world.bank = get_bank()
def draw_dashboard():
im.text(f"Current User: {world.current_user}")
for _ in range(5):
@ -274,6 +305,21 @@ def draw_dashboard():
for id,(name,balance) in world.bank[1].items():
im.text(f"{name.capitalize()}: {balance}")
for _ in range(10):
im.spacing()
resources = world.bank[1]
can_sell = True
for _,supply in resources.values():
if supply < 10:
can_sell = False
im.text("Sell 10 resources for 1 Moon Bucks")
if can_sell:
if im.button("Sell"):
trade()
else:
im.text("Sell (Not enough funds)")
def draw_store():
for id,(name,price,claim,duration) in world.store.items():
owned = False
@ -351,19 +397,20 @@ def draw_moons():
im.spacing()
im.next_column()
for stake_id,(_,invId,amount,dur,start) in stakes.items():
for stake_id,(well_id,invId,amount,dur,start) in stakes.items():
start_time = parse(start)
now = datetime.datetime.utcnow().replace(microsecond=0)
elapsed = now - start_time
remaining = start_time + datetime.timedelta(minutes=dur) - now
btn_txt = f"Claim {amount} {world.wells[well_id][0].capitalize()}"
if elapsed > datetime.timedelta(minutes=dur):
im.push_id(f"Claim{stake_id}")
if im.button("Claim"):
if im.button(btn_txt):
claim(stake_id)
im.pop_id()
im.text(f"Finished {elapsed} ago")
else:
im.text_disabled("Claim")
im.text_disabled(btn_txt)
im.text(f"{remaining} left")
im.next_column()
@ -461,6 +508,7 @@ world.store = get_store_items()
world.inventory = get_inventory()
world.staking_sources = get_moons()
world.stakes = get_stakes()
world.wells = get_all_wells()
def imgui_init():
world.moon_img_tex_id = texture_id = load_texture("moon.png")