Ejemplo n.º 1
0
  @Override
  public void execute() {
    //		playerName = "";
    boolean isNPC = false;
    if ((playerName == "")) {
      playerName = ConfigBasis.NPC_0;
      isNPC = true;
    }
    Owner owner = rModel.getOwners().getOwnerName(playerName);
    if (owner == null) {
      Owner fOwner = rModel.getOwners().getOwner(0);
      if (fOwner == null) {
        owner = Owner.initDefaultOwner();
      } else {
        owner = fOwner;
      }
    }
    LocationData position;
    SuperRegion sRegion = rModel.getServer().getSuperRegion(superRegionName);
    if (sRegion == null) {
      System.out.println("[REALMS]  SuperRegion not found on create settlement !");
      return;
    }
    sRegion.setBalance(10000.0);
    position =
        new LocationData(
            sRegion.getLocation().getWorld().getName(),
            sRegion.getLocation().getX(),
            sRegion.getLocation().getY(),
            sRegion.getLocation().getZ());

    Settlement settlement =
        new Settlement(
            owner.getId(), position, settleType, superRegionName, biome); // , rModel.getLogList());
    rModel.getSettlements().addSettlement(settlement);
    //		System.out.println(superRegionName+" : "+settlement.getId());
    for (Region region : rModel.getServer().getRegionInSuperRegion(superRegionName)) {
      int regionId = region.getID();
      String hsRegionType = region.getType();
      BuildPlanType buildingType = rModel.getConfig().regionToBuildingType(hsRegionType);
      //			Building building = new Building(
      //					buildingType,
      //					hsRegion,
      //					new LocationData(
      //					region.getLocation().getWorld().getName(),
      //					region.getLocation().getX(),
      //					region.getLocation().getY(),
      //					region.getLocation().getZ()),
      //					settlement.getId()
      //					);
      //			rModel.getBuildings().addBuilding(building);
      //			rModel.getData().writeBuilding(building);
      if ((BuildPlanType.getBuildGroup(buildingType) < 900)
          && (BuildPlanType.getBuildGroup(buildingType) >= 10)) {
        if (rModel.getData().getBuildings().containRegion(regionId) == false) {
          Building building =
              new Building(
                  buildingType,
                  regionId,
                  new LocationData(
                      region.getLocation().getWorld().getName(),
                      region.getLocation().getX(),
                      region.getLocation().getY(),
                      region.getLocation().getZ()),
                  settlement.getId(),
                  0);
          rModel.getBuildings().addBuilding(building);
          rModel.getData().writeBuilding(building);
          System.out.println(
              "[REALMS] Modell Settle "
                  + building.getBuildingType()
                  + ":"
                  + building.getId()
                  + ":"
                  + building.getHsRegion());
        } else {
          Building building = rModel.getData().getBuildings().getBuildingByRegion(regionId);
          if ((building.getSettleId() == 0) && (building.getLehenId() == 0)) {
            building.setSettleId(settlement.getId());
            rModel.getData().writeBuilding(building);
            System.out.println(
                "[REALMS] Model Settle "
                    + building.getBuildingType()
                    + ":"
                    + building.getId()
                    + ":"
                    + building.getHsRegion());
          }
        }
      } else {
        System.out.println(
            "[REALMS] Model Settle wrong Building Group"
                + BuildPlanType.getBuildGroup(buildingType));
      }
    }
    // make not dynamic initialization

    settlement.setBuildingList(rModel.getBuildings().getSubList(settlement.getId()));
    settlement.initSettlement(rModel.getData().getPriceList());

    // minimum settler on create
    settlement.getResident().setSettlerCount(settlement.getResident().getSettlerMax() / 2);

    settlement
        .getWarehouse()
        .depositItemValue("WHEAT", settlement.getResident().getSettlerMax() * 2);
    settlement
        .getWarehouse()
        .depositItemValue("BREAD", settlement.getResident().getSettlerMax() * 2);
    settlement
        .getWarehouse()
        .depositItemValue("WOOD_HOE", settlement.getResident().getSettlerMax());
    settlement
        .getWarehouse()
        .depositItemValue("WOOD_AXE", settlement.getResident().getSettlerMax());
    settlement
        .getWarehouse()
        .depositItemValue("WOOD_PICKAXE", settlement.getResident().getSettlerMax());
    settlement.getWarehouse().depositItemValue("LOG", settlement.getResident().getSettlerMax());
    settlement.getWarehouse().depositItemValue("WOOD", settlement.getResident().getSettlerMax());
    settlement.getWarehouse().depositItemValue("STICK", settlement.getResident().getSettlerMax());
    settlement
        .getWarehouse()
        .depositItemValue("COBBLESTONE", settlement.getResident().getSettlerMax());
    settlement.getWarehouse().depositItemValue("SOIL", 64);
    settlement.getWarehouse().depositItemValue("WATER", settlement.getResident().getSettlerMax());
    settlement
        .getBank()
        .depositKonto(
            (double) (settlement.getResident().getSettlerCount() * 10),
            "CREATE",
            settlement.getId());
    System.out.println(
        "[REALMS] Model Write Settlement: "
            + settlement.getName()
            + " Activ:"
            + settlement.isActive()
            + " Enable:"
            + settlement.isEnabled());
    rModel.getData().writeSettlement(settlement);
  }
Ejemplo n.º 2
0
  public Settlement readSettledata(int id) {
    String path = "\\GIT\\OwnPlugins\\Realms\\plugins"; // \\Realms";
    LogList logTest = new LogList(path);
    Settlement settle = new Settlement(); // logTest);
    String settleSec = getSettleKey(id);
    try {
      File settleFile = new File("\\Program Files\\BuckitTest\\plugins\\Realms", "settlement.yml");
      if (!settleFile.exists()) {
        System.out.println("New File");
        settleFile.createNewFile();
      }
      FileConfiguration config = new YamlConfiguration();
      config.load(settleFile);
      System.out.println("Load File");

      if (config.isConfigurationSection(settleSec)) {
        settle.setId(config.getInt(settleSec + ".id"));
        settle.setSettleType(SettleType.valueOf(config.getString(settleSec + ".settleType")));
        // settle.setposition()
        settle.setName(config.getString(settleSec + ".name"));
        settle.setOwner(null);
        settle.setIsCapital(config.getBoolean(settleSec + ".isCapital"));
        settle.setIsActive(config.getBoolean(settleSec + ".isActive"));

        // die werte werden als String gelesen, da verschiedene Datentypen im array sind
        settle
            .getTownhall()
            .setIsEnabled(Boolean.valueOf(config.getString(settleSec + ".townhall" + ".isEnable")));
        settle
            .getTownhall()
            .setWorkerNeeded(
                Integer.valueOf(config.getString(settleSec + ".townhall" + ".workerNeeded")));
        settle
            .getTownhall()
            .setWorkerCount(
                Integer.valueOf(config.getString(settleSec + ".townhall" + ".workerCount")));

        // die werte werden als String gelesen, da verschiedene Datentypen im array sind
        settle
            .getResident()
            .setSettlerMax(
                Integer.valueOf(config.getString(settleSec + ".resident" + ".settlerMax")));
        settle
            .getResident()
            .setSettlerCount(
                Integer.valueOf(config.getString(settleSec + ".resident" + ".settlerCount")));
        settle
            .getResident()
            .setFeritilityCounter(
                Double.valueOf(config.getString(settleSec + ".resident" + ".fertilityCounter")));
        //
        //	settle.getResident().setHappiness(Double.valueOf(config.getString(settleSec+".resident"+".happiness")));
        settle
            .getResident()
            .setCowCount(Integer.valueOf(config.getString(settleSec + ".resident" + ".cowCount")));
        settle
            .getResident()
            .setHorseCount(
                Integer.valueOf(config.getString(settleSec + ".resident" + ".horseCount")));

        System.out.println("================================");
        System.out.println("== SETTLEMENT read from File ===");
        System.out.println(settle.getId());
        System.out.println(settle.getName());
        System.out.println(settle.getSettleType());
        System.out.println(settle.getResident().getSettlerMax());
        System.out.println(settle.getResident().getSettlerCount());
        System.out.println(settle.getResident().getHappiness());
        System.out.println(settle.getTownhall().getWorkerCount());
        System.out.println(settle.getTownhall().getWorkerNeeded());

        //            	System.out.println("Part 4
        // "+config.getConfigurationSection(settleSec+".buildinglist").getValues(false));
        ArrayList<String> msg = new ArrayList<String>();

        Map<String, Object> buildings =
            config.getConfigurationSection(settleSec + ".buildinglist").getValues(false);
        for (String ref : buildings.keySet()) {
          System.out.println("Part 5 " + ref);

          int buildingId =
              Integer.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".id"));
          BuildPlanType bType =
              BuildPlanType.getBuildPlanType(
                  config.getString(settleSec + ".buildinglist." + ref + ".buildingType"));
          int settler =
              Integer.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".settler"));
          int workerNeeded =
              Integer.valueOf(
                  config.getString(settleSec + ".buildinglist." + ref + ".workerNeeded"));
          int workerInstalled =
              Integer.valueOf(
                  config.getString(settleSec + ".buildinglist." + ref + ".workerInstalled"));
          Boolean isRegion =
              Boolean.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".isRegion"));
          int hsRegion =
              Integer.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".hsRegion"));
          String hsRegionType =
              config.getString(settleSec + ".buildinglist." + ref + ".hsRegionType");
          String hsSuperRegion =
              config.getString(settleSec + ".buildinglist." + ref + ".hsSuperRegion");
          Boolean isEnabled =
              Boolean.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".isEnabled"));
          boolean isActiv =
              Boolean.valueOf(config.getString(settleSec + ".buildinglist." + ref + ".isActiv"));
          String slot1 = config.getString(settleSec + ".buildinglist." + ref + ".slot1", "");
          //        			String slot2 = config.getString(settleSec+".buildinglist."+ref+".slot2","");
          //        			String slot3 = config.getString(settleSec+".buildinglist."+ref+".slot3","");
          //        			String slot4 = config.getString(settleSec+".buildinglist."+ref+".slot4","");
          //        			String slot5 = config.getString(settleSec+".buildinglist."+ref+".slot5","");
          // debug messages
          msg.add("== Building read from File ===" + buildings.size());
          msg.add("id   = " + buildingId);
          msg.add("Type = " + bType);
          msg.add("Settler = " + settler);
          msg.add("Need    = " + workerNeeded);
          msg.add("Install = " + workerInstalled);
          msg.add("isRegion= " + isRegion);
          msg.add("hsRegion= " + hsRegion);
          msg.add("Reg.Type= " + hsRegionType);
          msg.add("SuperReg= " + hsSuperRegion);
          msg.add("Enabled = " + isEnabled);
          msg.add("Active  = " + isActiv);
          msg.add("Slot1   = " + slot1);
          //        			msg.add("===================");

          for (String line : msg) {
            System.out.println(line);
          }
        }
      }
    } catch (Exception e) {
      // TODO: handle exception

    }
    return settle;
  }