Skip to content

Commit 061e801

Browse files
committed
修复一些问题
2 parents 3b4c4e4 + 356cfd4 commit 061e801

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

LifemaxExtra/PluginContainer.cs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class LifemaxExtra : TerrariaPlugin
1111
public override string Author => "佚名,肝帝熙恩添加自定义";
1212
public override string Description => "提升生命值上限";
1313
public override string Name => "LifemaxExtra";
14-
public override Version Version => new Version(1, 0, 0, 4);
14+
public override Version Version => new Version(1, 0, 0, 5);
1515
public static Configuration Config;
1616
private bool[] controlUseItemOld;
1717
private int[] itemUseTime;
@@ -27,7 +27,12 @@ private static void LoadConfig()
2727
{
2828
Config = Configuration.Read(Configuration.FilePath);
2929
Config.Write(Configuration.FilePath);
30+
}
3031

32+
private static void ReloadConfig(ReloadEventArgs args)
33+
{
34+
LoadConfig();
35+
args.Player?.SendSuccessMessage("[{0}] 重新加载配置完毕。", typeof(LifemaxExtra).Name);
3136
}
3237

3338
public override void Initialize()
@@ -48,12 +53,6 @@ protected override void Dispose(bool disposing)
4853
base.Dispose(disposing);
4954
}
5055

51-
private static void ReloadConfig(ReloadEventArgs args)
52-
{
53-
LoadConfig();
54-
args.Player?.SendSuccessMessage("[{0}] 重新加载配置完毕。", typeof(LifemaxExtra).Name);
55-
}
56-
5756
private void OnPlayerPostLogin(PlayerPostLoginEventArgs args)
5857
{
5958
foreach (TSPlayer tsplayer in TShock.Players)
@@ -90,52 +89,48 @@ private void OnUpdate(EventArgs args)
9089
int index = tsplayer.Index;
9190
Player tplayer = tsplayer.TPlayer;
9291
Item heldItem = tplayer.HeldItem;
92+
9393
if (!this.controlUseItemOld[index] && tsplayer.TPlayer.controlUseItem && this.itemUseTime[index] <= 0)
9494
{
95-
int useTime = heldItem.useTime;
96-
int type = heldItem.type;
95+
int useTime = heldItem.useTime; // 获取物品使用时间
96+
int type = heldItem.type; // 获取物品类型
9797

98-
if (type != 29)
98+
if (type != 29) // 如果物品不是 ID 为 29 的物品
9999
{
100-
if (type == 1291)
100+
if (type == 1291) // 如果物品是 ID 为 1291 的物品(Life Fruit)
101101
{
102-
if (tplayer.statLifeMax >= Config.LifeCrystalMaxLife)
102+
if (tplayer.statLifeMax >= Config.LifeCrystalMaxLife) // 如果玩家的生命上限大于等于配置的最大水晶生命值
103103
{
104-
if(tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife)
104+
if (tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife) // 如果玩家当前生命上限小于配置的最大果实生命值
105105
{
106-
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
107-
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
108-
tplayer.statLifeMax += 5;
109-
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
110-
106+
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--; // 减少玩家背包中选定物品的堆叠数量
107+
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem); // 更新客户端的选定物品槽位
108+
tplayer.statLifeMax += 5; // 增加玩家的生命上限
109+
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
111110
}
112-
if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife)
111+
else if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife) // 如果玩家当前生命上限大于配置的最大果实生命值
113112
{
114-
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
115-
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
116-
tplayer.statLifeMax = Config.LifeFruitMaxLife;
117-
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
118-
}
113+
tplayer.statLifeMax = Config.LifeFruitMaxLife; // 将玩家的生命上限设置为配置的最大果实生命值
114+
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
115+
}
119116
}
120117
}
121118
}
122-
else
119+
else // 如果物品是 ID 为 29 的物品(Life Crystal)
123120
{
124-
if (tplayer.statLifeMax >= 400)
125-
{
126-
if(tsplayer.TPlayer.statLifeMax < Config.LifeCrystalMaxLife)
121+
if (tplayer.statLifeMax <= Config.LifeCrystalMaxLife) // 如果玩家的生命上限小于等于最大水晶生命值
127122
{
128-
tsplayer.TPlayer.inventory[tplayer.selectedItem].stack--;
129-
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
130-
tplayer.statLifeMax += 20;
131-
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
132-
}
133-
else if(tsplayer.TPlayer.statLifeMax > Config.LifeCrystalMaxLife && tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife)
134-
{
135-
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
136-
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
137-
tplayer.statLifeMax = Config.LifeCrystalMaxLife;
138-
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
123+
if (tsplayer.TPlayer.statLifeMax < Config.LifeCrystalMaxLife) // 如果玩家当前生命上限小于配置的最大水晶生命值
124+
{
125+
tsplayer.TPlayer.inventory[tplayer.selectedItem].stack--; // 减少玩家背包中选定物品的堆叠数量
126+
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem); // 更新客户端的选定物品槽位
127+
tplayer.statLifeMax += 20; // 增加玩家的生命上限
128+
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
129+
}
130+
else if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife) // 如果玩家当前生命上限大于配置的最大果生命值
131+
{
132+
tplayer.statLifeMax = Config.LifeFruitMaxLife; // 将玩家的生命上限设置为配置的最大生命果生命值
133+
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
139134
}
140135
}
141136
}

0 commit comments

Comments
 (0)