コード例 #1
0
ファイル: ServerArmorTemplate.java プロジェクト: bacta/swg
    @Override
    protected void load(final Iff iff) {
      iff.enterForm();
      iff.enterChunk();
      final int paramCount = iff.readInt();
      iff.exitChunk();
      for (int i = 0; i < paramCount; ++i) {
        iff.enterChunk();
        final String parameterName = iff.readString();

        if ("type".equalsIgnoreCase(parameterName)) {
          type.loadFromIff(objectTemplateList, iff);
        } else if ("effectiveness".equalsIgnoreCase(parameterName)) {
          effectiveness.loadFromIff(objectTemplateList, iff);
        } else {
          LOGGER.trace("Unexpected parameter {}", parameterName);
        }

        iff.exitChunk();
      }
      iff.exitForm();
    }
コード例 #2
0
ファイル: LoadoutEquipment.java プロジェクト: bacta/swg
/** Created by crush on 3/29/14. */
@Singleton
public class LoadoutEquipment implements SharedFileLoader {
  private final Logger logger = LoggerFactory.getLogger(getClass());

  private final Map<String, LoadoutEquipmentInfo> equipmentInfos = new HashMap<>();

  private static final int ID_LOEQ = Iff.createChunkId("LOEQ");
  private static final int ID_0000 = Iff.createChunkId("0000");
  private static final int ID_PTMP = Iff.createChunkId("PTMP");
  private static final int ID_NAME = Iff.createChunkId("NAME");
  private static final int ID_ITEM = Iff.createChunkId("ITEM");

  private final TreeFile treeFile;

  @Inject
  public LoadoutEquipment(final TreeFile treeFile) {
    this.treeFile = treeFile;
    load();
  }

  private void load() {
    logger.trace("Loading default loadout equipment.");

    logger.error("Not implemented.");

    // TODO: Replace with new Iff library.

    //        final ChunkReader chunkReader = new ChunkReader("player/default_pc_equipment.iff",
    // treeFile.open("player/default_pc_equipment.iff"));
    //
    //        ChunkBufferContext root = chunkReader.openChunk();
    //
    //        if (root == null || !root.isFormType(ID_LOEQ))
    //            throw new RuntimeException("Failed to load default loadout equipment. Not a LOEQ
    // file.");
    //
    //        root = chunkReader.nextChunk();
    //
    //        if (!root.isFormType(TAG_0000))
    //            throw new RuntimeException("Failed to load default loadout equipment. Wrong
    // version.");
    //
    //        while (root.hasMoreChunks(chunkReader.readerIndex())) {
    //            ChunkBufferContext context = chunkReader.nextChunk();
    //
    //            if (context.isFormType(ID_PTMP)) {
    //                LoadoutEquipmentInfo styleInfo = new LoadoutEquipmentInfo(chunkReader);
    //                equipmentInfos.put(styleInfo.getPlayerTemplate(), styleInfo);
    //            }
    //        }
    //
    //        chunkReader.closeChunk(); //Closes TAG_0000
    //        chunkReader.closeChunk(); //Closes ID_HAIR

    logger.debug(
        String.format("Loaded %d default loadout equipment entries.", equipmentInfos.size()));
  }

  @Override
  public void reload() {
    synchronized (this) {
      equipmentInfos.clear();
      load();
    }
  }

  public static final class LoadoutEquipmentInfo {
    private static final Logger logger = LoggerFactory.getLogger(LoadoutEquipmentInfo.class);

    @Getter private String playerTemplate;
    @Getter private Collection<String> itemTemplates = new ArrayList<>();

    //        public LoadoutEquipmentInfo(ChunkReader reader) {
    //            logger.trace("Parsing loadout equipment info.");
    //            final ChunkBufferContext root = reader.getCurrentContext();
    //
    //            while (root.hasMoreChunks(reader.readerIndex())) {
    //                ChunkBufferContext context = reader.nextChunk();
    //
    //                if (context.isChunkId(ID_NAME)) {
    //                    playerTemplate = reader.readNullTerminatedAscii();
    //                    logger.trace("NAME: " + playerTemplate);
    //                } else if (context.isChunkId(ID_ITEM)) {
    //                    final int unknownInt = reader.readInt();
    //                    final String itemTemplate = reader.readNullTerminatedAscii();
    //                    itemTemplates.add(itemTemplate);
    //                    logger.trace(String.format("%d:%s", unknownInt, itemTemplate));
    //                }
    //            }
    //        }
  }
}
コード例 #3
0
ファイル: ServerArmorTemplate.java プロジェクト: bacta/swg
  @Override
  protected void load(final Iff iff) {
    if (iff.getCurrentName() != TAG_SERVERARMORTEMPLATE) {
      return;
    }

    iff.enterForm();
    templateVersion = iff.getCurrentName();

    if (templateVersion == Tag.TAG_DERV) {
      iff.enterForm();
      iff.enterChunk();
      final String baseFilename = iff.readString();
      iff.exitChunk();
      final ObjectTemplate base = objectTemplateList.fetch(baseFilename);
      Preconditions.checkNotNull(base, "was unable to load base template %s", baseFilename);
      if (baseData == base && base != null) {
        base.releaseReference();
      } else {
        if (baseData != null) baseData.releaseReference();
        baseData = base;
      }
      iff.exitForm();
      templateVersion = iff.getCurrentName();
    }

    iff.enterForm();
    iff.enterChunk();
    final int paramCount = iff.readInt();
    iff.exitChunk();
    for (int i = 0; i < paramCount; ++i) {
      iff.enterChunk();
      final String parameterName = iff.readString();

      if ("rating".equalsIgnoreCase(parameterName)) {
        rating.loadFromIff(objectTemplateList, iff);
      } else if ("integrity".equalsIgnoreCase(parameterName)) {
        integrity.loadFromIff(objectTemplateList, iff);
      } else if ("effectiveness".equalsIgnoreCase(parameterName)) {
        effectiveness.loadFromIff(objectTemplateList, iff);
      } else if ("specialProtection".equalsIgnoreCase(parameterName)) {
        specialProtection.clear();
        specialProtectionAppend = iff.readBoolean();
        int listCount = iff.readInt();
        for (int j = 0; j < listCount; ++j) {
          final StructParam<ObjectTemplate> newData = new StructParam<ObjectTemplate>();
          newData.loadFromIff(objectTemplateList, iff);
          specialProtection.add(newData);
        }
        specialProtectionLoaded = true;
      } else if ("vulnerability".equalsIgnoreCase(parameterName)) {
        vulnerability.loadFromIff(objectTemplateList, iff);
      } else if ("encumbrance".equalsIgnoreCase(parameterName)) {
        int listCount = iff.readInt();
        int j;
        for (j = 0; j < 3 && j < listCount; ++j)
          encumbrance[j].loadFromIff(objectTemplateList, iff);
        for (; j < listCount; ++j) {
          final IntegerParam dummy = new IntegerParam();
          dummy.loadFromIff(objectTemplateList, iff);
        }
      } else {
        LOGGER.trace("Unexpected parameter {}", parameterName);
      }

      iff.exitChunk();
    }
    iff.exitForm();
  }
コード例 #4
0
  @Override
  protected void load(final Iff iff) {
    if (iff.getCurrentName() != TAG_SHAREDFACTORYOBJECTTEMPLATE) {
      super.load(iff);
      return;
    }

    iff.enterForm();
    templateVersion = iff.getCurrentName();

    if (templateVersion == Tag.TAG_DERV) {
      iff.enterForm();
      iff.enterChunk();
      final String baseFilename = iff.readString();
      iff.exitChunk();
      final ObjectTemplate base = objectTemplateList.fetch(baseFilename);
      Preconditions.checkNotNull(base, "was unable to load base template %s", baseFilename);
      if (baseData == base && base != null) {
        base.releaseReference();
      } else {
        if (baseData != null) baseData.releaseReference();
        baseData = base;
      }
      iff.exitForm();
      templateVersion = iff.getCurrentName();
    }

    iff.enterForm();
    iff.enterChunk();
    final int paramCount = iff.readInt();
    iff.exitChunk();
    iff.exitForm();

    super.load(iff);
    iff.exitForm();
  }