|
|
@@ -24,97 +24,3 @@ export class FrontcraftShopComponent{
|
|
24
|
24
|
private dialogService : NbDialogService
|
|
25
|
25
|
){}
|
|
26
|
26
|
}
|
|
27
|
|
-
|
|
28
|
|
-@Component({
|
|
29
|
|
- selector: 'buyToken',
|
|
30
|
|
- template: `
|
|
31
|
|
- <nb-card class="col-12 col-xl-9">
|
|
32
|
|
- <nb-card-header>
|
|
33
|
|
- Buy {{item.itemname}}
|
|
34
|
|
- </nb-card-header>
|
|
35
|
|
- <nb-card-body>
|
|
36
|
|
- <p>
|
|
37
|
|
- You currently have {{currency}} softreserve currency
|
|
38
|
|
- </p>
|
|
39
|
|
- <div *ngIf="currency>0">
|
|
40
|
|
- <div *ngFor="let kv of modifier | keyvalue">
|
|
41
|
|
- <button
|
|
42
|
|
- (click)="buyToken(kv.key)"
|
|
43
|
|
- [disabled]="currency<=0"
|
|
44
|
|
- nbButton
|
|
45
|
|
- outline
|
|
46
|
|
- status="success"
|
|
47
|
|
- size="tiny">
|
|
48
|
|
- buy
|
|
49
|
|
- </button>
|
|
50
|
|
- {{kv.key}} <span *ngIf="kv.value>0">(<b>+{{kv.value}}</b> from priorities)</span>
|
|
51
|
|
- </div>
|
|
52
|
|
- <div *ngFor="let token of ownedtokens">
|
|
53
|
|
- <button
|
|
54
|
|
- (click)="buyToken(token.charactername)"
|
|
55
|
|
- nbButton
|
|
56
|
|
- outline
|
|
57
|
|
- status="success"
|
|
58
|
|
- size="tiny">
|
|
59
|
|
- buy
|
|
60
|
|
- </button>
|
|
61
|
|
- {{token.charactername}} [ {{token.level}} ] => [ {{token.level+1}} ]
|
|
62
|
|
- </div>
|
|
63
|
|
- </div>
|
|
64
|
|
- </nb-card-body>
|
|
65
|
|
-</nb-card>
|
|
66
|
|
-
|
|
67
|
|
- `,
|
|
68
|
|
-})
|
|
69
|
|
-export class FrontcraftBuyTokenComponent implements OnInit{
|
|
70
|
|
-
|
|
71
|
|
- item : Item
|
|
72
|
|
- characters: Character[]
|
|
73
|
|
- modifier = {}
|
|
74
|
|
- currency: number = 0
|
|
75
|
|
- ownedtokens: SRToken[] = []
|
|
76
|
|
-
|
|
77
|
|
- constructor(
|
|
78
|
|
- private toastr: NbToastrService,
|
|
79
|
|
- protected dialogRef: NbDialogRef<FrontcraftBuyTokenComponent>,
|
|
80
|
|
- private api : ApiService
|
|
81
|
|
- ){}
|
|
82
|
|
-
|
|
83
|
|
- ngOnInit(): void {
|
|
84
|
|
- const usr = this.api.getCurrentUser()
|
|
85
|
|
- this.api.get('CharacterManager')
|
|
86
|
|
- .getCharactersOfUser(usr.username)
|
|
87
|
|
- .then(chars => {
|
|
88
|
|
- chars.forEach(char => {
|
|
89
|
|
- char['color'] = getClassColor(char.class)
|
|
90
|
|
- this.api.get('ItemManager').getToken(char, this.item).then(token => {
|
|
91
|
|
- if(token) this.ownedtokens.push(token)
|
|
92
|
|
- else{
|
|
93
|
|
- this.api.get('ItemManager').calculatePriorities(this.item.itemname, char).then(modifier => {
|
|
94
|
|
- this.modifier[char.charactername] = modifier
|
|
95
|
|
- })
|
|
96
|
|
- }
|
|
97
|
|
- })
|
|
98
|
|
- })
|
|
99
|
|
- this.characters = chars
|
|
100
|
|
- })
|
|
101
|
|
- this.api.get('UserManager').getUser(usr.username).then(u => {
|
|
102
|
|
- if(!u) return
|
|
103
|
|
- this.currency = u.currency
|
|
104
|
|
- })
|
|
105
|
|
- }
|
|
106
|
|
-
|
|
107
|
|
- buyToken = async (charactername:string) => {
|
|
108
|
|
-
|
|
109
|
|
- const src = this.api.get('ItemManager')
|
|
110
|
|
- const token = await src.buyToken(this.api.getAuth().token.value, charactername, this.item.itemname)
|
|
111
|
|
-
|
|
112
|
|
-
|
|
113
|
|
- if(token){
|
|
114
|
|
- this.toastr.show(token.characterid+' now has a token for '+token.itemname+' of level '+token.level, 'Yay', {status: 'success'})
|
|
115
|
|
- }else{
|
|
116
|
|
- this.toastr.show('Error (something went wrong)', 'Oh no', {status: 'danger'})
|
|
117
|
|
- }
|
|
118
|
|
- this.dialogRef.close()
|
|
119
|
|
- }
|
|
120
|
|
-}
|