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

添加插件:EndureBoost 物品一定数量后长时间buff #167

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
60 changes: 60 additions & 0 deletions EndureBoost/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Newtonsoft.Json;
using TShockAPI;

public class Configuration
{
public static readonly string FilePath = Path.Combine(TShock.SavePath, "EndureBoost.json");
[JsonProperty("猪猪储钱罐")]
public bool bank = true;
[JsonProperty("保险箱")]
public bool bank2 = true;
[JsonProperty("护卫熔炉")]
public bool bank3 = false;
[JsonProperty("虚空宝藏袋")]
public bool bank4 = false;
[JsonProperty("持续时间(s)")]
public int duration = 3600;

public class Potion
{
[JsonProperty("药水id")]
public int[] ItemID { get; set; }
[JsonProperty("药水数量")]
public int RequiredStack { get; set; }
}

public class Station
{
[JsonProperty("物品id")]
public int[] Type { get; set; }
[JsonProperty("物品数量")]
public int RequiredStack { get; set; }
[JsonProperty("给buff的id")]
public int BuffType { get; set; }
}
[JsonProperty("药水")]
public List<Potion> Potions { get; set; } = new List<Potion>();
[JsonProperty("其他物品")]
public List<Station> Stations { get; set; } = new List<Station>();

public void Write(string path)
{
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
{
var str = JsonConvert.SerializeObject(this, Formatting.Indented);
using (var sw = new StreamWriter(fs))
{
sw.Write(str);
}
}
}

public static Configuration Read(string path)
{
if (!File.Exists(path))
return new Configuration();
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
using var sr = new StreamReader(fs);
return JsonConvert.DeserializeObject<Configuration>(sr.ReadToEnd()) ?? new();
}
}
172 changes: 172 additions & 0 deletions EndureBoost/EndureBoost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System;
using System.IO;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;

namespace Plugin
{
[ApiVersion(2, 1)]
public class EndureBoost : TerrariaPlugin
{
public static Configuration Config;

public override string Author => "鑲濆笣鐔欐仼";
ACaiCat marked this conversation as resolved.
Show resolved Hide resolved

public override string Description => "涓�瀹氭暟閲忓悗闀挎椂闂碽uff";

public override string Name => "EndureBoost";

public override Version Version => new Version(1, 0, 0);

public EndureBoost(Main game) : base(game)
{
LoadConfig();
}

public override void Initialize()
{
GeneralHooks.ReloadEvent += ReloadConfig;
ServerApi.Hooks.ServerJoin.Register(this, OnServerJoin);
GetDataHandlers.PlayerSpawn += Rebirth;
Commands.ChatCommands.Add(new Command("EndureBoost", SetPlayerBuffcmd, "ebbuff","ldbuff","loadbuff"));
}

private void SetPlayerBuffcmd(CommandArgs args)
{
TSPlayer player = args.Player;
SetPlayerBuff(player);
}

private static void LoadConfig()
{
Config = Configuration.Read(Configuration.FilePath);
Config.Write(Configuration.FilePath);
}

private static void ReloadConfig(ReloadEventArgs args)
{
LoadConfig();
args.Player.SendSuccessMessage("[{0}] 閲嶆柊鍔犺浇閰嶇疆瀹屾瘯銆�", typeof(EndureBoost).Name);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
Commands.ChatCommands.RemoveAll(x => x.CommandDelegate == SetPlayerBuffcmd);
GeneralHooks.ReloadEvent -= ReloadConfig;
ServerApi.Hooks.ServerJoin.Deregister(this, OnServerJoin);
GetDataHandlers.PlayerSpawn -= Rebirth;
}
base.Dispose(disposing);
}

private void OnServerJoin(JoinEventArgs args)
{
TSPlayer playerBuff = TShock.Players[args.Who];
if (playerBuff == null)
{
return;
}
SetPlayerBuff(playerBuff);
}

private void Rebirth(object o, GetDataHandlers.SpawnEventArgs args)
{
TSPlayer player = args.Player;
SetPlayerBuff(player);
}

private void SetPlayerBuff(TSPlayer player)
{

// 澶勭悊 potions
foreach (var potion in Config.Potions)
{
foreach (var itemId in potion.ItemID)
{
int itemCount = 0;

// 妫�鏌ヨ儗鍖呬腑鐨勭墿鍝�
for (int i = 0; i < 58; i++)
{
if (player.TPlayer.inventory[i].type == itemId)
{
itemCount += player.TPlayer.inventory[i].stack;
}
}

// 妫�鏌ヤ笉鍚屽瓨鍌ㄥ尯涓殑鐗╁搧
CheckBanksForItem(player, itemId, ref itemCount);

if (itemCount >= potion.RequiredStack)
{
int buffType = GetBuffIDByItemID(itemId); // 鑾峰彇鐗╁搧鐨� buff 绫诲瀷
if (buffType != 0)
{
player.SetBuff(buffType, Config.duration*60);
}
}
}
}

// 澶勭悊 stations
foreach (var station in Config.Stations)
{
foreach (var itemId in station.Type)
{
int itemCount = 0;

// 妫�鏌ヨ儗鍖呬腑鐨勭墿鍝�
for (int i = 0; i < 58; i++)
{
if (player.TPlayer.inventory[i].type == itemId)
{
itemCount += player.TPlayer.inventory[i].stack;
}
}

// 妫�鏌ヤ笉鍚屽瓨鍌ㄥ尯涓殑鐗╁搧
CheckBanksForItem(player, itemId, ref itemCount);

if (itemCount >= station.RequiredStack)
{
player.SetBuff(station.BuffType, Config.duration*60);
}
}
}
}

private void CheckBanksForItem(TSPlayer player, int itemId, ref int itemCount)
{
for (int j = 0; j < 40; j++)
{
if (player.TPlayer.bank.item[j].type == itemId && Config.bank)// 妫�鏌ョ尓鐚偍閽辩綈
{
itemCount += player.TPlayer.bank.item[j].stack;
}
if (player.TPlayer.bank2.item[j].type == itemId && Config.bank2)// 妫�鏌ヤ繚闄╃
{
itemCount += player.TPlayer.bank2.item[j].stack;
}
if (player.TPlayer.bank3.item[j].type == itemId && Config.bank3)// 妫�鏌ユ姢鍗啍鐐�
{
itemCount += player.TPlayer.bank3.item[j].stack;
}
if (player.TPlayer.bank4.item[j].type == itemId && Config.bank4)// 妫�鏌ヨ櫄绌哄疂钘忚
{
itemCount += player.TPlayer.bank4.item[j].stack;
}
}
}

private int GetBuffIDByItemID(int itemId)
{
Item item = new Item();
item.SetDefaults(itemId);
return item.buffType;
}
}
}
5 changes: 5 additions & 0 deletions EndureBoost/EndureBoost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\template.targets" />

</Project>
65 changes: 65 additions & 0 deletions EndureBoost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# EndureBoost 鐗╁搧涓�瀹氭暟閲忓悗闀挎椂闂碽uff

- 浣滆��: 鑲濆笣鐔欐仼
- 鍑哄: 鏃�
- 褰撶帺瀹惰儗鍖呮煇浜涚墿鍝佸埌杈句竴瀹氭暟閲忓悗锛岀粰涓庢寚瀹歜uff

## 鏇存柊鏃ュ織

```
鏆傛棤
```

## 鎸囦护

| 璇硶 | 鏉冮檺 | 璇存槑 |
| -------------- | :-----------------: | :------: |
| /ebbuff锛�/ldbuff锛�/loadbuff" | 绔嬪嵆鍒锋柊闀挎椂闂碽uff鐘舵�亅

ACaiCat marked this conversation as resolved.
Show resolved Hide resolved
## 閰嶇疆

```json
{
"鐚尓鍌ㄩ挶缃�": false,// 绀轰緥
"淇濋櫓绠�": false,
"鎶ゅ崼鐔旂倝": false,
"铏氱┖瀹濊棌琚�": true,
"鎸佺画鏃堕棿(s)": 3600,
"鑽按": [
{
"鑽按id": [
288,
289
],//鍙互鏄竴涓暟缁勶紝涔熷氨鏄噷闈㈠彲浠ユ斁鍗曚釜鎴栬�呭涓墿鍝乮d
"鑽按鏁伴噺": 30
},
{
"鑽按id": [
290
],
"鑽按鏁伴噺": 200
}
],
"鍏朵粬鐗╁搧": [
{
"鐗╁搧id": [
2,
3
],
"鐗╁搧鏁伴噺": 3,
"缁檅uff鐨刬d": 87
},
{
"鐗╁搧id": [
5
],
"鐗╁搧鏁伴噺": 3,
"缁檅uff鐨刬d": 89
}
]
}
```

## 鍙嶉
- 鍏卞悓缁存姢鐨勬彃浠跺簱锛歨ttps://github.com/Controllerdestiny/TShockPlugin
- 鍥藉唴绀惧尯trhub.cn 鎴� TShock瀹樻柟缇ょ瓑
10 changes: 10 additions & 0 deletions Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Economics.WeaponPlus", "Eco
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Respawn", "Respawn\Respawn.csproj", "{E4792205-8095-4333-AFE7-79B64CD02935}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EndureBoost", "EndureBoost\EndureBoost.csproj", "{B7ED7F50-82BB-4865-B338-041871A33E42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -806,6 +808,14 @@ Global
{E4792205-8095-4333-AFE7-79B64CD02935}.Release|Any CPU.Build.0 = Release|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Release|x64.ActiveCfg = Release|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Release|x64.Build.0 = Release|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Debug|x64.Build.0 = Debug|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Release|Any CPU.Build.0 = Release|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Release|x64.ActiveCfg = Release|Any CPU
{B7ED7F50-82BB-4865-B338-041871A33E42}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
| [ChattyBridge](ChattyBridge/README.md) | 鐢ㄤ簬璺ㄦ湇鑱婂ぉ | 鏃� |
| [EconomicsAPI](EconomicsAPI/README.md) | 缁忔祹鎻掍欢鍓嶇疆 | 鏃� |
| [Economics.RPG](Economics.RPG/README.md) | RPG | EconomicsAPI |
| [Economics.WeaponPlus](Economics.WeaponPlus/README.md) | 寮哄寲姝﹀櫒 | EconomicsAPI |
| [Economics.WeaponPlus](Economics.WeaponPlus/README.md) | 寮哄寲姝﹀櫒 | EconomicsAPI |
| [Economics.Deal](Economics.RPG/README.md) | 浜ゆ槗鎻掍欢 | EconomicsAPI |
| [Economics.Shop](Economics.Shop/README.md) | 鍟嗗簵鎻掍欢 | EconomicsAPI<br>Economics.RPG |
| [Economics.Skill](Economics.Skill/README.md) | 鎶�鑳芥彃浠� | EconomicsAPI<br>Economics.RPG |
Expand Down Expand Up @@ -126,6 +126,7 @@
| [SignInSign](SignInSign/README.md) | 鍛婄ず鐗岀櫥褰曟彃浠� | 鏃� |
| [WeaponPlusCostCoin](WeaponPlusCostCoin/README.md) | 姝﹀櫒寮哄寲閽卞竵鐗� | 鏃� |
| [Respawn](Respawn/README.md) | 鍘熷湴澶嶆椿 | 鏃� |
| [EndureBoost](EndureBoost/README.md) | 鐗╁搧涓�瀹氭暟閲忓悗闀挎椂闂碽uff | 鏃� |

</Details>

Expand Down
Loading