-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathMonsterCollectionRewardSheet.cs
102 lines (88 loc) · 2.9 KB
/
MonsterCollectionRewardSheet.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 Bencodex.Types;
using Nekoyume.Model.State;
using static Nekoyume.TableData.TableExtensions;
using static Lib9c.SerializeKeys;
namespace Nekoyume.TableData
{
[Serializable]
public class MonsterCollectionRewardSheet : Sheet<int, MonsterCollectionRewardSheet.Row>
{
[Serializable]
public class RewardInfo
{
protected bool Equals(RewardInfo other)
{
return ItemId == other.ItemId && Quantity == other.Quantity;
}
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) ^ Quantity;
}
}
public readonly int ItemId;
public readonly int Quantity;
public RewardInfo(params string[] fields)
{
ItemId = ParseInt(fields[0]);
Quantity = ParseInt(fields[1]);
}
public RewardInfo(int itemId, int quantity)
{
ItemId = itemId;
Quantity = quantity;
}
public RewardInfo(Dictionary dictionary)
{
ItemId = dictionary[IdKey].ToInteger();
Quantity = dictionary[QuantityKey].ToInteger();
}
public IValue Serialize()
{
return Dictionary.Empty
.Add(IdKey, ItemId.Serialize())
.Add(QuantityKey, Quantity.Serialize());
}
}
[Serializable]
public class Row : SheetRow<int>
{
public override int Key => MonsterCollectionLevel;
public int MonsterCollectionLevel { get; private set; }
public List<RewardInfo> Rewards { get; private set; }
public override void Set(IReadOnlyList<string> fields)
{
MonsterCollectionLevel = ParseInt(fields[0]);
var info = new RewardInfo(fields.Skip(1).ToArray());
Rewards = new List<RewardInfo> {info};
}
}
public MonsterCollectionRewardSheet() : base(nameof(MonsterCollectionRewardSheet))
{
}
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]);
}
}
}