Search in sources :

Example 6 with PlayerEntry

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));
    }
}
Also used : GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) TypeToken(com.google.common.reflect.TypeToken) Maps(com.google.common.collect.Maps) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) Detection(com.ichorpowered.guardianapi.detection.Detection) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) MapValue(com.ichorpowered.guardianapi.util.item.value.mutable.MapValue) Map(java.util.Map) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) Player(org.spongepowered.api.entity.living.player.Player) Nonnull(javax.annotation.Nonnull) Player(org.spongepowered.api.entity.living.player.Player)

Example 7 with PlayerEntry

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);
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) SequenceContext(com.abilityapi.sequenceapi.SequenceContext)

Aggregations

PlayerEntry (com.ichorpowered.guardianapi.entry.entity.PlayerEntry)7 Player (org.spongepowered.api.entity.living.player.Player)7 TypeToken (com.google.common.reflect.TypeToken)4 GuardianSequence (com.ichorpowered.guardian.sequence.GuardianSequence)4 AbstractCapture (com.ichorpowered.guardian.sequence.capture.AbstractCapture)4 GuardianCaptureKey (com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey)4 GuardianValue (com.ichorpowered.guardian.util.item.mutable.GuardianValue)4 ContentKeys (com.ichorpowered.guardianapi.content.ContentKeys)4 Detection (com.ichorpowered.guardianapi.detection.Detection)4 CaptureContainer (com.ichorpowered.guardianapi.detection.capture.CaptureContainer)4 CaptureKey (com.ichorpowered.guardianapi.detection.capture.CaptureKey)4 Value (com.ichorpowered.guardianapi.util.item.value.mutable.Value)4 Nonnull (javax.annotation.Nonnull)4 Keys (org.spongepowered.api.data.key.Keys)4 SequenceContext (com.abilityapi.sequenceapi.SequenceContext)3 Maps (com.google.common.collect.Maps)3 GuardianMapValue (com.ichorpowered.guardian.util.item.mutable.GuardianMapValue)3 Map (java.util.Map)3 ContentUtil (com.ichorpowered.guardian.util.ContentUtil)2 WorldUtil (com.ichorpowered.guardian.util.WorldUtil)2