/// <summary> /// Loads all history one date close to center /// </summary> public void LoadAllRange(DateTime date, CoordDouble pos, int dimension) { List <HistoryNode> l = new List <HistoryNode> (); string[] files = Directory.GetFiles("log/packet/" + date.ToString("yyyy-MM-dd") + "/"); foreach (string f in files) { LoadFile(l, f); } List <HistoryNode> l2 = new List <HistoryNode> (); players.ClearMarked(); foreach (var n in l) { if (n.Dimension != dimension) { continue; } if (n.Position.DistanceXZTo(pos) < 10) { l2.Add(n); if (n.Item != null && n.Color == Color.Yellow) { Console.WriteLine(n.Username + " picked " + n.Item + " at " + n.Position); } players.Mark(n.Username); } } list = l2; if (list.Count > 0) { center = list [0].Timestamp.Date.AddHours(12); } Invalidate(); }
/// <param name='volume'> /// 1.0 == full /// </param> /// <param name='pitch'> /// 63 == 100% speed /// </param> public SoundEffect(string name, CoordDouble pos, double volume, int pitch) { this.Name = name; this.Position = pos; this.Volume = (float)volume; this.Pitch = (byte)pitch; }
public EntityTeleport(int eid, CoordDouble pos) { this.EID = eid; this.Position = pos; this.Yaw = Math.PI / 2; this.Pitch = 0; }
public Explosion(CoordDouble pos) { Position = pos; Radius = 2; Records = new Record[0]; PlayerMotion = new float[3]; }
public void Spawn(SpawnObject so, CoordDouble playerPos) { if (so.Type != Vehicles.Item) { return; } if (playerPos.Y > 50) { return; //Above ground probably a self created ore } //if (so.SourceEntity == 1) //break; //if (so..Item.Count != 1) // break; if (so.Position.DistanceTo(playerPos) > 10) { return; //Too far away, not your dig } if (DateTime.Now - BrokeBlock > TimeSpan.FromSeconds(3)) { return; //not from block broken } //DO track TrackEID = so.EID; }
public SoundEffect(string name, CoordDouble pos) { this.Name = name; this.Position = pos; this.Volume = 1.0f; this.Pitch = 63; }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Velocity = new CoordDouble(); Velocity.X = ((double)r.ReadInt16()) / scale; Velocity.Y = ((double)r.ReadInt16()) / scale; Velocity.Z = ((double)r.ReadInt16()) / scale; }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble(); Position.X = r.ReadDouble(); Position.Y = r.ReadDouble(); Position.Z = r.ReadDouble(); OnGround = r.ReadByte(); }
bool IsCubeCoord(CoordDouble coord) { //Console.WriteLine(coord.Q + coord.R + coord.S); //Console.WriteLine(Math.Abs(Math.Round(coord.Q + coord.R + coord.S, 14))); //return Math.Abs(coord.Q + coord.R + coord.S) < (0 + float.Epsilon); return(Math.Abs(Math.Round(coord.Q + coord.R + coord.S, 14)) < double.Epsilon); //return Mathf.Approximately((float)(coord.Q + coord.R + coord.S), 0); }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble (); Position.X = r.ReadDouble (); Position.Y = r.ReadDouble (); Position.Z = r.ReadDouble (); OnGround = r.ReadByte (); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Type = r.ReadSByte(); Position = new CoordDouble(); Position.X = ((double)r.ReadInt32()) / 32; Position.Y = ((double)r.ReadInt32()) / 32; Position.Z = ((double)r.ReadInt32()) / 32; }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Delta = new CoordDouble(); Delta.X = ((double)r.ReadSByte()) / scale; Delta.Y = ((double)r.ReadSByte()) / scale; Delta.Z = ((double)r.ReadSByte()) / scale; OnGround = r.ReadBoolean(); }
protected static CoordDouble ReadInt8(EndianBinaryReader r) { CoordDouble Position = new CoordDouble(); Position.X = ((double)r.ReadInt32()) / 8; Position.Y = ((double)r.ReadInt32()) / 8; Position.Z = ((double)r.ReadInt32()) / 8; return(Position); }
public static void Tp(string player, CoordDouble position, Dimensions dimension) { ControlMessage cm = new ControlMessage(); cm.TP = new TpPlayer(); cm.TP.Username = player; cm.TP.Position = position; cm.TP.Dimension = (int)dimension; Send(cm); }
void NewPos(CoordDouble p) { if (first) { pos = p; first = false; } if (pos.DistanceTo(p) > 0.1) Back(); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Delta = new CoordDouble(); Delta.X = ((double)r.ReadSByte()) / 32; Delta.Y = ((double)r.ReadSByte()) / 32; Delta.Z = ((double)r.ReadSByte()) / 32; Yaw = r.ReadSByte() * Math.PI / 128; Pitch = r.ReadSByte() * Math.PI / 128; OnGround = r.ReadBoolean(); }
private bool FilterDirection(CoordInt block) { if (block.X == -1 && block.Y == 255 && block.Z == -1) { return(false); } //Player view is 1.5 above its position CoordDouble offset = block - this.Position + new CoordDouble(0.5, -1, 0.5); CoordDouble unit = new CoordDouble( -Math.Cos(Pitch * Math.PI / 180) * Math.Sin(Yaw * Math.PI / 180), -Math.Sin(Pitch * Math.PI / 180), Math.Cos(Pitch * Math.PI / 180) * Math.Cos(Yaw * Math.PI / 180)); double viewDist = offset.Scalar(unit); double perDist = (offset - unit * viewDist).Abs; #if DEBUG /*this.Tell ("Block: " + block + * //"Offset: " + offset.ToString ("0.0") + * //" Unit: " + unit.ToString ("0.0") + * " Dist: " + viewDist.ToString ("0.0") + * " Per: " + perDist.ToString ("0.0")); */ #endif //Ignore extreme values if (perDist > 20) { return(false); } if (viewDist > 20) { return(false); } //Logical max i 0.87 //Dont block anymore since client does not restore uncomfirmed blocks if (perDist > 1.5) { //Log.WritePlayer (this, "Aimed sideways: " + perDist.ToString ("0.00") + " > 0.87"); //return true; } if (viewDist > 6) { //Log.WritePlayer (this, "Aimed too far: " + viewDist.ToString ("0.0") + " > 6.0, " + block); //return true; } if (viewDist < -0.1) { //Log.WritePlayer (this, "Aimed behind: " + viewDist.ToString ("0.0") + " < 0"); //return true; } return(false); }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Delta = new CoordDouble (); Delta.X = ((double)r.ReadSByte ()) / 32; Delta.Y = ((double)r.ReadSByte ()) / 32; Delta.Z = ((double)r.ReadSByte ()) / 32; Yaw = r.ReadSByte () * Math.PI / 128; Pitch = r.ReadSByte () * Math.PI / 128; OnGround = r.ReadBoolean(); }
protected override void Parse(EndianBinaryReader r) { Target = ReadVarInt(r); Type = (Types)ReadVarInt(r); if (Type == Types.InteractAt) { TargetPos = new CoordDouble(); TargetPos.X = r.ReadSingle(); TargetPos.Y = r.ReadSingle(); TargetPos.Z = r.ReadSingle(); } }
public WorldSession(Client player) { this.Player = player; Mode = GameMode.Survival; Position = new CoordDouble(); if (player.Session != null) { Dimension = player.Session.Dimension; Position = player.Session.Position; } }
void NewPos(CoordDouble p) { if (first) { pos = p; first = false; } if (pos.DistanceTo(p) > 0.1) { Back(); } }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble(); Position.X = r.ReadDouble(); Position.Y = r.ReadDouble(); Position.Z = r.ReadDouble(); Yaw = r.ReadSingle() * Math.PI / 180; Pitch = r.ReadSingle() * Math.PI / 180; OnGround = r.ReadBoolean(); #if DEBUG //Console.WriteLine("PPL: " + Pitch); #endif }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble(); Position.X = r.ReadDouble(); Position.Y = r.ReadDouble(); Position.Z = r.ReadDouble(); Yaw = r.ReadSingle() * Math.PI / 180; Pitch = r.ReadSingle() * Math.PI / 180; Relative = r.ReadByte(); //Console.WriteLine("Parsed: " + this); //Debug.WriteLine("Parsed: " + this); }
public void TestLerp() { //Tests.EqualHex("hex_round 1", new Hex(5, -10, 5), FractionalHex.HexRound(FractionalHex.HexLerp(new FractionalHex(0, 0, 0), new FractionalHex(10, -20, 10), 0.5))); //Tests.EqualHex("hex_round 2", FractionalHex.HexRound(a), FractionalHex.HexRound(FractionalHex.HexLerp(a, b, 0.499))); //Tests.EqualHex("hex_round 3", FractionalHex.HexRound(b), FractionalHex.HexRound(FractionalHex.HexLerp(a, b, 0.501))); CoordDouble a = new CoordDouble(0, 0, 0); CoordDouble b = new CoordDouble(1, -1, 0); Assert.That(new CoordDouble(0, 0, 0).Lerp(new CoordDouble(10, -20, 10), 0.5).Round(), Is.EqualTo(new Coord(5, -10, 5))); Assert.That(a.Lerp(b, 0.499).Round(), Is.EqualTo(a.Round())); Assert.That(a.Lerp(b, 0.501).Round(), Is.EqualTo(b.Round())); }
protected virtual void SetPosition(CoordDouble pos, bool speedguard) { if (World.Regions != null) RegionCrossing.SetRegion(this); if (Mode == GameMode.Creative) speedguard = false; if (Mode == GameMode.Spectator) speedguard = false; if (speedguard) SpeedGuard.ClientMovement(this, pos); Position = pos; }
protected override void Parse(EndianBinaryReader r) { ParticleID = r.ReadInt32(); LongDistance = r.ReadBoolean(); Position = new CoordDouble(); Position.X = r.ReadSingle(); Position.Y = r.ReadSingle(); Position.Z = r.ReadSingle(); Size = new CoordDouble(); Size.X = r.ReadSingle(); Size.Y = r.ReadSingle(); Size.Z = r.ReadSingle(); Speed = r.ReadSingle(); Count = r.ReadInt32(); Debug.WriteLine(this); }
public SpawnMob(MobType type) { Type = type; Pos = new CoordDouble(); Metadata = new Metadata(); Metadata.SetByte(17, 0); Metadata.SetByte(0, 0); Metadata.SetByte(16, -1); Metadata.SetShort(1, 300); Metadata.SetFloat(6, 20); Metadata.SetInt(7, 0); Metadata.SetByte(8, 0); Metadata.SetByte(9, 0); Metadata.SetString(10, ""); Metadata.SetByte(11, 0); }
public SpawnPlayer(int eid, Client player) { EID = eid; PlayerUUID = player.UUID; Position = new CoordDouble(); Meta = new Metadata(); Meta.SetByte(17, 0); Meta.SetByte(0, 0); Meta.SetByte(16, 0); Meta.SetShort(1, 300); Meta.SetInt(18, 0); Meta.SetFloat(5, 20); Meta.SetFloat(6, 20); Meta.SetInt(7, 0); Meta.SetByte(8, 0); Meta.SetByte(9, 0); }
public void Spawn(SpawnObject so, CoordDouble playerPos) { if (so.Type != Vehicles.Item) return; if (playerPos.Y > 50) return; //Above ground probably a self created ore //if (so.SourceEntity == 1) //break; //if (so..Item.Count != 1) // break; if (so.Position.DistanceTo(playerPos) > 10) return; //Too far away, not your dig if (DateTime.Now - BrokeBlock > TimeSpan.FromSeconds(3)) return; //not from block broken //DO track TrackEID = so.EID; }
public void TestProperties() { CoordDouble c = new CoordDouble(3.5, 2.1); Assert.That(c.Q, Is.EqualTo(3.5)); Assert.That(c.R, Is.EqualTo(2.1)); c = new CoordDouble(12.74, -9.3); Assert.That(c.Q, Is.EqualTo(12.74)); Assert.That(c.R, Is.EqualTo(-9.3)); c = new CoordDouble(5.2, 6.8, -12); Assert.That(c.Q, Is.EqualTo(5.2)); Assert.That(c.R, Is.EqualTo(6.8)); Assert.That(c.S, Is.EqualTo(-12)); c = new CoordDouble(-4.4, -8.8, 13.2); Assert.That(c.Q, Is.EqualTo(-4.4)); Assert.That(c.R, Is.EqualTo(-8.8)); Assert.That(c.S, Is.EqualTo(13.2)); }
public SpawnPlayer(int eid, Client player) { EID = eid; PlayerUUID = player.UUID; Position = new CoordDouble(); Meta = new Metadata(); Meta.SetFloat(17, 0); Meta.SetByte(0, 0); Meta.SetByte(16, 0); Meta.SetShort(1, 300); Meta.SetString(2, ""); Meta.SetInt(18, 0); Meta.SetByte(3, 0); Meta.SetByte(4, 0); Meta.SetFloat(6, 10); Meta.SetInt(7, 0); Meta.SetByte(8, 0); Meta.SetByte(9, 0); Meta.SetByte(10, 0); }
public void TestRound() { //FractionalHex a = new FractionalHex(0, 0, 0); //FractionalHex b = new FractionalHex(1, -1, 0); //FractionalHex c = new FractionalHex(0, -1, 1); //Tests.EqualHex("hex_round 4", FractionalHex.HexRound(a), FractionalHex.HexRound(new FractionalHex(a.q * 0.4 + b.q * 0.3 + c.q * 0.3, a.r * 0.4 + b.r * 0.3 + c.r * 0.3, a.s * 0.4 + b.s * 0.3 + c.s * 0.3))); //Tests.EqualHex("hex_round 5", FractionalHex.HexRound(c), FractionalHex.HexRound(new FractionalHex(a.q * 0.3 + b.q * 0.3 + c.q * 0.4, a.r * 0.3 + b.r * 0.3 + c.r * 0.4, a.s * 0.3 + b.s * 0.3 + c.s * 0.4))); CoordDouble a = new CoordDouble(0, 0, 0); CoordDouble b = new CoordDouble(1, -1, 0); CoordDouble c = new CoordDouble(0, -1, 1); Assert.That(new CoordDouble(a.Q * 0.4 + b.Q * 0.3 + c.Q * 0.3, a.R * 0.4 + b.R * 0.3 + c.R * 0.3, a.S * 0.4 + b.S * 0.3 + c.S * 0.3).Round(), Is.EqualTo(a.Round())); Assert.That(new CoordDouble(a.Q * 0.3 + b.Q * 0.3 + c.Q * 0.4, a.R * 0.3 + b.R * 0.3 + c.R * 0.4, a.S * 0.3 + b.S * 0.3 + c.S * 0.4).Round(), Is.EqualTo(c.Round())); }
protected override void Parse(EndianBinaryReader r) { Position = new CoordDouble(); Position.X = r.ReadSingle(); Position.Y = r.ReadSingle(); Position.Z = r.ReadSingle(); Radius = r.ReadSingle(); int count = r.ReadInt32(); Records = new Record[count]; for (int n = 0; n < count; n++) { Records [n] = new Record(); Records [n].X = r.ReadSByte(); Records [n].Y = r.ReadSByte(); Records [n].Z = r.ReadSByte(); } PlayerMotion = new float[3]; PlayerMotion [0] = r.ReadSingle(); PlayerMotion [1] = r.ReadSingle(); PlayerMotion [2] = r.ReadSingle(); }
protected virtual void SetPosition(CoordDouble pos, bool speedguard) { if (World.Regions != null) { RegionCrossing.SetRegion(this); } if (Mode == GameMode.Creative) { speedguard = false; } if (Mode == GameMode.Spectator) { speedguard = false; } if (speedguard) { SpeedGuard.ClientMovement(this, pos); } Position = pos; }
/// <summary> /// Return true if region was created /// </summary> void CreateRegion(Client player, CoordDouble start, CoordDouble end) { RegionList regions = player.Session.World.Regions; try { WorldRegion wr = Create(player.Session.Dimension, start, end, player.Name + "'s place", player, player.MinecraftUsername, regions); if (wr == null) { return; } regionStart.Remove(player.MinecraftUsername); Log.WritePlayer(player, "Region Created: " + wr); player.TellSystem(Chat.Aqua, "Region created"); return; } catch (InvalidOperationException ioe) { player.TellSystem(Chat.Red, ioe.Message); return; } }
protected override void SetPosition(CoordDouble pos, bool speedguard) { base.SetPosition(pos, speedguard); //AFK detection /*if (AfkPos.DistanceTo(pos) > 1) * { * AfkTime = DateTime.Now; * AfkPos = pos; * } * if (DateTime.Now - AfkTime > AfkWorld.Timeout) * { * //Dont go afk world automatically, since it could break book writing * //Player.SetWorld(World.AFK); * }*/ if (Dimension == Dimensions.Nether && pos.Y > 127 && this.Mode != GameMode.Creative) { Player.Warp(new CoordDouble(16, 200, -16), Dimensions.Overworld, World.Main); return; } }
protected static void WriteInt8(EndianBinaryWriter writer, CoordDouble Position) { writer.Write((int)(Position.X * 8)); writer.Write((int)(Position.Y * 8)); writer.Write((int)(Position.Z * 8)); }
protected static CoordDouble ReadInt8(EndianBinaryReader r) { CoordDouble Position = new CoordDouble(); Position.X = ((double)r.ReadInt32()) / 8; Position.Y = ((double)r.ReadInt32()) / 8; Position.Z = ((double)r.ReadInt32()) / 8; return Position; }
public SpawnGlobalEntity(CoordDouble pos) { Position = pos; Type = 1; }
public SpawnExperienceOrb() { Position = new CoordDouble(); }
public void SetPositionServer(CoordDouble pos) { this.SetPosition(pos, false); }
/// <summary> /// Return true if region was created /// </summary> void CreateRegion(Client player, CoordDouble start, CoordDouble end) { RegionList regions = player.Session.World.Regions; try { WorldRegion wr = Create(player.Session.Dimension, start, end, player.Name + "'s place", player, player.MinecraftUsername, regions); if (wr == null) return; regionStart.Remove(player.MinecraftUsername); Log.WritePlayer(player, "Region Created: " + wr); player.TellSystem(Chat.Aqua, "Region created"); return; } catch (InvalidOperationException ioe) { player.TellSystem(Chat.Red, ioe.Message); return; } }
protected override void SetPosition(CoordDouble pos, bool speedguard) { base.SetPosition(pos, false); }
internal static WorldRegion Create(Dimensions dimension, CoordDouble start, CoordDouble end, string regionName, Client player, string resident, RegionList regions) { if (regions == null) throw new ErrorException("No regions in this world"); WorldRegion w = new WorldRegion(dimension, start, end, regionName); w.Residents.Add(resident); w.Type = "protected"; lock (regions) { //Test for overlapping regions WorldRegion existing = RegionCrossing.GetBaseRegion(regions.List, w, dimension); if (existing == null) { //New Top level region regions.List.Add(w); RegionLoader.Save(regions); return w; } //Make sure you already are a part of the region if (existing.ResidentPermissions(player) == false) throw new ErrorException("You can't set a subregion unless you are a resident in the parent region."); //All inside, make subregion if (existing.Cover(w)) { if (existing.SubRegions == null) existing.SubRegions = new List<WorldRegion>(); existing.SubRegions.Add(w); RegionLoader.Save(regions); return w; } //Need to make a wrapping region //Only admins may create wrapping regions if (player != null && player.Admin() == false) throw new ErrorException("New region must be fully inside " + existing); //New region covering several old ones? var parentList = WorldRegion.GetParentList(regions, existing); if (parentList == null) throw new ErrorException("Parent list not found for " + existing); //regions to move inside the new one var moving = new List<WorldRegion>(); //Determine if we are breaking any boundaries bool breaking = false; foreach (var s in parentList) { if (w.Cover(s)) { moving.Add(s); } else if (w.Overlap(s)) //Overlap but not cover completely { player.TellSystem(Chat.Red, "Breaking boundaries: " + s); breaking = true; } } if (breaking) { player.TellSystem(Chat.Red, "Failed creating: " + w); player.TellSystem(Chat.Red, "Aborting: Broke region boundaries"); return null; } //Move subregions into new region and remove from parentlist w.SubRegions = moving; foreach (var s in moving) { player.TellSystem(Chat.Aqua, "New subregion: " + s); parentList.Remove(s); } parentList.Add(w); RegionLoader.Save(regions); return w; } }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); Position = ReadAbsInt(r); Count = r.ReadInt16(); }
protected static void WriteAbsInt(EndianBinaryWriter writer, CoordDouble Position) { writer.Write((int)(Position.X * 32)); writer.Write((int)(Position.Y * 32)); writer.Write((int)(Position.Z * 32)); }