-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathStakeRegularFixedRewardSheet.cs
102 lines (85 loc) · 2.87 KB
/
StakeRegularFixedRewardSheet.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
using System;
using System.Collections.Generic;
using System.Linq;
using Nekoyume.Model.State;
using static Nekoyume.TableData.TableExtensions;
namespace Nekoyume.TableData
{
/// <summary>
/// This sheet is used for setting the regular rewards for staking.
/// The difference between this sheet and <see cref="StakeRegularRewardSheet"/> is that
/// the <see cref="RewardInfo"/> of this sheet has a fixed count of reward.
/// </summary>
[Serializable]
public class StakeRegularFixedRewardSheet :
Sheet<int, StakeRegularFixedRewardSheet.Row>,
IStakeRewardSheet
{
[Serializable]
public class RewardInfo
{
protected bool Equals(RewardInfo other)
{
return ItemId == other.ItemId && Count == other.Count;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((RewardInfo) obj);
}
public override int GetHashCode()
{
unchecked
{
return (ItemId * 397) ^ Count;
}
}
public readonly int ItemId;
public readonly int Count;
public RewardInfo(params string[] fields)
{
ItemId = ParseInt(fields[0]);
Count = ParseInt(fields[1]);
}
public RewardInfo(int itemId, int count)
{
ItemId = itemId;
Count = count;
}
}
[Serializable]
public class Row : SheetRow<int>, IStakeRewardRow
{
public override int Key => Level;
public int Level { get; private set; }
public long RequiredGold { get; private set; }
public List<RewardInfo> Rewards { get; private set; }
public override void Set(IReadOnlyList<string> fields)
{
Level = ParseInt(fields[0]);
RequiredGold = ParseInt(fields[1]);
var info = new RewardInfo(fields.Skip(2).ToArray());
Rewards = new List<RewardInfo> {info};
}
}
public StakeRegularFixedRewardSheet() : base(nameof(StakeRegularFixedRewardSheet))
{
}
protected override void AddRow(int key, Row value)
{
if (!TryGetValue(key, out var row))
{
Add(key, value);
return;
}
if (!value.Rewards.Any())
{
return;
}
row.Rewards.Add(value.Rewards[0]);
}
public IReadOnlyList<IStakeRewardRow> OrderedRows => OrderedList;
}
}