Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat 添加插件 VeinMiner 连锁挖矿
  • Loading branch information
THEXN committed Apr 20, 2024
commit 6a937bff6260b6d9f7a7703f236d3fc37e89e589
10 changes: 10 additions & 0 deletions Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EssentialsPlus", "Essential
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShowArmors", "ShowArmors\ShowArmors.csproj", "{32AA74DF-D75A-44B7-9BFD-F48BE66247CB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VeinMiner", "VeinMiner\VeinMiner.csproj", "{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -476,6 +478,14 @@ Global
{32AA74DF-D75A-44B7-9BFD-F48BE66247CB}.Release|Any CPU.Build.0 = Release|Any CPU
{32AA74DF-D75A-44B7-9BFD-F48BE66247CB}.Release|x64.ActiveCfg = Release|Any CPU
{32AA74DF-D75A-44B7-9BFD-F48BE66247CB}.Release|x64.Build.0 = Release|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Debug|x64.ActiveCfg = Debug|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Debug|x64.Build.0 = Debug|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Release|Any CPU.Build.0 = Release|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Release|x64.ActiveCfg = Release|Any CPU
{BC20D582-EBEF-4FC4-832C-49EC814CF9A9}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
72 changes: 72 additions & 0 deletions VeinMiner/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using TShockAPI;
using TShockAPI.Hooks;

namespace VeinMiner
{
public class Config
{
public static void Load(ReloadEventArgs args = null)
{
try
{
FileTools.CreateIfNot(Path.Combine(TShock.SavePath, "VeinMiner.json"), JsonConvert.SerializeObject(new Config()
{
Exchange = new()
{
new()
{
//OnlyGiveItem = true,
//MinSize = 10,
//Type = 169,
//Item = new() { { 953, 1 }, { 2425, 5 } }
}
},
Tile = new() { 7, 166, 6, 167, 9, 168, 8, 169, 37, 22, 204, 56, 58, 107, 221, 108, 222, 111, 223, 211, 408, 123, 224, 404, 178, 63, 64, 65, 66, 67, 68 }
}, Formatting.Indented));

VeinMiner.Config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(Path.Combine(TShock.SavePath, "VeinMiner.json")));
if (args != null)
TShock.Log.ConsoleInfo($"<VeinMiner> 配置已重新加载。");
}
catch (Exception ex)
{
TShock.Log.Error(ex.Message);
TShock.Log.ConsoleError("<VeinMiner> 读取配置文件失败。");
}
}

[JsonProperty("启用")]
public bool Enable { get; set; } = true;

[JsonProperty("广播")]
public bool Broadcast { get; set; } = true;

[JsonProperty("放入背包")]
public bool PutInInventory { get; set; } = true;

[JsonProperty("矿石类型")]
public List<int> Tile { get; set; } = new();

[JsonProperty("兑换规则")]
public List<Exchange> Exchange { get; set; } = new();
}

public struct Exchange
{
[JsonProperty("仅给予物品")]
public bool OnlyGiveItem;

[JsonProperty("最小尺寸")]
public int MinSize;

[JsonProperty("类型")]
public int Type;

[JsonProperty("物品")]
public Dictionary<int, int> Item;
}
}
136 changes: 136 additions & 0 deletions VeinMiner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# VeinMiner 连锁挖矿

- 作者: Megghy|YSpoof|Maxthegreat99|肝帝熙恩
- 出处: [github](https://github.com/Maxthegreat99/TSHockVeinMiner)
- 连锁挖矿,字面意思
- 可以连锁挖一堆矿然后爆指定物品

## 更新日志

```
暂无
```

## 指令

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| /vm | veinminer | 开关连锁挖矿指令|
| /vm [任意参数]| veinminer | 开关连锁挖矿提示消息指令|

## 配置

```json
{
"启用": true,
"广播": true,
"放入背包": true,
"矿石类型": [
7,
166,
6,
167,
9,
168,
8,
169,
37,
22,
204,
56,
58,
107,
221,
108,
222,
111,
223,
211,
408,
123,
224,
404,
178,
63,
64,
65,
66,
67,
68
],
"兑换规则": [
{
"仅给予物品": false,
"最小尺寸": 0,
"类型": 0,
"物品": null
}
]
}
```
### 示例
```json
{
"启用": true,
"广播": true,
"放入背包": true,
"矿石类型": [
7,
166,
6,
167,
9,
168,
8,
169,
37,
22,
204,
56,
58,
107,
221,
108,
222,
111,
223,
211,
408,
123,
224,
404,
178,
63,
64,
65,
66,
67,
68
],
"兑换规则": [
{
"仅给予物品": true,
"最小尺寸": 10,
"类型": 168,
"物品": {
"666": 1,
"669": 1
}
},
{
"仅给予物品": true,
"最小尺寸": 10,
"类型": 8,
"物品": {
"662": 5,
"219": 1
}
}
]
}
```


## 反馈
- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/
- 国内社区trhub.cn 或 TShock官方群等
49 changes: 49 additions & 0 deletions VeinMiner/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Terraria;
using TShockAPI;

namespace VeinMiner
{
class Utils
{
public static Item GetItemFromTile(int x, int y)
{
WorldGen.KillTile_GetItemDrops(x, y, Main.tile[x, y], out int id, out int stack, out _, out _);
Item item = new();
item.SetDefaults(id);
item.stack = stack;
return item;
}
}

public static class Expansion
{
public static int GetBlankSlot(this TSPlayer tsp)
{
int num = 0;
tsp.TPlayer.inventory.ForEach(s => { if (s.netID == 0) num++; });
return num;
}

public static bool IsSpaceEnough(this TSPlayer tsp, int id, int stack)
{
int available = 0;
Item item = new Item();
item.SetDefaults(id);
Item s;
for (int i = 0; i < 50; i++)
{
s = tsp.TPlayer.inventory[i];
if (available < stack)
{
if (s.netID == id) available += (s.maxStack - s.stack);
else if (s.netID == 0) available += item.maxStack;
}
else
{
break;
}
}
return available >= stack;
}
}
}
Loading