ExServerPrimitive.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import java.awt.Color;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.model.interfaces.ILocational;
  24. /**
  25. * A packet used to draw points and lines on client.<br/>
  26. * <b>Note:</b> Names in points and lines are bugged they will appear even when not looking at them.
  27. * @author NosBit
  28. */
  29. public class ExServerPrimitive extends L2GameServerPacket
  30. {
  31. private final String _name;
  32. private final int _x;
  33. private final int _y;
  34. private final int _z;
  35. private final List<Point> _points = new ArrayList<>();
  36. private final List<Line> _lines = new ArrayList<>();
  37. /**
  38. * @param name A unique name this will be used to replace lines if second packet is sent
  39. * @param x the x coordinate usually middle of drawing area
  40. * @param y the y coordinate usually middle of drawing area
  41. * @param z the z coordinate usually middle of drawing area
  42. */
  43. public ExServerPrimitive(String name, int x, int y, int z)
  44. {
  45. _name = name;
  46. _x = x;
  47. _y = y;
  48. _z = z;
  49. }
  50. /**
  51. * @param name A unique name this will be used to replace lines if second packet is sent
  52. * @param locational the ILocational to take coordinates usually middle of drawing area
  53. */
  54. public ExServerPrimitive(String name, ILocational locational)
  55. {
  56. this(name, locational.getX(), locational.getY(), locational.getZ());
  57. }
  58. /**
  59. * Adds a point to be displayed on client.
  60. * @param name the name that will be displayed over the point
  61. * @param color the color
  62. * @param isNameColored if {@code true} name will be colored as well.
  63. * @param x the x coordinate for this point
  64. * @param y the y coordinate for this point
  65. * @param z the z coordinate for this point
  66. */
  67. public void addPoint(String name, int color, boolean isNameColored, int x, int y, int z)
  68. {
  69. _points.add(new Point(name, color, isNameColored, x, y, z));
  70. }
  71. /**
  72. * Adds a point to be displayed on client.
  73. * @param name the name that will be displayed over the point
  74. * @param color the color
  75. * @param isNameColored if {@code true} name will be colored as well.
  76. * @param locational the ILocational to take coordinates for this point
  77. */
  78. public void addPoint(String name, int color, boolean isNameColored, ILocational locational)
  79. {
  80. addPoint(name, color, isNameColored, locational.getX(), locational.getY(), locational.getZ());
  81. }
  82. /**
  83. * Adds a point to be displayed on client.
  84. * @param color the color
  85. * @param x the x coordinate for this point
  86. * @param y the y coordinate for this point
  87. * @param z the z coordinate for this point
  88. */
  89. public void addPoint(int color, int x, int y, int z)
  90. {
  91. addPoint("", color, false, x, y, z);
  92. }
  93. /**
  94. * Adds a point to be displayed on client.
  95. * @param color the color
  96. * @param locational the ILocational to take coordinates for this point
  97. */
  98. public void addPoint(int color, ILocational locational)
  99. {
  100. addPoint("", color, false, locational);
  101. }
  102. /**
  103. * Adds a point to be displayed on client.
  104. * @param name the name that will be displayed over the point
  105. * @param color the color
  106. * @param isNameColored if {@code true} name will be colored as well.
  107. * @param x the x coordinate for this point
  108. * @param y the y coordinate for this point
  109. * @param z the z coordinate for this point
  110. */
  111. public void addPoint(String name, Color color, boolean isNameColored, int x, int y, int z)
  112. {
  113. addPoint(name, color.getRGB(), isNameColored, x, y, z);
  114. }
  115. /**
  116. * Adds a point to be displayed on client.
  117. * @param name the name that will be displayed over the point
  118. * @param color the color
  119. * @param isNameColored if {@code true} name will be colored as well.
  120. * @param locational the ILocational to take coordinates for this point
  121. */
  122. public void addPoint(String name, Color color, boolean isNameColored, ILocational locational)
  123. {
  124. addPoint(name, color.getRGB(), isNameColored, locational);
  125. }
  126. /**
  127. * Adds a point to be displayed on client.
  128. * @param color the color
  129. * @param x the x coordinate for this point
  130. * @param y the y coordinate for this point
  131. * @param z the z coordinate for this point
  132. */
  133. public void addPoint(Color color, int x, int y, int z)
  134. {
  135. addPoint("", color, false, x, y, z);
  136. }
  137. /**
  138. * Adds a point to be displayed on client.
  139. * @param color the color
  140. * @param locational the ILocational to take coordinates for this point
  141. */
  142. public void addPoint(Color color, ILocational locational)
  143. {
  144. addPoint("", color, false, locational);
  145. }
  146. /**
  147. * Adds a line to be displayed on client
  148. * @param name the name that will be displayed over the middle of line
  149. * @param color the color
  150. * @param isNameColored if {@code true} name will be colored as well.
  151. * @param x the x coordinate for this line start point
  152. * @param y the y coordinate for this line start point
  153. * @param z the z coordinate for this line start point
  154. * @param x2 the x coordinate for this line end point
  155. * @param y2 the y coordinate for this line end point
  156. * @param z2 the z coordinate for this line end point
  157. */
  158. public void addLine(String name, int color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
  159. {
  160. _lines.add(new Line(name, color, isNameColored, x, y, z, x2, y2, z2));
  161. }
  162. /**
  163. * Adds a line to be displayed on client
  164. * @param name the name that will be displayed over the middle of line
  165. * @param color the color
  166. * @param isNameColored if {@code true} name will be colored as well.
  167. * @param locational the ILocational to take coordinates for this line start point
  168. * @param x2 the x coordinate for this line end point
  169. * @param y2 the y coordinate for this line end point
  170. * @param z2 the z coordinate for this line end point
  171. */
  172. public void addLine(String name, int color, boolean isNameColored, ILocational locational, int x2, int y2, int z2)
  173. {
  174. addLine(name, color, isNameColored, locational.getX(), locational.getY(), locational.getZ(), x2, y2, z2);
  175. }
  176. /**
  177. * Adds a line to be displayed on client
  178. * @param name the name that will be displayed over the middle of line
  179. * @param color the color
  180. * @param isNameColored if {@code true} name will be colored as well.
  181. * @param x the x coordinate for this line start point
  182. * @param y the y coordinate for this line start point
  183. * @param z the z coordinate for this line start point
  184. * @param locational2 the ILocational to take coordinates for this line end point
  185. */
  186. public void addLine(String name, int color, boolean isNameColored, int x, int y, int z, ILocational locational2)
  187. {
  188. addLine(name, color, isNameColored, x, y, z, locational2.getX(), locational2.getY(), locational2.getZ());
  189. }
  190. /**
  191. * Adds a line to be displayed on client
  192. * @param name the name that will be displayed over the middle of line
  193. * @param color the color
  194. * @param isNameColored if {@code true} name will be colored as well.
  195. * @param locational the ILocational to take coordinates for this line start point
  196. * @param locational2 the ILocational to take coordinates for this line end point
  197. */
  198. public void addLine(String name, int color, boolean isNameColored, ILocational locational, ILocational locational2)
  199. {
  200. addLine(name, color, isNameColored, locational, locational2.getX(), locational2.getY(), locational2.getZ());
  201. }
  202. /**
  203. * Adds a line to be displayed on client
  204. * @param color the color
  205. * @param x the x coordinate for this line start point
  206. * @param y the y coordinate for this line start point
  207. * @param z the z coordinate for this line start point
  208. * @param x2 the x coordinate for this line end point
  209. * @param y2 the y coordinate for this line end point
  210. * @param z2 the z coordinate for this line end point
  211. */
  212. public void addLine(int color, int x, int y, int z, int x2, int y2, int z2)
  213. {
  214. addLine("", color, false, x, y, z, x2, y2, z2);
  215. }
  216. /**
  217. * Adds a line to be displayed on client
  218. * @param color the color
  219. * @param locational the ILocational to take coordinates for this line start point
  220. * @param x2 the x coordinate for this line end point
  221. * @param y2 the y coordinate for this line end point
  222. * @param z2 the z coordinate for this line end point
  223. */
  224. public void addLine(int color, ILocational locational, int x2, int y2, int z2)
  225. {
  226. addLine("", color, false, locational, x2, y2, z2);
  227. }
  228. /**
  229. * Adds a line to be displayed on client
  230. * @param color the color
  231. * @param x the x coordinate for this line start point
  232. * @param y the y coordinate for this line start point
  233. * @param z the z coordinate for this line start point
  234. * @param locational2 the ILocational to take coordinates for this line end point
  235. */
  236. public void addLine(int color, int x, int y, int z, ILocational locational2)
  237. {
  238. addLine("", color, false, x, y, z, locational2);
  239. }
  240. /**
  241. * Adds a line to be displayed on client
  242. * @param color the color
  243. * @param locational the ILocational to take coordinates for this line start point
  244. * @param locational2 the ILocational to take coordinates for this line end point
  245. */
  246. public void addLine(int color, ILocational locational, ILocational locational2)
  247. {
  248. addLine("", color, false, locational, locational2);
  249. }
  250. /**
  251. * Adds a line to be displayed on client
  252. * @param name the name that will be displayed over the middle of line
  253. * @param color the color
  254. * @param isNameColored if {@code true} name will be colored as well.
  255. * @param x the x coordinate for this line start point
  256. * @param y the y coordinate for this line start point
  257. * @param z the z coordinate for this line start point
  258. * @param x2 the x coordinate for this line end point
  259. * @param y2 the y coordinate for this line end point
  260. * @param z2 the z coordinate for this line end point
  261. */
  262. public void addLine(String name, Color color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
  263. {
  264. addLine(name, color.getRGB(), isNameColored, x, y, z, x2, y2, z2);
  265. }
  266. /**
  267. * Adds a line to be displayed on client
  268. * @param name the name that will be displayed over the middle of line
  269. * @param color the color
  270. * @param isNameColored if {@code true} name will be colored as well.
  271. * @param locational the ILocational to take coordinates for this line start point
  272. * @param x2 the x coordinate for this line end point
  273. * @param y2 the y coordinate for this line end point
  274. * @param z2 the z coordinate for this line end point
  275. */
  276. public void addLine(String name, Color color, boolean isNameColored, ILocational locational, int x2, int y2, int z2)
  277. {
  278. addLine(name, color.getRGB(), isNameColored, locational, x2, y2, z2);
  279. }
  280. /**
  281. * Adds a line to be displayed on client
  282. * @param name the name that will be displayed over the middle of line
  283. * @param color the color
  284. * @param isNameColored if {@code true} name will be colored as well.
  285. * @param x the x coordinate for this line start point
  286. * @param y the y coordinate for this line start point
  287. * @param z the z coordinate for this line start point
  288. * @param locational2 the ILocational to take coordinates for this line end point
  289. */
  290. public void addLine(String name, Color color, boolean isNameColored, int x, int y, int z, ILocational locational2)
  291. {
  292. addLine(name, color.getRGB(), isNameColored, x, y, z, locational2);
  293. }
  294. /**
  295. * Adds a line to be displayed on client
  296. * @param name the name that will be displayed over the middle of line
  297. * @param color the color
  298. * @param isNameColored if {@code true} name will be colored as well.
  299. * @param locational the ILocational to take coordinates for this line start point
  300. * @param locational2 the ILocational to take coordinates for this line end point
  301. */
  302. public void addLine(String name, Color color, boolean isNameColored, ILocational locational, ILocational locational2)
  303. {
  304. addLine(name, color.getRGB(), isNameColored, locational, locational2);
  305. }
  306. /**
  307. * Adds a line to be displayed on client
  308. * @param color the color
  309. * @param x the x coordinate for this line start point
  310. * @param y the y coordinate for this line start point
  311. * @param z the z coordinate for this line start point
  312. * @param x2 the x coordinate for this line end point
  313. * @param y2 the y coordinate for this line end point
  314. * @param z2 the z coordinate for this line end point
  315. */
  316. public void addLine(Color color, int x, int y, int z, int x2, int y2, int z2)
  317. {
  318. addLine("", color, false, x, y, z, x2, y2, z2);
  319. }
  320. /**
  321. * Adds a line to be displayed on client
  322. * @param color the color
  323. * @param locational the ILocational to take coordinates for this line start point
  324. * @param x2 the x coordinate for this line end point
  325. * @param y2 the y coordinate for this line end point
  326. * @param z2 the z coordinate for this line end point
  327. */
  328. public void addLine(Color color, ILocational locational, int x2, int y2, int z2)
  329. {
  330. addLine("", color, false, locational, x2, y2, z2);
  331. }
  332. /**
  333. * Adds a line to be displayed on client
  334. * @param color the color
  335. * @param x the x coordinate for this line start point
  336. * @param y the y coordinate for this line start point
  337. * @param z the z coordinate for this line start point
  338. * @param locational2 the ILocational to take coordinates for this line end point
  339. */
  340. public void addLine(Color color, int x, int y, int z, ILocational locational2)
  341. {
  342. addLine("", color, false, x, y, z, locational2);
  343. }
  344. /**
  345. * Adds a line to be displayed on client
  346. * @param color the color
  347. * @param locational the ILocational to take coordinates for this line start point
  348. * @param locational2 the ILocational to take coordinates for this line end point
  349. */
  350. public void addLine(Color color, ILocational locational, ILocational locational2)
  351. {
  352. addLine("", color, false, locational, locational2);
  353. }
  354. @Override
  355. protected void writeImpl()
  356. {
  357. writeC(0xFE);
  358. writeH(0x11);
  359. writeS(_name);
  360. writeD(_x);
  361. writeD(_y);
  362. writeD(_z);
  363. writeD(65535); // has to do something with display range and angle
  364. writeD(65535); // has to do something with display range and angle
  365. writeD(_points.size() + _lines.size());
  366. for (Point point : _points)
  367. {
  368. writeC(1); // Its the type in this case Point
  369. writeS(point.getName());
  370. int color = point.getColor();
  371. writeD((color >> 16) & 0xFF); // R
  372. writeD((color >> 8) & 0xFF); // G
  373. writeD(color & 0xFF); // B
  374. writeD(point.isNameColored() ? 1 : 0);
  375. writeD(point.getX());
  376. writeD(point.getY());
  377. writeD(point.getZ());
  378. }
  379. for (Line line : _lines)
  380. {
  381. writeC(2); // Its the type in this case Line
  382. writeS(line.getName());
  383. int color = line.getColor();
  384. writeD((color >> 16) & 0xFF); // R
  385. writeD((color >> 8) & 0xFF); // G
  386. writeD(color & 0xFF); // B
  387. writeD(line.isNameColored() ? 1 : 0);
  388. writeD(line.getX());
  389. writeD(line.getY());
  390. writeD(line.getZ());
  391. writeD(line.getX2());
  392. writeD(line.getY2());
  393. writeD(line.getZ2());
  394. }
  395. }
  396. private static class Point
  397. {
  398. private final String _name;
  399. private final int _color;
  400. private final boolean _isNameColored;
  401. private final int _x;
  402. private final int _y;
  403. private final int _z;
  404. public Point(String name, int color, boolean isNameColored, int x, int y, int z)
  405. {
  406. _name = name;
  407. _color = color;
  408. _isNameColored = isNameColored;
  409. _x = x;
  410. _y = y;
  411. _z = z;
  412. }
  413. /**
  414. * @return the name
  415. */
  416. public String getName()
  417. {
  418. return _name;
  419. }
  420. /**
  421. * @return the color
  422. */
  423. public int getColor()
  424. {
  425. return _color;
  426. }
  427. /**
  428. * @return the isNameColored
  429. */
  430. public boolean isNameColored()
  431. {
  432. return _isNameColored;
  433. }
  434. /**
  435. * @return the x
  436. */
  437. public int getX()
  438. {
  439. return _x;
  440. }
  441. /**
  442. * @return the y
  443. */
  444. public int getY()
  445. {
  446. return _y;
  447. }
  448. /**
  449. * @return the z
  450. */
  451. public int getZ()
  452. {
  453. return _z;
  454. }
  455. }
  456. private static class Line extends Point
  457. {
  458. private final int _x2;
  459. private final int _y2;
  460. private final int _z2;
  461. public Line(String name, int color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
  462. {
  463. super(name, color, isNameColored, x, y, z);
  464. _x2 = x2;
  465. _y2 = y2;
  466. _z2 = z2;
  467. }
  468. /**
  469. * @return the x2
  470. */
  471. public int getX2()
  472. {
  473. return _x2;
  474. }
  475. /**
  476. * @return the y2
  477. */
  478. public int getY2()
  479. {
  480. return _y2;
  481. }
  482. /**
  483. * @return the z2
  484. */
  485. public int getZ2()
  486. {
  487. return _z2;
  488. }
  489. }
  490. }