/
AmountSorter.cs
51 lines (46 loc) · 1.24 KB
/
AmountSorter.cs
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
using System;
using System.Collections.Generic;
namespace SortByAmountMod
{
public class AmountSorter : ICommListener
{
Dictionary<int, int> cardTypeAmount = new Dictionary<int, int> ();
protected void increaseAmount(int cardType) {
if (cardTypeAmount.ContainsKey(cardType)) {
cardTypeAmount [cardType] += 1;
} else {
cardTypeAmount [cardType] = 1;
}
}
public int getAmount(Card c) {
return getAmount (c.getCardType ().id);
}
public int getAmount(int cardType) {
if (cardTypeAmount.ContainsKey(cardType)) {
return cardTypeAmount [cardType];
} else {
return 0;
}
}
public void handleMessage (Message msg)
{
if (msg is LibraryViewMessage) {
LibraryViewMessage libraryViewMessage = (LibraryViewMessage)msg;
if (libraryViewMessage.profileId != App.MyProfile.ProfileInfo.id) {
return;
}
cardTypeAmount = new Dictionary<int, int> ();
foreach (Card card in libraryViewMessage.cards)
{
increaseAmount (card.getCardType ().id);
}
}
}
public int CompareByAmount(Card a, Card b) {
return getAmount (a).CompareTo (getAmount (b));
}
public void onReconnect () {}
public void onConnect (OnConnectData data) {
}
}
}