This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
lootbak
535 lines (430 loc) · 15.5 KB
/
lootbak
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
const fs = require("fs");
const gear = require('../../gearbox.js');
const paths = require("../../paths.json");
const Pixly = require("pixel-util");
const Canvas = require("canvas");
const locale = require('../../../utils/multilang_b');
const mm = locale.getT();
const eko = require("../../archetypes/ekonomist.js");
const cmd = 'loot';
let rollNo = 0;
const ej = gear.emoji;
const MEDALBASE = JSON.parse(fs.readFileSync("./resources/lists/medals.json"));
const BGBASE = JSON.parse(fs.readFileSync("./resources/lists/backgrounds.json"));
const LOOT = require("../../archetypes/lootbox.js")
const init = async function (message,options) {
if(message.author.looting)return;
message.author.looting = true;
if(!options) return;
let issuer = options.issuer;
let reducer = options.reducer || 0;
let event = options.event || false;
let boxaher = options.boxaher || 'lootbox_C_O';
let box_rarity = options.rarity || 'C';
let factors = ["C", "U", "R", "SR", "UR"].indexOf(box_rarity) || 0
let rerollCost = (rollNo+1)*(factors+1)*275;
}
const init = async function (message,issuer,reducer,event,boxaher) {
//if(message.author.username!="Flicky")return message.reply("Lootbox System Deactivated for Mantainance");
if(message.author.looting)return;
try{
message.author.looting = true
console.log(message.author.tag,{issuer,reducer,event,boxaher})
delete require.cache[require.resolve("../../archetypes/lootbox.js")]
let LOOT = require("../../archetypes/lootbox.js")
event = event
let now = Date.now();
let rerolls = 3
if (message.author.dDATA.modules.powerups){
if (message.author.dDATA.modules.powerups.extrarerolls){
if(message.author.dDATA.modules.powerups.extrarerolls[1]<now){
rerolls = message.author.dDATA.modules.powerups.extrarerolls[0]
}
}
};
rerolls = typeof reducer== "number" ? reducer : rerolls;
let balance = message.author.dDATA.modules.rubines;
if(message.author.id!= "88120564400553984" && issuer != "pollux")return;
const LANG=message.lang
let P={lngs:LANG, interpolation: {'escapeValue': false} };
let emb = new gear.Discord.RichEmbed;
emb.setColor("#f240a7");
P.user = message.member.displayName;
emb.description = ej("loot")+""+mm("loot.opening",P);
let sttup = await message.channel.send({embed:emb});
await gear.wait(3);
sttup.delete().catch();
/*
Canvas.registerFont(paths.FONTS + "/product-sans-bold.ttf", {
family: 'Product',
weigth: "bold"
});
Canvas.registerFont(paths.FONTS + "/product-sans-reg.ttf", {
family: 'Product',
weigth: "normal"
});
*/
const BOX = await LOOT.Lootbox(box_rarity);
//console.log(BOX)
let BOXB = require("util").inspect(BOX);
async function renderBG(bname) {
//console.log(bname)
let BGFILE = paths.BUILD + "backdrops/"+bname+".png";// +rarity+"/" +files[rand].name+".png"
const incanv = {}
incanv.neme = '"'+bname+'"'
incanv.pic = new Canvas.createCanvas(285,350);
const ctx = incanv.pic.getContext('2d');
let I = await gear.getCanvas(BGFILE)
let J = new Canvas.Image;
J.src = await Pixly.createBuffer(paths.BUILD+"LOOT/BG.png").then(b => {return b;});
await ctx.rotate(0.16);
await ctx.drawImage(I, 36, 80,260,140);
await ctx.rotate(-0.16);
await ctx.drawImage(J, 0, 0);
return incanv;
};
async function renderMedal(medal) {
//console.log(medal.name)
let medalfolder = fs.readdirSync(paths.MEDALS)
let filepath = paths.MEDALS + medal.item + ".png"
const incanv = {}
incanv.neme = '"'+medal.name+'"'
incanv.nmo = medal.item
incanv.pic = new Canvas.createCanvas(300, 300);
const ctx = incanv.pic.getContext('2d');
let I = new Canvas.Image;
I.src = await Pixly.createBuffer(filepath).then(b => {return b;});
let J = new Canvas.Image;
J.src = await Pixly.createBuffer(paths.BUILD+"LOOT/MEDAL.png").then(b => {return b;});
//await ctx.rotate(0.16)
await ctx.drawImage(I, 94, 128);
await ctx.drawImage(J, 26, 26);
//await ctx.rotate(-0.16)
return incanv;
};
async function renderSticker(stk) {
let filepath = paths.BUILD+"stickers/" + stk + ".png"
const incanv = {}
incanv.neme = stk
incanv.nmo = stk
incanv.pic = new Canvas.createCanvas(300, 300);
const ctx = incanv.pic.getContext('2d');
let I = new Canvas.Image;
I.src = await Pixly.createBuffer(filepath).then(b => {return b;});
let J = new Canvas.Image;
J.src = await Pixly.createBuffer(paths.BUILD+"LOOT/STAMP.png").then(b => {return b;});
//await ctx.rotate(0.16)
await ctx.drawImage(I, 94, 128,100,100);
await ctx.drawImage(J, 26, 26);
//await ctx.rotate(-0.16)
return incanv;
};
let Max = BOX.length
const canvas = new Canvas.createCanvas(800, 600);
const base = canvas.getContext('2d');
let LOOTS = []
for (i = 0; i < Max; ++i) {
try{
if (i>2)return; //console.log("+2===================================================>");
let img
let namely;
let nmo;
let eventide;
img= await gear.getCanvas(paths.BUILD + "LOOT/" +BOX[i].emblem + ".png")
if (BOX[i].type == "RUBINES" || BOX[i].type == "JADES") {
img =await gear.getCanvas(paths.BUILD + "LOOT/" +(BOX[i].emblem) + ".png")
} else if (BOX[i].type == "BG") {
try{
eventide == BGBASE.filter(m=>m.name==BOX[i].item)[0].event != undefined;
}catch(err){
//console.log(err);
eventide = false;
};
let img_pre = await renderBG(BOX[i].name);
namely = img_pre.neme;
img =await img_pre.pic;
}else if (BOX[i].type == "MEDAL") {
try{
let filtlet = MEDALBASE.filter(m=>m.icon==BOX[i].item);
eventide= filtlet[0].event != undefined;
}catch(err){
eventide = false;
}
let img_pre = await renderMedal(BOX[i]);
namely = img_pre.neme
img = await img_pre.pic;
nmo = img_pre.nmo
}else if (BOX[i].type == "STICKER") {
try{
let filtlet = BOX[i].item;
//eventide= filtlet[0].event != undefined;
}catch(err){
eventide = false;
}
let img_pre = await renderSticker(BOX[i].item);
namely = img_pre.neme
img = await img_pre.pic;
nmo = img_pre.nmo
} else {
img = await gear.getCanvas(paths.BUILD + "LOOT/" + BOX.emblem + ".png")
};
let qtd;
let rarity = await gear.getCanvas(paths.BUILD + "LOOT/rarity/" + BOX[i].rarity + ".png")
let rarityShine = await gear.getCanvas(paths.BUILD + "LOOT/shine" + BOX[i].rarity + ".png")
if (BOX[i].type == "RUBINES" || BOX[i].type == "JADES") qtd = await gear.tag(base, "x" + BOX[i].name, '36px Product,Sans', "#a0a0a0");
let eve = eventide?"EVENT":"";
let event = await gear.tag(base, " ", '26px Product,Sans', "#d82d2d");
let name = await gear.tag(base, BOX[i].type.toUpperCase(), '36px Product,Sans', "#d0d0d0");
let item = {
N: name,
I: img,
R: rarity,
EV: event,
RS: rarityShine,
Q: qtd || false,
prompt:{name:namely||BOX[i].name,rarity:BOX[i].rarity,type:BOX[i].type.toUpperCase()||"X",sidename:nmo}
}
LOOTS.push(item)
}catch(e){
//console.warn(BOX[i], e,"BXCON")
}
}
let sq = 70
let shift = (50-sq)/2
const B = await gear.getCanvas(paths.BUILD + "LOOT/mainframe.png")
for (i2=0;i2<LOOTS.length;++i2){
await base.drawImage(LOOTS[i2].RS, 74 + i2*230+shift, 45);
}
await base.drawImage(B, 0, 0);
for (i3=0;i3<LOOTS.length;++i3){
//DRAW RARITY
await base.drawImage(LOOTS[i3].R, 152 + i3*230+shift, 305, sq,sq);
//DRAW ITEM
await base.drawImage(LOOTS[i3].I, 32 + i3*230,32);
//DRAW NAME
await base.drawImage(LOOTS[i3].N.item, 175 + i3*230-(LOOTS[i3].N.width/2), 44);
//DRAW EVENT
await base.drawImage(LOOTS[i3].EV.item, 175 + i3*230-(LOOTS[i3].EV.width/2), 44);
//DRAW QUANT
if (LOOTS[i3].Q) await base.drawImage(LOOTS[i3].Q.item, 197 + i3*230+shift, 250);
}
const raretypes={
"UR":["ULTRA RARE","#ff59cc" ]
,"SR": ["SUPER RARE","#ed4949" ]
,"R": ["RARE","#3663db" ]
,"U": ["UNCOMMON","#ebcb19" ]
,"C": ["COMMON","#222" ]
}
const box={
"BG": "'Background': ",
"RUBINES":"'Rubines' : ",
"JADES": "'Jades' : ",
"MEDAL": "'Medal' : ",
"STICKER": "'Sticker' : "
,"UR": "ULTRA RARE |"
,"SR": "SUPER RARE |"
,"R": " RARE |"
,"U": " UNCOMMON |"
,"C": " COMMON |"
};
const exRate = {
"UR": 500
,"SR": 250
,"R": 125
,"U": 75
,"C": 50
}
////console.log(box)
let prize_lineup = []
for(bi=0;bi<3;bi++){
try{
prize_lineup.push(box[BOX[bi].rarity] + box[BOX[bi].type] +(typeof BOX[bi].name=='number'?BOX[bi].name: '"'+BOX[bi].name+'"'));
}catch(e){
console.log(e)
//console.log(",\n============================")
//console.log("Broken Box")
//console.log("------------------------------")
console.log(LOOTS)
//console.log("------------------------------")
//console.log(box)
console.log("============================\n")
}
}
function invent_merge(item){
try{
return new Promise(async resolve=>{
////console.log('entrypont',item)
let amt;
switch(item.prompt.type){
case "RUBINES":
//console.log('RUBINS------------------------------')
amt=Number(parseInt(item.prompt.name));
userDB.set(message.author.id,{$inc:{'modules.rubines':amt}}).then(ok=>{
P.X = ej("rubine")+"**"+item.prompt.name +"**"
return resolve(mm("loot.addedRubines",P));
});
break;
case "JADES":
//console.log('JADINS------------------------------')
amt=Number(parseInt(item.prompt.name));
userDB.set(message.author.id,{$inc:{'modules.jades':amt}}).then(ok=>{
P.X = ej("jade")+"**"+item.prompt.name +"**"
return resolve(mm("loot.addedJades",P));
});
break;
case "MEDAL":
//console.log('MEDLSE------------------------------')
let m=item.prompt.sidename;
//console.log(m)
if(message.author.dDATA.modules.medalInventory.includes(m)){
//console.log('predupe med')
dupeExchange().then(res=>resolve(res));
//console.log('posdué med')
}else{
//console.log('else med')
userDB.set(message.author.id,{$push:{'modules.medalInventory':m}}).then(ok=>{
//console.log('else ok med')
P.itm= item.prompt.name
return resolve(ej("no1")+mm("loot.addedMedal",P));
})
}
break;
case "BG":
//console.log('BG------------------------------')
let b
try{
b=item.prompt.name.replace(/"/g,"");
}catch(e){
console.log(e)
//console.log(item)
b=item.prompt.name
}
//console.log(b)
if(typeof b != 'string') b=b.name;
if(typeof b != 'string') throw(b);
if(message.author.dDATA.modules.bgInventory.includes(b)){
//console.log('pre dupe')
dupeExchange().then(res=>resolve(res));
//console.log('post dupe')
}else{
userDB.set(message.author.id,{$push:{'modules.bgInventory':b}}).then(ok=>{
P.itm= item.prompt.name
return resolve(ej("pic")+mm("loot.addedBG",P));
});
}
break;
case "stamps":
//console.log('STAMP------------------------------')
break;
default:
//console.log('BREAK DEFAULT',item.prompt)
break;
}
});
}catch(e){
console.log(e)
}
function dupeExchange(){
return new Promise(resolve=>{
let amt = exRate[item.prompt.rarity];
userDB.set(message.author.id,{$inc:{'modules.rubines':amt}}).then(ok=>{
P.itm= item.prompt.name
P.tpe= box[item.prompt.type].replace(/['| ]/g,"")
P.X ="**"+ exRate[item.prompt.rarity] +"**"+ej("rubine")
return resolve(mm("loot.duplicateExchange",P));
})
})
};
};
let embed = new gear.Discord.RichEmbed();
embed.setTitle(ej(box_rarity||"C")+(raretypes[box_rarity||"C"][0])+" LOOTBOX");
P.s = 30;
embed.setFooter(mm("CMD.timesOutIn",P),message.author.avatarURL || message.author.defaultAvatarURL);
embed.setColor(raretypes[box_rarity||"C"][1]);
embed.setDescription(`
${mm("loot.contains",P)}
\`\`\`ml
${prize_lineup[0]}
${prize_lineup[1]}
${prize_lineup[2]}
\`\`\`
\`keep\` ${mm("loot.keep",P)} | ${ balance>=rerollCost?rerolls>0?`\`reroll\` ${mm("loot.reroll",P)} : **${rerollCost}** ${ej("rubine")} `:"":mm("loot.noFunds",P)}
${ej("retweet")} ${mm("loot.rerollRemain",P)} **${rerolls}**
`);
async function breakit(){
gear.userDB.findOneAndUpdate({
'id':message.author.id,
'modules.inventory':boxaher
},{$set:{'modules.inventory.$':'DRAGGE'}}).then(async x=>{
await gear.userDB.findOneAndUpdate({'id':message.author.id},{$pull:{'modules.inventory':'DRAGGE'}});
})
}
async function keeppit() {
for (ikee = 0; ikee < 3; ikee++) {
let x = await invent_merge(LOOTS[ikee]);
await message.channel.send(x);
};
await breakit();
};
let lootpic=await message.channel.send({
files: [{
attachment: await canvas.toBuffer(),
name: "loot.png"
}]
});
let lootembed =await message.channel.send(embed)
if (rerolls===0){
message.channel.send(mm("loot.noMoreRolls",P))
};
const responses = await message.channel.awaitMessages(msg2 =>
msg2.author.id === message.author.id && (
(msg2.content.toLowerCase() === ("reroll")&&rerolls>0&&balance>=rerollCost)
|| msg2.content.toLowerCase() === ("keep")
), {
maxMatches: 1,
time: 30e3
});
message.author.looting = false;
let action
if (responses.size === 0) {
//////console.log("timeout")
action = "keep"
}else{
action = responses.first().content.toLowerCase()
}
let A;
//console.log(action," RESPONS")
if (action === "keep"){
message.author.looting = false;
await keeppit();
}
else if(action==="reroll"){
//console.log(action," REROLL")
eko.pay( rerollCost,message.author.id,{type: 'shop'})
lootpic.delete().catch(e=>{})
lootembed.delete().catch(e=>{})
rollNo++
let emb = new gear.Discord.RichEmbed
emb.setColor("#3251d0")
emb.description = ej("retweet")+""+mm("loot.rerolled",P)
let q = await message.channel.send({embed:emb})
await gear.wait(2);
q.delete().catch()
//console.log({issuer,rerolls,event,boxaher})
return this.init(message,issuer,rerolls-1,event,boxaher)
}else{
await keeppit();
};
}catch(e){
message.author.looting = false;
message.reply("an error has occurred, please report this issue")
console.log(e)
}
};
module.exports = {
pub:false,
cmd: cmd,
perms: 3,
init: init,
cat: 'structures'
};