Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.76 KB | None | 0 0
  1. package server.model.players;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import server.Server;
  6. import server.util.ISAACRandomGen;
  7. import server.util.Misc;
  8. import server.util.Stream;
  9. import server.world.map.VirtualWorld;
  10.  
  11. public abstract class Player {
  12.  
  13. public boolean
  14. initialized = false,
  15. disconnected = false,
  16. ruleAgreeButton = false,
  17. RebuildNPCList = false,
  18. isActive = false,
  19. isKicked = false,
  20. isSkulled = false,
  21. friendUpdate = false,
  22. newPlayer = false,
  23. hasMultiSign = false,
  24. saveCharacter = false,
  25. mouseButton = false,
  26. splitChat = false,
  27. chatEffects = true,
  28. acceptAid = false,
  29. nextDialogue = false,
  30. autocasting = false,
  31. usedSpecial = false,
  32. mageFollow = false,
  33. dbowSpec = false,
  34. craftingLeather = false,
  35. properLogout = false,
  36. secDbow = false,
  37. maxNextHit = false,
  38. ssSpec = false,
  39. vengOn = false,
  40. addStarter = false,
  41. accountFlagged = false,
  42. msbSpec = false
  43. ;
  44.  
  45.  
  46. public int
  47.  
  48. saveDelay,
  49. playerKilled,
  50. pkPoints,
  51. totalPlayerDamageDealt,
  52. killedBy,
  53. lastChatId = 1,
  54. privateChat,
  55. friendSlot = 0,
  56. dialogueId,
  57. randomCoffin,
  58. newLocation,
  59. specEffect,
  60. specBarId,
  61. attackLevelReq,
  62. defenceLevelReq,
  63. strengthLevelReq,
  64. rangeLevelReq,
  65. magicLevelReq,
  66. followId,
  67. skullTimer,
  68. votingPoints,
  69. nextChat = 0,
  70. talkingNpc = -1,
  71. dialogueAction = 0,
  72. autocastId,
  73. followDistance,
  74. followId2,
  75. barrageCount = 0,
  76. delayedDamage = 0,
  77. delayedDamage2 = 0,
  78. pcPoints = 0,
  79. magePoints = 0,
  80. desertTreasure = 0,
  81. lastArrowUsed = -1,
  82. clanId = -1,
  83. autoRet = 0,
  84. pcDamage = 0,
  85. xInterfaceId = 0,
  86. xRemoveId = 0,
  87. xRemoveSlot = 0,
  88. tzhaarToKill = 0,
  89. tzhaarKilled = 0,
  90. waveId,
  91. frozenBy = 0,
  92. poisonDamage = 0,
  93. teleAction = 0,
  94. bonusAttack = 0,
  95. lastNpcAttacked = 0,
  96. killCount = 0;
  97. public String clanName, properName;
  98. public int[] voidStatus = new int[5];
  99. public int[] itemKeptId = new int [4];
  100. public int[] pouches = new int[4];
  101. public final int[] POUCH_SIZE = {3,6,9,12};
  102. public boolean[] invSlot = new boolean[28], equipSlot = new boolean[14];
  103. public long friends[] = new long[200];
  104. public double specAmount = 0;
  105. public double specAccuracy = 1;
  106. public double specDamage = 1;
  107. public double prayerPoint = 1.0;
  108. public int teleGrabItem, teleGrabX, teleGrabY, duelCount, underAttackBy, underAttackBy2, wildLevel, teleTimer, respawnTimer, saveTimer = 0, teleBlockLength, poisonDelay;
  109. public long lastPlayerMove,lastPoison,lastPoisonSip,poisonImmune,lastSpear,lastProtItem, dfsDelay, lastVeng,lastYell,teleGrabDelay, protMageDelay, protMeleeDelay, protRangeDelay, lastAction, lastThieve,lastLockPick, alchDelay, specDelay = System.currentTimeMillis(), duelDelay, teleBlockDelay, godSpellDelay, singleCombatDelay, singleCombatDelay2, reduceStat, restoreStatsDelay, logoutDelay, buryDelay, foodDelay, potDelay;
  110. public boolean canChangeAppearance = false;
  111. public boolean mageAllowed;
  112. public byte poisonMask = 0;
  113.  
  114. public final int[] BOWS = {9185,839,845,847,851,855,859,841,843,849,853,857,861,4212,4214,4215,11235,4216,4217,4218,4219,4220,4221,4222,4223,6724,4734,4934,4935,4936,4937};
  115. public final int[] ARROWS = {882,884,886,888,890,892,4740,11212,9140,9141,4142,9143,9144,9240,9241,9242,9243,9244,9245};
  116. public final int[] NO_ARROW_DROP = {4212,4214,4215,4216,4217,4218,4219,4220,4221,4222,4223,4734,4934,4935,4936,4937};
  117. public final int[] OTHER_RANGE_WEAPONS = {863,864,865,866,867,868,869,806,807,808,809,810,811,825,826,827,828,829,830,800,801,802,803,804,805,6522};
  118.  
  119. public final int[][] MAGIC_SPELLS = {
  120. // example {magicId, level req, animation, startGFX, projectile Id, endGFX, maxhit, exp gained, rune 1, rune 1 amount, rune 2, rune 2 amount, rune 3, rune 3 amount, rune 4, rune 4 amount}
  121.  
  122. // Modern Spells
  123. {1152,1,711,90,91,92,2,5,556,1,558,1,0,0,0,0}, //wind strike
  124. {1154,5,711,93,94,95,4,7,555,1,556,1,558,1,0,0}, // water strike
  125. {1156,9,711,96,97,98,6,9,557,2,556,1,558,1,0,0},// earth strike
  126. {1158,13,711,99,100,101,8,11,554,3,556,2,558,1,0,0}, // fire strike
  127. {1160,17,711,117,118,119,9,13,556,2,562,1,0,0,0,0}, // wind bolt
  128. {1163,23,711,120,121,122,10,16,556,2,555,2,562,1,0,0}, // water bolt
  129. {1166,29,711,123,124,125,11,20,556,2,557,3,562,1,0,0}, // earth bolt
  130. {1169,35,711,126,127,128,12,22,556,3,554,4,562,1,0,0}, // fire bolt
  131. {1172,41,711,132,133,134,13,25,556,3,560,1,0,0,0,0}, // wind blast
  132. {1175,47,711,135,136,137,14,28,556,3,555,3,560,1,0,0}, // water blast
  133. {1177,53,711,138,139,140,15,31,556,3,557,4,560,1,0,0}, // earth blast
  134. {1181,59,711,129,130,131,16,35,556,4,554,5,560,1,0,0}, // fire blast
  135. {1183,62,711,158,159,160,17,36,556,5,565,1,0,0,0,0}, // wind wave
  136. {1185,65,711,161,162,163,18,37,556,5,555,7,565,1,0,0}, // water wave
  137. {1188,70,711,164,165,166,19,40,556,5,557,7,565,1,0,0}, // earth wave
  138. {1189,75,711,155,156,157,20,42,556,5,554,7,565,1,0,0}, // fire wave
  139. {1153,3,716,102,103,104,0,13,555,3,557,2,559,1,0,0}, // confuse
  140. {1157,11,716,105,106,107,0,20,555,3,557,2,559,1,0,0}, // weaken
  141. {1161,19,716,108,109,110,0,29,555,2,557,3,559,1,0,0}, // curse
  142. {1542,66,729,167,168,169,0,76,557,5,555,5,566,1,0,0}, // vulnerability
  143. {1543,73,729,170,171,172,0,83,557,8,555,8,566,1,0,0}, // enfeeble
  144. {1562,80,729,173,174,107,0,90,557,12,555,12,556,1,0,0}, // stun
  145. {1572,20,711,177,178,181,0,30,557,3,555,3,561,2,0,0}, // bind
  146. {1582,50,711,177,178,180,2,60,557,4,555,4,561,3,0,0}, // snare
  147. {1592,79,711,177,178,179,4,90,557,5,555,5,561,4,0,0}, // entangle
  148. {1171,39,724,145,146,147,15,25,556,2,557,2,562,1,0,0}, // crumble undead
  149. {1539,50,708,87,88,89,25,42,554,5,560,1,0,0,0,0}, // iban blast
  150. {12037,50,1576,327,328,329,19,30,560,1,558,4,0,0,0,0}, // magic dart
  151. {1190,60,811,0,0,76,20,60,554,2,565,2,556,4,0,0}, // sara strike
  152. {1191,60,811,0,0,77,20,60,554,1,565,2,556,4,0,0}, // cause of guthix
  153. {1192,60,811,0,0,78,20,60,554,4,565,2,556,1,0,0}, // flames of zammy
  154. {12445,85,1819,0,344,345,0,65,563,1,562,1,560,1,0,0}, // teleblock
  155.  
  156. // Ancient Spells
  157. {12939,50,1978,0,384,385,13,30,560,2,562,2,554,1,556,1}, // smoke rush
  158. {12987,52,1978,0,378,379,14,31,560,2,562,2,566,1,556,1}, // shadow rush
  159. {12901,56,1978,0,0,373,15,33,560,2,562,2,565,1,0,0}, // blood rush
  160. {12861,58,1978,0,360,361,16,34,560,2,562,2,555,2,0,0}, // ice rush
  161. {12963,62,1979,0,0,389,19,36,560,2,562,4,556,2,554,2}, // smoke burst
  162. {13011,64,1979,0,0,382,20,37,560,2,562,4,556,2,566,2}, // shadow burst
  163. {12919,68,1979,0,0,376,21,39,560,2,562,4,565,2,0,0}, // blood burst
  164. {12881,70,1979,0,0,363,22,40,560,2,562,4,555,4,0,0}, // ice burst
  165. {12951,74,1978,0,386,387,23,42,560,2,554,2,565,2,556,2}, // smoke blitz
  166. {12999,76,1978,0,380,381,24,43,560,2,565,2,556,2,566,2}, // shadow blitz
  167. {12911,80,1978,0,374,375,25,45,560,2,565,4,0,0,0,0}, // blood blitz
  168. {12871,82,1978,366,0,367,26,46,560,2,565,2,555,3,0,0}, // ice blitz
  169. {12975,86,1979,0,0,391,27,48,560,4,565,2,556,4,554,4}, // smoke barrage
  170. {13023,88,1979,0,0,383,28,49,560,4,565,2,556,4,566,3}, // shadow barrage
  171. {12929,92,1979,0,0,377,29,51,560,4,565,4,566,1,0,0}, // blood barrage
  172. {12891,94,1979,0,0,369,30,52,560,4,565,2,555,6,0,0}, // ice barrage
  173.  
  174. {-1,80,811,301,0,0,0,0,554,3,565,3,556,3,0,0}, // charge
  175. {-1,21,712,112,0,0,0,10,554,3,561,1,0,0,0,0}, // low alch
  176. {-1,55,713,113,0,0,0,20,554,5,561,1,0,0,0,0}, // high alch
  177. {-1,33,728,142,143,144,0,35,556,1,563,1,0,0,0,0} // telegrab
  178.  
  179. };
  180.  
  181. public boolean isAutoButton(int button) {
  182. for (int j = 0; j < autocastIds.length; j += 2) {
  183. if (autocastIds[j] == button)
  184. return true;
  185. }
  186. return false;
  187. }
  188.  
  189. public int[] autocastIds = {51133,32,51185,33,51091,34,24018,35,51159,36,51211,37,51111,38,51069,39,51146,40,51198,41,51102,42,51058,43,51172,44,51224,45,51122,46,51080,47,
  190. 7038,0,7039,1,7040,2,7041,3,7042,4,7043,5,7044,6,7045,7,7046,8,7047,9,7048,10,7049,11,7050,12,7051,13,7052,14,7053,15,
  191. 47019,27,47020,25,47021,12,47022,13,47023,14,47024,15};
  192.  
  193. //public String spellName = "Select Spell";
  194. public void assignAutocast(int button) {
  195. for (int j = 0; j < autocastIds.length; j++) {
  196. if (autocastIds[j] == button) {
  197. Client c = (Client) Server.playerHandler.players[this.playerId];
  198. autocasting = true;
  199. autocastId = autocastIds[j+1];
  200. c.getPA().sendFrame36(108, 1);
  201. c.setSidebarInterface(0, 328);
  202. //spellName = getSpellName(autocastId);
  203. //spellName = spellName;
  204. //c.getPA().sendFrame126(spellName, 354);
  205. c = null;
  206. break;
  207. }
  208. }
  209. }
  210.  
  211. public String getSpellName(int id) {
  212. switch (id) {
  213. case 0: return "Air Strike";
  214. case 1: return "Water Strike";
  215. case 2: return "Earth Strike";
  216. case 3: return "Fire Strike";
  217. case 4: return "Air Bolt";
  218. case 5: return "Water Bolt";
  219. case 6: return "Earth Bolt";
  220. case 7: return "Fire Bolt";
  221. case 8: return "Air Blast";
  222. case 9: return "Water Blast";
  223. case 10: return "Earth Blast";
  224. case 11: return "Fire Blast";
  225. case 12: return "Air Wave";
  226. case 13: return "Water Wave";
  227. case 14: return "Earth Wave";
  228. case 15: return "Fire Wave";
  229. case 32: return "Shadow Rush";
  230. case 33: return "Smoke Rush";
  231. case 34: return "Blood Rush";
  232. case 35: return "Ice Rush";
  233. case 36: return "Shadow Burst";
  234. case 37: return "Smoke Burst";
  235. case 38: return "Blood Burst";
  236. case 39: return "Ice Burst";
  237. case 40: return "Shadow Blitz";
  238. case 41: return "Smoke Blitz";
  239. case 42: return "Blood Blitz";
  240. case 43: return "Ice Blitz";
  241. case 44: return "Shadow Barrage";
  242. case 45: return "Smoke Barrage";
  243. case 46: return "Blood Barrage";
  244. case 47: return "Ice Barrage";
  245. default:
  246. return "Select Spell";
  247. }
  248. }
  249.  
  250. public boolean fullVoidRange() {
  251. return playerEquipment[playerHat] == 11664 && playerEquipment[playerLegs] == 8840 && playerEquipment[playerChest] == 8839 && playerEquipment[playerHands] == 8842;
  252. }
  253.  
  254. public boolean fullVoidMage() {
  255. return playerEquipment[playerHat] == 11663 && playerEquipment[playerLegs] == 8840 && playerEquipment[playerChest] == 8839 && playerEquipment[playerHands] == 8842;
  256. }
  257.  
  258. public boolean fullVoidMelee() {
  259. return playerEquipment[playerHat] == 11665 && playerEquipment[playerLegs] == 8840 && playerEquipment[playerChest] == 8839 && playerEquipment[playerHands] == 8842;
  260. }
  261.  
  262. public int[][] barrowsNpcs = {
  263. {2030, 0}, //verac
  264. {2029, 0}, //toarg
  265. {2028, 0}, // karil
  266. {2027, 0}, // guthan
  267. {2026, 0}, // dharok
  268. {2025, 0} // ahrim
  269. };
  270. public int barrowsKillCount;
  271.  
  272. public int reduceSpellId;
  273. public final int[] REDUCE_SPELL_TIME = {250000, 250000, 250000, 500000,500000,500000}; // how long does the other player stay immune to the spell
  274. public long[] reduceSpellDelay = new long[6];
  275. public final int[] REDUCE_SPELLS = {1153,1157,1161,1542,1543,1562};
  276. public boolean[] canUseReducingSpell = {true, true, true, true, true, true};
  277.  
  278. public int slayerTask,taskAmount;
  279.  
  280. public int prayerId = -1;
  281. public int headIcon = -1;
  282. public int bountyIcon = 0;
  283. public long stopPrayerDelay, prayerDelay;
  284. public boolean usingPrayer;
  285. public final int[] PRAYER_DRAIN_RATE = {500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500};
  286. public final int[] PRAYER_LEVEL_REQUIRED = {1,4,7,8,9,10,13,16,19,22,25,26,27,28,31,34,37,40,43,44,45,46,49,52,60,70};
  287. public final int[] PRAYER = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
  288. public final String[] PRAYER_NAME = {"Thick Skin", "Burst of Strength", "Clarity of Thought", "Sharp Eye", "Mystic Will", "Rock Skin", "Superhuman Strength", "Improved Reflexes","Rapid Restore",
  289. "Rapid Heal", "Protect Item", "Hawk Eye", "Mystic Lore", "Steel Skin", "Ultimate Strength", "Incredible Reflexes","Protect from Magic", "Protect from Missiles",
  290. "Protect from Melee","Eagle Eye", "Mystic Might", "Retribution", "Redemption", "Smite", "Chivalry", "Piety"};
  291. public final int[] PRAYER_GLOW = {83,84,85,601,602,86,87,88,89,90,91,603,604,92,93,94,95,96,97,605,606,98,99,100,607,608};
  292. public final int[] PRAYER_HEAD_ICONS = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,1,0,-1,-1,3,5,4,-1,-1};
  293. //{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,1,4,6,5};
  294.  
  295. public boolean[] prayerActive = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
  296.  
  297. public int duelTimer, duelTeleX, duelTeleY, duelSlot, duelSpaceReq, duelOption, duelingWith, duelStatus;
  298. public int headIconPk = -1, headIconHints;
  299. public boolean duelRequested;
  300. public boolean[] duelRule = new boolean[22];
  301. public final int[] DUEL_RULE_ID = {1, 2, 16, 32, 64, 128, 256, 512, 1024, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 2097152, 8388608, 16777216, 67108864, 134217728};
  302.  
  303. public boolean doubleHit, usingSpecial, npcDroppingItems, usingRangeWeapon, usingBow, usingMagic, castingMagic;
  304. public int specMaxHitIncrease, freezeDelay, freezeTimer = -6, killerId, playerIndex, oldPlayerIndex, lastWeaponUsed, projectileStage, crystalBowArrowCount, playerMagicBook, teleGfx, teleEndAnimation, teleHeight, teleX, teleY, rangeItemUsed, killingNpcIndex, totalDamageDealt, oldNpcIndex, fightMode, attackTimer, npcIndex,npcClickIndex, npcType, castingSpellId, oldSpellId, spellId, hitDelay;
  305. public boolean magicFailed, oldMagicFailed;
  306. public int bowSpecShot, clickNpcType, clickObjectType, objectId, objectX, objectY, objectXOffset, objectYOffset, objectDistance;
  307. public int pItemX, pItemY, pItemId;
  308. public boolean isMoving, walkingToItem;
  309. public boolean isShopping, updateShop;
  310. public int myShopId;
  311. public int tradeStatus, tradeWith;
  312. public boolean forcedChatUpdateRequired, inDuel, tradeAccepted, goodTrade, inTrade, tradeRequested, tradeResetNeeded, tradeConfirmed, tradeConfirmed2, canOffer, acceptTrade, acceptedTrade;
  313. public int attackAnim, animationRequest = -1,animationWaitCycles;
  314. public int[] playerBonus = new int[12];
  315. public boolean isRunning2 = true;
  316. public boolean takeAsNote;
  317. public int combatLevel;
  318. public boolean saveFile = false;
  319. public int playerAppearance[] = new int[13];
  320. public int apset;
  321. public int actionID;
  322. public int wearItemTimer, wearId, wearSlot, interfaceId;
  323. public int XremoveSlot, XinterfaceID, XremoveID, Xamount;
  324.  
  325. public int tutorial = 15;
  326. public boolean usingGlory = false;
  327. public int[] woodcut = new int [3];
  328. public int wcTimer = 0;
  329. public int[] mining = new int [3];
  330. public int miningTimer = 0;
  331. public boolean fishing = false;
  332. public int fishTimer = 0;
  333. public int smeltType; //1 = bronze, 2 = iron, 3 = steel, 4 = gold, 5 = mith, 6 = addy, 7 = rune
  334. public int smeltAmount;
  335. public int smeltTimer = 0;
  336. public boolean smeltInterface;
  337. public boolean patchCleared;
  338. public int[] farm = new int[2];
  339.  
  340.  
  341. public boolean antiFirePot = false;
  342.  
  343. /**
  344. * Castle Wars
  345. */
  346. public int castleWarsTeam;
  347. public boolean inCwGame;
  348. public boolean inCwWait;
  349.  
  350. /**
  351. * Fight Pits
  352. */
  353. public boolean inPits = false;
  354. public int pitsStatus = 0;
  355.  
  356. /**
  357. * SouthWest, NorthEast, SouthWest, NorthEast
  358. */
  359.  
  360. public boolean isInTut() {
  361. if(absX >= 2625 && absX <= 2687 && absY >= 4670 && absY <= 4735) {
  362. return true;
  363. }
  364. return false;
  365. }
  366.  
  367. public boolean inBarrows() {
  368. if(absX > 3520 && absX < 3598 && absY > 9653 && absY < 9750) {
  369. return true;
  370. }
  371. return false;
  372. }
  373.  
  374.  
  375. public boolean inArea(int x, int y, int x1, int y1) {
  376. if (absX > x && absX < x1 && absY < y && absY > y1) {
  377. return true;
  378. }
  379. return false;
  380. }
  381.  
  382. public boolean inWild() {
  383. if(absX > 2941 && absX < 3392 && absY > 3518 && absY < 3966 ||
  384. absX > 2941 && absX < 3392 && absY > 9918 && absY < 10366) {
  385. return true;
  386. }
  387. return false;
  388. }
  389.  
  390. public boolean arenas() {
  391. if(absX > 3331 && absX < 3391 && absY > 3242 && absY < 3260) {
  392. return true;
  393. }
  394. return false;
  395. }
  396.  
  397. public boolean inDuelArena() {
  398. if((absX > 3322 && absX < 3394 && absY > 3195 && absY < 3291) ||
  399. (absX > 3311 && absX < 3323 && absY > 3223 && absY < 3248)) {
  400. return true;
  401. }
  402. return false;
  403. }
  404.  
  405. public boolean inMulti() {
  406. if((absX >= 3136 && absX <= 3327 && absY >= 3519 && absY <= 3607) ||
  407. (absX >= 3190 && absX <= 3327 && absY >= 3648 && absY <= 3839) ||
  408. (absX >= 3200 && absX <= 3390 && absY >= 3840 && absY <= 3967) ||
  409. (absX >= 2992 && absX <= 3007 && absY >= 3912 && absY <= 3967) ||
  410. (absX >= 2946 && absX <= 2959 && absY >= 3816 && absY <= 3831) ||
  411. (absX >= 3008 && absX <= 3199 && absY >= 3856 && absY <= 3903) ||
  412. (absX >= 3008 && absX <= 3071 && absY >= 3600 && absY <= 3711) ||
  413. (absX >= 3072 && absX <= 3327 && absY >= 3608 && absY <= 3647) ||
  414. (absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619) ||
  415. (absX >= 2371 && absX <= 2422 && absY >= 5062 && absY <= 5117) ||
  416. (absX >= 2896 && absX <= 2927 && absY >= 3595 && absY <= 3630) ||
  417. (absX >= 2892 && absX <= 2932 && absY >= 4435 && absY <= 4464) ||
  418. (absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711)) {
  419. return true;
  420. }
  421. return false;
  422. }
  423.  
  424. public boolean inFightCaves()
  425. {
  426. return absX >= 2360 && absX <= 2445 && absY >= 5045 && absY <= 5125;
  427. }
  428.  
  429. public boolean inPirateHouse() {
  430. return absX >= 3038 && absX <= 3044 && absY >= 3949 && absY <= 3959;
  431. }
  432.  
  433.  
  434. public String connectedFrom="";
  435. public String globalMessage="";
  436. public abstract void initialize();
  437. public abstract void update();
  438. public int playerId = -1;
  439. public String playerName = null;
  440. public String playerName2 = null;
  441. public String playerPass = null;
  442. public int playerRights;
  443. public PlayerHandler handler = null;
  444. public int playerItems[] = new int[28];
  445. public int playerItemsN[] = new int[28];
  446. public int bankItems[] = new int[Config.BANK_SIZE];
  447. public int bankItemsN[] = new int[Config.BANK_SIZE];
  448. public boolean bankNotes = false;
  449.  
  450. public int playerStandIndex = 0x328;
  451. public int playerTurnIndex = 0x337;
  452. public int playerWalkIndex = 0x333;
  453. public int playerTurn180Index = 0x334;
  454. public int playerTurn90CWIndex = 0x335;
  455. public int playerTurn90CCWIndex = 0x336;
  456. public int playerRunIndex = 0x338;
  457.  
  458. public int playerHat=0;
  459. public int playerCape=1;
  460. public int playerAmulet=2;
  461. public int playerWeapon=3;
  462. public int playerChest=4;
  463. public int playerShield=5;
  464. public int playerLegs=7;
  465. public int playerHands=9;
  466. public int playerFeet=10;
  467. public int playerRing=12;
  468. public int playerArrows=13;
  469.  
  470. public int playerAttack = 0;
  471. public int playerDefence = 1;
  472. public int playerStrength = 2;
  473. public int playerHitpoints = 3;
  474. public int playerRanged = 4;
  475. public int playerPrayer = 5;
  476. public int playerMagic = 6;
  477. public int playerCooking = 7;
  478. public int playerWoodcutting = 8;
  479. public int playerFletching = 9;
  480. public int playerFishing = 10;
  481. public int playerFiremaking = 11;
  482. public int playerCrafting = 12;
  483. public int playerSmithing = 13;
  484. public int playerMining = 14;
  485. public int playerHerblore = 15;
  486. public int playerAgility = 16;
  487. public int playerThieving = 17;
  488. public int playerSlayer = 18;
  489. public int playerFarming = 19;
  490. public int playerRunecrafting = 20;
  491.  
  492. public int[] playerEquipment = new int[14];
  493. public int[] playerEquipmentN = new int[14];
  494. public int[] playerLevel = new int[25];
  495. public int[] playerXP = new int[25];
  496.  
  497. public void updateshop(int i){
  498. Client p = (Client) Server.playerHandler.players[playerId];
  499. p.getShops().resetShop(i);
  500. }
  501.  
  502. public void println_debug(String str) {
  503. System.out.println("[player-"+playerId+"]: "+str);
  504. }
  505. public void println(String str) {
  506. System.out.println("[player-"+playerId+"]: "+str);
  507. }
  508. public Player(int _playerId) {
  509. playerId = _playerId;
  510. playerRights = 0;
  511.  
  512. for (int i=0; i<playerItems.length; i++) {
  513. playerItems[i] = 0;
  514. }
  515. for (int i=0; i<playerItemsN.length; i++) {
  516. playerItemsN[i] = 0;
  517. }
  518.  
  519. for (int i=0; i<playerLevel.length; i++) {
  520. if (i == 3) {
  521. playerLevel[i] = 10;
  522. } else {
  523. playerLevel[i] = 1;
  524. }
  525. }
  526.  
  527. for (int i=0; i<playerXP.length; i++) {
  528. if (i == 3) {
  529. playerXP[i] = 1300;
  530. } else {
  531. playerXP[i] = 0;
  532. }
  533. }
  534. for (int i=0; i < Config.BANK_SIZE; i++) {
  535. bankItems[i] = 0;
  536. }
  537.  
  538. for (int i=0; i < Config.BANK_SIZE; i++) {
  539. bankItemsN[i] = 0;
  540. }
  541.  
  542. playerAppearance[0] = 0; // gender
  543. playerAppearance[1] = 7; // head
  544. playerAppearance[2] = 25;// Torso
  545. playerAppearance[3] = 29; // arms
  546. playerAppearance[4] = 35; // hands
  547. playerAppearance[5] = 39; // legs
  548. playerAppearance[6] = 44; // feet
  549. playerAppearance[7] = 14; // beard
  550. playerAppearance[8] = 7; // hair colour
  551. playerAppearance[9] = 8; // torso colour
  552. playerAppearance[10] = 9; // legs colour
  553. playerAppearance[11] = 5; // feet colour
  554. playerAppearance[12] = 0; // skin colour
  555.  
  556. apset = 0;
  557. actionID = 0;
  558.  
  559. playerEquipment[playerHat]=-1;
  560. playerEquipment[playerCape]=-1;
  561. playerEquipment[playerAmulet]=-1;
  562. playerEquipment[playerChest]=-1;
  563. playerEquipment[playerShield]=-1;
  564. playerEquipment[playerLegs]=-1;
  565. playerEquipment[playerHands]=-1;
  566. playerEquipment[playerFeet]=-1;
  567. playerEquipment[playerRing]=-1;
  568. playerEquipment[playerArrows]=-1;
  569. playerEquipment[playerWeapon]=-1;
  570.  
  571. heightLevel = 0;
  572.  
  573. teleportToX = Config.START_LOCATION_X;
  574. teleportToY = Config.START_LOCATION_Y;
  575.  
  576.  
  577. absX = absY = -1;
  578. mapRegionX = mapRegionY = -1;
  579. currentX = currentY = 0;
  580. resetWalkingQueue();
  581. }
  582.  
  583. void destruct() {
  584. playerListSize = 0;
  585. for(int i = 0; i < maxPlayerListSize; i++)
  586. playerList[i] = null;
  587. absX = absY = -1;
  588. mapRegionX = mapRegionY = -1;
  589. currentX = currentY = 0;
  590. resetWalkingQueue();
  591. }
  592.  
  593.  
  594. public static final int maxPlayerListSize = Config.MAX_PLAYERS;
  595. public Player playerList[] = new Player[maxPlayerListSize];
  596. public int playerListSize = 0;
  597.  
  598.  
  599. public byte playerInListBitmap[] = new byte[(Config.MAX_PLAYERS+7) >> 3];
  600.  
  601.  
  602. public static final int maxNPCListSize = NPCHandler.maxNPCs;
  603. public NPC npcList[] = new NPC[maxNPCListSize];
  604. public int npcListSize = 0;
  605.  
  606. public byte npcInListBitmap[] = new byte[(NPCHandler.maxNPCs+7) >> 3];
  607.  
  608.  
  609.  
  610. public boolean withinDistance(Player otherPlr) {
  611. if(heightLevel != otherPlr.heightLevel) return false;
  612. int deltaX = otherPlr.absX-absX, deltaY = otherPlr.absY-absY;
  613. return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  614. }
  615.  
  616. public boolean withinDistance(NPC npc) {
  617. if (heightLevel != npc.heightLevel) return false;
  618. if (npc.needRespawn == true) return false;
  619. int deltaX = npc.absX-absX, deltaY = npc.absY-absY;
  620. return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  621. }
  622.  
  623. public int distanceToPoint(int pointX,int pointY) {
  624. return (int) Math.sqrt(Math.pow(absX - pointX, 2) + Math.pow(absY - pointY, 2));
  625. }
  626.  
  627. public int mapRegionX, mapRegionY;
  628. public int absX, absY;
  629. public int currentX, currentY;
  630.  
  631. public int heightLevel;
  632. public int playerSE = 0x328;
  633. public int playerSEW = 0x333;
  634. public int playerSER = 0x334;
  635.  
  636. public boolean updateRequired = true;
  637.  
  638.  
  639. public final int walkingQueueSize = 50;
  640. public int walkingQueueX[] = new int[walkingQueueSize], walkingQueueY[] = new int[walkingQueueSize];
  641. public int wQueueReadPtr = 0;
  642. public int wQueueWritePtr = 0;
  643. public boolean isRunning = true;
  644. public int teleportToX = -1, teleportToY = -1;
  645.  
  646. public void resetWalkingQueue() {
  647. wQueueReadPtr = wQueueWritePtr = 0;
  648.  
  649. for(int i = 0; i < walkingQueueSize; i++) {
  650. walkingQueueX[i] = currentX;
  651. walkingQueueY[i] = currentY;
  652. }
  653. }
  654.  
  655. public void addToWalkingQueue(int x, int y) {
  656. //if (VirtualWorld.I(heightLevel, absX, absY, x, y, 0)) {
  657. int next = (wQueueWritePtr+1) % walkingQueueSize;
  658. if(next == wQueueWritePtr) return;
  659. walkingQueueX[wQueueWritePtr] = x;
  660. walkingQueueY[wQueueWritePtr] = y;
  661. wQueueWritePtr = next;
  662. //}
  663. }
  664.  
  665. public boolean goodDistance(int objectX, int objectY, int playerX, int playerY, int distance) {
  666. for (int i = 0; i <= distance; i++) {
  667. for (int j = 0; j <= distance; j++) {
  668. if ((objectX + i) == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
  669. return true;
  670. } else if ((objectX - i) == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
  671. return true;
  672. } else if (objectX == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
  673. return true;
  674. }
  675. }
  676. }
  677. return false;
  678. }
  679.  
  680. public int getNextWalkingDirection() {
  681. if(wQueueReadPtr == wQueueWritePtr)
  682. return -1;
  683. int dir;
  684. do {
  685. dir = Misc.direction(currentX, currentY, walkingQueueX[wQueueReadPtr], walkingQueueY[wQueueReadPtr]);
  686. if(dir == -1) {
  687. wQueueReadPtr = (wQueueReadPtr+1) % walkingQueueSize;
  688. } else if((dir&1) != 0) {
  689. println_debug("Invalid waypoint in walking queue!");
  690. resetWalkingQueue();
  691. return -1;
  692. }
  693. } while((dir == -1) && (wQueueReadPtr != wQueueWritePtr));
  694. if(dir == -1) return -1;
  695. dir >>= 1;
  696. currentX += Misc.directionDeltaX[dir];
  697. currentY += Misc.directionDeltaY[dir];
  698. absX += Misc.directionDeltaX[dir];
  699. absY += Misc.directionDeltaY[dir];
  700. return dir;
  701. }
  702.  
  703.  
  704. public boolean didTeleport = false;
  705. public boolean mapRegionDidChange = false;
  706. public int dir1 = -1, dir2 = -1;
  707. public boolean createItems = false;
  708. public int poimiX = 0, poimiY = 0;
  709.  
  710. public synchronized void getNextPlayerMovement() {
  711. mapRegionDidChange = false;
  712. didTeleport = false;
  713. dir1 = dir2 = -1;
  714.  
  715. if(teleportToX != -1 && teleportToY != -1) {
  716. mapRegionDidChange = true;
  717. if(mapRegionX != -1 && mapRegionY != -1) {
  718. int relX = teleportToX-mapRegionX*8, relY = teleportToY-mapRegionY*8;
  719. if(relX >= 2*8 && relX < 11*8 && relY >= 2*8 && relY < 11*8)
  720. mapRegionDidChange = false;
  721. }
  722. if(mapRegionDidChange) {
  723. mapRegionX = (teleportToX>>3)-6;
  724. mapRegionY = (teleportToY>>3)-6;
  725. }
  726. currentX = teleportToX - 8*mapRegionX;
  727. currentY = teleportToY - 8*mapRegionY;
  728. absX = teleportToX;
  729. absY = teleportToY;
  730. resetWalkingQueue();
  731.  
  732. teleportToX = teleportToY = -1;
  733. didTeleport = true;
  734. } else {
  735. dir1 = getNextWalkingDirection();
  736. if(dir1 == -1)
  737. return;
  738. if(isRunning) {
  739. dir2 = getNextWalkingDirection();
  740. }
  741. Client c = (Client)this;
  742. //c.sendMessage("Cycle Ended");
  743. int deltaX = 0, deltaY = 0;
  744. if(currentX < 2*8) {
  745. deltaX = 4*8;
  746. mapRegionX -= 4;
  747. mapRegionDidChange = true;
  748. } else if(currentX >= 11*8) {
  749. deltaX = -4*8;
  750. mapRegionX += 4;
  751. mapRegionDidChange = true;
  752. }
  753. if(currentY < 2*8) {
  754. deltaY = 4*8;
  755. mapRegionY -= 4;
  756. mapRegionDidChange = true;
  757. } else if(currentY >= 11*8) {
  758. deltaY = -4*8;
  759. mapRegionY += 4;
  760. mapRegionDidChange = true;
  761. }
  762.  
  763. if(mapRegionDidChange/* && VirtualWorld.I(heightLevel, currentX, currentY, currentX + deltaX, currentY + deltaY, 0)*/) {
  764. currentX += deltaX;
  765. currentY += deltaY;
  766. for(int i = 0; i < walkingQueueSize; i++) {
  767. walkingQueueX[i] += deltaX;
  768. walkingQueueY[i] += deltaY;
  769. }
  770. }
  771. //CoordAssistant.processCoords(this);
  772.  
  773. }
  774. }
  775.  
  776.  
  777. public void updateThisPlayerMovement(Stream str) {
  778. synchronized(this) {
  779. if(mapRegionDidChange) {
  780. str.createFrame(73);
  781. str.writeWordA(mapRegionX+6);
  782. str.writeWord(mapRegionY+6);
  783. }
  784.  
  785. if(didTeleport) {
  786. str.createFrameVarSizeWord(81);
  787. str.initBitAccess();
  788. str.writeBits(1, 1);
  789. str.writeBits(2, 3);
  790. str.writeBits(2, heightLevel);
  791. str.writeBits(1, 1);
  792. str.writeBits(1, (updateRequired) ? 1 : 0);
  793. str.writeBits(7, currentY);
  794. str.writeBits(7, currentX);
  795. return ;
  796. }
  797.  
  798.  
  799. if(dir1 == -1) {
  800. // don't have to update the character position, because we're just standing
  801. str.createFrameVarSizeWord(81);
  802. str.initBitAccess();
  803. isMoving = false;
  804. if(updateRequired) {
  805. // tell client there's an update block appended at the end
  806. str.writeBits(1, 1);
  807. str.writeBits(2, 0);
  808. } else {
  809. str.writeBits(1, 0);
  810. }
  811. if (DirectionCount < 50) {
  812. DirectionCount++;
  813. }
  814. } else {
  815. DirectionCount = 0;
  816. str.createFrameVarSizeWord(81);
  817. str.initBitAccess();
  818. str.writeBits(1, 1);
  819.  
  820. if(dir2 == -1) {
  821. isMoving = true;
  822. str.writeBits(2, 1);
  823. str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  824. if(updateRequired) str.writeBits(1, 1);
  825. else str.writeBits(1, 0);
  826. }
  827. else {
  828. isMoving = true;
  829. str.writeBits(2, 2);
  830. str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  831. str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  832. if(updateRequired) str.writeBits(1, 1);
  833. else str.writeBits(1, 0);
  834. }
  835. }
  836. }
  837. }
  838.  
  839.  
  840. public void updatePlayerMovement(Stream str) {
  841. synchronized(this) {
  842. if(dir1 == -1) {
  843. if(updateRequired || isChatTextUpdateRequired()) {
  844.  
  845. str.writeBits(1, 1);
  846. str.writeBits(2, 0);
  847. }
  848. else str.writeBits(1, 0);
  849. }
  850. else if(dir2 == -1) {
  851.  
  852. str.writeBits(1, 1);
  853. str.writeBits(2, 1);
  854. str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  855. str.writeBits(1, (updateRequired || isChatTextUpdateRequired()) ? 1: 0);
  856. }
  857. else {
  858.  
  859. str.writeBits(1, 1);
  860. str.writeBits(2, 2);
  861. str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  862. str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  863. str.writeBits(1, (updateRequired || isChatTextUpdateRequired()) ? 1: 0);
  864. }
  865. }
  866. }
  867.  
  868.  
  869. public byte cachedPropertiesBitmap[] = new byte[(Config.MAX_PLAYERS+7) >> 3];
  870.  
  871. public void addNewNPC(NPC npc, Stream str, Stream updateBlock) {
  872. synchronized(this) {
  873. int id = npc.npcId;
  874. npcInListBitmap[id >> 3] |= 1 << (id&7);
  875. npcList[npcListSize++] = npc;
  876.  
  877. str.writeBits(14, id);
  878.  
  879. int z = npc.absY-absY;
  880. if(z < 0) z += 32;
  881. str.writeBits(5, z);
  882. z = npc.absX-absX;
  883. if(z < 0) z += 32;
  884. str.writeBits(5, z);
  885.  
  886. str.writeBits(1, 0);
  887. str.writeBits(12, npc.npcType);
  888.  
  889. boolean savedUpdateRequired = npc.updateRequired;
  890. npc.updateRequired = true;
  891. npc.appendNPCUpdateBlock(updateBlock);
  892. npc.updateRequired = savedUpdateRequired;
  893. str.writeBits(1, 1);
  894. }
  895. }
  896.  
  897. public void addNewPlayer(Player plr, Stream str, Stream updateBlock) {
  898. synchronized(this) {
  899. if(playerListSize >= 255) {
  900. return;
  901. }
  902. int id = plr.playerId;
  903. playerInListBitmap[id >> 3] |= 1 << (id&7);
  904. playerList[playerListSize++] = plr;
  905. str.writeBits(11, id);
  906. str.writeBits(1, 1);
  907. boolean savedFlag = plr.isAppearanceUpdateRequired();
  908. boolean savedUpdateRequired = plr.updateRequired;
  909. plr.setAppearanceUpdateRequired(true);
  910. plr.updateRequired = true;
  911. plr.appendPlayerUpdateBlock(updateBlock);
  912. plr.setAppearanceUpdateRequired(savedFlag);
  913. plr.updateRequired = savedUpdateRequired;
  914. str.writeBits(1, 1);
  915. int z = plr.absY-absY;
  916. if(z < 0) z += 32;
  917. str.writeBits(5, z);
  918. z = plr.absX-absX;
  919. if(z < 0) z += 32;
  920. str.writeBits(5, z);
  921. }
  922. }
  923.  
  924. public int DirectionCount = 0;
  925. private boolean appearanceUpdateRequired = true;
  926. protected int hitDiff2;
  927. private int hitDiff = 0;
  928. protected boolean hitUpdateRequired2;
  929. private boolean hitUpdateRequired = false;
  930. public boolean isDead = false;
  931.  
  932. protected static Stream playerProps;
  933. static {
  934. playerProps = new Stream(new byte[100]);
  935. }
  936. protected void appendPlayerAppearance(Stream str) {
  937. synchronized(this) {
  938. playerProps.currentOffset = 0;
  939.  
  940. playerProps.writeByte(playerAppearance[0]);
  941.  
  942. playerProps.writeByte(headIcon);
  943. playerProps.writeByte(headIconPk);
  944. //playerProps.writeByte(headIconHints);
  945. //playerProps.writeByte(bountyIcon);
  946.  
  947. if (playerEquipment[playerHat] > 1) {
  948. playerProps.writeWord(0x200 + playerEquipment[playerHat]);
  949. } else {
  950. playerProps.writeByte(0);
  951. }
  952.  
  953. if (playerEquipment[playerCape] > 1) {
  954. playerProps.writeWord(0x200 + playerEquipment[playerCape]);
  955. } else {
  956. playerProps.writeByte(0);
  957. }
  958.  
  959. if (playerEquipment[playerAmulet] > 1) {
  960. playerProps.writeWord(0x200 + playerEquipment[playerAmulet]);
  961. } else {
  962. playerProps.writeByte(0);
  963. }
  964.  
  965. if (playerEquipment[playerWeapon] > 1) {
  966. playerProps.writeWord(0x200 + playerEquipment[playerWeapon]);
  967. } else {
  968. playerProps.writeByte(0);
  969. }
  970.  
  971. if (playerEquipment[playerChest] > 1) {
  972. playerProps.writeWord(0x200 + playerEquipment[playerChest]);
  973. } else {
  974. playerProps.writeWord(0x100+playerAppearance[2]);
  975. }
  976.  
  977. if (playerEquipment[playerShield] > 1) {
  978. playerProps.writeWord(0x200 + playerEquipment[playerShield]);
  979. } else {
  980. playerProps.writeByte(0);
  981. }
  982.  
  983. if (!Item.isFullBody(playerEquipment[playerChest])) {
  984. playerProps.writeWord(0x100+playerAppearance[3]);
  985. } else {
  986. playerProps.writeByte(0);
  987. }
  988.  
  989. if (playerEquipment[playerLegs] > 1) {
  990. playerProps.writeWord(0x200 + playerEquipment[playerLegs]);
  991. } else {
  992. playerProps.writeWord(0x100+playerAppearance[5]);
  993. }
  994.  
  995. if (!Item.isFullHelm(playerEquipment[playerHat]) && !Item.isFullMask(playerEquipment[playerHat])) {
  996. playerProps.writeWord(0x100 + playerAppearance[1]);
  997. } else {
  998. playerProps.writeByte(0);
  999. }
  1000.  
  1001. if (playerEquipment[playerHands] > 1) {
  1002. playerProps.writeWord(0x200 + playerEquipment[playerHands]);
  1003. } else {
  1004. playerProps.writeWord(0x100+playerAppearance[4]);
  1005. }
  1006.  
  1007. if (playerEquipment[playerFeet] > 1) {
  1008. playerProps.writeWord(0x200 + playerEquipment[playerFeet]);
  1009. } else {
  1010. playerProps.writeWord(0x100+playerAppearance[6]);
  1011. }
  1012.  
  1013. if (playerAppearance[0] != 1 && !Item.isFullMask(playerEquipment[playerHat])) {
  1014. playerProps.writeWord(0x100 + playerAppearance[7]);
  1015. } else {
  1016. playerProps.writeByte(0);
  1017. }
  1018.  
  1019. playerProps.writeByte(playerAppearance[8]);
  1020. playerProps.writeByte(playerAppearance[9]);
  1021. playerProps.writeByte(playerAppearance[10]);
  1022. playerProps.writeByte(playerAppearance[11]);
  1023. playerProps.writeByte(playerAppearance[12]);
  1024. playerProps.writeWord(playerStandIndex); // standAnimIndex
  1025. playerProps.writeWord(playerTurnIndex); // standTurnAnimIndex
  1026. playerProps.writeWord(playerWalkIndex); // walkAnimIndex
  1027. playerProps.writeWord(playerTurn180Index); // turn180AnimIndex
  1028. playerProps.writeWord(playerTurn90CWIndex); // turn90CWAnimIndex
  1029. playerProps.writeWord(playerTurn90CCWIndex); // turn90CCWAnimIndex
  1030. playerProps.writeWord(playerRunIndex); // runAnimIndex
  1031.  
  1032. playerProps.writeQWord(Misc.playerNameToInt64(playerName));
  1033.  
  1034. int mag = (int) ((getLevelForXP(playerXP[6])) * 1.5);
  1035. int ran = (int) ((getLevelForXP(playerXP[4])) * 1.5);
  1036. int attstr = (int) ((double) (getLevelForXP(playerXP[0])) + (double) (getLevelForXP(playerXP[2])));
  1037.  
  1038. combatLevel = 0;
  1039. if (ran > attstr) {
  1040. combatLevel = (int) (((getLevelForXP(playerXP[1])) * 0.25)
  1041. + ((getLevelForXP(playerXP[3])) * 0.25)
  1042. + ((getLevelForXP(playerXP[5])) * 0.125) + ((getLevelForXP(playerXP[4])) * 0.4875));
  1043. } else if (mag > attstr) {
  1044. combatLevel = (int) (((getLevelForXP(playerXP[1])) * 0.25)
  1045. + ((getLevelForXP(playerXP[3])) * 0.25)
  1046. + ((getLevelForXP(playerXP[5])) * 0.125) + ((getLevelForXP(playerXP[6])) * 0.4875));
  1047. } else {
  1048. combatLevel = (int) (((getLevelForXP(playerXP[1])) * 0.25)
  1049. + ((getLevelForXP(playerXP[3])) * 0.25)
  1050. + ((getLevelForXP(playerXP[5])) * 0.125)
  1051. + ((getLevelForXP(playerXP[0])) * 0.325) + ((getLevelForXP(playerXP[2])) * 0.325));
  1052. }
  1053. playerProps.writeByte(combatLevel); // combat level
  1054. playerProps.writeWord(0);
  1055. str.writeByteC(playerProps.currentOffset);
  1056. str.writeBytes(playerProps.buffer, playerProps.currentOffset, 0);
  1057. }
  1058. }
  1059.  
  1060.  
  1061. public int getLevelForXP(int exp) {
  1062. int points = 0;
  1063. int output = 0;
  1064.  
  1065. for (int lvl = 1; lvl <= 99; lvl++) {
  1066. points += Math.floor((double)lvl + 300.0 * Math.pow(2.0, (double)lvl / 7.0));
  1067. output = (int)Math.floor(points / 4);
  1068. if (output >= exp)
  1069. return lvl;
  1070. }
  1071. return 99;
  1072. }
  1073.  
  1074. private boolean chatTextUpdateRequired = false;
  1075. private byte chatText[] = new byte[4096];
  1076. private byte chatTextSize = 0;
  1077. private int chatTextColor = 0;
  1078. private int chatTextEffects = 0;
  1079.  
  1080. protected void appendPlayerChatText(Stream str) {
  1081. synchronized(this) {
  1082. str.writeWordBigEndian(((getChatTextColor()&0xFF) << 8) + (getChatTextEffects()&0xFF));
  1083. str.writeByte(playerRights);
  1084. str.writeByteC(getChatTextSize());
  1085. str.writeBytes_reverse(getChatText(), getChatTextSize(), 0);
  1086. }
  1087. }
  1088.  
  1089. public void forcedChat(String text) {
  1090. forcedText = text;
  1091. forcedChatUpdateRequired = true;
  1092. updateRequired = true;
  1093. setAppearanceUpdateRequired(true);
  1094. }
  1095. public String forcedText = "null";
  1096. public void appendForcedChat(Stream str) {
  1097. synchronized(this) {
  1098. str.writeString(forcedText);
  1099. }
  1100. }
  1101.  
  1102. /**
  1103. *Graphics
  1104. **/
  1105.  
  1106. public int mask100var1 = 0;
  1107. public int mask100var2 = 0;
  1108. protected boolean mask100update = false;
  1109.  
  1110. public void appendMask100Update(Stream str) {
  1111. synchronized(this) {
  1112. str.writeWordBigEndian(mask100var1);
  1113. str.writeDWord(mask100var2);
  1114. }
  1115. }
  1116.  
  1117. public void gfx100(int gfx) {
  1118. mask100var1 = gfx;
  1119. mask100var2 = 6553600;
  1120. mask100update = true;
  1121. updateRequired = true;
  1122. }
  1123. public void gfx0(int gfx) {
  1124. mask100var1 = gfx;
  1125. mask100var2 = 65536;
  1126. mask100update = true;
  1127. updateRequired = true;
  1128. }
  1129.  
  1130. public boolean wearing2h() {
  1131. Client c = (Client)this;
  1132. String s = c.getItems().getItemName(c.playerEquipment[c.playerWeapon]);
  1133. if (s.contains("2h"))
  1134. return true;
  1135. else if (s.contains("godsword"))
  1136. return true;
  1137. return false;
  1138. }
  1139.  
  1140. /**
  1141. *Animations
  1142. **/
  1143. public void startAnimation(int animId) {
  1144. if (wearing2h() && animId == 829)
  1145. return;
  1146. animationRequest = animId;
  1147. animationWaitCycles = 0;
  1148. updateRequired = true;
  1149. }
  1150.  
  1151. public void startAnimation(int animId, int time) {
  1152. animationRequest = animId;
  1153. animationWaitCycles = time;
  1154. updateRequired = true;
  1155. }
  1156.  
  1157. public void appendAnimationRequest(Stream str) {
  1158. synchronized(this) {
  1159. str.writeWordBigEndian((animationRequest==-1) ? 65535 : animationRequest);
  1160. str.writeByteC(animationWaitCycles);
  1161. }
  1162. }
  1163.  
  1164. /**
  1165. *Face Update
  1166. **/
  1167.  
  1168. protected boolean faceUpdateRequired = false;
  1169. public int face = -1;
  1170. public int FocusPointX = -1, FocusPointY = -1;
  1171.  
  1172. public void faceUpdate(int index) {
  1173. face = index;
  1174. faceUpdateRequired = true;
  1175. updateRequired = true;
  1176. }
  1177.  
  1178. public void appendFaceUpdate(Stream str) {
  1179. synchronized(this) {
  1180. str.writeWordBigEndian(face);
  1181. }
  1182. }
  1183.  
  1184. public void turnPlayerTo(int pointX, int pointY){
  1185. FocusPointX = 2*pointX+1;
  1186. FocusPointY = 2*pointY+1;
  1187. updateRequired = true;
  1188. }
  1189.  
  1190. private void appendSetFocusDestination(Stream str) {
  1191. synchronized(this) {
  1192. str.writeWordBigEndianA(FocusPointX);
  1193. str.writeWordBigEndian(FocusPointY);
  1194. }
  1195. }
  1196.  
  1197. /**
  1198. *Hit Update
  1199. **/
  1200.  
  1201. protected void appendHitUpdate(Stream str) {
  1202. synchronized(this) {
  1203. str.writeByte(getHitDiff()); // What the perseon got 'hit' for
  1204. if (poisonMask == 1) {
  1205. str.writeByteA(2);
  1206. } else if (getHitDiff() > 0) {
  1207. str.writeByteA(1); // 0: red hitting - 1: blue hitting
  1208. } else {
  1209. str.writeByteA(0); // 0: red hitting - 1: blue hitting
  1210. }
  1211. if (playerLevel[3] <= 0) {
  1212. playerLevel[3] = 0;
  1213. isDead = true;
  1214. }
  1215. str.writeByteC(playerLevel[3]); // Their current hp, for HP bar
  1216. str.writeByte(getLevelForXP(playerXP[3])); // Their max hp, for HP bar
  1217. }
  1218. }
  1219.  
  1220.  
  1221. protected void appendHitUpdate2(Stream str) {
  1222. synchronized(this) {
  1223. str.writeByte(hitDiff2); // What the perseon got 'hit' for
  1224. if (poisonMask == 2) {
  1225. str.writeByteS(2);
  1226. poisonMask = -1;
  1227. } else if (hitDiff2 > 0) {
  1228. str.writeByteS(1); // 0: red hitting - 1: blue hitting
  1229. } else {
  1230. str.writeByteS(0); // 0: red hitting - 1: blue hitting
  1231. }
  1232. if (playerLevel[3] <= 0) {
  1233. playerLevel[3] = 0;
  1234. isDead = true;
  1235. }
  1236. str.writeByte(playerLevel[3]); // Their current hp, for HP bar
  1237. str.writeByteC(getLevelForXP(playerXP[3])); // Their max hp, for HP bar
  1238. }
  1239. }
  1240.  
  1241.  
  1242. public void appendPlayerUpdateBlock(Stream str){
  1243. synchronized(this) {
  1244. if(!updateRequired && !isChatTextUpdateRequired()) return; // nothing required
  1245. int updateMask = 0;
  1246. if(mask100update) {
  1247. updateMask |= 0x100;
  1248. }
  1249. if(animationRequest != -1) {
  1250. updateMask |= 8;
  1251. }
  1252. if(forcedChatUpdateRequired) {
  1253. updateMask |= 4;
  1254. }
  1255. if(isChatTextUpdateRequired()) {
  1256. updateMask |= 0x80;
  1257. }
  1258. if(isAppearanceUpdateRequired()) {
  1259. updateMask |= 0x10;
  1260. }
  1261. if(faceUpdateRequired) {
  1262. updateMask |= 1;
  1263. }
  1264. if(FocusPointX != -1) {
  1265. updateMask |= 2;
  1266. }
  1267. if (isHitUpdateRequired()) {
  1268. updateMask |= 0x20;
  1269. }
  1270.  
  1271. if(hitUpdateRequired2) {
  1272. updateMask |= 0x200;
  1273. }
  1274.  
  1275. if(updateMask >= 0x100) {
  1276. updateMask |= 0x40;
  1277. str.writeByte(updateMask & 0xFF);
  1278. str.writeByte(updateMask >> 8);
  1279. } else {
  1280. str.writeByte(updateMask);
  1281. }
  1282.  
  1283. // now writing the various update blocks itself - note that their order crucial
  1284. if(mask100update) {
  1285. appendMask100Update(str);
  1286. }
  1287. if(animationRequest != -1) {
  1288. appendAnimationRequest(str);
  1289. }
  1290. if(forcedChatUpdateRequired) {
  1291. appendForcedChat(str);
  1292. }
  1293. if(isChatTextUpdateRequired()) {
  1294. appendPlayerChatText(str);
  1295. }
  1296. if(faceUpdateRequired) {
  1297. appendFaceUpdate(str);
  1298. }
  1299. if(isAppearanceUpdateRequired()) {
  1300. appendPlayerAppearance(str);
  1301. }
  1302. if(FocusPointX != -1) {
  1303. appendSetFocusDestination(str);
  1304. }
  1305. if(isHitUpdateRequired()) {
  1306. appendHitUpdate(str);
  1307. }
  1308. if(hitUpdateRequired2) {
  1309. appendHitUpdate2(str);
  1310. }
  1311. }
  1312. }
  1313.  
  1314. public void clearUpdateFlags(){
  1315. updateRequired = false;
  1316. setChatTextUpdateRequired(false);
  1317. setAppearanceUpdateRequired(false);
  1318. setHitUpdateRequired(false);
  1319. hitUpdateRequired2 = false;
  1320. forcedChatUpdateRequired = false;
  1321. mask100update = false;
  1322. animationRequest = -1;
  1323. FocusPointX = -1;
  1324. FocusPointY = -1;
  1325. poisonMask = -1;
  1326. faceUpdateRequired = false;
  1327. face = 65535;
  1328. }
  1329.  
  1330. public void stopMovement() {
  1331. if(teleportToX <= 0 && teleportToY <= 0) {
  1332. teleportToX = absX;
  1333. teleportToY = absY;
  1334. }
  1335. newWalkCmdSteps = 0;
  1336. getNewWalkCmdX()[0] = getNewWalkCmdY()[0] = travelBackX[0] = travelBackY[0] = 0;
  1337. getNextPlayerMovement();
  1338. }
  1339.  
  1340.  
  1341. private int newWalkCmdX[] = new int[walkingQueueSize];
  1342. private int newWalkCmdY[] = new int[walkingQueueSize];
  1343. public int newWalkCmdSteps = 0;
  1344. private boolean newWalkCmdIsRunning = false;
  1345. protected int travelBackX[] = new int[walkingQueueSize];
  1346. protected int travelBackY[] = new int[walkingQueueSize];
  1347. protected int numTravelBackSteps = 0;
  1348.  
  1349. public void preProcessing() {
  1350. newWalkCmdSteps = 0;
  1351. }
  1352.  
  1353. public abstract void process();
  1354. public abstract boolean processQueuedPackets();
  1355.  
  1356. public synchronized void postProcessing() {
  1357. if(newWalkCmdSteps > 0) {
  1358. int firstX = getNewWalkCmdX()[0], firstY = getNewWalkCmdY()[0];
  1359.  
  1360. int lastDir = 0;
  1361. boolean found = false;
  1362. numTravelBackSteps = 0;
  1363. int ptr = wQueueReadPtr;
  1364. int dir = Misc.direction(currentX, currentY, firstX, firstY);
  1365. if(dir != -1 && (dir&1) != 0) {
  1366. do {
  1367. lastDir = dir;
  1368. if(--ptr < 0)
  1369. ptr = walkingQueueSize-1;
  1370.  
  1371. travelBackX[numTravelBackSteps] = walkingQueueX[ptr];
  1372. travelBackY[numTravelBackSteps++] = walkingQueueY[ptr];
  1373. dir = Misc.direction(walkingQueueX[ptr], walkingQueueY[ptr], firstX, firstY);
  1374. if(lastDir != dir) {
  1375. found = true;
  1376. break;
  1377. }
  1378.  
  1379. } while(ptr != wQueueWritePtr);
  1380. }
  1381. else found = true;
  1382.  
  1383. if(!found) println_debug("Fatal: couldn't find connection vertex! Dropping packet.");
  1384. else {
  1385. wQueueWritePtr = wQueueReadPtr;
  1386.  
  1387. addToWalkingQueue(currentX, currentY);
  1388.  
  1389. if(dir != -1 && (dir&1) != 0) {
  1390.  
  1391.  
  1392. for(int i = 0; i < numTravelBackSteps-1; i++) {
  1393. addToWalkingQueue(travelBackX[i], travelBackY[i]);
  1394. }
  1395. int wayPointX2 = travelBackX[numTravelBackSteps-1], wayPointY2 = travelBackY[numTravelBackSteps-1];
  1396. int wayPointX1, wayPointY1;
  1397. if(numTravelBackSteps == 1) {
  1398. wayPointX1 = currentX;
  1399. wayPointY1 = currentY;
  1400. }
  1401. else {
  1402. wayPointX1 = travelBackX[numTravelBackSteps-2];
  1403. wayPointY1 = travelBackY[numTravelBackSteps-2];
  1404. }
  1405.  
  1406. dir = Misc.direction(wayPointX1, wayPointY1, wayPointX2, wayPointY2);
  1407. if(dir == -1 || (dir&1) != 0) {
  1408. println_debug("Fatal: The walking queue is corrupt! wp1=("+wayPointX1+", "+wayPointY1+"), "+
  1409. "wp2=("+wayPointX2+", "+wayPointY2+")");
  1410. }
  1411. else {
  1412. dir >>= 1;
  1413. found = false;
  1414. int x = wayPointX1, y = wayPointY1;
  1415. while(x != wayPointX2 || y != wayPointY2) {
  1416. x += Misc.directionDeltaX[dir];
  1417. y += Misc.directionDeltaY[dir];
  1418. if((Misc.direction(x, y, firstX, firstY)&1) == 0) {
  1419. found = true;
  1420. break;
  1421. }
  1422. }
  1423. if(!found) {
  1424. println_debug("Fatal: Internal error: unable to determine connection vertex!"+
  1425. " wp1=("+wayPointX1+", "+wayPointY1+"), wp2=("+wayPointX2+", "+wayPointY2+"), "+
  1426. "first=("+firstX+", "+firstY+")");
  1427. }
  1428. else addToWalkingQueue(wayPointX1, wayPointY1);
  1429. }
  1430. }
  1431. else {
  1432. for(int i = 0; i < numTravelBackSteps; i++) {
  1433. addToWalkingQueue(travelBackX[i], travelBackY[i]);
  1434. }
  1435. }
  1436.  
  1437.  
  1438. for(int i = 0; i < newWalkCmdSteps; i++) {
  1439. addToWalkingQueue(getNewWalkCmdX()[i], getNewWalkCmdY()[i]);
  1440. }
  1441.  
  1442. }
  1443.  
  1444. isRunning = isNewWalkCmdIsRunning() || isRunning2;
  1445. }
  1446. }
  1447.  
  1448. public int getMapRegionX() {
  1449. return mapRegionX;
  1450. }
  1451. public int getMapRegionY() {
  1452. return mapRegionY;
  1453. }
  1454.  
  1455. public int getX() {
  1456. return absX;
  1457. }
  1458.  
  1459. public int getY() {
  1460. return absY;
  1461. }
  1462.  
  1463. public int getId() {
  1464. return playerId;
  1465. }
  1466.  
  1467. public boolean inPcBoat() {
  1468. return absX >= 2660 && absX <= 2663 && absY >= 2638 && absY <= 2643;
  1469. }
  1470.  
  1471. public boolean inPcGame() {
  1472. return absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619;
  1473. }
  1474.  
  1475.  
  1476. public void setHitDiff(int hitDiff) {
  1477. this.hitDiff = hitDiff;
  1478. }
  1479.  
  1480. public void setHitDiff2(int hitDiff2) {
  1481. this.hitDiff2 = hitDiff2;
  1482. }
  1483.  
  1484.  
  1485. public int getHitDiff() {
  1486. return hitDiff;
  1487. }
  1488.  
  1489.  
  1490. public void setHitUpdateRequired(boolean hitUpdateRequired) {
  1491. this.hitUpdateRequired = hitUpdateRequired;
  1492. }
  1493.  
  1494. public void setHitUpdateRequired2(boolean hitUpdateRequired2) {
  1495. this.hitUpdateRequired2 = hitUpdateRequired2;
  1496. }
  1497.  
  1498.  
  1499. public boolean isHitUpdateRequired() {
  1500. return hitUpdateRequired;
  1501. }
  1502.  
  1503. public boolean getHitUpdateRequired() {
  1504. return hitUpdateRequired;
  1505. }
  1506.  
  1507. public boolean getHitUpdateRequired2() {
  1508. return hitUpdateRequired2;
  1509. }
  1510.  
  1511.  
  1512. public void setAppearanceUpdateRequired(boolean appearanceUpdateRequired) {
  1513. this.appearanceUpdateRequired = appearanceUpdateRequired;
  1514. }
  1515.  
  1516.  
  1517. public boolean isAppearanceUpdateRequired() {
  1518. return appearanceUpdateRequired;
  1519. }
  1520.  
  1521.  
  1522. public void setChatTextEffects(int chatTextEffects) {
  1523. this.chatTextEffects = chatTextEffects;
  1524. }
  1525.  
  1526.  
  1527. public int getChatTextEffects() {
  1528. return chatTextEffects;
  1529. }
  1530.  
  1531.  
  1532. public void setChatTextSize(byte chatTextSize) {
  1533. this.chatTextSize = chatTextSize;
  1534. }
  1535.  
  1536.  
  1537. public byte getChatTextSize() {
  1538. return chatTextSize;
  1539. }
  1540.  
  1541.  
  1542. public void setChatTextUpdateRequired(boolean chatTextUpdateRequired) {
  1543. this.chatTextUpdateRequired = chatTextUpdateRequired;
  1544. }
  1545.  
  1546.  
  1547. public boolean isChatTextUpdateRequired() {
  1548. return chatTextUpdateRequired;
  1549. }
  1550.  
  1551.  
  1552. public void setChatText(byte chatText[]) {
  1553. this.chatText = chatText;
  1554. }
  1555.  
  1556.  
  1557. public byte[] getChatText() {
  1558. return chatText;
  1559. }
  1560.  
  1561.  
  1562. public void setChatTextColor(int chatTextColor) {
  1563. this.chatTextColor = chatTextColor;
  1564. }
  1565.  
  1566.  
  1567. public int getChatTextColor() {
  1568. return chatTextColor;
  1569. }
  1570.  
  1571.  
  1572. public void setNewWalkCmdX(int newWalkCmdX[]) {
  1573. this.newWalkCmdX = newWalkCmdX;
  1574. }
  1575.  
  1576.  
  1577. public int[] getNewWalkCmdX() {
  1578. return newWalkCmdX;
  1579. }
  1580.  
  1581.  
  1582. public void setNewWalkCmdY(int newWalkCmdY[]) {
  1583. this.newWalkCmdY = newWalkCmdY;
  1584. }
  1585.  
  1586.  
  1587. public int[] getNewWalkCmdY() {
  1588. return newWalkCmdY;
  1589. }
  1590.  
  1591.  
  1592. public void setNewWalkCmdIsRunning(boolean newWalkCmdIsRunning) {
  1593. this.newWalkCmdIsRunning = newWalkCmdIsRunning;
  1594. }
  1595.  
  1596.  
  1597. public boolean isNewWalkCmdIsRunning() {
  1598. return newWalkCmdIsRunning;
  1599. }
  1600.  
  1601. private ISAACRandomGen inStreamDecryption = null, outStreamDecryption = null;
  1602.  
  1603. public void setInStreamDecryption(ISAACRandomGen inStreamDecryption) {
  1604. this.inStreamDecryption = inStreamDecryption;
  1605. }
  1606.  
  1607. public void setOutStreamDecryption(ISAACRandomGen outStreamDecryption) {
  1608. this.outStreamDecryption = outStreamDecryption;
  1609. }
  1610.  
  1611. public boolean samePlayer() {
  1612. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  1613. if (j == playerId)
  1614. continue;
  1615. if (Server.playerHandler.players[j] != null) {
  1616. if (Server.playerHandler.players[j].playerName.equalsIgnoreCase(playerName)) {
  1617. disconnected = true;
  1618. return true;
  1619. }
  1620. }
  1621. }
  1622. return false;
  1623. }
  1624.  
  1625. public void putInCombat(int attacker) {
  1626. underAttackBy = attacker;
  1627. logoutDelay = System.currentTimeMillis();
  1628. singleCombatDelay = System.currentTimeMillis();
  1629. }
  1630.  
  1631. public void dealDamage(int damage) {
  1632. if (teleTimer <= 0)
  1633. playerLevel[3] -= damage;
  1634. else {
  1635. if (hitUpdateRequired)
  1636. hitUpdateRequired = false;
  1637. if (hitUpdateRequired2)
  1638. hitUpdateRequired2 = false;
  1639. }
  1640.  
  1641. }
  1642.  
  1643. public int[] damageTaken = new int[Config.MAX_PLAYERS];
  1644.  
  1645. public void handleHitMask(int damage) {
  1646. if (!hitUpdateRequired) {
  1647. hitUpdateRequired = true;
  1648. hitDiff = damage;
  1649. } else if (!hitUpdateRequired2) {
  1650. hitUpdateRequired2 = true;
  1651. hitDiff2 = damage;
  1652. }
  1653. updateRequired = true;
  1654. }
  1655.  
  1656. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement