-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathArenaSheet.cs
168 lines (147 loc) · 5.63 KB
/
ArenaSheet.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using Nekoyume.Model.Arena;
using Nekoyume.Model.EnumType;
namespace Nekoyume.TableData
{
using static TableExtensions;
[Serializable]
public class ArenaSheet : Sheet<int, ArenaSheet.Row>
{
[Serializable]
public class RoundData
{
public int ChampionshipId { get; }
public int Round { get; }
public ArenaType ArenaType { get; }
public long StartBlockIndex { get; }
public long EndBlockIndex { get; }
public int RequiredMedalCount { get; }
public long EntranceFee { get; }
public long TicketPrice { get; }
public long AdditionalTicketPrice { get; }
public int MaxPurchaseCount { get; }
public int MaxPurchaseCountWithInterval { get; }
public int MedalId { get; }
public RoundData(int championshipId,
int round,
ArenaType arenaType,
long startBlockIndex,
long endBlockIndex,
int requiredMedalCount,
long entranceFee,
long ticketPrice,
long additionalTicketPrice,
int maxPurchaseCount,
int maxPurchaseCountWithInterval,
int medalId = 0)
{
ChampionshipId = championshipId;
Round = round;
ArenaType = arenaType;
StartBlockIndex = startBlockIndex;
EndBlockIndex = endBlockIndex;
RequiredMedalCount = requiredMedalCount;
EntranceFee = entranceFee;
TicketPrice = ticketPrice;
AdditionalTicketPrice = additionalTicketPrice;
MaxPurchaseCount = maxPurchaseCount;
MaxPurchaseCountWithInterval = maxPurchaseCountWithInterval;
MedalId = medalId;
}
public bool IsTheRoundOpened(long blockIndex)
{
return StartBlockIndex <= blockIndex && blockIndex <= EndBlockIndex;
}
}
[Serializable]
public class Row : SheetRow<int>
{
public override int Key => ChampionshipId;
public int ChampionshipId { get; private set; }
public List<RoundData> Round { get; private set; }
public override void Set(IReadOnlyList<string> fields)
{
ChampionshipId = ParseInt(fields[0]);
var round = ParseInt(fields[1]);
var arenaType = (ArenaType)Enum.Parse(typeof(ArenaType), fields[2]);
var startIndex = ParseLong(fields[3]);
var endIndex = ParseLong(fields[4]);
var requiredWins = ParseInt(fields[5]);
var entranceFee = ParseLong(fields[6]);
var ticketPrice = ParseLong(fields[7]);
var additionalTicketPrice = ParseLong(fields[8]);
var maxPurchaseCount = 0;
var maxPurchaseCountWithInterval = 0;
var medalId = 0;
if (fields.Count > 9)
{
maxPurchaseCount = ParseInt(fields[9]);
maxPurchaseCountWithInterval = ParseInt(fields[10]);
}
if (fields.Count > 11)
{
medalId = ParseInt(fields[11]);
}
Round = new List<RoundData>
{
new RoundData(ChampionshipId,
round,
arenaType,
startIndex,
endIndex,
requiredWins,
entranceFee,
ticketPrice,
additionalTicketPrice,
maxPurchaseCount,
maxPurchaseCountWithInterval,
medalId)
};
}
public bool TryGetRound(int round, out RoundData roundData)
{
roundData = Round.FirstOrDefault(x => x.Round.Equals(round));
return !(roundData is null);
}
public bool TryGetChampionshipRound(out RoundData roundData)
{
roundData = Round.FirstOrDefault(x => x.ArenaType.Equals(ArenaType.Championship));
return !(roundData is null);
}
}
public ArenaSheet() : base(nameof(ArenaSheet))
{
}
protected override void AddRow(int key, Row value)
{
if (!TryGetValue(key, out var row))
{
Add(key, value);
return;
}
if (!value.Round.Any())
{
return;
}
row.Round.Add(value.Round[0]);
}
public Row GetRowByBlockIndex(long blockIndex) => OrderedList.First(e =>
e.Round.Any(roundData => roundData.IsTheRoundOpened(blockIndex)));
public RoundData GetRoundByBlockIndex(long blockIndex)
{
var roundList = OrderedList.SelectMany(row => row.Round);
if (roundList == null || !roundList.Any())
{
throw new SheetRowNotFoundException(nameof(ArenaSheet), $"BlockIndex : {blockIndex}");
}
var round = roundList.FirstOrDefault(e => e.IsTheRoundOpened(blockIndex));
if (round == null)
{
throw new RoundNotFoundException($"[{nameof(ArenaSheet)}] BlockIndex({blockIndex})");
}
return round;
}
}
}