@occultus/toolkit 0.23.1 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -173,7 +173,7 @@ export function clearEffect(
|
|
|
173
173
|
* 状态效果持续时间,以刻为单位 *(20刻 = 1秒)*
|
|
174
174
|
*
|
|
175
175
|
* 其值必须在范围`[0, 20000000]`内
|
|
176
|
-
*
|
|
176
|
+
*
|
|
177
177
|
* 如果值为`"infinite"`,则状态效果将无限期持续
|
|
178
178
|
* @param options 状态效果选项
|
|
179
179
|
* @since Starock 0.6.0 (0.1.0)
|
|
@@ -304,3 +304,63 @@ export function heal(entity: Entity, amount: number): number {
|
|
|
304
304
|
} else health.setCurrentValue(newHealth);
|
|
305
305
|
return newHealth;
|
|
306
306
|
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 获取实体当前生命值
|
|
310
|
+
* @param entity 要获取生命值的实体
|
|
311
|
+
* @returns
|
|
312
|
+
*/
|
|
313
|
+
export function getCurrentHealth(entity: Entity): number {
|
|
314
|
+
const health = entity.getComponent("minecraft:health");
|
|
315
|
+
if (!health)
|
|
316
|
+
throw new OccultusSDKError("The entity does not have health component!");
|
|
317
|
+
return health.currentValue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 设置实体当前生命值
|
|
322
|
+
* @param entity 要设置生命值的实体
|
|
323
|
+
* @param value 要设置的生命值,若超出实体最大生命值,则重置为最大生命值
|
|
324
|
+
* @returns
|
|
325
|
+
*/
|
|
326
|
+
export function setCurrentHealth(entity: Entity, value: number): number {
|
|
327
|
+
const health = entity.getComponent("minecraft:health");
|
|
328
|
+
if (!health)
|
|
329
|
+
throw new OccultusSDKError("The entity does not have health component!");
|
|
330
|
+
if(value > health.effectiveMax) {
|
|
331
|
+
health.resetToMaxValue();
|
|
332
|
+
return health.effectiveMax;
|
|
333
|
+
}
|
|
334
|
+
health.setCurrentValue(value);
|
|
335
|
+
return value;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 消耗实体生命值,这一行为不会被视为攻击
|
|
340
|
+
* @param entity
|
|
341
|
+
* @param amount
|
|
342
|
+
* @returns
|
|
343
|
+
*/
|
|
344
|
+
export function consumeHealth(entity: Entity, amount: number): number {
|
|
345
|
+
const newHealth = getCurrentHealth(entity) - amount;
|
|
346
|
+
if(newHealth <= 0) {
|
|
347
|
+
entity.kill();
|
|
348
|
+
return 0;
|
|
349
|
+
}
|
|
350
|
+
return setCurrentHealth(entity, getCurrentHealth(entity) - amount);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 以指定倍率消耗实体的生命值,这一行为不会被视为攻击
|
|
355
|
+
* @param entity
|
|
356
|
+
* @param amplifier 消耗生命的倍率,例如`0.8`将会被视为消耗实体当前 80% 的生命值
|
|
357
|
+
* @returns
|
|
358
|
+
*/
|
|
359
|
+
export function consumeHealthAmplifier(entity: Entity, amplifier: number): number {
|
|
360
|
+
const newHealth = getCurrentHealth(entity) - (getCurrentHealth(entity) * amplifier);
|
|
361
|
+
if(newHealth <= 0) {
|
|
362
|
+
entity.kill();
|
|
363
|
+
return 0;
|
|
364
|
+
}
|
|
365
|
+
return setCurrentHealth(entity, newHealth);
|
|
366
|
+
}
|