Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. /*
  2. Copyright <SWGEmu>
  3. See file COPYING for copying conditions.*/
  4.  
  5. #ifndef MOVEFURNITURECOMMAND_H_
  6. #define MOVEFURNITURECOMMAND_H_
  7.  
  8. #include "server/zone/objects/scene/SceneObject.h"
  9. #include "server/zone/objects/building/BuildingObject.h"
  10. #include "server/zone/packets/object/DataTransform.h"
  11. #include "server/zone/packets/object/DataTransformWithParent.h"
  12. #include "templates/appearance/PortalLayout.h"
  13. #include "templates/appearance/FloorMesh.h"
  14. #include "templates/appearance/MeshAppearanceTemplate.h"
  15. #include "server/zone/objects/tangible/components/vendor/VendorDataComponent.h"
  16.  
  17. class MoveFurnitureCommand : public QueueCommand {
  18. public:
  19.  
  20. MoveFurnitureCommand(const String& name, ZoneProcessServer* server)
  21. : QueueCommand(name, server) {
  22.  
  23. }
  24.  
  25. //returns false on collision detection
  26. bool checkCollision(SceneObject* object, Vector3& endPoint) const {
  27. return CollisionManager::checkLineOfSightInParentCell(object, endPoint);
  28. }
  29.  
  30. int doQueueCommand(CreatureObject* creature, const uint64& target, const UnicodeString& arguments) const {
  31. if (!checkStateMask(creature))
  32. return INVALIDSTATE;
  33.  
  34. if (!checkInvalidLocomotions(creature))
  35. return INVALIDLOCOMOTION;
  36.  
  37. ManagedReference<PlayerObject*> ghost = creature->getPlayerObject();
  38.  
  39. if (ghost == NULL)
  40. return GENERALERROR;
  41.  
  42. ManagedReference<SceneObject*> obj = server->getZoneServer()->getObject(target);
  43.  
  44. if (obj == NULL || !obj->isTangibleObject() || obj->isPlayerCreature() || obj->isPet()) {
  45. if (ghost->getAdminLevel() >= 15 && obj != NULL) {
  46. creature->sendSystemMessage("Ingoring Movement Check - God"); //What do you want to move?
  47. } else {
  48. creature->sendSystemMessage("@player_structure:move_what"); //What do you want to move?
  49. return GENERALERROR;
  50. }
  51. }
  52.  
  53. ManagedReference<SceneObject*> rootParent = obj->getRootParent();
  54. ManagedReference<SceneObject*> creatureParent = creature->getRootParent();
  55.  
  56. if (creatureParent == NULL || !creatureParent->isBuildingObject()) {
  57. if (ghost->getAdminLevel() >= 15) {
  58. creature->sendSystemMessage("Ingoring Building Check - God"); //What do you want to move?
  59. } else {
  60. creature->sendSystemMessage("@player_structure:must_be_in_building"); //You must be in a building to do that.
  61. return GENERALERROR;
  62. BuildingObject* buildingObject = cast<BuildingObject*>( creatureParent.get());
  63.  
  64. if (buildingObject == NULL || obj->getRootParent() != buildingObject || buildingObject->containsChildObject(obj)) {
  65. creature->sendSystemMessage("@player_structure:move_what"); //What do you want to move?
  66. return GENERALERROR;
  67. }
  68.  
  69. if (buildingObject != rootParent || !buildingObject->isOnAdminList(creature)) {
  70. creature->sendSystemMessage("@player_structure:must_be_admin"); //You must be a building admin to do that.
  71. return GENERALERROR;
  72. }
  73.  
  74. if (buildingObject->isGCWBase()) {
  75. creature->sendSystemMessage("@player_structure:no_move_hq"); // You may not move or rotate objects inside a factional headquarters.
  76. return GENERALERROR;
  77. }
  78. }
  79. }
  80.  
  81. if (obj->isVendor()) {
  82. creature->sendSystemMessage("@player_structure:cant_move_vendor"); // To move a vendor, pick it up and drop it again at the new location.
  83. return GENERALERROR;
  84. }
  85.  
  86.  
  87.  
  88. String dir;
  89. float dist = 0.f;
  90.  
  91. try {
  92. UnicodeTokenizer tokenizer(arguments);
  93. tokenizer.getStringToken(dir);
  94. dir = dir.toLowerCase();
  95.  
  96. if (Character::isDigit(dir.charAt(0)))
  97. throw Exception("Please specify the name of the object before the direction and distance.");
  98.  
  99. if (ghost->getAdminLevel() >= 15) {
  100. if (dir != "up" && dir != "down" && dir != "forward" && dir != "back" && dir != "x" && dir != "z" && dir != "y")
  101. throw Exception("@player_structure:format_movefurniture_distance"); //Format: /moveFurniture <FORWARD/BACK/UP/DOWN> <distance>
  102. } else {
  103. if (dir != "up" && dir != "down" && dir != "forward" && dir != "back")
  104. throw Exception("@player_structure:format_movefurniture_distance"); //Format: /moveFurniture <FORWARD/BACK/UP/DOWN> <distance>
  105. }
  106.  
  107. dist = tokenizer.getIntToken();
  108.  
  109. if (dist < 1.f || dist > 500.f) {
  110. if (ghost->getAdminLevel() >=15) {
  111. creature->sendSystemMessage("Ingoring Limitation - GOD"); // God Mode - Ignoring Limitation.
  112. } else {
  113. throw Exception("@player_structure:movefurniture_params"); //The amount to move must be between 1 and 500.
  114. }
  115. }
  116.  
  117. } catch (ArrayIndexOutOfBoundsException& e) {
  118. throw Exception("@player_structure:format_movefurniture_distance"); //Format: /moveFurniture <FORWARD/BACK/UP/DOWN> <distance>
  119. return INVALIDPARAMETERS;
  120.  
  121. } catch (Exception& e) {
  122. creature->sendSystemMessage(e.getMessage());
  123. return INVALIDPARAMETERS;
  124. }
  125.  
  126. float degrees = creature->getDirectionAngle();
  127. float radians = Math::deg2rad(degrees);
  128.  
  129. if (dir != "x" && dir != "z" && dir != "y") {
  130. dist /= 100.0f;
  131. }
  132.  
  133. float offsetX = dist * sin(radians);
  134. float offsetY = dist * cos(radians);
  135.  
  136. float x = obj->getPositionX();
  137. float y = obj->getPositionY();
  138. float z = obj->getPositionZ();
  139.  
  140. if (dir == "forward") {
  141. x += (offsetX);
  142. y += (offsetY);
  143. } else if (dir == "back") {
  144. x -= (offsetX);
  145. y -= (offsetY);
  146. } else if (dir == "up") {
  147. z += dist;
  148. } else if (dir == "down") {
  149. z -= dist;
  150. } else if (dir == "x") {
  151. x = dist;
  152. } else if (dir == "z") {
  153. z = dist;
  154. } else if (dir == "y") {
  155. y = dist;
  156. }
  157.  
  158. Vector3 endPoint(x, y, z);
  159.  
  160. if (!checkCollision(obj, endPoint)) {
  161. if (ghost->getAdminLevel() >= 15) {
  162. creature->sendSystemMessage("Ingoring Collision Check - Trusted Players Only"); //That is not a valid location.
  163. } else {
  164. creature->sendSystemMessage("@player_structure:not_valid_location"); //That is not a valid location.
  165. return GENERALERROR;
  166. }
  167. }
  168.  
  169. obj->incrementMovementCounter();
  170.  
  171. if (obj->getParent() != NULL)
  172. obj->teleport(x, z, y, obj->getParent().get()->getObjectID());
  173. else
  174. obj->teleport(x, z, y);
  175.  
  176.  
  177. return SUCCESS;
  178. }
  179.  
  180. };
  181.  
  182. #endif //MOVEFURNITURECOMMAND_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement