-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseHandler.cs
More file actions
144 lines (136 loc) · 4.38 KB
/
Copy pathDatabaseHandler.cs
File metadata and controls
144 lines (136 loc) · 4.38 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
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
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TShockAPI;
using TShockAPI.DB;
namespace QuestSystem
{
public partial class Quest
{
private string ReadDB(string QuestName)
{
string listaccounts = "";
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if (QuestName == reader.Get<string>("QuestName"))
{
listaccounts = reader.Get<string>("Accounts");
}
}
}
return listaccounts;
}
private bool GetEnabledStatus(string QuestName)
{
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if (QuestName == reader.Get<string>("QuestName"))
{
if ((reader.Get<string>("Status") == "Enabled"))
{
return true;
}
}
}
}
return false;
}
private int GetID(string QuestName)
{
int ID = -1;
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if (QuestName == reader.Get<string>("QuestName"))
{
ID = reader.Get<int>("ID");
}
}
}
return ID;
}
private string GetLastCheck(string QuestName)
{
string time = null;
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if (QuestName == reader.Get<string>("QuestName"))
{
time = reader.Get<string>("LastRefresh");
}
}
}
return time;
}
private int CheckCompletion(int userID, string QuestName)
{
int totalcount = 0;
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if ((reader.Get<string>("QuestName") == QuestName))
{
string listaccount = (reader.Get<string>("Accounts"));
if (listaccount != null)
{
totalcount = Regex.Matches(listaccount, Convert.ToString(userID)).Count;
}
return totalcount;
}
}
}
return -1;
}
private bool checkregion(TSPlayer ply, string regionname)
{
if (regionname == null)
{
return true;
}
else if ((TShock.Regions.GetRegionByName(regionname) == null))
{
ply.SendMessage("Invalid region!", Color.LightBlue);
return false;
}
Region region = TShock.Regions.GetRegionByName(regionname);
if (region.InArea(ply.TileX, ply.TileY))
{
return true;
}
return false;
}
private void UpdateDB()
{
foreach (var questitem in config.All)
{
bool exist = false;
using (var reader = QuestDB.QueryReader("SELECT * FROM QuestCount"))
{
while (reader.Read())
{
if (questitem.DisplayName == reader.Get<string>("QuestName"))
{
exist = true;
};
}
}
if (exist == false)
{
var add = QuestDB.Query("INSERT INTO QuestCount (QuestName, Status, LastRefresh) VALUES (@0, @1, @2);", questitem.DisplayName, "Disabled", DateTime.Now);
}
}
}
}
}