Refactored currencies

* Removed game class (superseded)
* Refactored currencies
* Bug fixes
This commit is contained in:
LoafyLemon 2024-04-25 20:39:50 +01:00
parent 085a4d8e9c
commit c7f7f6c8a0
10 changed files with 73 additions and 120 deletions

View File

@ -0,0 +1,29 @@
init python:
def animate_int_value(st, at, old, new, prefix="G"):
if st > 1.0:
return Text(f"{prefix} {new}"), None
else:
if new > old:
value = int((new-old)*(1.0-st)) + 1
d = Text("{} {}\n+{}".format(prefix, old + int((new-old)*st), value))
else:
value = int((old-new)*(1.0-st)) + 1
d = Text("{} {}\n-{}".format(prefix, old - int((old-new)*st), value))
return d, 0.01
screen currency(old, new, prefix):
tag gold
zorder 50
default d = DynamicDisplayable(animate_int_value, old, new, prefix)
frame:
xpadding 10
ysize 44
xminimum 80
background Frame(gui.format("interface/frames/{}/iconmed.webp"), 6, 6)
pos (50, 50)
add d yoffset 3
timer 3.0 action Hide("currency")

View File

@ -7,7 +7,6 @@ init python:
"Juliasep": (10, 10, 8, 1, 2, 6, 9),
"Octobrinde": (6, 7, 9, 9, 10, 6, 6),
}
_weather = None
@staticmethod
def _interpolate_weights(day, period):
@ -29,7 +28,8 @@ init python:
@staticmethod
def get_weather():
return Weather._weather
# Proxy
return states.env.weather
@staticmethod
def set_weather(value=None):
@ -45,8 +45,6 @@ init python:
Weather._weather = value
return value
weather = property(get_weather, set_weather)
@staticmethod
def forecast(span=35):
forecast = {}

View File

@ -1,87 +0,0 @@
init -100 python:
def show_gold(st, at, old, new):
if st > 1.0:
return Text(f"G {new}"), None
else:
if new > old:
value = int((new-old)*(1.0-st)) + 1
d = Text("G {}\n+{}".format(old + int((new-old)*st), value))
else:
value = int((old-new)*(1.0-st)) + 1
d = Text("G {}\n-{}".format(old - int((old-new)*st), value))
return d, 0.01
class Game(object):
weather_types = ("clear", "cloudy", "overcast", "blizzard", "snow", "storm", "rain")
weather_weights = (35, 35, 20, 5, 10, 10, 15)
def __init__(self, gold=0, day=0):
# Protected values
self._gold = gold
self._day = day
self._gryf = 0
self._slyt = 0
self._rave = 0
self._huff = 0
self._weather = "clear"
# Normal values
self.daytime = True
self.difficulty = 2
self.cheats = False
self.moon = True
@property
def gold(self):
return self._gold
@gold.setter
def gold(self, value):
old = self._gold
self._gold = max(0, min(value, 99999))
if not renpy.in_rollback() and not _in_replay:
renpy.hide_screen("gold")
renpy.show_screen("gold", old, self._gold)
@property
def day(self):
return self._day
@day.setter
def day(self, value):
self._day = max(0, min(value, 99999))
@property
def weather(self):
return Weather.get_weather()
@weather.setter
def weather(self, value):
Weather.set_weather(value)
self.moon = (self.day % 7 == 0)
screen gold(old, new):
tag gold
zorder 50
default d = DynamicDisplayable(show_gold, old, new)
frame:
xpadding 10
ysize 44
xminimum 80
background Frame(gui.format("interface/frames/{}/iconmed.webp"), 6, 6)
pos (50, 50)
add d yoffset 3
timer 3.0 action Hide("gold")
init offset = -99
default game = Game()
# Points change displayable
# Day change displayable
# Add one of X generator

View File

@ -16,7 +16,6 @@ default playercolor_rgb = Color((51, 92, 147, 255))
default enemycolor_rgb = Color((116, 0, 0, 255))
default geniecard_level = 1
default tokens = 0
default cardgame_eoc = False # End of content flag
default table_cards = [[None for x in range(0,3)] for y in range(0,3)]

View File

@ -105,7 +105,7 @@ label hermione_first_duel:
else:
her "This game is stupid, I'm leaving!" ("angry", "closed", "angry", "mid")
$ tokens += 1
$ states.env.tokens += 1
call her_walk(action="leave")
jump end_hermione_event
@ -139,7 +139,7 @@ label hermione_second_duel:
else:
her "This game is stupid, I'm leaving!" ("angry", "closed", "angry", "mid")
$ tokens += 1
$ states.env.tokens+= 1
call her_walk(action="leave")
jump end_hermione_event
@ -195,9 +195,9 @@ label hermione_third_duel:
$ unlocked_cards += [card_her_librarian]
call give_reward("You have received a card!", "images/cardgame/t1/hermione/her_librarian_v1.webp")
$ tokens += 3
$ states.env.tokens+= 3
else:
$ tokens += 1
$ states.env.tokens+= 1
her "I'll be going now, goodbye."
call her_walk(action="leave")
@ -260,9 +260,9 @@ label hermione_random_duel:
if states.her.ev.cardgame.stage < 4:
$ states.her.ev.cardgame.stage = 4
$ tokens += 3
$ states.env.tokens+= 3
else:
$ tokens += 1
$ states.env.tokens+= 1
gen "Seems like I've won this one [name_hermione_genie]." ("base", xpos="far_left", ypos="head")
her "I noticed..." ("normal", "base", "worried", "R")

View File

@ -187,7 +187,7 @@ label snape_first_duel:
if states.sna.ev.cardgame.stage < 1:
$ states.sna.ev.cardgame.stage = 1
$ tokens += 1
$ states.env.tokens+= 1
jump main_room_menu
@ -228,7 +228,7 @@ label snape_second_duel:
if states.sna.ev.cardgame.stage < 2:
$ states.sna.ev.cardgame.stage = 2
$ tokens += 1
$ states.env.tokens+= 1
jump main_room_menu
@ -293,9 +293,9 @@ label snape_third_duel:
$ states.sna.ev.cardgame.stage = 3
$ unlocked_cards += [card_snape]
call give_reward("You have received a special card!", "images/cardgame/t1/special/snape_v1.webp")
$ tokens += 3
$ states.env.tokens+= 3
else:
$ tokens += 1
$ states.env.tokens+= 1
play sound "sounds/door.ogg"
call hide_characters
@ -414,7 +414,7 @@ label snape_random_duel:
with d3
$ states.sna.busy = True
$ tokens += 1
$ states.env.tokens+= 1
jump main_room_menu

View File

@ -39,7 +39,7 @@ label twins_first_duel:
"You return to your office."
$ tokens += 1
$ states.env.tokens+= 1
jump main_room
@ -87,11 +87,11 @@ label twins_second_duel:
$ unlocked_cards += [card_rand_twins[0]]
call give_reward("You have received a special card!", "images/cardgame/t1/special/%s_v1.webp" % str(card_rand_twins[1]))
$ states.twi.ev.cardgame.stage = 2
$ tokens += 3
$ states.env.tokens+= 3
else:
twi "Not again..."
gen "Tough luck boys." ("base", xpos="far_left", ypos="head")
$ tokens += 1
$ states.env.tokens+= 1
"You return to your office."
jump main_room
@ -216,16 +216,16 @@ label twins_random_duel:
call give_reward("You have received 5%% of the twins' profits!", "interface/icons/cards.webp")
$ states.twi.ev.cardgame.profit += 0.05
$ states.twi.ev.cardgame.stage = 3
$ tokens += 3
$ states.env.tokens+= 3
elif states.twi.ev.cardgame.profit >= 1.2:
fre "Nice job but you've reached the cap I'm afraid."
ger "Yeah, we don't want to go into the minus, do we?"
$ tokens += 1
$ states.env.tokens+= 1
else:
twi "Not again..."
gen "Time to pay up, boys." ("base", xpos="far_left", ypos="head")
ger "Fine... We'll up your weekly cut by 1%%..."
$ tokens += 1
$ states.env.tokens+= 1
$ states.twi.ev.cardgame.profit += 0.01
"You return to your office."

View File

@ -1,7 +1,7 @@
label purchase_item(item):
if item.currency == "tokens":
if tokens < item.price:
if states.env.tokens< item.price:
gen "(I don't have enough tokens.)" ("base", xpos="far_left", ypos="head")
return
else:
@ -85,7 +85,7 @@ label purchase_item(item):
play sound "sounds/money.ogg"
if item.currency == "tokens":
$ tokens -= item.price
$ states.env.tokens-= item.price
else:
$ states.env.gold -= item.price
$ item.owned += 1

View File

@ -212,7 +212,7 @@ screen shop_item_menuitem(xx, yy):
add crop_image_zoom(
menu_items[i].get_image(), 42, 42,
(menu_items[i].currency != "tokens" or tokens < menu_items[i].price) and (menu_items[i].owned >= 99 or states.env.gold < menu_items[i].price)
(menu_items[i].currency != "tokens" or states.env.tokens< menu_items[i].price) and (menu_items[i].owned >= 99 or states.env.gold < menu_items[i].price)
) align (0.5, 0.5)
button:
@ -226,7 +226,7 @@ screen shop_item_menuitem(xx, yy):
text str(menu_items[i].owned) size 10 align (0.1, 0.1) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
if menu_items[i].currency == "tokens":
if tokens >= menu_items[i].price:
if states.env.tokens>= menu_items[i].price:
text "{color=#2055da}T{/color} [price]" size 10 pos (0.95, 0.95) anchor (1.0, 1.0) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
else:
text "{color=#2055da}T{/color} {color=#ff0000}[price]{/color}" size 10 pos (0.95, 0.95) anchor (1.0, 1.0) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
@ -249,7 +249,7 @@ screen shop_item_menuitem(xx, yy):
add crop_image_zoom(
current_item.get_image(), 84, 84,
(current_item.currency != "tokens" or tokens < current_item.price) and (current_item.owned >= 99 or states.env.gold < current_item.price)
(current_item.currency != "tokens" or states.env.tokens< current_item.price) and (current_item.owned >= 99 or states.env.gold < current_item.price)
) align (0.5, 0.5)
add "interface/achievements/glass_selected.webp" pos (6, 6)
@ -257,7 +257,7 @@ screen shop_item_menuitem(xx, yy):
text "[current_item.owned]" size 14 align (0.1, 0.1) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
if current_item.currency == "tokens":
if tokens >= current_item.price:
if states.env.tokens>= current_item.price:
text "{color=#2055da}T{/color} [current_item.price]" size 14 pos (0.9, 0.9) anchor (1.0, 1.0) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
else:
text "{color=#2055da}T{/color} {color=#ff0000}[current_item.price]{/color}" size 14 pos (0.90, 0.90) anchor (1.0, 1.0) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ]
@ -280,7 +280,7 @@ screen shop_item_menuitem(xx, yy):
xoffset 45
ypos 374
text_size 16
sensitive ((current_item.currency == "tokens" and tokens >= current_item.price) or (current_item.owned < 99 and states.env.gold >= current_item.price))
sensitive ((current_item.currency == "tokens" and states.env.tokens>= current_item.price) or (current_item.owned < 99 and states.env.gold >= current_item.price))
action Return("buy")
hbox:

View File

@ -36,6 +36,7 @@ init python:
def __init__(self):
# Protected values
self._gold = 0
self._tokens = 0
self._day = 0
self._gryf = 0
self._slyt = 0
@ -59,8 +60,21 @@ init python:
self._gold = max(0, min(value, 99999))
if not renpy.in_rollback() and not _in_replay:
renpy.hide_screen("gold")
renpy.show_screen("gold", old, self._gold)
renpy.hide_screen("currency")
renpy.show_screen("currency", old, self._gold, "💰")
@property
def tokens(self):
return self._tokens
@tokens.setter
def tokens(self, value):
old = self._tokens
self._tokens = max(0, min(value, 99999))
if not renpy.in_rollback() and not _in_replay:
renpy.hide_screen("currency")
renpy.show_screen("currency", old, self._tokens, "🪙")
@property
def day(self):
@ -72,10 +86,10 @@ init python:
@property
def weather(self):
return Weather.get_weather()
return self._weather
@weather.setter
def weather(self, value):
Weather.set_weather(value)
self._weather = Weather.set_weather(value)
default states.env = Environment()