-
Notifications
You must be signed in to change notification settings - Fork 0
/
+UniversalShop.js
192 lines (172 loc) · 5.39 KB
/
+UniversalShop.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
function onActionServerSide(cmd) {
switch (cmd) {
case "buy":
temp.product = params[1];
temp.purchaseQty = params[2];
for (temp.n : npcs) {
if ("n_component_shop" in n.joinedclasses && product in n.shopItems) {
n.onPurchaseTransaction(product, purchaseQty);
}
}
break;
}
}
//#CLIENTSIDE
function onCreated() {
join("mudfunctions");
}
function onActionClientside() {
switch (params[0]) {
case "openshop":
OpenShop(params[1], params[2]);
break;
}
}
function ShowShop() {
UpdateProfiles();
if (CTFShopWindow.visible) this.lastselected = CTFShopList.getselectedrow();
if (CTFShopWindow != NULL) CTFShopWindow.destroy();
if (CTFShopSellWindow != NULL) CTFShopSellWindow.destroy();
new GuiBitmapBorderCtrl(CTFShopWindow) {
profile = "ZodiacBorderProfile";
temp.iw = 32;
width = 315 + temp.iw;
height = 178;
x = (screenwidth - width) / 2;
y = (screenheight - height) / 2;
canresize = canminimize = canmaximize = canclose = false;
canmove = true;
this.ctfwindow = true;
new GuiScrollCtrl(CTFShopScroll) {
profile = "ZodiacScrollProfile";
x = 6;
y = 6;
width = 220 + temp.iw;
height = 136;
vScrollBar = "dynamic";
hScrollBar = "alwaysOff";
new GuiTextListCtrl(CTFShopList) {
profile = "ZodiacListProfile";
columns = "0 180";
x = 0;
y = 0;
width = 300;
height = 136;
}
}
new GuiShowImgCtrl(CTFShopItemIcon) {
image = "";
x = 6 + 250 + 6 + temp.iw;
y = 10;
}
new GuiTextCtrl(CTFShopTextPower) {
profile = "ZodiacTextProfile";
profile.align = "center";
x = 6 + 220 + 6 + temp.iw;
y = 50;
width = 72;
height = 20;
}
new GuiButtonCtrl(CTFShopButtonClose) {
profile = "ZodiacButtonProfile";
x = 210 - 10 - 50 + temp.iw;
y = 144;
width = 60;
height = 28;
text = "Close";
}
new GuiButtonCtrl(CTFShopButtonBuy2) {
profile = "ZodiacButtonProfile";
x = 210 - 10 - 38 - 77 - 80;
y = 144;
width = 60;
height = 28;
text = "Buy";
}
new GuiTextEditCtrl(Quantity_Edit) {
profile = ZodiacTextEditProfile;
useownprofile = true;
x = 210 - 10 - 38 - 77 - 80 + 65;
y = 144;
width = 108;
height = 28;
text = 1;
profile.numbersonly = true;
}
}
for (s = 0; s < this.CTFShopitems.size()/3; s++) {
//if (clientr.("item-" @ this.CTFShopitems[s*3])[0] != NULL && this.CTFShopitems[s*3] != "Mysterious Flag Key") continue;
CTFShopList.addrow(0,this.CTFShopitems[s*3] @ "\t" @ this.CTFShopitems[s*3+2]);
}
CTFShopList.setselectedrow((this.lastselected > 0) ? this.lastselected : 0);
}
public function OpenShop(items, itemvar) {
if (this.CTFShopopen) return;
this.currency = (itemvar ? itemvar : "clientr.ctfpoints");
this.currency_type = (itemvar ? getCurrType(itemvar) : "CTF Points");
this.CTFShopmode = "buy";
this.CTFShopitems = items;
this.CTFShopopen = true;
ShowShop();
}
function getCurrType(ivar) {
if (ivar == "clientr.ctfpoints") {
return "CTF Points";
}
if (ivar == "clientr.ecpoints") {
return "Event Points";
}
return ivar.starts("clientr.item-") ? ivar.substring("clientr.item-".length()) : ivar;
}
function getCurrQty(ivar) {
temp.val = makevar(ivar);
return (ivar.starts("clientr.item-") ? temp.val[0] : temp.val);
}
function ceil(val) {
if (val.pos(".") >= 0) val = int(val)+1;
return val;
}
function CTFShopButtonBuy2.onAction() {
temp.qitem = CTFShopList.getselectedtext().substring(0,CTFShopList.getselectedtext().pos("\t"));
temp.amount = getCurrQty(this.currency);
temp.purchaseQty = Quantity_Edit.text;
if (purchaseQty < 1 || purchaseQty > 100000000) {
client.temp_addmessages.add("Please enter a valid purchase quantity");
return;
}
triggerserver("weapon", name, "buy", temp.qitem, purchaseQty);
}
function CTFShopList.onSelect() {
if (!this.CTFShopopen) return;
temp.item = CTFShopList.getselectedtext().substring(0,CTFShopList.getselectedtext().pos("\t"));
temp.etype = etype(temp.item);
CTFShopItemIcon.image = eicon(temp.item);
CTFShopItemIcon.x = (42 + 243 - getimgwidth(CTFShopItemIcon.image)/2);
CTFShopItemIcon.y = (30 - getimgheight(CTFShopItemIcon.image)/2);
if (temp.etype == "armor") {
CTFShopTextPower.text = "Defense:" SPC emax(CTFShopList.getselectedtext().substring(0,CTFShopList.getselectedtext().pos("\t")));
if (emax(temp.item) <= 0) {
CTFShopTextPower.text = "";
}
} else if (temp.etype == "weapon") {
CTFShopTextPower.text = "Power:" SPC emax(temp.item);
if (emax(temp.item) <= 0) CTFShopTextPower.text = "";
}
else CTFShopTextPower.text = "";
}
function CTFShopList.onDblClick() {
findweapon("+Inventory").onShowItemStats(CTFShopList.getselectedtext().substring(0,CTFShopList.getselectedtext().pos("\t")));
}
function CTFShopList.onRightMouseDown() {
temp.growid = CTFShopList.getrowatpoint(mousescreenx,mousescreeny);
CTFShopList.setselectedrow(temp.growid);
findweapon("+Inventory").onShowItemStats(CTFShopList.getselectedtext().substring(0,CTFShopList.getselectedtext().pos("\t")));
}
function CTFShopButtonClose.onAction() {
this.CTFShopopen = false;
CTFShopWindow.destroy();
}
function onPlayerEnters() {
if (this.CTFShopopen) this.CTFShopopen = false;
if (CTFShopWindow.visible) CTFShopWindow.destroy();
}