mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 14:34:52 +00:00
Make hazard radius and barrier duration accurate
- Hazards only checked who was inside once per damage interval, so the boundary where damage started and stopped drifted by however far an entity moved in between - several blocks at sprint speed. Membership is now checked every tick and damage accrues per entity from the time it actually spends inside. - Barriers counted elapsed ticks instead of holding a deadline, so every tick the entity missed extended it past its configured duration. They now expire on an absolute world time like the other energy entities.
This commit is contained in:
1 parent
7cafa4f677
commit
6477ede022
2 files changed
+36
-17
No files matched your search
@@ -23,8 +23,10 @@ import noppes.npcs.NpcDamageSource;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -170,8 +172,9 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
private transient Set<Integer> triggeredEntities = new HashSet<>();
|
||||
private transient int triggerFlashTick = -1;
|
||||
|
||||
private transient int ticksSinceDamage = 0;
|
||||
private transient Set<Integer> damagedThisTick = new HashSet<>();
|
||||
/** Ticks each entity has spent inside the zone since it was last damaged, by entity id. */
|
||||
private transient Map<Integer, Integer> ticksInZone = new HashMap<>();
|
||||
|
||||
private transient Ability sourceAbility = null;
|
||||
|
||||
@@ -216,7 +219,6 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
this.ownerEntityId = owner != null ? owner.getEntityId() : -1;
|
||||
double groundY = Ability.findGroundLevel(worldObj, x, y, z) + GROUND_OFFSET;
|
||||
this.setPosition(x, groundY, z);
|
||||
this.ticksSinceDamage = damageInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +311,6 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
zone.effects.add(e.copy());
|
||||
}
|
||||
}
|
||||
zone.ticksSinceDamage = damageInterval;
|
||||
return zone;
|
||||
}
|
||||
|
||||
@@ -495,13 +496,10 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
|
||||
private void tickHazard() {
|
||||
damagedThisTick.clear();
|
||||
ticksSinceDamage++;
|
||||
|
||||
if (ticksSinceDamage < damageInterval) {
|
||||
return;
|
||||
}
|
||||
ticksSinceDamage = 0;
|
||||
|
||||
// Membership is checked every tick, not once per damage interval. Sampling on the
|
||||
// interval alone made the effective boundary drift by however far an entity moved in
|
||||
// between, which on a large radius reads as the radius itself being wrong.
|
||||
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - radius, posY - 0.5, posZ - radius,
|
||||
posX + radius, posY + zoneHeight, posZ + radius
|
||||
@@ -511,19 +509,35 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox);
|
||||
|
||||
Set<Integer> insideThisTick = new HashSet<>();
|
||||
for (EntityLivingBase entity : entities) {
|
||||
if (owner != null && entity == owner && !affectsCaster) continue;
|
||||
if (damagedThisTick.contains(entity.getEntityId())) continue;
|
||||
if (entity != owner && owner instanceof EntityLivingBase && !AbilityTargetHelper.shouldAffect((EntityLivingBase) owner, entity, TargetFilter.ENEMIES, false)) continue;
|
||||
if (!isInZone(entity)) continue;
|
||||
|
||||
int entityId = entity.getEntityId();
|
||||
insideThisTick.add(entityId);
|
||||
|
||||
// Entities that just entered are hit immediately, then once per interval of time
|
||||
// actually spent inside.
|
||||
Integer elapsed = ticksInZone.get(entityId);
|
||||
int ticks = elapsed == null ? damageInterval : elapsed + 1;
|
||||
if (ticks < damageInterval) {
|
||||
ticksInZone.put(entityId, ticks);
|
||||
continue;
|
||||
}
|
||||
ticksInZone.put(entityId, 0);
|
||||
|
||||
if (damagePerSecond > 0) {
|
||||
applyDamage(entity, owner, damagePerSecond);
|
||||
}
|
||||
|
||||
applyEffects(entity);
|
||||
damagedThisTick.add(entity.getEntityId());
|
||||
damagedThisTick.add(entityId);
|
||||
}
|
||||
|
||||
ticksInZone.keySet().retainAll(insideThisTick);
|
||||
}
|
||||
|
||||
private boolean isInZone(EntityLivingBase entity) {
|
||||
|
||||
Reference in new issue
Block a user