Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.43 KB | None | 0 0
  1. package com.runescape.entity;
  2.  
  3. import com.runescape.Client;
  4. import com.runescape.Configuration;
  5. import com.runescape.cache.anim.Animation;
  6. import com.runescape.cache.anim.Frame;
  7. import com.runescape.cache.anim.Graphic;
  8. import com.runescape.cache.def.ItemDefinition;
  9. import com.runescape.cache.def.NpcDefinition;
  10. import com.runescape.collection.ReferenceCache;
  11. import com.runescape.entity.model.IdentityKit;
  12. import com.runescape.entity.model.Model;
  13. import com.runescape.io.Buffer;
  14. import com.runescape.util.StringUtils;
  15.  
  16. public final class Player extends Mob {
  17.  
  18.  
  19. public static ReferenceCache models = new ReferenceCache(260);
  20. public final int[] appearanceColors = new int[5];
  21. public final int[] equipment = new int[12];
  22. public NpcDefinition npcDefinition;
  23. public boolean aBoolean1699;
  24. public int team;
  25. public String name;
  26. public int combatLevel;
  27. public int headIcon;
  28. public int skullIcon;
  29. public int hintIcon;
  30. public int objectModelStart;
  31. public int objectModelStop;
  32. public int anInt1709;
  33. public boolean visible;
  34. public int objectXPos;
  35. public int objectCenterHeight;
  36. public int objectYPos;
  37. public Model playerModel;
  38. public int objectAnInt1719LesserXLoc;
  39. public int objectAnInt1720LesserYLoc;
  40. public int objectAnInt1721GreaterXLoc;
  41. public int objectAnInt1722GreaterYLoc;
  42. public int skill;
  43. public String clanName = "None";
  44. public int rights;
  45. private long cachedModel = -1L;
  46. private int gender;
  47. private long appearanceOffset;
  48.  
  49. public Model getRotatedModel() {
  50.  
  51. if (!visible) {
  52. return null;
  53. }
  54.  
  55. Model animatedModel = getAnimatedModel();
  56.  
  57. if (animatedModel == null) {
  58. return null;
  59. }
  60.  
  61. super.height = animatedModel.modelBaseY;
  62. animatedModel.fits_on_single_square = true;
  63.  
  64. if (aBoolean1699) {
  65. return animatedModel;
  66. }
  67.  
  68. if (super.graphic != -1 && super.currentAnimation != -1) {
  69. Graphic spotAnim = Graphic.cache[super.graphic];
  70.  
  71. Model spotAnimationModel = spotAnim.getModel();
  72.  
  73. /**
  74. * MAKE SURE WE'VE LOADED THE GRAPHIC BEFORE ATTEMPTING TO DO IT.
  75. * Fixes graphics flickering.
  76. */
  77. if (Frame.animationlist[spotAnim.animationSequence.primaryFrames[0] >> 16].length == 0) {
  78. spotAnimationModel = null;
  79. }
  80.  
  81. if (spotAnimationModel != null) {
  82.  
  83. Model model_3 = new Model(true, Frame.noAnimationInProgress(super.currentAnimation), false, spotAnimationModel);
  84. int nextFrame = spotAnim.animationSequence.primaryFrames[super.nextGraphicsAnimationFrame];
  85. int cycle1 = spotAnim.animationSequence.durations[super.currentAnimation];
  86. int cycle2 = super.anInt1522;
  87. model_3.translate(0, -super.graphicHeight, 0);
  88. model_3.skin();
  89. /*model_3.applyAnimationFrame(spotAnim.animationSequence.primaryFrames[super.currentAnimation], nextFrame,
  90. cycle1, cycle2);*/
  91. model_3.applyTransform(spotAnim.animationSequence.primaryFrames[super.currentAnimation]);
  92. model_3.faceGroups = null;
  93. model_3.vertexGroups = null;
  94. if (spotAnim.resizeXY != 128 || spotAnim.resizeZ != 128)
  95. model_3.scale(spotAnim.resizeXY, spotAnim.resizeXY, spotAnim.resizeZ);
  96. model_3.light(64 + spotAnim.modelShadow, 850 + spotAnim.modelBrightness, -30, -50, -30, true);
  97. Model models[] = {animatedModel, model_3};
  98. animatedModel = new Model(models);
  99. }
  100. }
  101.  
  102. if (playerModel != null) {
  103. if (Client.tick >= objectModelStop)
  104. playerModel = null;
  105. if (Client.tick >= objectModelStart && Client.tick < objectModelStop) {
  106. Model model_1 = playerModel;
  107. model_1.translate(objectXPos - super.x, objectCenterHeight - anInt1709, objectYPos - super.y);
  108. if (super.nextStepOrientation == 512) {
  109. model_1.rotate90Degrees();
  110. model_1.rotate90Degrees();
  111. model_1.rotate90Degrees();
  112. } else if (super.nextStepOrientation == 1024) {
  113. model_1.rotate90Degrees();
  114. model_1.rotate90Degrees();
  115. } else if (super.nextStepOrientation == 1536)
  116. model_1.rotate90Degrees();
  117. Model models[] = {animatedModel, model_1};
  118. animatedModel = new Model(models);
  119. if (super.nextStepOrientation == 512)
  120. model_1.rotate90Degrees();
  121. else if (super.nextStepOrientation == 1024) {
  122. model_1.rotate90Degrees();
  123. model_1.rotate90Degrees();
  124. } else if (super.nextStepOrientation == 1536) {
  125. model_1.rotate90Degrees();
  126. model_1.rotate90Degrees();
  127. model_1.rotate90Degrees();
  128. }
  129. model_1.translate(super.x - objectXPos, anInt1709 - objectCenterHeight, super.y - objectYPos);
  130. }
  131. }
  132. animatedModel.fits_on_single_square = true;
  133. return animatedModel;
  134. }
  135.  
  136. public void updateAppearance(Buffer buffer) {
  137. buffer.currentPosition = 0;
  138.  
  139. gender = buffer.readUnsignedByte();
  140. headIcon = buffer.readUnsignedByte();
  141. skullIcon = buffer.readUnsignedByte();
  142. hintIcon = buffer.readUnsignedByte();
  143. npcDefinition = null;
  144. team = 0;
  145.  
  146. for (int bodyPart = 0; bodyPart < 12; bodyPart++) {
  147.  
  148. int reset = buffer.readUnsignedByte();
  149.  
  150. if (reset == 0) {
  151. equipment[bodyPart] = 0;
  152. continue;
  153. }
  154.  
  155. int id = buffer.readUnsignedByte();
  156.  
  157. equipment[bodyPart] = (reset << 8) + id;
  158.  
  159. if (bodyPart == 0 && equipment[0] == 65535) {
  160. npcDefinition = NpcDefinition.lookup(buffer.readUShort());
  161. break;
  162. }
  163.  
  164. if (equipment[bodyPart] >= 512 && equipment[bodyPart] - 512 < ItemDefinition.TOTAL_ITEMS) {
  165. int team = ItemDefinition.lookup(equipment[bodyPart] - 512).team;
  166.  
  167. if (team != 0) {
  168. this.team = team;
  169. }
  170.  
  171. }
  172.  
  173. }
  174.  
  175. for (int part = 0; part < 5; part++) {
  176. int color = buffer.readUnsignedByte();
  177. if (color < 0 || color >= Client.PLAYER_BODY_RECOLOURS[part].length) {
  178. color = 0;
  179. }
  180. appearanceColors[part] = color;
  181. }
  182.  
  183. super.idleAnimation = buffer.readUShort();
  184. if (super.idleAnimation == 65535) {
  185. super.idleAnimation = -1;
  186. }
  187.  
  188. super.standTurnAnimIndex = buffer.readUShort();
  189. if (super.standTurnAnimIndex == 65535) {
  190. super.standTurnAnimIndex = -1;
  191. }
  192.  
  193. super.walkAnimIndex = buffer.readUShort();
  194. if (super.walkAnimIndex == 65535) {
  195. super.walkAnimIndex = -1;
  196. }
  197.  
  198. super.turn180AnimIndex = buffer.readUShort();
  199. if (super.turn180AnimIndex == 65535) {
  200. super.turn180AnimIndex = -1;
  201. }
  202.  
  203. super.turn90CWAnimIndex = buffer.readUShort();
  204. if (super.turn90CWAnimIndex == 65535) {
  205. super.turn90CWAnimIndex = -1;
  206. }
  207.  
  208. super.turn90CCWAnimIndex = buffer.readUShort();
  209. if (super.turn90CCWAnimIndex == 65535) {
  210. super.turn90CCWAnimIndex = -1;
  211. }
  212.  
  213. super.runAnimIndex = buffer.readUShort();
  214. if (super.runAnimIndex == 65535) {
  215. super.runAnimIndex = -1;
  216. }
  217.  
  218. name = StringUtils.formatText(StringUtils.decodeBase37(buffer.readLong()));
  219. combatLevel = buffer.readUnsignedByte();
  220. rights = buffer.readUnsignedByte();
  221.  
  222. //skill = buffer.readUShort();
  223. visible = true;
  224. appearanceOffset = 0L;
  225.  
  226. for (int index = 0; index < 12; index++) {
  227. appearanceOffset <<= 4;
  228.  
  229. if (equipment[index] >= 256) {
  230. appearanceOffset += equipment[index] - 256;
  231. }
  232.  
  233. }
  234.  
  235. if (equipment[0] >= 256) {
  236. appearanceOffset += equipment[0] - 256 >> 4;
  237. }
  238.  
  239. if (equipment[1] >= 256) {
  240. appearanceOffset += equipment[1] - 256 >> 8;
  241. }
  242.  
  243. for (int index = 0; index < 5; index++) {
  244. appearanceOffset <<= 3;
  245. appearanceOffset += appearanceColors[index];
  246. }
  247.  
  248. appearanceOffset <<= 1;
  249. appearanceOffset += gender;
  250. }
  251.  
  252. public Model getAnimatedModel() {
  253. if (npcDefinition != null) {
  254. int currentFrame = -1;
  255. int nextFrame = -1;
  256. int cycle1 = 0;
  257. int cycle2 = 0;
  258.  
  259. if (super.emoteAnimation >= 0 && super.animationDelay == 0) {
  260. Animation animation = Animation.animations[super.emoteAnimation];
  261. currentFrame = animation.primaryFrames[super.displayedEmoteFrames];
  262. if (Configuration.enableTweening && super.nextAnimationFrame != -1) {
  263. nextFrame = animation.primaryFrames[super.nextAnimationFrame];
  264. cycle1 = animation.durations[super.displayedEmoteFrames];
  265. cycle2 = super.emoteTimeRemaining;
  266. }
  267. } else if (super.movementAnimation >= 0) {
  268. Animation animation = Animation.animations[super.movementAnimation];
  269. currentFrame = animation.primaryFrames[super.displayedMovementFrames];
  270. if (Configuration.enableTweening && super.nextIdleAnimationFrame != -1) {
  271. nextFrame = animation.primaryFrames[super.nextIdleAnimationFrame];
  272. cycle1 = animation.durations[super.displayedMovementFrames];
  273. cycle2 = super.anInt1519;
  274. }
  275. }
  276. Model model = npcDefinition.method164(-1, currentFrame, null, nextFrame, cycle1, cycle2);
  277. return model;
  278. }
  279.  
  280.  
  281. long l = appearanceOffset;
  282. int currentFrame = -1;
  283. int nextFrame = -1;
  284. int cycle1 = 0;
  285. int cycle2 = 0;
  286. int i1 = -1;
  287. int j1 = -1;
  288. int k1 = -1;
  289. if (super.emoteAnimation >= 0 && super.animationDelay == 0) {
  290. Animation animation = Animation.animations[super.emoteAnimation];
  291. currentFrame = animation.primaryFrames[super.displayedEmoteFrames];
  292. if (Configuration.enableTweening && super.nextAnimationFrame != -1) {
  293. nextFrame = animation.primaryFrames[super.nextAnimationFrame];
  294. cycle1 = animation.durations[super.displayedEmoteFrames];
  295. cycle2 = super.emoteTimeRemaining;
  296. }
  297. if (super.movementAnimation >= 0 && super.movementAnimation != super.idleAnimation)
  298. i1 = Animation.animations[super.movementAnimation].primaryFrames[super.displayedMovementFrames];
  299. if (animation.playerOffhand >= 0) {
  300. j1 = animation.playerOffhand;
  301. l += j1 - equipment[5] << 40;
  302. }
  303. if (animation.playerMainhand >= 0) {
  304. k1 = animation.playerMainhand;
  305. l += k1 - equipment[3] << 48;
  306. }
  307. } else if (super.movementAnimation >= 0) {
  308. Animation animation = Animation.animations[super.movementAnimation];
  309. currentFrame = animation.primaryFrames[super.displayedMovementFrames];
  310.  
  311. /** DISABLED BECAUSE IT CAUSES FLICKERING WITH SOME GFXS **/
  312. /*if (Configuration.enableTweening && super.nextIdleAnimationFrame != -1) {
  313. nextFrame = animation.primaryFrames[super.nextIdleAnimationFrame];
  314. cycle1 = animation.durations[super.displayedMovementFrames];
  315. cycle2 = super.anInt1519;
  316. }*/
  317. }
  318. Model model_1 = (Model) models.get(l);
  319. if (model_1 == null) {
  320. boolean flag = false;
  321. for (int i2 = 0; i2 < 12; i2++) {
  322. int k2 = equipment[i2];
  323. if (k1 >= 0 && i2 == 3)
  324. k2 = k1;
  325. if (j1 >= 0 && i2 == 5)
  326. k2 = j1;
  327. if (k2 >= 256 && k2 < 512 && !IdentityKit.kits[k2 - 256].bodyLoaded())
  328. flag = true;
  329. if (k2 >= 512 && !ItemDefinition.lookup(k2 - 512).isEquippedModelCached(gender))
  330. flag = true;
  331. }
  332.  
  333. if (flag) {
  334. if (cachedModel != -1L)
  335. model_1 = (Model) models.get(cachedModel);
  336. if (model_1 == null)
  337. return null;
  338. }
  339. }
  340. if (model_1 == null) {
  341. Model aclass30_sub2_sub4_sub6s[] = new Model[14];
  342. int j2 = 0;
  343. for (int l2 = 0; l2 < 12; l2++) {
  344. int i3 = equipment[l2];
  345. if (k1 >= 0 && l2 == 3)
  346. i3 = k1;
  347. if (j1 >= 0 && l2 == 5)
  348. i3 = j1;
  349. if (i3 >= 256 && i3 < 512) {
  350. Model model_3 = IdentityKit.kits[i3 - 256].bodyModel();
  351. if (model_3 != null)
  352. aclass30_sub2_sub4_sub6s[j2++] = model_3;
  353. }
  354. if (i3 >= 512) {
  355. Model model_4 = ItemDefinition.lookup(i3 - 512).getEquippedModel(gender);
  356. if (model_4 != null)
  357. aclass30_sub2_sub4_sub6s[j2++] = model_4;
  358. }
  359. }
  360. model_1 = new Model(j2, aclass30_sub2_sub4_sub6s);
  361. for (int j3 = 0; j3 < 5; j3++)
  362. if (appearanceColors[j3] != 0) {
  363. model_1.recolor(Client.PLAYER_BODY_RECOLOURS[j3][0],
  364. Client.PLAYER_BODY_RECOLOURS[j3][appearanceColors[j3]]);
  365. if (j3 == 1)
  366. model_1.recolor(Client.anIntArray1204[0], Client.anIntArray1204[appearanceColors[j3]]);
  367. }
  368.  
  369. model_1.skin();
  370. model_1.scale(132, 132, 132);
  371. model_1.light(64, 850, -30, -50, -30, true);
  372. models.put(model_1, l);
  373. cachedModel = l;
  374. }
  375.  
  376. if (aBoolean1699) {
  377. return model_1;
  378. }
  379.  
  380. Model emptyModel = Model.EMPTY_MODEL;
  381.  
  382. emptyModel.method464(model_1, Frame.noAnimationInProgress(currentFrame) & Frame.noAnimationInProgress(i1));
  383. if (currentFrame != -1 && i1 != -1) {
  384. emptyModel.applyAnimationFrames(Animation.animations[super.emoteAnimation].interleaveOrder, i1, currentFrame);
  385. } else if (currentFrame != -1) {
  386. //emptyModel.apply(currentFrame);
  387. emptyModel.applyAnimationFrame(currentFrame, nextFrame, cycle1, cycle2);
  388. }
  389.  
  390. /*else if (currentFrame != -1 && nextFrame != -1) {
  391. emptyModel.applyAnimationFrame(currentFrame, nextFrame, cycle1, cycle2);
  392. } else {
  393. emptyModel.apply(currentFrame);
  394. }*/
  395. emptyModel.calculateDistances();
  396. emptyModel.faceGroups = null;
  397. emptyModel.vertexGroups = null;
  398. return emptyModel;
  399. }
  400.  
  401. public Model getHeadModel() {
  402. if (!visible) {
  403. return null;
  404. }
  405.  
  406. if (npcDefinition != null) {
  407. return npcDefinition.model();
  408. }
  409.  
  410. boolean cached = false;
  411.  
  412. for (int index = 0; index < 12; index++) {
  413. int appearanceId = equipment[index];
  414.  
  415. if (appearanceId >= 256 && appearanceId < 512 && !IdentityKit.kits[appearanceId - 256].headLoaded()) {
  416. cached = true;
  417. }
  418.  
  419. if (appearanceId >= 512 && !ItemDefinition.lookup(appearanceId - 512).isDialogueModelCached(gender)) {
  420. cached = true;
  421. }
  422. }
  423.  
  424. if (cached) {
  425. return null;
  426. }
  427.  
  428. Model headModels[] = new Model[12];
  429.  
  430. int headModelsOffset = 0;
  431.  
  432. for (int modelIndex = 0; modelIndex < 12; modelIndex++) {
  433. int appearanceId = equipment[modelIndex];
  434.  
  435. if (appearanceId >= 256 && appearanceId < 512) {
  436.  
  437. Model subModel = IdentityKit.kits[appearanceId - 256].headModel();
  438.  
  439. if (subModel != null) {
  440. headModels[headModelsOffset++] = subModel;
  441. }
  442.  
  443. }
  444. if (appearanceId >= 512) {
  445. Model subModel = ItemDefinition.lookup(appearanceId - 512).getChatEquipModel(gender);
  446.  
  447. if (subModel != null) {
  448. headModels[headModelsOffset++] = subModel;
  449. }
  450.  
  451. }
  452. }
  453.  
  454. Model headModel = new Model(headModelsOffset, headModels);
  455.  
  456. for (int index = 0; index < 5; index++) {
  457. if (appearanceColors[index] != 0) {
  458. headModel.recolor(Client.PLAYER_BODY_RECOLOURS[index][0],
  459. Client.PLAYER_BODY_RECOLOURS[index][appearanceColors[index]]);
  460. if (index == 1) {
  461. headModel.recolor(Client.anIntArray1204[0], Client.anIntArray1204[appearanceColors[index]]);
  462. }
  463. }
  464. }
  465.  
  466. return headModel;
  467. }
  468.  
  469. public boolean isVisible() {
  470. return visible;
  471. }
  472.  
  473. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement