-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestConfigHandler.cs
More file actions
93 lines (90 loc) · 3.06 KB
/
Copy pathQuestConfigHandler.cs
File metadata and controls
93 lines (90 loc) · 3.06 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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;
namespace QuestSystem
{
public partial class Quest
{
private void CreateConfig()
{
string filepath = Path.Combine(TShock.SavePath, "Quest.json");
try
{
using (var stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.Write))
{
using (var sr = new StreamWriter(stream))
{
if (File.Exists(filepath))
{ }
else
config = new Config(1);
var configString = JsonConvert.SerializeObject(config, Formatting.Indented);
sr.Write(configString);
}
stream.Close();
}
}
catch (Exception ex)
{
TShock.Log.ConsoleError(ex.Message);
}
}
private bool ReadConfig()
{
string filepath = Path.Combine(TShock.SavePath, "Quest.json");
try
{
if (File.Exists(filepath))
{
using (var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var sr = new StreamReader(stream))
{
var configString = sr.ReadToEnd();
config = JsonConvert.DeserializeObject<Config>(configString);
foreach (var element in config.All)
{
foreach (var element2 in element.IncludeItems)
{
element2.Full();
}
}
}
stream.Close();
}
return true;
}
else
{
TShock.Log.ConsoleError("Create new config file for Quest System.");
CreateConfig();
return false;
}
}
catch (Exception ex)
{
TShock.Log.ConsoleError(ex.Message);
}
return false;
}
private void ReloadConfig(ReloadEventArgs args)
{
if (ReadConfig() && ReadRankConfig() && ReadJobConfig())
{
UpdateDB();
args.Player.SendSuccessMessage("[Quest System] Reload success.");
return;
}
args.Player.SendErrorMessage("[Quest System] Load fails. Check log for more details.");
}
//----------------------------------------
//----------------------------------------
}
}