-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayerStore.cs
More file actions
246 lines (204 loc) · 8.32 KB
/
Copy pathPlayerStore.cs
File metadata and controls
246 lines (204 loc) · 8.32 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Auction.mod
{
public class PlayerStore
{
private static PlayerStore instance;
public static PlayerStore Instance
{
get
{
if (instance == null)
{
instance = new PlayerStore();
}
return instance;
}
}
private PlayerStore()
{
this.helpf = Helpfunktions.Instance;
sellOfferFilter = new AuctionFilter();
createCardsFilter = new AuctionFilter();
this.prcs = Prices.Instance;
this.sttngs = Settings.Instance;
}
int maxLen = 1000;
Helpfunktions helpf;
public AuctionFilter sellOfferFilter;
public AuctionFilter createCardsFilter;
protected List<Auction> addAuctionList = new List<Auction>();
protected List<Auction> fullSellOfferList = new List<Auction>();
protected List<Auction> fullOWNOfferList = new List<Auction>();
protected List<Auction> sellOfferListFiltered = new List<Auction>();
protected List<Auction> createOfferListFiltered = new List<Auction>();
protected AuctionHouse.SortMode sellSortMode = AuctionHouse.SortMode.TIME;
private AuctionHouse.SortMode sellSortModeCopy = AuctionHouse.SortMode.TIME;
public bool newSellOffers { get; private set; }
private Settings sttngs;
private Prices prcs;
private void updateCardFilter()
{
// the own cards have changed, we have to update the CardFilter (because the amountfilter needs our own cards)
sellOfferFilter.setCardFilterAmountfilter();
createCardsFilter.setCardFilterAmountfilter();
this.helpf.playerstoreAllCardsChanged = false;
}
public void clearAuctions()
{
this.addAuctionList.Clear();
createCardsFilter.filtersChanged = true;
helpf.addmode = false;
}
public void delOffer(Auction a)
{
this.addAuctionList.Remove(a);
createCardsFilter.filtersChanged = true;
if (addAuctionList.Count == 0) helpf.addmode = false;
}
public void addOffer(Auction a)
{
this.addAuctionList.Add(a);
createCardsFilter.filtersChanged = true;
}
public List<Auction> getAddOffers()
{
return new List<Auction>(addAuctionList);
}
public List<Auction> getSellOffers()
{
newSellOffers = false;
if (this.helpf.playerstoreAllCardsChanged) this.updateCardFilter();
if (sellOfferFilter.filtersChanged || this.sellSortMode != this.sellSortModeCopy)
{
//sellOfferListFiltered = new List<Auction> (fullSellOfferList);
sellOfferListFiltered.Clear();
sellOfferListFiltered.AddRange(fullSellOfferList);
sellOfferListFiltered.RemoveAll(sellOfferFilter.isFiltered);
sellOfferFilter.filtersChanged = false;
this.sellSortModeCopy = this.sellSortMode;
sellOfferListFiltered.Sort(Auction.getComparison(sellSortMode));
}
return new List<Auction>(sellOfferListFiltered);
}
public List<Auction> getCreateOffers()
{
if (this.helpf.playerstoreAllCardsChanged) this.updateCardFilter();
if (createCardsFilter.filtersChanged)
{
//sellOfferListFiltered = new List<Auction> (fullSellOfferList);
createOfferListFiltered.Clear();
//createOfferListFiltered.AddRange(this.helpf.allOwnTradeableAuctions);
foreach (Auction c in this.helpf.allOwnTradeableAuctions)
{
bool found = false;
foreach (Auction a in this.addAuctionList)
{
if (a.card.id == c.card.id)
{
found = true;
break;
}
}
if (found) continue;
createOfferListFiltered.Add(c);
}
foreach (Auction c in this.createOfferListFiltered)
{
int index = helpf.cardidToArrayIndex(c.card.getType());
if(index>=1)c.setPrice(prcs.getPrice(index, sttngs.wtbAHpriceType));
//if (c.price == 0) c.setPrice(1);
if (index >= 0)
{
c.setPrice(Prices.Instance.getPrice(index, ScrollsPostPriceType.BLACKMARKET));
}
}
createOfferListFiltered.RemoveAll(createCardsFilter.isFiltered);
createCardsFilter.filtersChanged = false;
createOfferListFiltered.Sort(Auction.getComparison(AuctionHouse.SortMode.PRICE_REVERSE)); //.CARD
}
return new List<Auction>(createOfferListFiltered);
}
public List<Auction> getOwnOffers()
{
List<Auction> sellOwnOfferListFiltered = new List<Auction>(this.fullOWNOfferList);
/*foreach (Auction x in this.fullOfferList)
{
//if (x.message.Split(';')[4] == App.MyProfile.ProfileInfo.id.ToString()) sellOwnOfferListFiltered.Add(x);
}*/
sellOwnOfferListFiltered.Sort(Auction.getComparison(AuctionHouse.SortMode.CARD));
return new List<Auction>(sellOwnOfferListFiltered);
}
public void setSellSortMode(AuctionHouse.SortMode sortMode)
{
this.sellSortMode = sortMode;
}
public void setSellSortMode(int sortint)
{
if (sortint == 1) this.sellSortMode = AuctionHouse.SortMode.CARD;
if (sortint == 2) this.sellSortMode = AuctionHouse.SortMode.PRICE;
if (sortint == 3) this.sellSortMode = AuctionHouse.SortMode.SELLER;
if (sortint == 0) this.sellSortMode = AuctionHouse.SortMode.TIME;
}
public void addAuctions(List<Auction> list)
{
list.ForEach(addAuction);
if (fullSellOfferList.Count > maxLen)
{
fullSellOfferList.RemoveRange(maxLen, fullSellOfferList.Count - maxLen);
this.sellOfferFilter.filtersChanged = true;
}
sellOfferListFiltered.Sort(Auction.getComparison(sellSortMode));
}
public void addOwnAuctions(List<Auction> list)
{
list.ForEach(addOwnAuction);
}
private void addAuction(Auction a)
{
if (a.offer == Auction.OfferType.SELL)
{
fullSellOfferList.Insert(0, a);
if (!sellOfferFilter.isFiltered(a))
{
sellOfferListFiltered.Insert(0, a);
newSellOffers = true;
}
}
}
private void addOwnAuction(Auction a)
{
if (a.offer == Auction.OfferType.SELL)
{
fullOWNOfferList.Insert(0, a);
/*if (!sellOfferFilter.isFiltered(a))
{
sellOfferListFiltered.Insert(0, a);
newSellOffers = true;
}*/
}
}
public void removeMessages(string seller, Auction.OfferType aot, string cname)
{
fullSellOfferList.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
sellOfferListFiltered.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
}
public void removeAllMessages()
{
fullSellOfferList.Clear();
sellOfferListFiltered.Clear();
}
public void removeAllOwnMessages()
{
fullOWNOfferList.Clear();
}
public void removeSeller(string seller)
{
fullSellOfferList.RemoveAll(a => a.seller.Equals(seller));
sellOfferListFiltered.RemoveAll(a => a.seller.Equals(seller));
}
}
}