Search in sources :

Example 1 with MapValue

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

Example 2 with MapValue

use of com.ichorpowered.guardianapi.util.item.value.mutable.MapValue 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)

Aggregations

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