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

添加插件:Respawn 原地复活 #159

Merged
merged 8 commits into from
Jun 1, 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 @@ -162,6 +162,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Economics.Task", "Economics
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolesModifying", "RolesModifying\RolesModifying.csproj", "{12D5F858-3716-4BD7-ACD0-141D926E7E63}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Respawn", "Respawn\Respawn.csproj", "{E4792205-8095-4333-AFE7-79B64CD02935}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -786,6 +788,14 @@ Global
{12D5F858-3716-4BD7-ACD0-141D926E7E63}.Release|Any CPU.Build.0 = Release|Any CPU
{12D5F858-3716-4BD7-ACD0-141D926E7E63}.Release|x64.ActiveCfg = Release|Any CPU
{12D5F858-3716-4BD7-ACD0-141D926E7E63}.Release|x64.Build.0 = Release|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Debug|x64.ActiveCfg = Debug|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Debug|x64.Build.0 = Debug|Any CPU
{E4792205-8095-4333-AFE7-79B64CD02935}.Release|Any CPU.ActiveCfg = Release|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
| [HouseRegion](HouseRegion/README.md) | 圈地插件 | |
| [SignInSign](SignInSign/README.md) | 告示牌登录插件 | 无 |
| [WeaponPlusCostCoin](WeaponPlusCostCoin/README.md) | 武器强化钱币版 | 无 |
| [Respawn](Respawn/README.md) | 原地复活 | 无 |

</Details>

Expand Down
27 changes: 27 additions & 0 deletions Respawn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Respawn 原地复活

- 作者: leader,肝帝熙恩
- 出处: Tshock官方中文群
- 原地复活,复活时间与tshock自带config内容相同

## 更新日志

```
暂无
```

## 指令

```
暂无
```

## 配置

```
暂无
```

## 反馈
- 共同维护的插件库:https://github.com/Controllerdestiny/TShockPlugin
- 国内社区trhub.cn 或 TShock官方群等
89 changes: 89 additions & 0 deletions Respawn/Respawn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Microsoft.Xna.Framework;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;
using System;
using System.Collections.Generic;

namespace Respawn
{
[ApiVersion(2, 1)]
public class Respawn : TerrariaPlugin
{
public override string Author => "leader,肝帝熙恩";
public override string Description => "原地复活";
public override string Name => "Respawn";
public override Version Version => new Version(1, 0, 1);
private long TimerCount = 0;
private Dictionary<int, (DateTime DeathTime, Vector2 DeathPosition)> playerDeathRecords = new Dictionary<int, (DateTime, Vector2)>();
private int respawnTime;

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

public override void Initialize()
{
GetDataHandlers.KillMe.Register(OnKillMe);
ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
GetDataHandlers.KillMe.UnRegister(OnKillMe);
ServerApi.Hooks.GameUpdate.Deregister(this, OnUpdate);
}
base.Dispose(disposing);
}

private void OnKillMe(object? sender, GetDataHandlers.KillMeEventArgs e)
{
if (!playerDeathRecords.ContainsKey(e.Player.Index))
{
playerDeathRecords[e.Player.Index] = (DateTime.UtcNow, e.Player.TPlayer.position);
}
}

private void OnUpdate(EventArgs args)
{
TimerCount++;

if (TimerCount % 60 == 0)
{
List<int> playersToRespawn = new List<int>();

foreach (var kvp in playerDeathRecords)
{
TSPlayer player = TShock.Players[kvp.Key];
var (deathTime, position) = kvp.Value;
respawnTime = TShock.Config.Settings.RespawnSeconds;
foreach (NPC npc in Main.npc)
{
if (npc.active && (npc.boss || npc.type == 13 || npc.type == 14 || npc.type == 15) &&
Math.Abs(player.TPlayer.Center.X - npc.Center.X) + Math.Abs(player.TPlayer.Center.Y - npc.Center.Y) < 4000f)
{
respawnTime = TShock.Config.Settings.RespawnBossSeconds;
break;
}
}
if (DateTime.UtcNow - deathTime > TimeSpan.FromSeconds(respawnTime))
{
playersToRespawn.Add(kvp.Key);

//player.Spawn(PlayerSpawnContext.ReviveFromDeath);
player.Teleport(position.X, position.Y, 1);
}
}

// 移除已复活玩家的记录,防止重复处理
foreach (int playerId in playersToRespawn)
{
playerDeathRecords.Remove(playerId);
}
}
}
}
}
3 changes: 3 additions & 0 deletions Respawn/Respawn.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>
2 changes: 1 addition & 1 deletion journeyUnlock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## 更新日志

Expand Down
Loading