-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemShop.verse
76 lines (55 loc) · 2.35 KB
/
ItemShop.verse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# Device Configuration:
# 1. Set the 'Cashier' Conditional Button Device's Key Item to use the currency type you want (Gold, etc).
# 2. Set the HUD Message Device to 'Message Recipient: Triggering Player'.
# 3. Set the Button Device to the desired Interact Time.
# 4. Add the Item being purchased to the Item List of the Item Granter.
shop_device := class(creative_device):
@editable
Cashier: conditional_button_device = conditional_button_device{}
@editable
HUDMessage: hud_message_device = hud_message_device{}
@editable
ShopItems: []shop_item = array{}
MakeMessage<localizes>(Text: string): message = "{Text}"
OnBegin<override>()<suspends>:void=
ShopSetup()
ShopSetup(): void =
for (Item : ShopItems):
Item.Init(Self)
ShowHUDMessage(Agent: agent, Text: string): void =
HUDMessage.SetText(MakeMessage(Text))
HUDMessage.Show(Agent)
shop_item := class<concrete>():
var VerseDevice: shop_device = shop_device{}
@editable
ItemName: string = "Item"
@editable
ItemCost: type{X: int where X >= 0} = 10
@editable
Button: button_device = button_device{}
@editable
ItemGranter: item_granter_device = item_granter_device{}
MakeMessage<localizes>(Text: string): message = "{Text}"
Init(MainDevice: shop_device): void =
set VerseDevice = MainDevice
Button.InteractedWithEvent.Subscribe(PurchaseAttempt)
if (ItemCost > 0):
Button.SetInteractionText(MakeMessage("Purchase {ItemName}"))
else:
Button.SetInteractionText(MakeMessage("Pick Up {ItemName}"))
PurchaseAttempt(Agent: agent): void =
if (ItemCost > 0):
PlayerGold := VerseDevice.Cashier.GetItemCount(Agent, 0)
if (PlayerGold >= ItemCost):
VerseDevice.Cashier.SetItemCountRequired(0, ItemCost)
VerseDevice.Cashier.Activate(Agent)
ItemGranter.GrantItem(Agent)
VerseDevice.ShowHUDMessage(Agent, "Purchased {ItemName}.")
else:
VerseDevice.ShowHUDMessage(Agent, "Not enough resources.")
else:
ItemGranter.GrantItem(Agent)
VerseDevice.ShowHUDMessage(Agent, "Obtained {ItemName}.")