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

添加插件: journeyUnlock 解锁旅途物品 #54

Merged
merged 3 commits into from
Apr 25, 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
10 changes: 10 additions & 0 deletions Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniGamesAPI", "MiniGamesAP
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildMaster", "BuildMaster\BuildMaster.csproj", "{B0BE2A00-4B6C-4170-B159-EFE5EAA175DA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "journeyUnlock", "journeyUnlock\journeyUnlock.csproj", "{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -556,6 +558,14 @@ Global
{B0BE2A00-4B6C-4170-B159-EFE5EAA175DA}.Release|Any CPU.Build.0 = Release|Any CPU
{B0BE2A00-4B6C-4170-B159-EFE5EAA175DA}.Release|x64.ActiveCfg = Release|Any CPU
{B0BE2A00-4B6C-4170-B159-EFE5EAA175DA}.Release|x64.Build.0 = Release|Any CPU
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Debug|x64.ActiveCfg = Debug|x64
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Debug|x64.Build.0 = Debug|x64
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Release|Any CPU.Build.0 = Release|Any CPU
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Release|x64.ActiveCfg = Release|x64
{5F1AE666-CFDD-4BE7-9C24-1D505BC56BAE}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
| [PersonalPermission](PersonalPermission/README.md) | 为玩家单独设置权限 | 无 |
| [ItemPreserver](ItemPreserver/README.md) | 指定物品不消耗 | 无 |
| [SimultaneousUseFix](SimultaneousUseFix/README.md) | 解决卡双锤卡星旋机枪之类的问题|[Chireiden.TShock.Omni](https://github.com/sgkoishi/yaaiomni/releases)|
| [Challenger](Challenger/README.md) | 挑战者模式 | 无 |
| [MiniGamesAPI](MiniGamesAPI/README.md) | 豆沙小游戏API | 无 |
| [BuildMaster](BuildMaster/README.md) | 豆沙小游戏·建筑大师模式 |[MiniGamesAPI](https://github.com/Controllerdestiny/TShockPlugin/tree/master/MiniGamesAPI)|
| [Challenger](Challenger/README.md) | 挑战者模式 | 无 |
| [MiniGamesAPI](MiniGamesAPI/README.md) | 豆沙小游戏API | 无 |
| [BuildMaster](BuildMaster/README.md) | 豆沙小游戏·建筑大师模式 |[MiniGamesAPI](https://github.com/Controllerdestiny/TShockPlugin/tree/master/MiniGamesAPI)|
| [journeyUnlock](journeyUnlock/README.md) | 解锁旅途物品 | 无 |
30 changes: 30 additions & 0 deletions journeyUnlock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# journeyUnlock 解锁旅途物品

- 作者: Maxthegreat99,肝帝熙恩汉化
- 出处: [github](https://github.com/Maxthegreat99/journeyUnlock)
- 解锁旅途物品,可以一件解锁全部物品

## 更新日志

```
暂无
```

## 指令

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| /journeyunlock 或 /junlock 或 /i解锁" | journeyunlock.unlock | 给自己解锁物品|
| /unlockfor 或 /unlockf 或 /g解锁玩家" | journeyunlock.unlockfor | 给别人解锁物品|

## 配置

```json

```
暂无

```
## 反馈
- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/
- 国内社区trhub.cn 或 TShock官方群等
155 changes: 155 additions & 0 deletions journeyUnlock/journeyUnlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using System.Security.Policy;
using Terraria;
using Terraria.GameContent.NetModules;
using Terraria.ID;
using Terraria.Net;
using TerrariaApi.Server;
using TShockAPI;

namespace journeyUnlock
{
[ApiVersion(2, 1)]
public class journeyUnlock : TerrariaPlugin
{
public override string Author => "Maxthegreat99,肝帝熙恩汉化";

public override string Description => "允许您为旅途中的角色解锁所有或特定物品";

public override string Name => "journeyUnlock";

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

public journeyUnlock(Main game) : base(game)
{
}

public override void Initialize()
{
Commands.ChatCommands.Add(new Command(
permissions: new List<string> { "journeyunlock.unlock" },
cmd: this.unlockCommand,
"journeyunlock", "junlock" , "i解锁"));

Commands.ChatCommands.Add(new Command(
permissions: new List<string> { "journeyunlock.unlockfor" },
cmd: this.unlockForCommand,
"unlockfor", "unlockf" , "g解锁玩家"));
}

private void unlock(Player tplayer, TSPlayer sender , string parameter, bool isSelf)
{

//Case: unlock every item
if (parameter == "*")
{
for (var i = 0; i < ItemID.Count; i++)
{
tplayer.creativeTracker.ItemSacrifices.RegisterItemSacrifice(i, 999);
var _response = NetCreativeUnlocksModule.SerializeItemSacrifice(i, 999);
NetManager.Instance.SendToClient(_response, tplayer.whoAmI);
}
if (!isSelf)
{
TSPlayer.FindByNameOrID(tplayer.name)[0].SendInfoMessage("[旅程解锁] {0} 已为您解锁所有物品!", sender.Name);
sender.SendSuccessMessage("[旅程解锁] 成功为 {0} 解锁所有物品!", tplayer.name);
}
else
sender.SendSuccessMessage("[旅程解锁] 成功解锁所有物品!");

return;
}

//Case: unlock a specific item via id
int itemid;
if (int.TryParse(parameter, out itemid) && TShock.Utils.GetItemById(itemid) != null)
{
tplayer.creativeTracker.ItemSacrifices.RegisterItemSacrifice(itemid, 999);
var _response = NetCreativeUnlocksModule.SerializeItemSacrifice(itemid, 999);
NetManager.Instance.SendToClient(_response, tplayer.whoAmI);

if (!isSelf)
{
TSPlayer.FindByNameOrID(tplayer.name)[0].SendInfoMessage("[旅程解锁] {0} 为您解锁了物品 [i:{1}]!", sender.Name, itemid);
sender.SendSuccessMessage("[旅程解锁] 成功为 {1} 解锁了物品 [i:{0}]!", itemid, tplayer.name);
}
else
sender.SendSuccessMessage("[旅程解锁] 成功解锁物品 [i:{0}]!", itemid);

return;
}
else if (TShock.Utils.GetItemById(itemid) == null || itemid < 1 || itemid > ItemID.Count)
{
sender.SendErrorMessage("[旅程解锁] 物品ID无效!");
return;
}

//Case: unlock a specific item via name
string itemname = parameter;

if (TShock.Utils.GetItemByName(itemname).Count == 0)
{
sender.SendErrorMessage("[旅程解锁] 未找到对应物品!");
return;
}

if (TShock.Utils.GetItemByName(itemname).Count > 1)
{
sender.SendErrorMessage("[旅程解锁] 找到了多个同名物品!");
return;
}

itemid = TShock.Utils.GetItemByName(itemname)[0].netID;

tplayer.creativeTracker.ItemSacrifices.RegisterItemSacrifice(itemid, 999);
var response = NetCreativeUnlocksModule.SerializeItemSacrifice(itemid, 999);
NetManager.Instance.SendToClient(response, tplayer.whoAmI);

if (!isSelf)
{
TSPlayer.FindByNameOrID(tplayer.name)[0].SendInfoMessage("[旅程解锁] {0} 为您解锁了物品 [i:{1}]!", sender.Name, itemid);
sender.SendSuccessMessage("[旅程解锁] 成功为 {1} 解锁了物品 [i:{0}]!", itemid, tplayer.name);
}
else
sender.SendSuccessMessage("[旅程解锁] 成功解锁物品 [i:{0}]!", itemid);
}

private void unlockCommand(CommandArgs args)
{
// 使用不当
if (args.Parameters.Count != 1)
{
args.Player.SendInfoMessage("[旅程解锁] /i解锁 {物品名/ID} - 解锁指定物品。");
args.Player.SendInfoMessage("[旅程解锁] /i解锁 * - 解锁所有物品。");
return;
}

unlock(args.TPlayer, args.Player, args.Parameters[0], true);
}

private void unlockForCommand(CommandArgs args)
{
// 使用不当
if (args.Parameters.Count != 2)
{
args.Player.SendInfoMessage("[旅程解锁] /g解锁 {玩家名} {物品名/ID} - 为指定玩家解锁物品。");
args.Player.SendInfoMessage("[旅程解锁] /g解锁 {玩家名} * - 为指定玩家解锁所有物品。");
return;
}

if (TSPlayer.FindByNameOrID(args.Parameters[0]).Count == 0)
{
args.Player.SendErrorMessage("[旅程解锁] 未找到玩家!");
return;
}
if (TSPlayer.FindByNameOrID(args.Parameters[0]).Count > 1)
{
args.Player.SendErrorMessage("[旅程解锁] 找到多个同名玩家!");
return;
}

TSPlayer player = TSPlayer.FindByNameOrID(args.Parameters[0])[0];

unlock(player.TPlayer, args.Player, args.Parameters[1], false);
}
}
}
3 changes: 3 additions & 0 deletions journeyUnlock/journeyUnlock.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\template.targets" />
</Project>
Loading