Skip to content
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
5 changes: 5 additions & 0 deletions BedSet/BedSet.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>
186 changes: 186 additions & 0 deletions BedSet/Class1.cs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这文件名改一下不要。Class1.cs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好经典的名字

Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System.Reflection;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;
using Main = Terraria.Main;
using Version = System.Version;
using Color = Microsoft.Xna.Framework.Color;
using System.Net.Sockets;

namespace Plugin
{
[ApiVersion(2, 1)]
public class Plugin : TerrariaPlugin
{
private TerrariaPlugin join;
public override string Author => "cmgy";
public override string Description => "";
public override string Name => "BedSet 床设置";
public override Version Version => new(1, 0, 0, 1);
public Plugin(Main game) : base(game) { }

//hook
public override void Initialize()
{
GetDataHandlers.PlayerUpdate.Register(backbed);//使用回城物品 set
PlayerHooks.PlayerPostLogin += PlayerHooks_PlayerPostLogin;//登录返回床位置 login
GetDataHandlers.KillMe.Register(deadafter);//死亡返回床位置 death
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这不该是Spawn事件吗

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道,不过改了之后用起来挺怪

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道,不过改了之后用起来挺怪

应该放到Spawn事件处理,这样写不会一死就复活吧。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以多问问羽学他有经验

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道,不过改了之后用起来挺怪

应该放到Spawn事件处理,这样写不会一死就复活吧。

没一死就复活吧,毕竟我写了个while等着玩家复活(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道,不过改了之后用起来挺怪

应该放到Spawn事件处理,这样写不会一死就复活吧。

测试了下只用spawn的,最大缺点是得等魔镜之类的使用时间结束才触发
第二只能把传送位置,记录位置,和清除位置放一起
1.先记录后传送,重进后马上记录了出生地而非床位置,直接废弃
2.先传送后记录,第一次会先传送到床位置清除再记录,但第二次甚至之后依旧只能传送到第一次传送的地方

因为没接触过spawn事件所以以上特性在我写的时候都没遇到(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道,不过改了之后用起来挺怪

应该放到Spawn事件处理,这样写不会一死就复活吧。

测试了下只用spawn的,最大缺点是得等魔镜之类的使用时间结束才触发 第二只能把传送位置,记录位置,和清除位置放一起 1.先记录后传送,重进后马上记录了出生地而非床位置,直接废弃 2.先传送后记录,第一次会先传送到床位置清除再记录,但第二次甚至之后依旧只能传送到第一次传送的地方

因为没接触过spawn事件所以以上特性在我写的时候都没遇到(

1不在第1次触发时触发,2只在第1次触发可以互补,不过写起来应该和单独分成3个钩没差多少了

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlayerSpawnContext判断这个

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spawn事件里

}
//set
private async void backbed(object? sender, GetDataHandlers.PlayerUpdateEventArgs e)
{
//魔镜
if (e.Player.TPlayer.controlUseItem &&
(e.Player.SelectedItem.netID == 50 ||
e.Player.SelectedItem.netID == 3199 ||
e.Player.SelectedItem.netID == 3124 ||
e.Player.SelectedItem.netID == 5358
)
)
{
await Task.Delay(300);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await 开个线程

string path = $@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


路径用Path.Combine弄个变量

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? 路径用Path.Combine弄个变量

{e.Player.Name}{Main.worldName}已经是变量吧

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? 路径用Path.Combine弄个变量

{e.Player.Name}{Main.worldName}已经是变量吧

你不觉得重复太多代码了吗
正常做法是把这路径作为类属性使用。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在有个问题
你用魔境之类的物品去记录出生点
如果重进后魔晶的出生点依然是默认的点,当人物再次使用魔晶,那你是记录新的点还是传送到已经记录的点,如果记录新的点,OK那就变成记录世界默认出生点了,如果传送到已经记录的点那你这个魔境记录点变得没意义了,用死亡记录的话也有这种问题,所以这个解决方案不是一个好的方法。

if (!Directory.Exists(@".\重生点"))
{
Directory.CreateDirectory(@".\重生点");
}
if (!File.Exists(path))
{
FileStream bed = File.Create($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一样

StreamWriter xy = new StreamWriter(bed);
xy.Close();
bed.Close();
}
FileStream clear = new FileStream($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt", FileMode.Truncate, FileAccess.ReadWrite);
Comment thread
Controllerdestiny marked this conversation as resolved.
Outdated
clear.Close();
e.Player.SendData(PacketTypes.CreateCombatTextExtended, $"updata", 255255255, e.Player.X, e.Player.Y, 3000);
NetMessage.PlayNetSound(new NetMessage.NetSoundInfo(e.Player.TPlayer.Center, 159), e.Player.Index, -1);
StreamWriter set = File.AppendText($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
set.WriteLine($"{e.Player.TileX+1} {e.Player.TileY}");
set.Close();
}
//回忆
if (e.Player.TPlayer.controlUseItem &&
(e.Player.SelectedItem.netID == 2350 ||
e.Player.SelectedItem.netID == 4870)
)
{
await Task.Delay(300);
string path = $@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt";
if (!Directory.Exists(@".\重生点"))
{
Directory.CreateDirectory(@".\重生点");
}
if (!File.Exists(path))
{
FileStream bed = File.Create($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
StreamWriter xy = new StreamWriter(bed);
xy.Close();
bed.Close();
}
FileStream clear = new FileStream($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt", FileMode.Truncate, FileAccess.ReadWrite);
clear.Close();
e.Player.SendData(PacketTypes.CreateCombatTextExtended, $"updata", 255255255, e.Player.X, e.Player.Y, 3000);
NetMessage.PlayNetSound(new NetMessage.NetSoundInfo(e.Player.TPlayer.Center, 159), e.Player.Index, -1);
StreamWriter set = File.AppendText($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
set.WriteLine($"{e.Player.TileX+1} {e.Player.TileY}");
set.Close();
}
}
//login
private async void PlayerHooks_PlayerPostLogin(PlayerPostLoginEventArgs e)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议异步

{
while (true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个Whiletrue很爆炸

{
await Task.Delay(1000);
if (e.Player.X != 0)
{
string path = $@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt";
Copy link
Copy Markdown
Member

@ACaiCat ACaiCat Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种SQL存可能会更好,而且路径不要放中文,不然任意爆掉,不要用worldName,用WorldID,也不要用PlayerName,用AccountID

if (!Directory.Exists(@".\重生点"))
{
Directory.CreateDirectory(@".\重生点");
}
if (!File.Exists(path))
{
FileStream bed = File.Create($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
StreamWriter xy = new StreamWriter(bed);
xy.Close();
bed.Close();
}
string[] line = File.ReadAllLines($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
if (line.Length > 0)
{
string tile = line[0];
string x = tile.Remove(4, tile.Length - 4);
string y = tile.Remove(0, tile.Length - 4);
string x2 = x.Replace(" ", "");
string y2 = y.Replace(" ", "");
int x3 = Convert.ToInt32(x2);
int y3 = Convert.ToInt32(y2);
e.Player.SendInfoMessage($" 传送至重生点,记得重新保存床重生点");
e.Player.Teleport(x3 * 16, y3 * 16, 6);
Color c = new Color(0, 169, 255);
e.Player.SendData(PacketTypes.CreateCombatTextExtended, "return", (int)c.packedValue, e.Player.X, e.Player.Y - 16);
NetMessage.PlayNetSound(new NetMessage.NetSoundInfo(e.Player.TPlayer.Center, 114), e.Player.Index, -1);
}
break;
}
}
}
//death
private async void deadafter(object? sender, GetDataHandlers.KillMeEventArgs e)
{
while (true)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要while和异步

await Task.Delay(500);
if (e.Player.Dead == false)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

读取保存位置建议单独出一个方法,这里重复太多了,而且位置必须缓存

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

读取保存位置建议单独出一个方法,这里重复太多了,而且位置必须缓存

位置确实)考虑到一个人物逛多个地图的情况

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是,你缓存到内存里,不要一直从磁盘读数据,一般是建议服务器启动和Reload的时候才从文件读,其余全放内存里

string path = $@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt";
if (!Directory.Exists(@".\重生点"))
{
Directory.CreateDirectory(@".\重生点");
}
if (!File.Exists(path))
{
FileStream bed = File.Create($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
StreamWriter xy = new StreamWriter(bed);
xy.Close();
bed.Close();
}
string[] line = File.ReadAllLines($@".\重生点\{e.Player.Name}{Main.worldName}重生点.txt");
if (line.Length > 0)
{
string tile = line[0];
string x = tile.Remove(4, tile.Length - 4);
string y = tile.Remove(0, tile.Length - 4);
string x2 = x.Replace(" ", "");
string y2 = y.Replace(" ", "");
int x3 = Convert.ToInt32(x2);
int y3 = Convert.ToInt32(y2);
e.Player.Teleport(x3 * 16, y3 * 16, 6);
Color c = new Color(0, 169, 255);
e.Player.SendData(PacketTypes.CreateCombatTextExtended, "return", (int)c.packedValue, e.Player.X, e.Player.Y - 16);
NetMessage.PlayNetSound(new NetMessage.NetSoundInfo(e.Player.TPlayer.Center, 114), e.Player.Index, -1);
}
break;
}
}
}


protected override void Dispose(bool disposing)
{
if (disposing)
{
var asm = Assembly.GetExecutingAssembly();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有点多余了

Commands.ChatCommands.RemoveAll(c => c.CommandDelegate.Method?.DeclaringType?.Assembly == asm);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这插件他没指令

}
base.Dispose(disposing);
}

private class List
{
}
}
}
19 changes: 19 additions & 0 deletions BedSet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# BedSet 设置重生点

- 作者: pang2333
- 使用回城物品记录重生点,在退出及死亡后传送
- 无权限,无指令


## 更新日志

```
1.0.0.1
修正位置偏移
```



## 文件位置
> tshock/重生点/{PlayerName}{WorldName}.txt

9 changes: 9 additions & 0 deletions Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandstorm", "Sandstorm\Sand
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RandomBroadcast", "RandomBroadcast\RandomBroadcast.csproj", "{15CBEE46-0107-4C80-8CFE-97E3B4CDAC0D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedSet", "BedSet\BedSet.csproj", "{09973E86-440F-4545-AE4C-2202958558EC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConvertWorld", "ConvertWorld\ConvertWorld.csproj", "{D748F74C-6AD1-48EF-A180-B48B7155DF50}"
EndProject
Global
Expand Down Expand Up @@ -968,6 +969,14 @@ Global
{15CBEE46-0107-4C80-8CFE-97E3B4CDAC0D}.Release|Any CPU.Build.0 = Release|Any CPU
{15CBEE46-0107-4C80-8CFE-97E3B4CDAC0D}.Release|x64.ActiveCfg = Release|Any CPU
{15CBEE46-0107-4C80-8CFE-97E3B4CDAC0D}.Release|x64.Build.0 = Release|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Debug|x64.ActiveCfg = Debug|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Debug|x64.Build.0 = Debug|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Release|Any CPU.Build.0 = Release|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Release|x64.ActiveCfg = Release|Any CPU
{09973E86-440F-4545-AE4C-2202958558EC}.Release|x64.Build.0 = Release|Any CPU
{D748F74C-6AD1-48EF-A180-B48B7155DF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D748F74C-6AD1-48EF-A180-B48B7155DF50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D748F74C-6AD1-48EF-A180-B48B7155DF50}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
| [ReFishTask](ReFishTask/README.md) | 自动刷新渔夫任务 | 无 |
| [Sandstorm](Sandstorm/README.md) | 切换沙尘暴 | 无 |
| [RandomBroadcast](RandomBroadcast/README.md) | 随机广播 | 无 |
| [BedSet](BedSet/README.md) | 设置并记录重生点 | 无 |
| [ConvertWorld](ConvertWorld/README.md) | 击败怪物转换世界物品 | 无 |

</Details>
Expand Down