public override void Handle(Game game, Packet_Server packet) { Entity entity = game.entities[packet.EntityPosition.Id]; EntityPosition_ pos = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation); entity.networkPosition = pos; entity.networkPosition.PositionLoaded = true; entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart(); if (packet.EntityPosition.Id == game.LocalPlayerId) { // Override local player position if necessary (teleport) game.player.position.x = pos.x; game.player.position.y = pos.y; game.player.position.z = pos.z; game.player.position.rotx = pos.rotx; game.player.position.roty = pos.roty; game.player.position.rotz = pos.rotz; entity.networkPosition = null; } else if (entity.push != null) { // Create push force for any player except local player entity.push.XFloat = packet.EntityPosition.PositionAndOrientation.X; entity.push.YFloat = packet.EntityPosition.PositionAndOrientation.Z; entity.push.ZFloat = packet.EntityPosition.PositionAndOrientation.Y; } }
public static EntityPosition_ ToClientEntityPosition(Packet_PositionAndOrientation pos) { float one = 1; EntityPosition_ p = new EntityPosition_(); p.x = (one * pos.X) / 32; p.y = (one * pos.Y) / 32; p.z = (one * pos.Z) / 32; p.rotx = Game.Angle256ToRad(pos.Pitch); p.roty = Game.Angle256ToRad(pos.Heading); return(p); }
public override void Handle(Game game, Packet_Server packet) { Entity entity = game.entities[packet.EntityPosition.Id]; EntityPosition_ pos = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation); entity.networkPosition = pos; entity.networkPosition.PositionLoaded = true; entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart(); if (packet.EntityPosition.Id == game.LocalPlayerId) { game.player.position.x = pos.x; game.player.position.y = pos.y; game.player.position.z = pos.z; entity.networkPosition = null; } }
public void Update(EntityPosition_ stateplayerposition, Controls move, float dt, BoolRef soundnow, Vector3Ref push, float modelheight) { if (game.stopPlayerMove) { movedz = 0; game.stopPlayerMove = false; } // No air control if (!isplayeronground) { acceleration.acceleration1 = 0.99f; acceleration.acceleration2 = 0.2f; acceleration.acceleration3 = 70; } // Trampoline { int blockunderplayer = game.BlockUnderPlayer(); if (blockunderplayer != -1 && blockunderplayer == game.d_Data.BlockIdTrampoline() && (!isplayeronground) && !game.controls.shiftkeydown) { game.controls.wantsjump = true; jumpstartacceleration = 20.666f * constGravity; } } // Slippery walk on ice and when swimming { int blockunderplayer = game.BlockUnderPlayer(); if ((blockunderplayer != -1 && game.d_Data.IsSlipperyWalk()[blockunderplayer]) || game.SwimmingBody()) { acceleration.acceleration1 = 0.99f; acceleration.acceleration2 = 0.2f; acceleration.acceleration3 = 70; } } soundnow.value = false; Vector3Ref diff1ref = new Vector3Ref(); VectorTool.ToVectorInFixedSystem (move.movedx * movespeednow * dt, 0, move.movedy * movespeednow * dt, stateplayerposition.rotx, stateplayerposition.roty, diff1ref); Vector3Ref diff1 = new Vector3Ref(); diff1.X = diff1ref.X; diff1.Y = diff1ref.Y; diff1.Z = diff1ref.Z; if (MiscCi.Vec3Length(push.X, push.Y, push.Z) > 0.01f) { push.Normalize(); push.X *= 5; push.Y *= 5; push.Z *= 5; } diff1.X += push.X * dt; diff1.Y += push.Y * dt; diff1.Z += push.Z * dt; bool loaded = false; int cx = game.platform.FloatToInt(game.player.position.x / Game.chunksize); int cy = game.platform.FloatToInt(game.player.position.z / Game.chunksize); int cz = game.platform.FloatToInt(game.player.position.y / Game.chunksize); if (game.map.IsValidChunkPos(cx, cy, cz)) { if (game.map.chunks[MapUtilCi.Index3d(cx, cy, cz, game.map.MapSizeX / Game.chunksize, game.map.MapSizeY / Game.chunksize)] != null) { loaded = true; } } else { loaded = true; } if ((!(move.freemove)) && loaded) { if (!game.SwimmingBody()) { movedz += -constGravity;//gravity } else { movedz += -constGravity * constWaterGravityMultiplier; //more gravity because it's slippery. } } game.movedz = movedz; if (constEnableAcceleration) { curspeed.X *= acceleration.acceleration1; curspeed.Y *= acceleration.acceleration1; curspeed.Z *= acceleration.acceleration1; curspeed.X = MakeCloserToZero(curspeed.X, acceleration.acceleration2 * dt); curspeed.Y = MakeCloserToZero(curspeed.Y, acceleration.acceleration2 * dt); curspeed.Z = MakeCloserToZero(curspeed.Z, acceleration.acceleration2 * dt); diff1.Y += move.moveup ? 2 * movespeednow * dt : 0; diff1.Y -= move.movedown ? 2 * movespeednow * dt : 0; curspeed.X += diff1.X * acceleration.acceleration3 * dt; curspeed.Y += diff1.Y * acceleration.acceleration3 * dt; curspeed.Z += diff1.Z * acceleration.acceleration3 * dt; if (curspeed.Length() > movespeednow) { curspeed.Normalize(); curspeed.X *= movespeednow; curspeed.Y *= movespeednow; curspeed.Z *= movespeednow; } } else { if (MiscCi.Vec3Length(diff1.X, diff1.Y, diff1.Z) > 0) { diff1.Normalize(); } curspeed.X = diff1.X * movespeednow; curspeed.Y = diff1.Y * movespeednow; curspeed.Z = diff1.Z * movespeednow; } Vector3Ref newposition = Vector3Ref.Create(0, 0, 0); if (!(move.freemove)) { newposition.X = stateplayerposition.x + curspeed.X; newposition.Y = stateplayerposition.y + curspeed.Y; newposition.Z = stateplayerposition.z + curspeed.Z; if (!game.SwimmingBody()) { newposition.Y = stateplayerposition.y; } // Fast move when looking at the ground float diffx = newposition.X - stateplayerposition.x; float diffy = newposition.Y - stateplayerposition.y; float diffz = newposition.Z - stateplayerposition.z; float difflength = MiscCi.Vec3Length(diffx, diffy, diffz); if (difflength > 0) { diffx /= difflength; diffy /= difflength; diffz /= difflength; diffx *= curspeed.Length(); diffy *= curspeed.Length(); diffz *= curspeed.Length(); } newposition.X = stateplayerposition.x + diffx * dt; newposition.Y = stateplayerposition.y + diffy * dt; newposition.Z = stateplayerposition.z + diffz * dt; } else { newposition.X = stateplayerposition.x + (curspeed.X) * dt; newposition.Y = stateplayerposition.y + (curspeed.Y) * dt; newposition.Z = stateplayerposition.z + (curspeed.Z) * dt; } newposition.Y += movedz * dt; Vector3Ref previousposition = Vector3Ref.Create(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z); if (!move.noclip) { float[] v = WallSlide( Vec3.FromValues(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z), Vec3.FromValues(newposition.X, newposition.Y, newposition.Z), modelheight); stateplayerposition.x = v[0]; stateplayerposition.y = v[1]; stateplayerposition.z = v[2]; } else { stateplayerposition.x = newposition.X; stateplayerposition.y = newposition.Y; stateplayerposition.z = newposition.Z; } if (!(move.freemove)) { if ((isplayeronground) || game.SwimmingBody()) { jumpacceleration = 0; movedz = 0; } if ((move.wantsjump || move.wantsjumphalf) && (((jumpacceleration == 0 && isplayeronground) || game.SwimmingBody()) && loaded) && (!game.SwimmingEyes())) { jumpacceleration = move.wantsjumphalf ? jumpstartaccelerationhalf : jumpstartacceleration; soundnow.value = true; } if (jumpacceleration > 0) { isplayeronground = false; jumpacceleration = jumpacceleration / 2; } //if (!this.reachedceiling) { movedz += jumpacceleration * constJump; } } else { isplayeronground = true; } game.isplayeronground = isplayeronground; }
public static EntityPosition_ ToClientEntityPosition(Packet_PositionAndOrientation pos) { float one = 1; EntityPosition_ p = new EntityPosition_(); p.x = (one * pos.X) / 32; p.y = (one * pos.Y) / 32; p.z = (one * pos.Z) / 32; p.rotx = Game.Angle256ToRad(pos.Pitch); p.roty = Game.Angle256ToRad(pos.Heading); return p; }