use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class PotionEffectCapture method update.
@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
final List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).orElse(Lists.newArrayList());
if (!potionEffects.isEmpty()) {
for (PotionEffect potionEffect : potionEffects) {
final String potionName = potionEffect.getType().getName().toLowerCase();
if (this.effectSpeed.containsKey(potionName)) {
final double effectValue = this.effectSpeed.get(potionName);
captureContainer.getValue(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
}
if (this.effectLift.containsKey(potionName)) {
final double effectValue = this.effectLift.get(potionName);
captureContainer.getValue(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
}
}
}
}
use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class MaterialCapture method update.
@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
final Location<World> location = player.getLocation();
final MapValue<String, Integer> activeMaterials = GuardianMapValue.builder(MaterialCapture.ACTIVE_MATERIAL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
activeMaterials.put(GAS, 0);
activeMaterials.put(LIQUID, 0);
activeMaterials.put(SOLID, 0);
captureContainer.offerIfEmpty(activeMaterials);
captureContainer.offerIfEmpty(GuardianValue.builder(MaterialCapture.SPEED_MODIFIER).defaultElement(1d).element(1d).create());
final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
if (!WorldUtil.containsBlocksUnder(location, playerBox, 1.25)) {
final double gasSpeed = this.matterSpeed.get(GAS);
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * gasSpeed));
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(GAS, value.get().get(GAS) + 1));
} else if (WorldUtil.anyLiquidAtDepth(location, playerBox, 1d) || WorldUtil.anyLiquidAtDepth(location, playerBox, 0) || WorldUtil.anyLiquidAtDepth(location, playerBox, isSneaking ? -(playerHeight - 0.25) : -playerHeight)) {
final double liquidSpeed = this.matterSpeed.get(LIQUID);
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * liquidSpeed));
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(LIQUID, value.get().get(LIQUID) + 1));
} else {
final List<BlockType> surroundingBlockTypes = WorldUtil.getBlocksUnder(location, playerBox, 1.25);
for (final BlockType blockType : surroundingBlockTypes) {
final double speedModifier = this.materialSpeed.getOrDefault(blockType.getName().toLowerCase(), this.matterSpeed.get(SOLID));
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * speedModifier));
}
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(SOLID, value.get().get(SOLID) + 1));
}
}
use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class GuardianSequence method applyObserve.
@Override
public boolean applyObserve(final Event event, final SequenceContext sequenceContext) {
final PlayerEntry entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Player player = entityEntry.getEntity(Player.class).orElse(Sponge.getServer().getPlayer(entityEntry.getUniqueId()).orElse(null));
if (player == null)
return false;
final SequenceContext mergedContext = SequenceContext.from(sequenceContext).custom(CommonContextKeys.LAST_ACTION_TIME, super.getLastActionTime()).custom(CommonContextKeys.CAPTURE_REGISTRY, this.captureRegistry).custom(CommonContextKeys.SUMMARY, this.summary).build();
if (this.getState().equals(State.INACTIVE)) {
this.captureRegistry.getContainer().offerIfEmpty(GuardianValue.builder(GuardianSequence.INITIAL_LOCATION).defaultElement(player.getLocation()).element(player.getLocation()).create());
}
return super.applyObserve(event, mergedContext);
}
use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class GuardianSequence method applyAfter.
@Override
public final Tristate applyAfter(SequenceContext sequenceContext) {
final PlayerEntry entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Player player = entityEntry.getEntity(Player.class).orElse(Sponge.getServer().getPlayer(entityEntry.getUniqueId()).orElse(null));
if (player == null)
return Tristate.FALSE;
final SequenceContext mergedContext = SequenceContext.from(sequenceContext).custom(CommonContextKeys.LAST_ACTION_TIME, super.getLastActionTime()).custom(CommonContextKeys.CAPTURE_REGISTRY, this.captureRegistry).custom(CommonContextKeys.SUMMARY, this.summary).build();
if (this.getState().equals(State.INACTIVE)) {
this.captureRegistry.getContainer().offerIfEmpty(GuardianValue.builder(GuardianSequence.INITIAL_LOCATION).defaultElement(player.getLocation()).element(player.getLocation()).create());
}
return super.applyAfter(mergedContext);
}
use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class AltitudeCapture method update.
@Override
public void update(PlayerEntry entry, CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
final Location location = player.getLocation();
Location relativeAltitude = null;
double blockDepthOffset = 0;
captureContainer.offerIfEmpty(GuardianValue.builder(AltitudeCapture.RELATIVE_ALTITUDE).defaultElement(1d).element(1d).create());
for (int n = 0; n < Math.abs(location.getY()); n++) {
double i = this.amount * n;
Optional<Location> maximumDepth = captureContainer.get(AltitudeCapture.INITIAL_DEPTH);
Location currentDepth = location.sub(0, i, 0);
if (!WorldUtil.isEmptyAtDepth(location, playerBox, i)) {
if (maximumDepth.isPresent() && maximumDepth.get().getY() == currentDepth.getY()) {
relativeAltitude = currentDepth.add(0, this.amount, 0);
blockDepthOffset = 1;
break;
} else if (maximumDepth.isPresent() && maximumDepth.get().getY() < currentDepth.getY()) {
relativeAltitude = currentDepth.add(0, this.amount, 0);
blockDepthOffset = (currentDepth.getY() - maximumDepth.get().getY()) > -1 ? -1 : currentDepth.getY() - maximumDepth.get().getY();
break;
} else if (maximumDepth.isPresent() && maximumDepth.get().getY() > currentDepth.getY()) {
relativeAltitude = currentDepth.add(0, this.amount, 0);
blockDepthOffset = (maximumDepth.get().getY() - currentDepth.getY()) < 1 ? 1 : maximumDepth.get().getY() - currentDepth.getY();
break;
} else if (!maximumDepth.isPresent()) {
captureContainer.offer(GuardianValue.builder(AltitudeCapture.INITIAL_DEPTH).defaultElement(currentDepth).element(currentDepth).create());
relativeAltitude = currentDepth.add(0, this.amount, 0);
break;
}
} else if ((currentDepth.getY() - 1) < 0) {
if (!maximumDepth.isPresent()) {
captureContainer.offer(GuardianValue.builder(AltitudeCapture.INITIAL_DEPTH).defaultElement(location.getExtent().getLocation(currentDepth.getX(), -256, currentDepth.getZ())).element(location.getExtent().getLocation(currentDepth.getX(), -256, currentDepth.getZ())).create());
}
if (maximumDepth.isPresent() && maximumDepth.get().getY() == currentDepth.getY()) {
relativeAltitude = currentDepth.add(0, this.amount, 0);
blockDepthOffset = -1;
break;
}
}
}
if (!captureContainer.get(AltitudeCapture.INITIAL_DEPTH).isPresent() || relativeAltitude == null) {
relativeAltitude = player.getLocation().setPosition(new Vector3d(player.getLocation().getX(), 0, player.getLocation().getZ()));
}
double relativeAltitudeOffset = (player.getLocation().getY() - relativeAltitude.getY()) - Math.abs(blockDepthOffset);
if (this.liftOnly && relativeAltitudeOffset < 0)
return;
final double offset = relativeAltitudeOffset;
captureContainer.getValue(AltitudeCapture.RELATIVE_ALTITUDE).ifPresent(value -> value.transform(original -> original + offset));
captureContainer.getValue(AltitudeCapture.LAST_ALTITUDE).ifPresent(value -> value.set(offset));
}
Aggregations