private ForegroundBlock(Foreground.Id id, BlockArgsType requiredArgsType) { this.Id = id; this._args = null; var argsType = WorldUtils.GetBlockArgsType(this.Type); if (argsType != requiredArgsType) { throw WorldUtils.GetMissingArgsErrorMessage(argsType, nameof(id)); } }
public ForegroundBlock(Foreground.Id id, string text, string textColor) { ForegroundType type = WorldUtils.GetForegroundType(id); if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.Label) { throw new ArgumentException("Invalid arguments for the specified block.", "id"); } this._args = new LabelArgs(text, textColor); this._type = type; this._id = id; }
public ForegroundBlock(Foreground.Id id, uint args) { ForegroundType type = WorldUtils.GetForegroundType(id); if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.Number) { throw new ArgumentException("Invalid arguments for the specified block.", "id"); } this._args = args; this._type = type; this._id = id; }
public ForegroundBlock(Foreground.Id id) { ForegroundType type = WorldUtils.GetForegroundType(id); if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.None) { throw new ArgumentException("The given block is missing required arguments.", "id"); } this._args = null; this._type = ForegroundType.Normal; this._id = id; }
public ForegroundBlock(Foreground.Id id, uint portalId, uint portalTarget, Morph.Id portalRotation) { ForegroundType type = WorldUtils.GetForegroundType(id); if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.Portal) { throw new ArgumentException("The given block is not a portal.", "id"); } this._args = new PortalArgs(portalId, portalTarget, portalRotation); this._type = ForegroundType.Portal; this._id = id; }
internal ForegroundBlock?GetExpectedForeground(Point p) { PlaceSendMessage msg; if (!this._queuedItems.TryGetValue(new Point3D(Layer.Foreground, p.X, p.Y), out msg)) { lock (this._sentBlocks) { CheckHandle handle; if (!this._sentLocations.TryGetValue(new Point3D(Layer.Foreground, p.X, p.Y), out handle)) { return(null); } msg = handle.Message; } } return(WorldUtils.GetForegroundFromArgs((Foreground.Id)msg.Id, msg.Args)); }
private void UnserializeFromComplexObject(DatabaseArray worlddata) { foreach (DatabaseObject ct in worlddata) { if (ct.Count == 0) { continue; } try { var type = Convert.ToUInt32(ct.GetValue("type")); var layerNum = ct.GetInt("layer", 0); var xArr = ct.GetBytes("x", new byte[0]); var yArr = ct.GetBytes("y", new byte[0]); var x1Arr = ct.GetBytes("x1", new byte[0]); var y1Arr = ct.GetBytes("y1", new byte[0]); var points = WorldUtils.GetShortPos(x1Arr, y1Arr) .Concat(WorldUtils.GetPos(xArr, yArr)); if (layerNum == 0) { var foreground = (Foreground.Id)type; var block = WorldUtils.GetForegroundFromDatabase(ct, foreground); foreach (var loc in points) { this.Foreground[loc.X, loc.Y] = block; } } else { var background = (Background.Id)type; var block = new BackgroundBlock(background); foreach (var loc in points) { this.Background[loc.X, loc.Y] = block; } } } catch (Exception) { } } }
private static bool AreSame <T, TBlock>(PlaceSendMessage sent, T received) where T : PlaceEvent <T, TBlock> where TBlock : struct { var bg = received as BackgroundPlaceEvent; if (bg != null) { return(WorldUtils.AreSame(sent, bg)); } var fg = received as ForegroundPlaceEvent; if (fg != null) { return(WorldUtils.AreSame(sent, fg)); } throw new NotSupportedException("Unknown PlaceEvent."); }
public ForegroundBlock(Foreground.Id id, uint args) { var type = WorldUtils.GetForegroundType(id); var argsType = WorldUtils.GetBlockArgsType(type); switch (argsType) { case BlockArgsType.Number: this._args = args; break; case BlockArgsType.SignedNumber: this._args = (int)args; break; default: throw WorldUtils.GetMissingArgsErrorMessage(argsType, nameof(id)); } this.Type = type; this.Id = id; }
private void UnserializeFromComplexObject(DatabaseArray worlddata) { foreach (DatabaseObject ct in worlddata) { if (ct.Count == 0) { continue; } var type = (uint)ct.GetValue("type"); var layerNum = ct.GetInt("layer", 0); var xs = ct.GetBytes("x", new byte[0]); var ys = ct.GetBytes("y", new byte[0]); if (layerNum == 0) { var foreground = (Foreground.Id)type; var block = WorldUtils.GetDatabaseBlock(ct, foreground); for (var b = 0; b < xs.Length; b += 2) { var nx = (xs[b] << 8) + xs[b + 1]; var ny = (ys[b] << 8) + ys[b + 1]; this.Foreground[nx, ny] = block; } } else { var background = (Background.Id)type; var block = new BackgroundBlock(background); for (var b = 0; b < xs.Length; b += 2) { var nx = (xs[b] << 8) + xs[b + 1]; var ny = (ys[b] << 8) + ys[b + 1]; this.Background[nx, ny] = block; } } } }
private bool ShouldSend(PlaceSendMessage b, Point3D p) { if (b.NoChecks) { return(true); } if (!Actions.Of(this.BotBits).CanEdit) { return(false); } if (b.SendCount > 10) { return(false); } var playerData = ConnectionManager.Of(this.BotBits).PlayerData; if (!playerData.HasBlockInternal(b.Id)) { return(false); } var blocks = Blocks.Of(this.BotBits); if (!WorldUtils.IsPlaceable(b, blocks)) { return(false); } CheckHandle handle; return(!(this._sentLocations.TryGetValue(p, out handle) ? WorldUtils.AreSame(b, handle.Message) : WorldUtils.IsAlreadyPlaced(b, blocks))); }
private void Repair <T, TBlock>(Layer layer, T e) where T : PlaceEvent <T, TBlock> where TBlock : struct { // Make sure the block was uploaded by this bot var p = e.New.Placer; if (p != null && p != Package <Players> .Of(this.BotBits).OwnPlayer) { return; } lock (this._sentBlocks) { var point = new Point3D(layer, e.X, e.Y); // Make sure we have sent a block at this location CheckHandle testB; if (!this._sentLocations.TryGetValue(point, out testB)) { return; } // If we have sent mutliple blocks at this position, wait until we receive the last one if (testB.OverwrittenSends != 0) { testB.OverwrittenSends--; } else if (WorldUtils.AreSame <T, TBlock>(testB.Message, e)) { // Reset the timeout this._timeoutResetEvent.Set(); this.RepairMissed(point); } } }
internal static BlockDataWorld GetWorld(Message m, int width, int height, uint offset = InitOffset) { var world = new BlockDataWorld(width, height); uint pointer = GetStart(m, offset); string strValue2; while ((strValue2 = m[pointer] as string) == null || strValue2 != "we") { var block = m.GetInteger(pointer++); var l = (Layer)m.GetInteger(pointer++); byte[] byteArrayX = m.GetByteArray(pointer++); byte[] byteArrayY = m.GetByteArray(pointer++); switch (l) { case Layer.Background: var bgWorldBlock = new BackgroundBlock((Background.Id)block); foreach (Point pos in GetPos(byteArrayX, byteArrayY)) { world.Background[pos.X, pos.Y] = new BlockData <BackgroundBlock>(bgWorldBlock); } break; case Layer.Foreground: ForegroundBlock foregroundBlock; BlockArgsType blockArgsType = WorldUtils.GetBlockArgsType(WorldUtils.GetForegroundType(id: (Foreground.Id)block)); switch (blockArgsType) { case BlockArgsType.None: foregroundBlock = new ForegroundBlock((Foreground.Id)block); break; case BlockArgsType.Number: uint i = m.GetUInt(pointer++); foregroundBlock = new ForegroundBlock((Foreground.Id)block, i); break; case BlockArgsType.String: string str = m.GetString(pointer++); foregroundBlock = new ForegroundBlock((Foreground.Id)block, str); break; case BlockArgsType.Portal: var portalRotation = (Morph.Id)m.GetUInt(pointer++); uint portalId = m.GetUInt(pointer++); uint portalTarget = m.GetUInt(pointer++); foregroundBlock = new ForegroundBlock((Foreground.Id)block, portalId, portalTarget, portalRotation); break; case BlockArgsType.Label: string text = m.GetString(pointer++); string textcolor = m.GetString(pointer++); foregroundBlock = new ForegroundBlock((Foreground.Id)block, text, textcolor); break; default: throw new NotSupportedException("Invalid block."); } var fg = new BlockData <ForegroundBlock>(foregroundBlock); foreach (Point pos in GetPos(byteArrayX, byteArrayY)) { world.Foreground[pos.X, pos.Y] = fg; } break; } } return(world); }