Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. HerosDetector = new(function(self = this) {
  2. class HerosAlert {
  3. constructor(npc) {
  4. this.npc = npc;
  5. this.alert = {
  6. main: document.createElement('div'),
  7. header: document.createElement('div'),
  8. name: document.createElement('div'),
  9. lvl: document.createElement('div'),
  10. imgWrapper: document.createElement('div'),
  11. img: document.createElement('img'),
  12. location: document.createElement('div'),
  13. controls: document.createElement('div'),
  14. callout: document.createElement('button'),
  15. close: document.createElement('button')
  16. }
  17. }
  18. draw() {
  19. Object.assign(this.alert.main.style, {
  20. position: 'absolute',
  21. zIndex: '499',
  22. top: '5px',
  23. left: '5px',
  24. border: '3px solid #753434',
  25. minWidth: '170px',
  26. width: 'auto',
  27. height: 'auto',
  28. display: 'table',
  29. background: 'url(img/console-back.jpg) no-repeat',
  30. ['box-shadow']: 'inset 0 0 0 100px #8209099c',
  31. ['-moz-box-shadow']: 'inset 0 0 0 100px #8209099c',
  32. ['-webkit-box-shadow']: 'inset 0 0 0 100px #8209099c',
  33. ['-ms-box-shadow']: 'inset 0 0 0 100px #8209099c',
  34. ['-o-box-shadow']: 'inset 0 0 0 100px #8209099c'
  35. });
  36. Object.assign(this.alert.header.style, {
  37. padding: '4px',
  38. height: '40px',
  39. lineHeight: '20px',
  40. marginLeft: '10px',
  41. marginRight: '10px',
  42. textAlign: 'center',
  43. color: 'white'
  44. });
  45. Object.assign(this.alert.name.style, {
  46. fontWeight: 'bold'
  47. });
  48. Object.assign(this.alert.lvl.style, {
  49. fontSize: '14px'
  50. });
  51. Object.assign(this.alert.imgWrapper.style, {
  52. display: 'grid',
  53. alignContent: 'center',
  54. justifyContent: 'center',
  55. padding: '10px'
  56. });
  57. Object.assign(this.alert.location.style, {
  58. height: '20px',
  59. padding: '4px',
  60. lineHeight: '20px',
  61. marginLeft: '10px',
  62. marginRight: '10px',
  63. textAlign: 'center',
  64. color: 'white'
  65. });
  66. Object.assign(this.alert.controls.style, {
  67. height: '35px',
  68. display: 'flex',
  69. justifyContent: 'center',
  70. alignContent: 'center'
  71. });
  72. [this.alert.callout, this.alert.close].forEach(e => {
  73. Object.assign(e.style, {
  74. margin: '4px',
  75. height: '20px',
  76. border: 'none',
  77. background: '#804668',
  78. color: 'white',
  79. borderRadius: '4px',
  80. fontSize: '11px'
  81. });
  82. });
  83.  
  84. this.alert.name.innerHTML = this.npc.nick;
  85. this.alert.lvl.innerHTML = `(${this.npc.lvl} lvl)`;
  86. this.alert.img.src = `https://www.margonem.pl/obrazki/npc/${this.npc.icon}`;
  87. this.alert.location.innerHTML = `(${this.npc.x}, ${this.npc.y})`;
  88.  
  89. this.alert.callout.innerHTML = "Zawołaj";
  90. this.alert.close.innerHTML = "Zamknij";
  91.  
  92. this.alert.header.appendChild(this.alert.name);
  93. this.alert.header.appendChild(this.alert.lvl);
  94. this.alert.imgWrapper.appendChild(this.alert.img);
  95. this.alert.controls.appendChild(this.alert.callout);
  96. this.alert.controls.appendChild(this.alert.close);
  97.  
  98. this.alert.main.appendChild(this.alert.header);
  99. this.alert.main.appendChild(this.alert.imgWrapper);
  100. this.alert.main.appendChild(this.alert.location);
  101. this.alert.main.appendChild(this.alert.controls);
  102.  
  103.  
  104. document.querySelector('#centerbox2').appendChild(this.alert.main);
  105. this.events();
  106. }
  107. events() {
  108. this.alert.callout.addEventListener('click', () => {
  109. chatSend(`/k NA RYJU! ${this.npc.nick} na mapie: ${map.name} (${this.npc.x}, ${this.npc.y})`);
  110. this.alert.main.remove();
  111. });
  112. this.alert.close.addEventListener('click', () => {
  113. this.alert.main.remove();
  114. });
  115. }
  116. }
  117.  
  118. this.newNpc = newNpc;
  119. newNpc = npcs => {
  120. if (isset(npcs)) {
  121. for (const npc of Object.values(npcs)) {
  122. if (isset(npc.nick) && npc.wt > 79 && npc.wt <= 99) {
  123. new HerosAlert(npc).draw();
  124. }
  125. }
  126. }
  127. self.newNpc.call(this, npcs);
  128. }
  129. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement