Skip to content

Commit

Permalink
修复一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
THEXN committed Mar 3, 2024
2 parents 3b4c4e4 + 356cfd4 commit 061e801
Showing 1 changed file with 34 additions and 39 deletions.
73 changes: 34 additions & 39 deletions LifemaxExtra/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class LifemaxExtra : TerrariaPlugin
public override string Author => "佚名,肝帝熙恩添加自定义";
public override string Description => "提升生命值上限";
public override string Name => "LifemaxExtra";
public override Version Version => new Version(1, 0, 0, 4);
public override Version Version => new Version(1, 0, 0, 5);
public static Configuration Config;
private bool[] controlUseItemOld;
private int[] itemUseTime;
Expand All @@ -27,7 +27,12 @@ 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(LifemaxExtra).Name);
}

public override void Initialize()
Expand All @@ -48,12 +53,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

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

private void OnPlayerPostLogin(PlayerPostLoginEventArgs args)
{
foreach (TSPlayer tsplayer in TShock.Players)
Expand Down Expand Up @@ -90,52 +89,48 @@ private void OnUpdate(EventArgs args)
int index = tsplayer.Index;
Player tplayer = tsplayer.TPlayer;
Item heldItem = tplayer.HeldItem;

if (!this.controlUseItemOld[index] && tsplayer.TPlayer.controlUseItem && this.itemUseTime[index] <= 0)
{
int useTime = heldItem.useTime;
int type = heldItem.type;
int useTime = heldItem.useTime; // 获取物品使用时间
int type = heldItem.type; // 获取物品类型

if (type != 29)
if (type != 29) // 如果物品不是 ID 为 29 的物品
{
if (type == 1291)
if (type == 1291) // 如果物品是 ID 为 1291 的物品(Life Fruit)
{
if (tplayer.statLifeMax >= Config.LifeCrystalMaxLife)
if (tplayer.statLifeMax >= Config.LifeCrystalMaxLife) // 如果玩家的生命上限大于等于配置的最大水晶生命值
{
if(tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife)
if (tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife) // 如果玩家当前生命上限小于配置的最大果实生命值
{
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
tplayer.statLifeMax += 5;
tsplayer.SendData(PacketTypes.PlayerHp, "", index);

tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--; // 减少玩家背包中选定物品的堆叠数量
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem); // 更新客户端的选定物品槽位
tplayer.statLifeMax += 5; // 增加玩家的生命上限
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
}
if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife)
else if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife) // 如果玩家当前生命上限大于配置的最大果实生命值
{
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
tplayer.statLifeMax = Config.LifeFruitMaxLife;
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
}
tplayer.statLifeMax = Config.LifeFruitMaxLife; // 将玩家的生命上限设置为配置的最大果实生命值
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
}
}
}
}
else
else // 如果物品是 ID 为 29 的物品(Life Crystal)
{
if (tplayer.statLifeMax >= 400)
{
if(tsplayer.TPlayer.statLifeMax < Config.LifeCrystalMaxLife)
if (tplayer.statLifeMax <= Config.LifeCrystalMaxLife) // 如果玩家的生命上限小于等于最大水晶生命值
{
tsplayer.TPlayer.inventory[tplayer.selectedItem].stack--;
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
tplayer.statLifeMax += 20;
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
}
else if(tsplayer.TPlayer.statLifeMax > Config.LifeCrystalMaxLife && tsplayer.TPlayer.statLifeMax < Config.LifeFruitMaxLife)
{
tsplayer.TPlayer.inventory[tsplayer.TPlayer.selectedItem].stack--;
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem);
tplayer.statLifeMax = Config.LifeCrystalMaxLife;
tsplayer.SendData(PacketTypes.PlayerHp, "", index);
if (tsplayer.TPlayer.statLifeMax < Config.LifeCrystalMaxLife) // 如果玩家当前生命上限小于配置的最大水晶生命值
{
tsplayer.TPlayer.inventory[tplayer.selectedItem].stack--; // 减少玩家背包中选定物品的堆叠数量
tsplayer.SendData(PacketTypes.PlayerSlot, "", index, (float)tplayer.selectedItem); // 更新客户端的选定物品槽位
tplayer.statLifeMax += 20; // 增加玩家的生命上限
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
}
else if (tsplayer.TPlayer.statLifeMax > Config.LifeFruitMaxLife) // 如果玩家当前生命上限大于配置的最大果生命值
{
tplayer.statLifeMax = Config.LifeFruitMaxLife; // 将玩家的生命上限设置为配置的最大生命果生命值
tsplayer.SendData(PacketTypes.PlayerHp, "", index); // 更新客户端的生命值显示
}
}
}
Expand Down

0 comments on commit 061e801

Please sign in to comment.