Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复: 连锁挖矿刷矿 | 更新: 添加连锁挖矿多语言支持 #446

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/VeinMiner/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public static void Load(ReloadEventArgs args = null)
VeinMiner.Config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(Path.Combine(TShock.SavePath, "VeinMiner.json")));
if (args != null)
{
TShock.Log.ConsoleInfo($"<VeinMiner> 配置已重新加载。");
TShock.Log.ConsoleInfo(GetString("<VeinMiner> 配置已重新加载。"));
}
}
catch (Exception ex)
{
TShock.Log.Error(ex.Message);
TShock.Log.ConsoleError("<VeinMiner> 读取配置文件失败。");
TShock.Log.ConsoleError(GetString("<VeinMiner> 读取配置文件失败。"));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/VeinMiner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
## 更新日志

```
v1.6.0.5
修复刷矿,添加英文翻译

v1.6.0.4
完善卸载函数

Expand Down
113 changes: 61 additions & 52 deletions src/VeinMiner/VeinMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ namespace VeinMiner;
public class VeinMiner : TerrariaPlugin
{
public override string Name => "VeinMiner";
public override Version Version => new Version(1, 6, 0, 4);
public override Version Version => new Version(1, 6, 0, 5);
public override string Author => "Megghy|YSpoof|Maxthegreat99|肝帝熙恩";
public override string Description => "VeinMiner by Megghy 适用于 TShock 5.2 支持!";

internal static Config Config = new();
internal static Config Config = new ();

public VeinMiner(Main game) : base(game)
{

}

public override void Initialize()
{
Config.Load();
Commands.ChatCommands.Add(new Command(
permissions: "veinminer",
cmd: delegate (CommandArgs args)
cmd: delegate(CommandArgs args)
{
var tsp = args.Player;
var result = tsp.GetData<VMStatus>("VeinMiner");
if (args.Parameters.Count >= 1)
{
result.EnableBroadcast = !result.EnableBroadcast;
tsp.SendMessage($"[c/95CFA6:<VeinMiner> 挖矿消息已{(result.EnableBroadcast ? "开启" : "关闭")}].", Color.White);
tsp.SendMessage(GetString($"[c/95CFA6:<VeinMiner> 挖矿消息已{(result.EnableBroadcast ? GetString("开启") : GetString("关闭"))}]."), Color.White);
}
else
{
result.Enable = !result.Enable;
tsp.SendMessage($"[c/95CFA6:<VeinMiner> 已{(result.Enable ? "开启" : "关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}")}.]", Color.White);
tsp.SendMessage(GetString($"[c/95CFA6:<VeinMiner> 已{(result.Enable ? GetString("开启") : GetString("关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}"))}.]"), Color.White);
}
},
"veinminer", "chain mining", "vm"));
Expand All @@ -54,6 +54,7 @@ protected override void Dispose(bool disposing)
TShockAPI.Hooks.GeneralHooks.ReloadEvent -= Config.Load;
ServerApi.Hooks.ServerJoin.Deregister(this, this.OnPlayerJoin);
}

base.Dispose(disposing);
}

Expand All @@ -71,18 +72,20 @@ void OnPlayerJoin(JoinEventArgs args)
}
}

void OnTileEdit(object o, GetDataHandlers.TileEditEventArgs args)
void OnTileEdit(object? sender, GetDataHandlers.TileEditEventArgs args)
{
if (Main.tile[args.X, args.Y] is { } tile && args.Player.HasPermission("veinminer") && Config.Enable && args.Player.GetData<VMStatus>("VeinMiner").Enable && Config.Tile.Contains(tile.type) && args.Action == GetDataHandlers.EditAction.KillTile && args.EditData == 0)
if (Main.tile[args.X, args.Y] is not { } tile || !args.Player.HasPermission("veinminer") || !Config.Enable || !args.Player.GetData<VMStatus>("VeinMiner").Enable || !Config.Tile.Contains(tile.type) || args.Action != GetDataHandlers.EditAction.KillTile || args.EditData != 0)
{
args.Handled = true;
this.Mine(args.Player, args.X, args.Y, tile.type);
return;
}

args.Handled = true;
this.Mine(args.Player, args.X, args.Y, tile.type);
}

void Mine(TSPlayer plr, int x, int y, int type)
{
var list = GetVein(new(), x, y, type).Result;
var list = GetVein(new (), x, y, type);
var count = list.Count;
var item = Utils.GetItemFromTile(x, y);
var mineableList = new List<Point>();
Expand Down Expand Up @@ -112,22 +115,19 @@ void Mine(TSPlayer plr, int x, int y, int type)
e.Item.ForEach(ex => plr.GiveItem(ex.Key, ex.Value));
if (e.OnlyGiveItem)
{
KillTileAndSend(list, true);
mineCount = KillTileAndSend(list, true);
}
else
{
GiveItem();
}

plr.SendMessage($"[c/95CFA6:<VeinMiner>] 挖掘了 [c/95CFA6: {mineCount} {(item.type == 0 ? "未知" : item.Name)}].", Color.White);
return;
}
else
{
plr.SendInfoMessage($"[c/95CFA6:<VeinMiner>] 背包已满,还需空位:[c/95CFA6:{e.Item.Count}] .");
plr.SendTileSquareCentered(x, y, 1);
plr.SendMessage(GetString($"[c/95CFA6:<VeinMiner>] 挖掘了 [c/95CFA6: {mineCount} {(item.type == 0 ? GetString("未知") : item.Name)}]."), Color.White);
return;
}

plr.SendInfoMessage(GetString($"[c/95CFA6:<VeinMiner>] 背包已满,还需空位:[c/95CFA6:{e.Item.Count}] ."));
plr.SendTileSquareCentered(x, y, 1);
});
}
else
Expand All @@ -141,71 +141,80 @@ void GiveItem()
{
if (plr.IsSpaceEnough(item.netID, mineCount))
{
mineCount = KillTileAndSend(list, true);
plr.GiveItem(item.netID, mineCount);
KillTileAndSend(list, true);

}
else
{
WorldGen.KillTile(x, y);
plr.SendInfoMessage($"[c/95CFA6:<VeinMiner>] 背包已满,需额外空位:[c/95CFA6:{mineCount}] 以放入 [c/95CFA6:{item.Name}] .");
plr.SendInfoMessage(GetString($"[c/95CFA6:<VeinMiner>] 背包已满,需额外空位:[c/95CFA6:{mineCount}] 以放入 [c/95CFA6:{item.Name}] ."));
}
}
else
{
KillTileAndSend(list, false);
mineCount = KillTileAndSend(list, false);
}

if (plr.GetData<VMStatus>("VeinMiner").EnableBroadcast && Config.Broadcast && mineCount > 1)
{
plr.SendMessage($"[c/95CFA6:<VeinMiner>] 正在挖掘 [c/95CFA6:{mineCount} {(item.type == 0 ? "未知" : item.Name)}].", Color.White);
plr.SendMessage(GetString($"[c/95CFA6:<VeinMiner>] 正在挖掘 [c/95CFA6:{mineCount} {(item.type == 0 ? "未知" : item.Name)}]."), Color.White);
}
}
}
else if (count > 0)
{
plr.SendMessage($"[c/95CFA6:<VeinMiner>] 无法挖取矿石,可能是因为矿石上方有不可破坏的物体.", Color.White);
plr.SendMessage(GetString($"[c/95CFA6:<VeinMiner>] 无法挖取矿石,可能是因为矿石上方有不可破坏的物体."), Color.White);
}
}

public static void KillTileAndSend(List<Point> list, bool noItem)
public static int KillTileAndSend(List<Point> list, bool noItem)
{
Task.Run(() =>
if (!list.Any())
{
return 0;
}

int killCount = 0;
list.ForEach(p =>
{
if (!list.Any())
WorldGen.KillTile(p.X, p.Y, false, false, noItem);
NetMessage.SendData(17, -1, -1, null, 4, p.X, p.Y, false.GetHashCode());
});
list.ForEach(p =>
{

ITile tile = Main.tile[p.X, p.Y];
if (tile == null || !tile.active())
{
return;
killCount++;
}

list.ForEach(p =>
{
WorldGen.KillTile(p.X, p.Y, false, false, noItem);
NetMessage.SendData(17, -1, -1, null, 4, p.X, p.Y, false.GetHashCode());
});
});
return killCount;
}

public static Task<List<Point>> GetVein(List<Point> list, int x, int y, int type)
public static List<Point> GetVein(List<Point> list, int x, int y, int type)
{
return Task.Run(() =>

if (!list.Any(p => p.Equals(new Point(x, y))) && Main.tile[x, y] is { } tile && tile.active() && tile.type == type)
{
if (!list.Any(p => p.Equals(new Point(x, y))) && Main.tile[x, y] is { } tile && tile.active() && tile.type == type)
if (list.Count > 5000)
{
if (list.Count > 5000)
{
return list;
}

list.Add(new(x, y));
list = GetVein(list, x + 1, y, type).Result;
list = GetVein(list, x - 1, y, type).Result;
list = GetVein(list, x, y + 1, type).Result;
list = GetVein(list, x, y - 1, type).Result;
list = GetVein(list, x + 1, y + 1, type).Result;
list = GetVein(list, x + 1, y - 1, type).Result;
list = GetVein(list, x - 1, y + 1, type).Result;
list = GetVein(list, x - 1, y - 1, type).Result;
return list;
}
return list;
});

list.Add(new (x, y));
list = GetVein(list, x + 1, y, type);
list = GetVein(list, x - 1, y, type);
list = GetVein(list, x, y + 1, type);
list = GetVein(list, x, y - 1, type);
list = GetVein(list, x + 1, y + 1, type);
list = GetVein(list, x + 1, y - 1, type);
list = GetVein(list, x - 1, y + 1, type);
list = GetVein(list, x - 1, y - 1, type);
}

return list;
}
}
3 changes: 3 additions & 0 deletions src/VeinMiner/VeinMiner.csproj
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\template.targets" />
<ItemGroup>
<Folder Include="i18n\" />
</ItemGroup>
</Project>
83 changes: 83 additions & 0 deletions src/VeinMiner/i18n/en-US.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
msgid ""
msgstr ""
"Project-Id-Version: VeinMiner\n"
"POT-Creation-Date: 2024-08-31 17:14:06+0800\n"
"PO-Revision-Date: 2024-08-31 19:55+0800\n"
"Last-Translator: Cai\n"
"Language-Team: UnrealMultiple\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.5\n"

#: ..\..\VeinMiner.cs:34 ..\..\VeinMiner.cs:39
msgid "开启"
msgstr "Activated"

#: ..\..\VeinMiner.cs:161
#, csharp-format
msgid "[c/95CFA6:<VeinMiner>] 正在挖掘 [c/95CFA6:{0} {1}]."
msgstr "[c/95CFA6:<VeinMiner>] Mining [c/95CFA6: {0} {1} ]."

#: ..\..\VeinMiner.cs:151
#, csharp-format
msgid ""
"[c/95CFA6:<VeinMiner>] 背包已满,需额外空位:[c/95CFA6:{0}] 以"
"放入 [c/95CFA6:{1}] ."
msgstr ""
"[c/95CFA6:<VeinMiner>] Inventory full, space needed: [c/95CFA6:"
"{0}] to insert [c/95CFA6:{1}] ."

#: ..\..\VeinMiner.cs:167
msgid ""
"[c/95CFA6:<VeinMiner>] 无法挖取矿石,可能是因为矿石上方有不可破"
"坏的物体."
msgstr ""
"[c/95CFA6:<VeinMiner>] Unable to mine ore, possibly because "
"there is an indestructible object above the ore."

#: ..\..\Config.cs:38
msgid "<VeinMiner> 读取配置文件失败。"
msgstr "<VeinMiner> Failed to read config file."

#: ..\..\VeinMiner.cs:129
#, csharp-format
msgid ""
"[c/95CFA6:<VeinMiner>] 背包已满,还需空位:[c/95CFA6:{0}] ."
msgstr ""
"[c/95CFA6:<VeinMiner>] Inventory full, space needed: [c/95CFA6:"
"{0}] ."

#: ..\..\VeinMiner.cs:39
#, csharp-format
msgid "[c/95CFA6:<VeinMiner> 已{0}.]"
msgstr "[c/95CFA6:<VeinMiner> {0} .]"

#: ..\..\VeinMiner.cs:39
msgid "关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}"
msgstr ""
"Deactivated! | To turn off only mining status messages use: /"
"vm msg"

#: ..\..\Config.cs:32
msgid "<VeinMiner> 配置已重新加载。"
msgstr "<VeinMiner> Config reloaded."

#: ..\..\VeinMiner.cs:34
msgid "关闭"
msgstr "Deactivated"

#: ..\..\VeinMiner.cs:34
#, csharp-format
msgid "[c/95CFA6:<VeinMiner> 挖矿消息已{0}]."
msgstr "[c/95CFA6:<VeinMiner> Mining Status {0}.]"

#: ..\..\VeinMiner.cs:125
msgid "未知"
msgstr "Unknown"

#: ..\..\VeinMiner.cs:125
#, csharp-format
msgid "[c/95CFA6:<VeinMiner>] 挖掘了 [c/95CFA6: {0} {1}]."
msgstr "[c/95CFA6:<VeinMiner>] Mined [c/95CFA6: {0} {1} ]."
Loading
Loading