コード例 #1
0
ファイル: SimulateBatch.java プロジェクト: S-Toad/MagicPlugin
  protected void die() {
    String message = spell.getMessage("death_broadcast").replace("$name", commandName);
    if (message.length() > 0) {
      controller.sendToMages(message, center);
    }

    // Kill power block
    if (castCommandBlock == null) {
      castCommandBlock = center.getBlock();
    }

    for (BlockFace powerFace : POWER_FACES) {
      Block checkForPower = castCommandBlock.getRelative(powerFace);
      if (commandReload) {
        controller.unregisterAutomata(checkForPower);
      }
      if (checkForPower.getType() == POWER_MATERIAL) {
        BlockData commitBlock = UndoList.register(checkForPower);
        commitBlock.setMaterial(Material.AIR);
        commitBlock.modify(checkForPower);
        commitBlock.commit();
      } else {
        BlockData commitBlock = UndoList.getBlockData(checkForPower.getLocation());
        if (commitBlock != null) {
          commitBlock.setMaterial(Material.AIR);
        }
      }
    }

    // Drop item
    if (dropItem != null && dropItem.length() > 0) {
      Wand magicItem = controller.createWand(dropItem);
      if (magicItem != null) {
        center.getWorld().dropItemNaturally(center, magicItem.getItem());
      }
    }

    // Drop Xp
    if (dropXp > 0) {
      Entity entity = center.getWorld().spawnEntity(center, EntityType.EXPERIENCE_ORB);
      if (entity != null && entity instanceof ExperienceOrb) {
        ExperienceOrb orb = (ExperienceOrb) entity;
        orb.setExperience(dropXp);
      }
    }
    if (includeCommands && castCommandBlock != null) {
      BlockData commitBlock = UndoList.register(castCommandBlock);
      commitBlock.setMaterial(Material.AIR);
      commitBlock.modify(castCommandBlock);
      commitBlock.commit();
    }

    if (level != null) {
      level.onDeath(mage, birthMaterial);
    }
    if (!mage.isPlayer()) {
      controller.removeMage(mage);
    }
  }
コード例 #2
0
ファイル: SimulateBatch.java プロジェクト: S-Toad/MagicPlugin
 public void setLevel(AutomatonLevel level) {
   this.level = level;
   this.commandMoveRangeSquared = level.getMoveRangeSquared(commandMoveRangeSquared);
   this.dropXp = level.getDropXp(dropXp);
   this.liveRangeSquared = level.getLiveRangeSquared(liveRangeSquared);
   this.birthRangeSquared = level.getBirthRangeSquared(birthRangeSquared);
   this.radius = level.getRadius(radius);
   this.yRadius = level.getYRadius(yRadius);
 }
コード例 #3
0
ファイル: SimulateBatch.java プロジェクト: S-Toad/MagicPlugin
  public void target(TargetMode mode) {
    targetMode = mode == null ? TargetMode.STABILIZE : mode;
    switch (targetMode) {
      case FLEE:
      case HUNT:
      case DIRECTED:
        Target bestTarget = null;
        reverseTargetDistanceScore = true;
        if (targetType == TargetType.ANY || targetType == TargetType.MOB) {
          List<Entity> entities =
              CompatibilityUtils.getNearbyEntities(
                  center, huntMaxRange, huntMaxRange, huntMaxRange);
          for (Entity entity : entities) {
            // We'll get the players from the Mages list
            if (entity instanceof Player || !(entity instanceof LivingEntity) || entity.isDead())
              continue;
            if (!entity.getLocation().getWorld().equals(center.getWorld())) continue;
            LivingEntity li = (LivingEntity) entity;
            if (li.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            Target newScore =
                new Target(center, entity, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }
        if (targetType == TargetType.MAGE
            || targetType == TargetType.AUTOMATON
            || targetType == TargetType.ANY
            || targetType == TargetType.PLAYER) {
          Collection<Mage> mages = controller.getMages();
          for (Mage mage : mages) {
            if (mage == this.mage) continue;
            if (targetType == TargetType.AUTOMATON && mage.getPlayer() != null) continue;
            if (targetType == TargetType.PLAYER && mage.getPlayer() == null) continue;
            if (mage.isDead() || !mage.isOnline() || !mage.hasLocation()) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;

            if (!mage.isPlayer()) {
              // Check for automata of the same type, kinda hacky.. ?
              Block block = mage.getLocation().getBlock();
              if (block.getType() == Material.COMMAND) {
                BlockState blockState = block.getState();
                if (blockState != null && blockState instanceof CommandBlock) {
                  CommandBlock command = (CommandBlock) blockState;
                  String commandString = command.getCommand();
                  if (commandString != null
                      && commandString.length() > 0
                      && commandString.startsWith("cast " + spell.getKey())) {
                    continue;
                  }
                }
              }
            } else {
              Player player = mage.getPlayer();
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            }

            Target newScore = new Target(center, mage, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }

        if (bestTarget != null) {
          String targetDescription =
              bestTarget.getEntity() == null
                  ? "NONE"
                  : ((bestTarget instanceof Player)
                      ? ((Player) bestTarget.getEntity()).getName()
                      : bestTarget.getEntity().getType().name());

          if (DEBUG) {
            controller
                .getLogger()
                .info(
                    " *Tracking "
                        + targetDescription
                        + " score: "
                        + bestTarget.getScore()
                        + " location: "
                        + center
                        + " -> "
                        + bestTarget.getLocation()
                        + " move "
                        + commandMoveRangeSquared);
          }
          Vector direction = null;

          if (targetMode == TargetMode.DIRECTED) {
            direction = bestTarget.getLocation().getDirection();
            if (DEBUG) {
              controller.getLogger().info(" *Directed: " + direction);
            }
          } else {
            Location targetLocation = bestTarget.getLocation();
            direction = targetLocation.toVector().subtract(center.toVector());
          }

          if (direction != null) {
            center.setDirection(direction);
          }

          // Check for obstruction
          // TODO Think about this more..
          /*
          Block block = spell.getInteractBlock();
          if (block.getType() != Material.AIR && block.getType() != POWER_MATERIAL && !!birthMaterial.is(block)) {
          	// TODO: Use location.setDirection in 1.7+
          	center = CompatibilityUtils.setDirection(center, new Vector(0, 1, 0));
          }
          */

          if (level != null
              && center.distanceSquared(bestTarget.getLocation()) < castRange * castRange) {
            level.onTick(mage, birthMaterial);
          }

          // After ticking, re-position for movement. This way spells still fire towards the target.
          if (targetMode == TargetMode.FLEE) {
            direction = direction.multiply(-1);
            // Don't Flee upward
            if (direction.getY() > 0) {
              direction.setY(-direction.getY());
            }
          }
        }
        break;
      case GLIDE:
        reverseTargetDistanceScore = true;
        break;
      default:
        reverseTargetDistanceScore = false;
    }
  }