Get resource trading for moon bucks
This commit is contained in:
parent
dd42a9880e
commit
3996f54663
54
mm.py
54
mm.py
@ -85,6 +85,21 @@ def get_wells(source_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
return wells
|
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():
|
def get_moons():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
@ -264,6 +279,22 @@ def sell_all():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
world.inventory = get_inventory()
|
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():
|
def draw_dashboard():
|
||||||
im.text(f"Current User: {world.current_user}")
|
im.text(f"Current User: {world.current_user}")
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
@ -274,6 +305,21 @@ def draw_dashboard():
|
|||||||
for id,(name,balance) in world.bank[1].items():
|
for id,(name,balance) in world.bank[1].items():
|
||||||
im.text(f"{name.capitalize()}: {balance}")
|
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():
|
def draw_store():
|
||||||
for id,(name,price,claim,duration) in world.store.items():
|
for id,(name,price,claim,duration) in world.store.items():
|
||||||
owned = False
|
owned = False
|
||||||
@ -351,19 +397,20 @@ def draw_moons():
|
|||||||
im.spacing()
|
im.spacing()
|
||||||
|
|
||||||
im.next_column()
|
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)
|
start_time = parse(start)
|
||||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||||
elapsed = now - start_time
|
elapsed = now - start_time
|
||||||
remaining = start_time + datetime.timedelta(minutes=dur) - now
|
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):
|
if elapsed > datetime.timedelta(minutes=dur):
|
||||||
im.push_id(f"Claim{stake_id}")
|
im.push_id(f"Claim{stake_id}")
|
||||||
if im.button("Claim"):
|
if im.button(btn_txt):
|
||||||
claim(stake_id)
|
claim(stake_id)
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
im.text(f"Finished {elapsed} ago")
|
im.text(f"Finished {elapsed} ago")
|
||||||
else:
|
else:
|
||||||
im.text_disabled("Claim")
|
im.text_disabled(btn_txt)
|
||||||
im.text(f"{remaining} left")
|
im.text(f"{remaining} left")
|
||||||
|
|
||||||
im.next_column()
|
im.next_column()
|
||||||
@ -461,6 +508,7 @@ world.store = get_store_items()
|
|||||||
world.inventory = get_inventory()
|
world.inventory = get_inventory()
|
||||||
world.staking_sources = get_moons()
|
world.staking_sources = get_moons()
|
||||||
world.stakes = get_stakes()
|
world.stakes = get_stakes()
|
||||||
|
world.wells = get_all_wells()
|
||||||
|
|
||||||
def imgui_init():
|
def imgui_init():
|
||||||
world.moon_img_tex_id = texture_id = load_texture("moon.png")
|
world.moon_img_tex_id = texture_id = load_texture("moon.png")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user