use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class ControlCapture 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 MapValue<String, Integer> activeControls = GuardianMapValue.builder(ControlCapture.ACTIVE_CONTROL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
activeControls.put(FLY, 0);
activeControls.put(WALK, 0);
activeControls.put(SNEAK, 0);
activeControls.put(SPRINT, 0);
captureContainer.offerIfEmpty(activeControls);
captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.HORIZONTAL_DISTANCE).defaultElement(1d).element(1d).create());
captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.VERTICAL_DISTANCE).defaultElement(1d).element(1d).create());
double walkSpeedData = player.get(Keys.WALKING_SPEED).orElse(1d) * 10;
double flySpeedData = player.get(Keys.FLYING_SPEED).orElse(0.5) * 10;
if (player.getLocation().getY() != captureContainer.get(GuardianSequence.INITIAL_LOCATION).get().getY()) {
captureContainer.getValue(ControlCapture.VERTICAL_DISTANCE).ifPresent(value -> value.transform(original -> original * this.liftOffset));
}
if ((player.get(Keys.IS_FLYING).isPresent() && player.get(Keys.IS_FLYING).get())) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.flyOffset * flySpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(FLY, value.get().get(FLY) + 1));
} else if (player.get(Keys.IS_SPRINTING).isPresent() && player.get(Keys.IS_SPRINTING).get()) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sprintOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SPRINT, value.get().get(SPRINT) + 1));
} else if (player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sneakOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SNEAK, value.get().get(SNEAK) + 1));
} else {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.walkOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(WALK, value.get().get(WALK) + 1));
}
}
use of com.ichorpowered.guardianapi.entry.entity.PlayerEntry in project guardian by ichorpowered.
the class GuardianSequence method applySchedule.
@Override
public final void applySchedule(final SequenceContext sequenceContext) {
final PlayerEntry playerEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Player player = playerEntry.getEntity(Player.class).orElse(Sponge.getServer().getPlayer(playerEntry.getUniqueId()).orElse(null));
if (player == null)
return;
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());
}
super.applySchedule(mergedContext);
}
Aggregations