@@ -11,7 +11,7 @@ public class LifemaxExtra : TerrariaPlugin
11
11
public override string Author => "佚名,肝帝熙恩添加自定义" ;
12
12
public override string Description => "提升生命值上限" ;
13
13
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 ) ;
15
15
public static Configuration Config ;
16
16
private bool [ ] controlUseItemOld ;
17
17
private int [ ] itemUseTime ;
@@ -27,7 +27,12 @@ private static void LoadConfig()
27
27
{
28
28
Config = Configuration . Read ( Configuration . FilePath ) ;
29
29
Config . Write ( Configuration . FilePath ) ;
30
+ }
30
31
32
+ private static void ReloadConfig ( ReloadEventArgs args )
33
+ {
34
+ LoadConfig ( ) ;
35
+ args . Player ? . SendSuccessMessage ( "[{0}] 重新加载配置完毕。" , typeof ( LifemaxExtra ) . Name ) ;
31
36
}
32
37
33
38
public override void Initialize ( )
@@ -48,12 +53,6 @@ protected override void Dispose(bool disposing)
48
53
base . Dispose ( disposing ) ;
49
54
}
50
55
51
- private static void ReloadConfig ( ReloadEventArgs args )
52
- {
53
- LoadConfig ( ) ;
54
- args . Player ? . SendSuccessMessage ( "[{0}] 重新加载配置完毕。" , typeof ( LifemaxExtra ) . Name ) ;
55
- }
56
-
57
56
private void OnPlayerPostLogin ( PlayerPostLoginEventArgs args )
58
57
{
59
58
foreach ( TSPlayer tsplayer in TShock . Players )
@@ -90,52 +89,48 @@ private void OnUpdate(EventArgs args)
90
89
int index = tsplayer . Index ;
91
90
Player tplayer = tsplayer . TPlayer ;
92
91
Item heldItem = tplayer . HeldItem ;
92
+
93
93
if ( ! this . controlUseItemOld [ index ] && tsplayer . TPlayer . controlUseItem && this . itemUseTime [ index ] <= 0 )
94
94
{
95
- int useTime = heldItem . useTime ;
96
- int type = heldItem . type ;
95
+ int useTime = heldItem . useTime ; // 获取物品使用时间
96
+ int type = heldItem . type ; // 获取物品类型
97
97
98
- if ( type != 29 )
98
+ if ( type != 29 ) // 如果物品不是 ID 为 29 的物品
99
99
{
100
- if ( type == 1291 )
100
+ if ( type == 1291 ) // 如果物品是 ID 为 1291 的物品(Life Fruit)
101
101
{
102
- if ( tplayer . statLifeMax >= Config . LifeCrystalMaxLife )
102
+ if ( tplayer . statLifeMax >= Config . LifeCrystalMaxLife ) // 如果玩家的生命上限大于等于配置的最大水晶生命值
103
103
{
104
- if ( tsplayer . TPlayer . statLifeMax < Config . LifeFruitMaxLife )
104
+ if ( tsplayer . TPlayer . statLifeMax < Config . LifeFruitMaxLife ) // 如果玩家当前生命上限小于配置的最大果实生命值
105
105
{
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 ) ; // 更新客户端的生命值显示
111
110
}
112
- if ( tsplayer . TPlayer . statLifeMax > Config . LifeFruitMaxLife )
111
+ else if ( tsplayer . TPlayer . statLifeMax > Config . LifeFruitMaxLife ) // 如果玩家当前生命上限大于配置的最大果实生命值
113
112
{
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
+ }
119
116
}
120
117
}
121
118
}
122
- else
119
+ else // 如果物品是 ID 为 29 的物品(Life Crystal)
123
120
{
124
- if ( tplayer . statLifeMax >= 400 )
125
- {
126
- if ( tsplayer . TPlayer . statLifeMax < Config . LifeCrystalMaxLife )
121
+ if ( tplayer . statLifeMax <= Config . LifeCrystalMaxLife ) // 如果玩家的生命上限小于等于最大水晶生命值
127
122
{
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 ) ; // 更新客户端的生命值显示
139
134
}
140
135
}
141
136
}
0 commit comments