forked from MS2Community/Maple2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerTableMetadataStorage.cs
More file actions
114 lines (105 loc) · 6.58 KB
/
ServerTableMetadataStorage.cs
File metadata and controls
114 lines (105 loc) · 6.58 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
using Maple2.Database.Context;
using Maple2.Model.Common;
using Maple2.Model.Game.Event;
using Maple2.Model.Metadata;
namespace Maple2.Database.Storage;
public class ServerTableMetadataStorage {
private readonly Lazy<InstanceFieldTable> instanceFieldTable;
private readonly Lazy<ScriptConditionTable> scriptConditionTable;
private readonly Lazy<ScriptFunctionTable> scriptFunctionTable;
private readonly Lazy<ScriptEventConditionTable> scriptEventConditionTable;
private readonly Lazy<JobConditionTable> jobConditionTable;
private readonly Lazy<BonusGameTable> bonusGameTable;
private readonly Lazy<GlobalDropItemBoxTable> globalDropItemBoxTable;
private readonly Lazy<UserStatTable> userStatTable;
private readonly Lazy<IndividualDropItemTable> individualDropItemTable;
private readonly Lazy<PrestigeExpTable> prestigeExpTable;
private readonly Lazy<PrestigeIdExpTable> prestigeIdExpTable;
private readonly Lazy<TimeEventTable> timeEventTable;
private readonly Lazy<GameEventTable> gameEventTable;
private readonly Lazy<OxQuizTable> oxQuizTable;
private readonly Lazy<ItemMergeTable> itemMergeTable;
private readonly Lazy<ShopTable> shopTable;
private readonly Lazy<ShopItemTable> shopItemTable;
private readonly Lazy<BeautyShopTable> beautyShopTable;
private readonly Lazy<MeretMarketTable> meretMarketTable;
private readonly Lazy<FishTable> fishTable;
private readonly Lazy<CombineSpawnTable> combineSpawnTable;
private readonly Lazy<EnchantOptionTable> enchantOptionTable;
private readonly Lazy<UnlimitedEnchantOptionTable> unlimitedEnchantOptionTable;
private readonly Lazy<ConstantsTable> constantsTable;
public InstanceFieldTable InstanceFieldTable => instanceFieldTable.Value;
public ScriptConditionTable ScriptConditionTable => scriptConditionTable.Value;
public ScriptFunctionTable ScriptFunctionTable => scriptFunctionTable.Value;
public ScriptEventConditionTable ScriptEventConditionTable => scriptEventConditionTable.Value;
public JobConditionTable JobConditionTable => jobConditionTable.Value;
public BonusGameTable BonusGameTable => bonusGameTable.Value;
public GlobalDropItemBoxTable GlobalDropItemBoxTable => globalDropItemBoxTable.Value;
public UserStatTable UserStatTable => userStatTable.Value;
public IndividualDropItemTable IndividualDropItemTable => individualDropItemTable.Value;
public PrestigeExpTable PrestigeExpTable => prestigeExpTable.Value;
public PrestigeIdExpTable PrestigeIdExpTable => prestigeIdExpTable.Value;
public TimeEventTable TimeEventTable => timeEventTable.Value;
public GameEventTable GameEventTable => gameEventTable.Value;
public OxQuizTable OxQuizTable => oxQuizTable.Value;
public ItemMergeTable ItemMergeTable => itemMergeTable.Value;
public ShopTable ShopTable => shopTable.Value;
public ShopItemTable ShopItemTable => shopItemTable.Value;
public BeautyShopTable BeautyShopTable => beautyShopTable.Value;
public MeretMarketTable MeretMarketTable => meretMarketTable.Value;
public FishTable FishTable => fishTable.Value;
public CombineSpawnTable CombineSpawnTable => combineSpawnTable.Value;
public EnchantOptionTable EnchantOptionTable => enchantOptionTable.Value;
public UnlimitedEnchantOptionTable UnlimitedEnchantOptionTable => unlimitedEnchantOptionTable.Value;
public ConstantsTable ConstantsTable => constantsTable.Value;
public ServerTableMetadataStorage(MetadataContext context) {
instanceFieldTable = Retrieve<InstanceFieldTable>(context, ServerTableNames.INSTANCE_FIELD);
scriptConditionTable = Retrieve<ScriptConditionTable>(context, ServerTableNames.SCRIPT_CONDITION);
scriptFunctionTable = Retrieve<ScriptFunctionTable>(context, ServerTableNames.SCRIPT_FUNCTION);
scriptEventConditionTable = Retrieve<ScriptEventConditionTable>(context, ServerTableNames.SCRIPT_EVENT);
jobConditionTable = Retrieve<JobConditionTable>(context, ServerTableNames.JOB_CONDITION);
bonusGameTable = Retrieve<BonusGameTable>(context, ServerTableNames.BONUS_GAME);
globalDropItemBoxTable = Retrieve<GlobalDropItemBoxTable>(context, ServerTableNames.GLOBAL_DROP_ITEM_BOX);
userStatTable = Retrieve<UserStatTable>(context, ServerTableNames.USER_STAT);
individualDropItemTable = Retrieve<IndividualDropItemTable>(context, ServerTableNames.INDIVIDUAL_DROP_ITEM);
prestigeExpTable = Retrieve<PrestigeExpTable>(context, ServerTableNames.PRESTIGE_EXP);
prestigeIdExpTable = Retrieve<PrestigeIdExpTable>(context, ServerTableNames.PRESTIGE_ID_EXP);
timeEventTable = Retrieve<TimeEventTable>(context, ServerTableNames.TIME_EVENT);
gameEventTable = Retrieve<GameEventTable>(context, ServerTableNames.GAME_EVENT);
oxQuizTable = Retrieve<OxQuizTable>(context, ServerTableNames.OX_QUIZ);
itemMergeTable = Retrieve<ItemMergeTable>(context, ServerTableNames.ITEM_MERGE);
shopTable = Retrieve<ShopTable>(context, ServerTableNames.SHOP);
shopItemTable = Retrieve<ShopItemTable>(context, ServerTableNames.SHOP_ITEM);
beautyShopTable = Retrieve<BeautyShopTable>(context, ServerTableNames.BEAUTY_SHOP);
meretMarketTable = Retrieve<MeretMarketTable>(context, ServerTableNames.MERET_MARKET);
fishTable = Retrieve<FishTable>(context, ServerTableNames.FISH);
combineSpawnTable = Retrieve<CombineSpawnTable>(context, ServerTableNames.COMBINE_SPAWN);
enchantOptionTable = Retrieve<EnchantOptionTable>(context, ServerTableNames.ENCHANT_OPTION);
unlimitedEnchantOptionTable = Retrieve<UnlimitedEnchantOptionTable>(context, ServerTableNames.UNLIMITED_ENCHANT_OPTION);
constantsTable = Retrieve<ConstantsTable>(context, ServerTableNames.CONSTANTS);
}
public IEnumerable<GameEvent> GetGameEvents() {
foreach ((int id, GameEventMetadata gameEvent) in GameEventTable.Entries) {
if (gameEvent.EndTime < DateTime.Now) {
continue;
}
yield return new GameEvent(gameEvent);
}
}
private static Lazy<T> Retrieve<T>(MetadataContext context, string key) where T : ServerTable {
var result = new Lazy<T>(() => {
lock (context) {
ServerTableMetadata? row = context.ServerTableMetadata.Find(key);
if (row?.Table is not T result) {
throw new InvalidOperationException($"Row does not exist: {key}");
}
return result;
}
});
#if !DEBUG
// No lazy loading for RELEASE build.
_ = result.Value;
#endif
return result;
}
}