Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8KB

  1. using System;
  2. using RobocraftX.GUI.CommandLine;
  3. using RobocraftX.Multiplayer;
  4. using RobocraftX.StateSync;
  5. using RobocraftX.Character;
  6. using RobocraftX.Common;
  7. using Svelto.ECS;
  8. using Svelto.ECS.EntityStructs;
  9. using Unity.Entities;
  10. using UnityEngine;
  11. using uREPL;
  12. using Svelto.Context;
  13. using RobocraftX;
  14. namespace ExtraCommands.Building
  15. {
  16. //[CustomCommand("MoveBlocks", "Move blocks from their original position")]
  17. class MoveBlocksCommandEngine : CustomCommandEngine
  18. {
  19. public MoveBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  20. {
  21. }
  22. public override void Ready()
  23. {
  24. CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position");
  25. }
  26. private void MoveBlocksCommand(float x, float y, float z)
  27. {
  28. uint blockCount;
  29. PositionEntityStruct[] posStructs = this.entitiesDB.QueryEntities<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out blockCount);
  30. for (uint i = 0; i < blockCount; i++)
  31. {
  32. ref PositionEntityStruct posStruct = ref posStructs[i];
  33. if (!posStruct.Equals(null) && !posStruct.position.Equals(null))
  34. {
  35. posStruct.position.x += x;
  36. posStruct.position.y += y;
  37. posStruct.position.z += z;
  38. } else {
  39. uREPL.Log.Warn("Null position found for position "+i);
  40. }
  41. }
  42. }
  43. public override void Dispose()
  44. {
  45. CustomCommandUtility.Unregister("MoveBlocks");
  46. }
  47. }
  48. }