public bool TryChunk(Vector3i cworldPos, int posMult, Chunk chi = null) // TODO: Efficiency? { if (pkick) { return(false); } if (!ChunksAwareOf.ContainsKey(cworldPos) || ChunksAwareOf[cworldPos].LOD > posMult) // TODO: Efficiency - TryGetValue? { double dist = (cworldPos.ToLocation() * Chunk.CHUNK_SIZE - LoadRelPos).LengthSquared(); bool async = chi == null && dist > (Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * 2 * 2); if (async) { TheRegion.LoadChunk_Background(cworldPos, (chn) => { if (!pkick && chn != null) { ChunkNetwork.SendPacket(new ChunkInfoPacketOut(chn, posMult)); } }); } else { Chunk chk = chi != null ? chi : TheRegion.LoadChunk(cworldPos); ChunkNetwork.SendPacket(new ChunkInfoPacketOut(chk, posMult)); } ChunksAwareOf.Remove(cworldPos); ChunksAwareOf.Add(cworldPos, new ChunkAwarenessInfo() { ChunkPos = cworldPos, LOD = posMult }); return(true); } return(false); }
public override void Tick() { if (!IsSpawned) { return; } if (TheRegion.Delta <= 0) { return; } base.Tick(); opstt += TheRegion.Delta; while (opstt > 1.0) { opstt -= 1.0; OncePerSecondTick(); } ItemStack cit = Items.GetItemForSlot(Items.cItem); if (GetVelocity().LengthSquared() > 1) // TODO: Move animation to CharacterEntity { // TODO: Replicate animation automation on client? SetAnimation("human/stand/run", 0); SetAnimation("human/stand/" + AnimToHold(cit), 1); SetAnimation("human/stand/run", 2); } else { SetAnimation("human/stand/idle01", 0); SetAnimation("human/stand/" + AnimToHold(cit), 1); SetAnimation("human/stand/idle01", 2); } if (Click) // TODO: Move clicking to CharacterEntity { cit.Info.Click(this, cit); LastClick = TheRegion.GlobalTickTime; WasClicking = true; } else if (WasClicking) { cit.Info.ReleaseClick(this, cit); WasClicking = false; } if (AltClick) { cit.Info.AltClick(this, cit); LastAltClick = TheRegion.GlobalTickTime; WasAltClicking = true; } else if (WasAltClicking) { cit.Info.ReleaseAltClick(this, cit); WasAltClicking = false; } cit.Info.Tick(this, cit); WasItemLefting = ItemLeft; WasItemUpping = ItemUp; WasItemRighting = ItemRight; Location pos = LoadRelPos; Vector3i cpos = TheRegion.ChunkLocFor(pos); if (cpos != pChunkLoc) { for (int x = -2; x <= 2; x++) { for (int y = -2; y <= 2; y++) { for (int z = -2; z <= 2; z++) { TryChunk(cpos + new Vector3i(x, y, z), 1); } } } } ChunkMarchAndSend(); if (cpos != pChunkLoc) { /* * // TODO: Better system -> async? * TrySet(pos, 1, 1, 0, 1, false); * TrySet(pos, ViewRadiusInChunks / 2, ViewRadiusInChunks / 2, 0, 1, false); * TrySet(pos, ViewRadiusInChunks, ViewRadiusInChunks, 0, 1, false); * TrySet(pos, ViewRadiusInChunks + 1, ViewRadiusInChunks, 15, 2, true); * TrySet(pos, ViewRadiusInChunks + ViewRadExtra2, ViewRadiusInChunks + ViewRadExtra2Height, 30, 2, true); * TrySet(pos, ViewRadiusInChunks + ViewRadExtra5, ViewRadiusInChunks + ViewRadExtra5Height, 60, 5, true); */ /* * if (!loadedInitially) * { * loadedInitially = true; * ChunkNetwork.SendPacket(new TeleportPacketOut(GetPosition())); * ChunkNetwork.SendPacket(new OperationStatusPacketOut(StatusOperation.CHUNK_LOAD, 1)); * } * else * { * ChunkNetwork.SendPacket(new OperationStatusPacketOut(StatusOperation.CHUNK_LOAD, 2)); * } */ foreach (ChunkAwarenessInfo ch in ChunksAwareOf.Values) { if (!ShouldLoadChunk(ch.ChunkPos)) { removes.Add(ch.ChunkPos); } else if (!ShouldSeeChunk(ch.ChunkPos) && ch.LOD <= BestLOD) { ch.LOD = Chunk.CHUNK_SIZE; } } foreach (Vector3i loc in removes) { Chunk ch = TheRegion.GetChunk(loc); if (ch != null) { ForgetChunk(ch, loc); } else { ChunksAwareOf.Remove(loc); } } removes.Clear(); pChunkLoc = cpos; } if (Breadcrumbs.Count > 0) { double dist = (GetPosition() - Breadcrumbs[Breadcrumbs.Count - 1]).LengthSquared(); if (dist > BreadcrumbRadius * BreadcrumbRadius) { Location one = Breadcrumbs[Breadcrumbs.Count - 1]; Location two = GetPosition().GetBlockLocation() + new Location(0.5f, 0.5f, 0.5f); Breadcrumbs.Add((two - one).Normalize() * BreadcrumbRadius + one); // TODO: Effect? } } // TODO: Move use to CharacterEntity if (Use) { Location forw = ForwardVector(); CollisionResult cr = TheRegion.Collision.RayTrace(GetEyePosition(), GetEyePosition() + forw * 5, IgnoreThis); if (cr.Hit && cr.HitEnt != null && cr.HitEnt.Tag is EntityUseable) { if (UsedNow != (EntityUseable)cr.HitEnt.Tag) { if (UsedNow != null && ((Entity)UsedNow).IsSpawned) { UsedNow.StopUse(this); } UsedNow = (EntityUseable)cr.HitEnt.Tag; UsedNow.StartUse(this); } } else if (UsedNow != null) { if (((Entity)UsedNow).IsSpawned) { UsedNow.StopUse(this); } UsedNow = null; } } else if (UsedNow != null) { if (((Entity)UsedNow).IsSpawned) { UsedNow.StopUse(this); } UsedNow = null; } if (!CanReach(GetPosition())) { Teleport(posClamp(GetPosition())); } }