WTS/game/scripts/interface/parcel.rpy

100 lines
2.8 KiB
Plaintext
Raw Normal View History

2022-05-16 23:48:22 +00:00
init python:
class Parcel(object):
"""
contents - Contents of the parcel, has to be a list of tuples
containing an item object and integer quantity [ (lollipop_ITEM, 5) ].
wait - Wait time required for the item to be delivered.
label - Call label called after the parcel was opened.
func - A setup function called before the parcel contents is being shown to the player.
Queue is universal for all instanced objects.
"""
def __init__(self, contents, wait=1, label=None, func=None):
self.mailed = False
self.delivered = False
self.contents = contents
self.wait = wait
self.label = label
self.func = func
@property
def queue(self):
return mailbox.parcels
2022-05-16 23:48:22 +00:00
def send(self):
self.mailed = True
if not self in self.queue:
self.queue.append(self)
def open(self, silent=False):
self.mailed = True
self.delivered = True
if self in self.queue:
self.queue.remove(self)
if self.func:
self.func()
for i in self.contents:
item, quantity = i
if isinstance(item, Item):
item.owned += quantity
else:
item.unlock()
if not silent:
renpy.call("parcel", self, self.label)
def type(self):
return self.contents[0][0].type
def get_caption(self):
if len(self.contents) == 1:
item, quantity = self.contents[0]
if isinstance(item, Item):
icon = item.get_image()
else:
icon = item.image
2022-05-16 23:48:22 +00:00
if quantity == 1:
text = f"You have received one {item.name}."
2022-05-16 23:48:22 +00:00
else:
text = f"You have received {num_to_word(quantity)} pieces of {item.name}."
2022-05-16 23:48:22 +00:00
else:
items = ", ".join(f"{x[1]} {x[0].name}" for x in self.contents)
2022-05-16 23:48:22 +00:00
icon = "interface/icons/box_brown_"+str(random.randint(1, 4))+".webp"
text = "You have received your ordered items:\n{size=-4}"+items+"{/size}"
return (text, icon)
label parcel(parcel, lbl):
2022-05-16 23:48:22 +00:00
show screen bld1
show screen blktone
$ renpy.checkpoint()
call give_reward(*parcel.get_caption())
2022-05-16 23:48:22 +00:00
hide screen blktone
hide screen bld1
with d3
if lbl:
call expression lbl
2022-05-16 23:48:22 +00:00
return
label parcel_open_all:
while mailbox.get_parcels():
$ mailbox.get_parcels()[0].open()
$ parcel_OBJ.hidden = True
call tutorial("inventory")
jump main_room_menu