mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-16 14:42:53 +08:00
fixed gadget hp properties and invincibility handling (#1773)
* fixed gadget hp properties and invincibility handling * Allow killing of hp locked entities, if the damage is higher then the hp Co-authored-by: hartie95 <mail@hartie95.de>
This commit is contained in:
committed by
GitHub
Unverified
parent
21ff749dca
commit
08fdcf6ed4
@@ -37,6 +37,8 @@ public abstract class GameEntity {
|
||||
@Getter @Setter private int lastMoveSceneTimeMs;
|
||||
@Getter @Setter private int lastMoveReliableSeq;
|
||||
|
||||
@Getter @Setter private boolean lockHP;
|
||||
|
||||
// Abilities
|
||||
private Object2FloatMap<String> metaOverrideMap;
|
||||
private Int2ObjectMap<String> metaModifiers;
|
||||
@@ -106,6 +108,10 @@ public abstract class GameEntity {
|
||||
return this.getFightProperties().getOrDefault(prop.getId(), 0f);
|
||||
}
|
||||
|
||||
public boolean hasFightProperty(FightProperty prop) {
|
||||
return this.getFightProperties().containsKey(prop.getId());
|
||||
}
|
||||
|
||||
public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) {
|
||||
for (Int2FloatMap.Entry entry : this.getFightProperties().int2FloatEntrySet()) {
|
||||
if (entry.getIntKey() == 0) {
|
||||
@@ -153,7 +159,7 @@ public abstract class GameEntity {
|
||||
|
||||
public void damage(float amount, int killerId) {
|
||||
// Check if the entity has properties.
|
||||
if (this.getFightProperties() == null) {
|
||||
if (this.getFightProperties() == null || !hasFightProperty(FightProperty.FIGHT_PROP_CUR_HP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,9 +170,10 @@ public abstract class GameEntity {
|
||||
return; // If the event is canceled, do not damage the entity.
|
||||
}
|
||||
|
||||
if (getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) != Float.POSITIVE_INFINITY) {
|
||||
// Add negative HP to the current HP property.
|
||||
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -(event.getDamage()));
|
||||
float curHp = getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
||||
if (curHp != Float.POSITIVE_INFINITY && !lockHP || lockHP && curHp <= event.getDamage()) {
|
||||
// Add negative HP to the current HP property.
|
||||
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -(event.getDamage()));
|
||||
}
|
||||
|
||||
// Check if dead
|
||||
|
||||
Reference in New Issue
Block a user