protected override void Execute(WorldRange selection) { if (!File.Exists(this.fileName)) { throw new WorldEditCommandException($"Schematic file {fileName} not found!"); } using (FileStream stream = File.OpenRead(this.fileName)) { WorldEditSerializer serializer = new WorldEditSerializer(); serializer.Deserialize(stream); this.UserSession.Clipboard.Parse(serializer); this.UserSession.SetImportedSchematicAuthor(serializer.AuthorInformation); } }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); foreach (Vector3i pos in selection.SidesIterator()) { if (WorldEditBlockManager.IsImpenetrable(pos)) { continue; } this.AddBlockChangedEntry(pos); WorldEditBlockManager.SetBlock(blockType, pos); this.BlocksChanged++; } }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); Vector3i playerPos = this.UserSession.Player.Position.Round; this.UserSession.Clipboard.Clear(); void DoAction(Vector3i pos) { this.UserSession.Clipboard.Add(WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos, playerPos)); } selection.ForEachInc(DoAction); this.UserSession.AuthorInfo.MarkDirty(); }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); void DoAction(Vector3i pos) { if (WorldEditBlockManager.IsImpenetrable(pos)) { return; } this.AddBlockChangedEntry(pos); WorldEditBlockManager.SetBlock(blockType, pos); this.BlocksChanged++; } selection.ForEachInc(DoAction); }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); void DoAction(Vector3i pos) { Block block = Eco.World.World.GetBlock(pos); if (block.GetType() == typeof(PlantBlock) || block.GetType() == typeof(TreeBlock)) { var pb = PlantBlock.GetPlant(pos); pb.GrowthPercent = 1; pb.Tended = true; pb.Tick(); } } selection.ForEachInc(DoAction); }
public static WorldRange FixXZ(this WorldRange range, Vector3i worldSize = default) { Vector3i start = range.min; Vector3i end = range.max; range.Fix(worldSize); if (worldSize != default) { if (MathUtil.Min(start.y, end.y) < 0) { range.min.y = 0; } if (MathUtil.Max(start.y, end.y) > Shared.Voxel.World.VoxelSize.y) { range.max.y = Shared.Voxel.World.VoxelSize.y; } } return(range); }
public static void Addclaim(User user) { try { Vector3i pos = user.Position.Round; Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ); UserSession session = WorldEditManager.GetUserSession(user); WorldRange range = session.Selection; range.ExtendToInclude(claimPos.X_Z(pos.Y - 1)); range.ExtendToInclude(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y - 1)); session.SetSelection(range); user.Player.MsgLoc($"First Position now at {session.Selection.min}"); user.Player.MsgLoc($"Second Position now at {session.Selection.max}"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
protected override void Execute(WorldRange selection) { AffineTransform transform = new AffineTransform(); float radians = Mathf.DegToRad(this.angleDegrees); transform = transform.RotateY(radians); List <WorldEditBlock> blocks = new List <WorldEditBlock>(); blocks.AddRange(this.UserSession.Clipboard.GetBlocks()); blocks.AddRange(this.UserSession.Clipboard.GetPlants()); blocks.AddRange(this.UserSession.Clipboard.GetWorldObjects()); for (int i = 0; i < blocks.Count; i++) { WorldEditBlock block = blocks[i]; block.RotateBlock(transform, this.angleDegrees, radians); blocks[i] = block; } this.UserSession.Clipboard.Clear(); this.UserSession.Clipboard.Parse(blocks); }
protected override void Execute(WorldRange selection) { WorldEditManager.UpdateBlueprintList(); StringBuilder sb = new StringBuilder(); sb.Append(Localizer.DoStr("File name")) .Append(Text.Pos(300, Localizer.DoStr("Version"))) .Append(Text.Pos(500, Localizer.DoStr("File size"))) .Append(Text.Pos(700, Localizer.DoStr("Date"))) .AppendLine(Text.Pos(950, Localizer.DoStr("Player"))); foreach (EcoBlueprintInfo info in WorldEditManager.BlueprintList.Values.OrderBy(k => k.FileName)) { sb.Append(info.FileName) .Append(Text.Pos(300, $"ECO {info.EcoVersion} ({info.Version.ToString("0.00", CultureInfo.InvariantCulture)})")) .Append(Text.Pos(500, (info.FileSize / 1024).ToString() + " KB")) .Append(Text.Pos(700, info.FileChangedDate.ToString())) .AppendLine(Text.Pos(950, info.Author.Name)); } this.UserSession.Player.OpenInfoPanel(Localizer.Do($"WorldEdit Blueprint List"), sb.ToString(), "WorldEditBpList"); }
public static void Expclaim(User user, string args = "1") { try { UserSession session = WorldEditManager.GetUserSession(user); if (!session.Selection.IsSet()) { throw new WorldEditCommandException("Please set both points first!"); } Direction direction = WorldEditUtils.ParseDirectionAndAmountArgs(user, args, out int amount); if (direction == Direction.Unknown || direction == Direction.None || direction == Direction.Up || direction == Direction.Down) { throw new WorldEditCommandException("Unable to determine direction"); } WorldRange range = session.Selection; Vector3i pos = default; if (range.min.y <= range.max.y) { pos.y = range.min.y; } else { pos.y = range.max.y; } switch (direction) { case Direction.Left: case Direction.Back: if (range.min.x <= range.max.x) { pos.x = range.min.x; } else { pos.x = range.max.x; } if (range.min.z <= range.max.z) { pos.z = range.min.z; } else { pos.z = range.max.z; } break; case Direction.Right: case Direction.Forward: if (range.min.x <= range.max.x) { pos.x = range.max.x; } else { pos.x = range.min.x; } if (range.min.z <= range.max.z) { pos.z = range.max.z; } else { pos.z = range.min.z; } break; } pos += direction.ToVec() * (PlotUtil.PropertyPlotLength - 1) * amount; Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ); range.ExtendToInclude(claimPos.X_Z(pos.Y)); range.ExtendToInclude(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y)); session.SetSelection(range); user.Player.MsgLoc($"First Position now at {session.Selection.min}"); user.Player.MsgLoc($"Second Position now at {session.Selection.max}"); } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); Vector3i offset = this.direction.ToVec() * this.amount; Stack <WorldEditBlock> blocks = new Stack <WorldEditBlock>(); void DoAction(Vector3i pos) { if (WorldEditBlockManager.IsImpenetrable(pos)) { return; } WorldEditBlock sourceBlock = WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos); blocks.Push(sourceBlock); this.AddBlockChangedEntry(pos); WorldEditBlockManager.SetBlock(typeof(EmptyBlock), pos); } selection.ForEachInc(DoAction); while (blocks.TryPop(out WorldEditBlock sourceBlock)) { Vector3i finalPos = WorldEditBlockManager.ApplyOffset(sourceBlock.Position, offset); if (finalPos.Y < 0 || finalPos.Y > Shared.Voxel.World.VoxelSize.Y) { continue; } this.AddBlockChangedEntry(finalPos); WorldEditBlockManager.RestoreBlockOffset(sourceBlock, offset, this.UserSession); this.BlocksChanged++; } //Action<int, int, int> action = (int x, int y, int z) => //{ // Vector3i pos = new Vector3i(x, y, z); // if (WorldEditBlockManager.IsImpenetrable(pos)) return; // AddBlockChangedEntry(pos); // AddBlockChangedEntry(pos + offset); // WorldEditBlock sourceBlock = WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos); // WorldEditBlockManager.RestoreBlockOffset(sourceBlock, offset, this.UserSession); // WorldEditBlockManager.SetBlock(typeof(EmptyBlock), pos); // this.BlocksChanged++; //}; //if (this.direction == Direction.Left || this.direction == Direction.Back || this.direction == Direction.Down) //{ // for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) // { // for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) // { // for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) // { // action.Invoke(x, y, z); // } // } // } //} //else //{ // /* for (int x = vectors.Higher.X - 1; x >= vectors.Lower.X; x--) // for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--) // for (int z = vectors.Higher.Z - 1; z >= vectors.Lower.Z; z--)*/ // int x = vectors.Higher.X - 1; // if (x < 0) // { // x = x + Shared.Voxel.World.VoxelSize.X; // } // int startZ = vectors.Higher.Z - 1; // if (startZ < 0) // { // startZ = startZ + Shared.Voxel.World.VoxelSize.Z; // } // // Console.WriteLine("--------------"); // // Console.WriteLine(vectors.Lower); // // Console.WriteLine(vectors.Higher); // for (; x != (vectors.Lower.X - 1); x--) // { // if (x < 0) // { // x = x + Shared.Voxel.World.VoxelSize.X; // } // for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--) // { // for (int z = startZ; z != (vectors.Lower.Z - 1); z--) // { // if (z < 0) // { // z = z + Shared.Voxel.World.VoxelSize.Z; // } // // Console.WriteLine($"{x} {y} {z}"); // action.Invoke(x, y, z); // } // } // } //} }
protected abstract void Execute(WorldRange selection);
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); selection.ForEachInc(ReplaceBlock); }
protected override void Execute(WorldRange selection) { selection = selection.FixXZ(Shared.Voxel.World.VoxelSize); Dictionary <object, long> blocks = new Dictionary <object, long>(); long emptyBlocks = 0; foreach (Vector3i pos in selection.XYZIterInc()) { Block block = Eco.World.World.GetBlock(pos); Type blockType = null; switch (block) { case PlantBlock _: case TreeBlock _: Plant plant = EcoSim.PlantSim.GetPlant(pos); if (plant != null && plant.Position.Equals(pos)) { blockType = plant.Species.GetType(); } break; case WorldObjectBlock worldObjectBlock: WorldObject worldObject = worldObjectBlock.WorldObjectHandle.Object; if (worldObject.Position3i.Equals(pos)) { blockType = worldObject.GetType(); } break; default: if (BlockContainerManager.Obj.IsBlockContained(pos)) { WorldObject obj = ServiceHolder <IWorldObjectManager> .Obj.All.Where(x => x.Position3i.Equals(pos)).FirstOrDefault(); if (obj != null) { blockType = obj.GetType(); } } else { blockType = block.GetType(); } break; } if (blockType != null) { if (blockType == typeof(EmptyBlock)) { emptyBlocks++; continue; } if (this.outputType.Equals("brief")) { string name = this.GetBlockFancyName(blockType); blocks.TryGetValue(name, out long count); blocks[name] = count + 1; } else { blocks.TryGetValue(blockType, out long count); blocks[blockType] = count + 1; } } } decimal totalBlocks = blocks.Values.Sum(); // (vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z); StringBuilder sb = new StringBuilder(); sb.AppendLine(TextLoc.Header(Localizer.DoStr("Selection Info"))); sb.AppendLineLoc($"Region: {Text.Location(this.UserSession.Selection.min)} - {Text.Location(this.UserSession.Selection.max)}"); sb.Append(Localizer.DoStr("Width:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc)); sb.Append(Localizer.DoStr("Height:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.HeightInc)); sb.Append(Localizer.DoStr("Length:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.LengthInc)); sb.Append(Localizer.DoStr("Volume:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.VolumeInc)); sb.Append(Localizer.DoStr("Area:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc * selection.LengthInc)); sb.AppendLocStr("Empty blocks:"); sb.AppendLine($" {emptyBlocks,8}"); sb.AppendLocStr("Total blocks:"); sb.AppendLine($" {totalBlocks,8}"); sb.AppendLine().AppendLine(TextLoc.Header(Localizer.DoStr("Block List"))); foreach (KeyValuePair <object, long> entry in blocks) { decimal percent = Math.Round((entry.Value / totalBlocks) * 100, 2); sb.Append(this.outputType.Equals("detail") ? this.GetBlockFancyName((Type)entry.Key) : (string)entry.Key); sb.Append(Text.Pos(400, Text.Info(Text.Int(entry.Value)))); sb.Append($"({percent}%)".PadLeft(10)); if (this.outputType.Equals("detail")) { sb.Append(Text.Pos(500, $"[{Localizer.DoStr(((Type)entry.Key).Name)}]")); } sb.AppendLine(); } if (!string.IsNullOrEmpty(this.fileName)) { this.OutputToFile(sb.ToString()); this.UserSession.Player.MsgLoc($"Report saved into file with name <{WorldEditManager.SanitizeFileName(this.fileName)}.txt>"); } this.UserSession.Player.OpenInfoPanel(Localizer.Do($"WorldEdit Blocks Report"), sb.ToString(), "WorldEditDistr"); }
public static bool IsSet(this WorldRange range) => !range.min.Equals(Vector3i.MaxValue) && !range.max.Equals(Vector3i.MaxValue);
protected override void Execute(WorldRange selection) { Vector3i vector = this.direction.ToVec() * this.amount; switch (this._commandType) { case Command.SHIFT: selection.min += vector; selection.max += vector; break; case Command.EXPAND: switch (this.direction) { case Direction.Left: case Direction.Back: case Direction.Down: if (selection.min.x <= selection.max.x) { selection.min.x += vector.x; } else { selection.max.x += vector.x; } if (selection.min.y <= selection.max.y) { selection.min.y += vector.y; } else { selection.max.y += vector.y; } if (selection.min.z <= selection.max.z) { selection.min.z += vector.z; } else { selection.max.z += vector.z; } //selection.min += vector; break; case Direction.Right: case Direction.Forward: case Direction.Up: if (selection.min.x <= selection.max.x) { selection.max.x += vector.x; } else { selection.min.x += vector.x; } if (selection.min.y <= selection.max.y) { selection.max.y += vector.y; } else { selection.min.y += vector.y; } if (selection.min.z <= selection.max.z) { selection.max.z += vector.z; } else { selection.min.z += vector.z; } //selection.max += vector; break; case Direction.None: if (selection.min.x <= selection.max.x) { selection.min.x -= amount; selection.max.x += amount; } else { selection.max.x -= amount; selection.min.x += amount; } if (selection.min.y <= selection.max.y) { selection.min.y -= amount; selection.max.y += amount; } else { selection.max.y -= amount; selection.min.y += amount; } if (selection.min.z <= selection.max.z) { selection.min.z -= amount; selection.max.z += amount; } else { selection.max.z -= amount; selection.min.z += amount; } //selection.min -= amount; //selection.max += amount; break; default: throw new WorldEditCommandException("Unable to determine direction"); } break; case Command.REDUCE: switch (this.direction) { case Direction.Left: case Direction.Back: case Direction.Down: if (selection.min.x <= selection.max.x) { selection.max.x += vector.x; } else { selection.min.x += vector.x; } if (selection.min.y <= selection.max.y) { selection.max.y += vector.y; } else { selection.min.y += vector.y; } if (selection.min.z <= selection.max.z) { selection.max.z += vector.z; } else { selection.min.z += vector.z; } //selection.max += vector; break; case Direction.Right: case Direction.Forward: case Direction.Up: if (selection.min.x <= selection.max.x) { selection.min.x += vector.x; } else { selection.max.x += vector.x; } if (selection.min.y <= selection.max.y) { selection.min.y += vector.y; } else { selection.max.y += vector.y; } if (selection.min.z <= selection.max.z) { selection.min.z += vector.z; } else { selection.max.z += vector.z; } //selection.min += vector; break; case Direction.None: if (selection.min.x <= selection.max.x) { selection.min.x += amount; selection.max.x -= amount; } else { selection.max.x += amount; selection.min.x -= amount; } if (selection.min.y <= selection.max.y) { selection.min.y += amount; selection.max.y -= amount; } else { selection.max.y += amount; selection.min.y -= amount; } if (selection.min.z <= selection.max.z) { selection.min.z += amount; selection.max.z -= amount; } else { selection.max.z += amount; selection.min.z -= amount; } //selection.min += amount; //selection.max -= amount; break; default: throw new WorldEditCommandException("Unable to determine direction"); } break; } this.UserSession.SetSelection(selection); }