123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.network.serverpackets;
- import java.awt.Color;
- import java.util.ArrayList;
- import java.util.List;
- import com.l2jserver.gameserver.model.interfaces.ILocational;
- /**
- * A packet used to draw points and lines on client.<br/>
- * <b>Note:</b> Names in points and lines are bugged they will appear even when not looking at them.
- * @author NosBit
- */
- public class ExServerPrimitive extends L2GameServerPacket
- {
- private final String _name;
- private final int _x;
- private final int _y;
- private final int _z;
- private final List<Point> _points = new ArrayList<>();
- private final List<Line> _lines = new ArrayList<>();
-
- /**
- * @param name A unique name this will be used to replace lines if second packet is sent
- * @param x the x coordinate usually middle of drawing area
- * @param y the y coordinate usually middle of drawing area
- * @param z the z coordinate usually middle of drawing area
- */
- public ExServerPrimitive(String name, int x, int y, int z)
- {
- _name = name;
- _x = x;
- _y = y;
- _z = z;
- }
-
- /**
- * @param name A unique name this will be used to replace lines if second packet is sent
- * @param locational the ILocational to take coordinates usually middle of drawing area
- */
- public ExServerPrimitive(String name, ILocational locational)
- {
- this(name, locational.getX(), locational.getY(), locational.getZ());
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param name the name that will be displayed over the point
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this point
- * @param y the y coordinate for this point
- * @param z the z coordinate for this point
- */
- public void addPoint(String name, int color, boolean isNameColored, int x, int y, int z)
- {
- _points.add(new Point(name, color, isNameColored, x, y, z));
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param name the name that will be displayed over the point
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this point
- */
- public void addPoint(String name, int color, boolean isNameColored, ILocational locational)
- {
- addPoint(name, color, isNameColored, locational.getX(), locational.getY(), locational.getZ());
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param color the color
- * @param x the x coordinate for this point
- * @param y the y coordinate for this point
- * @param z the z coordinate for this point
- */
- public void addPoint(int color, int x, int y, int z)
- {
- addPoint("", color, false, x, y, z);
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param color the color
- * @param locational the ILocational to take coordinates for this point
- */
- public void addPoint(int color, ILocational locational)
- {
- addPoint("", color, false, locational);
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param name the name that will be displayed over the point
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this point
- * @param y the y coordinate for this point
- * @param z the z coordinate for this point
- */
- public void addPoint(String name, Color color, boolean isNameColored, int x, int y, int z)
- {
- addPoint(name, color.getRGB(), isNameColored, x, y, z);
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param name the name that will be displayed over the point
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this point
- */
- public void addPoint(String name, Color color, boolean isNameColored, ILocational locational)
- {
- addPoint(name, color.getRGB(), isNameColored, locational);
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param color the color
- * @param x the x coordinate for this point
- * @param y the y coordinate for this point
- * @param z the z coordinate for this point
- */
- public void addPoint(Color color, int x, int y, int z)
- {
- addPoint("", color, false, x, y, z);
- }
-
- /**
- * Adds a point to be displayed on client.
- * @param color the color
- * @param locational the ILocational to take coordinates for this point
- */
- public void addPoint(Color color, ILocational locational)
- {
- addPoint("", color, false, locational);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(String name, int color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
- {
- _lines.add(new Line(name, color, isNameColored, x, y, z, x2, y2, z2));
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(String name, int color, boolean isNameColored, ILocational locational, int x2, int y2, int z2)
- {
- addLine(name, color, isNameColored, locational.getX(), locational.getY(), locational.getZ(), x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(String name, int color, boolean isNameColored, int x, int y, int z, ILocational locational2)
- {
- addLine(name, color, isNameColored, x, y, z, locational2.getX(), locational2.getY(), locational2.getZ());
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(String name, int color, boolean isNameColored, ILocational locational, ILocational locational2)
- {
- addLine(name, color, isNameColored, locational, locational2.getX(), locational2.getY(), locational2.getZ());
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(int color, int x, int y, int z, int x2, int y2, int z2)
- {
- addLine("", color, false, x, y, z, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param locational the ILocational to take coordinates for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(int color, ILocational locational, int x2, int y2, int z2)
- {
- addLine("", color, false, locational, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(int color, int x, int y, int z, ILocational locational2)
- {
- addLine("", color, false, x, y, z, locational2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param locational the ILocational to take coordinates for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(int color, ILocational locational, ILocational locational2)
- {
- addLine("", color, false, locational, locational2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(String name, Color color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
- {
- addLine(name, color.getRGB(), isNameColored, x, y, z, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(String name, Color color, boolean isNameColored, ILocational locational, int x2, int y2, int z2)
- {
- addLine(name, color.getRGB(), isNameColored, locational, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(String name, Color color, boolean isNameColored, int x, int y, int z, ILocational locational2)
- {
- addLine(name, color.getRGB(), isNameColored, x, y, z, locational2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param name the name that will be displayed over the middle of line
- * @param color the color
- * @param isNameColored if {@code true} name will be colored as well.
- * @param locational the ILocational to take coordinates for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(String name, Color color, boolean isNameColored, ILocational locational, ILocational locational2)
- {
- addLine(name, color.getRGB(), isNameColored, locational, locational2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(Color color, int x, int y, int z, int x2, int y2, int z2)
- {
- addLine("", color, false, x, y, z, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param locational the ILocational to take coordinates for this line start point
- * @param x2 the x coordinate for this line end point
- * @param y2 the y coordinate for this line end point
- * @param z2 the z coordinate for this line end point
- */
- public void addLine(Color color, ILocational locational, int x2, int y2, int z2)
- {
- addLine("", color, false, locational, x2, y2, z2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param x the x coordinate for this line start point
- * @param y the y coordinate for this line start point
- * @param z the z coordinate for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(Color color, int x, int y, int z, ILocational locational2)
- {
- addLine("", color, false, x, y, z, locational2);
- }
-
- /**
- * Adds a line to be displayed on client
- * @param color the color
- * @param locational the ILocational to take coordinates for this line start point
- * @param locational2 the ILocational to take coordinates for this line end point
- */
- public void addLine(Color color, ILocational locational, ILocational locational2)
- {
- addLine("", color, false, locational, locational2);
- }
-
- @Override
- protected void writeImpl()
- {
- writeC(0xFE);
- writeH(0x11);
- writeS(_name);
- writeD(_x);
- writeD(_y);
- writeD(_z);
- writeD(65535); // has to do something with display range and angle
- writeD(65535); // has to do something with display range and angle
-
- writeD(_points.size() + _lines.size());
-
- for (Point point : _points)
- {
- writeC(1); // Its the type in this case Point
- writeS(point.getName());
- int color = point.getColor();
- writeD((color >> 16) & 0xFF); // R
- writeD((color >> 8) & 0xFF); // G
- writeD(color & 0xFF); // B
- writeD(point.isNameColored() ? 1 : 0);
- writeD(point.getX());
- writeD(point.getY());
- writeD(point.getZ());
- }
-
- for (Line line : _lines)
- {
- writeC(2); // Its the type in this case Line
- writeS(line.getName());
- int color = line.getColor();
- writeD((color >> 16) & 0xFF); // R
- writeD((color >> 8) & 0xFF); // G
- writeD(color & 0xFF); // B
- writeD(line.isNameColored() ? 1 : 0);
- writeD(line.getX());
- writeD(line.getY());
- writeD(line.getZ());
- writeD(line.getX2());
- writeD(line.getY2());
- writeD(line.getZ2());
- }
- }
-
- private static class Point
- {
- private final String _name;
- private final int _color;
- private final boolean _isNameColored;
- private final int _x;
- private final int _y;
- private final int _z;
-
- public Point(String name, int color, boolean isNameColored, int x, int y, int z)
- {
- _name = name;
- _color = color;
- _isNameColored = isNameColored;
- _x = x;
- _y = y;
- _z = z;
- }
-
- /**
- * @return the name
- */
- public String getName()
- {
- return _name;
- }
-
- /**
- * @return the color
- */
- public int getColor()
- {
- return _color;
- }
-
- /**
- * @return the isNameColored
- */
- public boolean isNameColored()
- {
- return _isNameColored;
- }
-
- /**
- * @return the x
- */
- public int getX()
- {
- return _x;
- }
-
- /**
- * @return the y
- */
- public int getY()
- {
- return _y;
- }
-
- /**
- * @return the z
- */
- public int getZ()
- {
- return _z;
- }
- }
-
- private static class Line extends Point
- {
- private final int _x2;
- private final int _y2;
- private final int _z2;
-
- public Line(String name, int color, boolean isNameColored, int x, int y, int z, int x2, int y2, int z2)
- {
- super(name, color, isNameColored, x, y, z);
- _x2 = x2;
- _y2 = y2;
- _z2 = z2;
- }
-
- /**
- * @return the x2
- */
- public int getX2()
- {
- return _x2;
- }
-
- /**
- * @return the y2
- */
- public int getY2()
- {
- return _y2;
- }
-
- /**
- * @return the z2
- */
- public int getZ2()
- {
- return _z2;
- }
- }
- }
|