Advertisement
Chiddix

SpotAnimation

Feb 3rd, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. package com.runescape.anim;
  2.  
  3. import com.runescape.cache.Archive;
  4. import com.runescape.graphic.Model;
  5. import com.runescape.net.Buffer;
  6. import com.runescape.node.Cache;
  7.  
  8. public class SpotAnimation {
  9.  
  10.     public static int spotAnimationCount;
  11.     public static SpotAnimation[] cache;
  12.     public int id;
  13.     public int modelId;
  14.     public int animationId = -1;
  15.     public AnimationSequence animationSequences;
  16.     public int[] originalModelColors = new int[6];
  17.     public int[] modifiedModelColors = new int[6];
  18.     public int resizeXY = 128;
  19.     public int resizeZ = 128;
  20.     public int rotation;
  21.     public int modelBrightness;
  22.     public int modelShadow;
  23.     public static Cache modelCache = new Cache(30);
  24.  
  25.     public static void load(Archive archive) {
  26.         Buffer buffer = new Buffer(archive.getFile("spotanim.dat"));
  27.         SpotAnimation.spotAnimationCount = buffer.getUnsignedLEShort();
  28.         if (SpotAnimation.cache == null) {
  29.             SpotAnimation.cache = new SpotAnimation[SpotAnimation.spotAnimationCount];
  30.         }
  31.         for (int spotAnimation = 0; spotAnimation < SpotAnimation.spotAnimationCount; spotAnimation++) {
  32.             if (SpotAnimation.cache[spotAnimation] == null) {
  33.                 SpotAnimation.cache[spotAnimation] = new SpotAnimation();
  34.             }
  35.             SpotAnimation.cache[spotAnimation].id = spotAnimation;
  36.             SpotAnimation.cache[spotAnimation].loadDefinition(buffer);
  37.         }
  38.     }
  39.  
  40.     public void loadDefinition(Buffer buffer) {
  41.         while (true) {
  42.             int attributeId = buffer.getUnsignedByte();
  43.             if (attributeId == 0) {
  44.                 break;
  45.             }
  46.             if (attributeId == 1) {
  47.                 modelId = buffer.getUnsignedLEShort();
  48.             } else if (attributeId == 2) {
  49.                 animationId = buffer.getUnsignedLEShort();
  50.                 if (AnimationSequence.animationSequences != null) {
  51.                     animationSequences = AnimationSequence.animationSequences[animationId];
  52.                 }
  53.             } else if (attributeId == 4) {
  54.                 resizeXY = buffer.getUnsignedLEShort();
  55.             } else if (attributeId == 5) {
  56.                 resizeZ = buffer.getUnsignedLEShort();
  57.             } else if (attributeId == 6) {
  58.                 rotation = buffer.getUnsignedLEShort();
  59.             } else if (attributeId == 7) {
  60.                 modelBrightness = buffer.getUnsignedByte();
  61.             } else if (attributeId == 8) {
  62.                 modelShadow = buffer.getUnsignedByte();
  63.             } else if (attributeId >= 40 && attributeId < 50) {
  64.                 originalModelColors[attributeId - 40] = buffer.getUnsignedLEShort();
  65.             } else if (attributeId >= 50 && attributeId < 60) {
  66.                 modifiedModelColors[attributeId - 50] = buffer.getUnsignedLEShort();
  67.             } else {
  68.                 System.out.println("Error unrecognised spotanim config code: " + attributeId);
  69.             }
  70.         }
  71.     }
  72.  
  73.     public Model getModel() {
  74.         Model model = (Model) SpotAnimation.modelCache.get(id);
  75.         if (model != null) {
  76.             return model;
  77.         }
  78.         model = Model.getModel(modelId);
  79.         if (model == null) {
  80.             return null;
  81.         }
  82.         for (int nodelColor = 0; nodelColor < 6; nodelColor++) {
  83.             if (originalModelColors[0] != 0) {
  84.                 model.recolor(originalModelColors[nodelColor], modifiedModelColors[nodelColor]);
  85.             }
  86.         }
  87.         SpotAnimation.modelCache.put(model, id);
  88.         return model;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement