|
15 | 15 | */ |
16 | 16 | package org.terasology.logic.debug; |
17 | 17 |
|
| 18 | +import org.terasology.config.Config; |
18 | 19 | import org.terasology.entitySystem.entity.EntityManager; |
19 | 20 | import org.slf4j.Logger; |
20 | 21 | import org.slf4j.LoggerFactory; |
21 | | -import org.terasology.logic.characters.CharacterImpulseEvent; |
22 | | -import org.terasology.logic.common.DisplayNameComponent; |
| 22 | +import org.terasology.logic.characters.CharacterComponent; |
| 23 | +import org.terasology.logic.characters.GazeMountPointComponent; |
23 | 24 | import org.terasology.logic.characters.CharacterMovementComponent; |
24 | 25 | import org.terasology.logic.characters.CharacterTeleportEvent; |
25 | | -import org.terasology.logic.characters.GazeMountPointComponent; |
| 26 | +import org.terasology.logic.characters.CharacterImpulseEvent; |
26 | 27 | import org.terasology.logic.characters.MovementMode; |
| 28 | +import org.terasology.logic.common.DisplayNameComponent; |
27 | 29 | import org.terasology.logic.location.Location; |
28 | 30 | import org.terasology.logic.location.LocationComponent; |
29 | 31 | import org.terasology.math.geom.Quat4f; |
@@ -57,6 +59,9 @@ public class MovementDebugCommands extends BaseComponentSystem { |
57 | 59 |
|
58 | 60 | @In |
59 | 61 | private EntityManager entityManager; |
| 62 | + |
| 63 | + @In |
| 64 | + private Config config; |
60 | 65 |
|
61 | 66 | @Command(shortDescription = "Grants flight and movement through walls", runOnServer = true, |
62 | 67 | requiredPermission = PermissionManager.CHEAT_PERMISSION) |
@@ -233,28 +238,61 @@ public String stepHeight(@Sender EntityRef client, @CommandParam("height") float |
233 | 238 | return ""; |
234 | 239 | } |
235 | 240 |
|
| 241 | + private float getJumpSpeed(float ratio, float defaultValue) { |
| 242 | + return (float) Math.pow(ratio, 0.74f) * 0.4f * defaultValue + 0.6f * defaultValue; |
| 243 | + } |
| 244 | + |
| 245 | + private float getInteractionRange(float ratio, float defaultValue) { |
| 246 | + return (float) Math.pow(ratio, 0.62f) * defaultValue; |
| 247 | + } |
| 248 | + |
| 249 | + private float getRunFactor(float ratio, float defaultValue) { |
| 250 | + return (float) Math.pow(ratio, 0.68f) * defaultValue; |
| 251 | + } |
| 252 | + |
236 | 253 | @Command(shortDescription = "Sets the height of the player", runOnServer = true, |
237 | 254 | requiredPermission = PermissionManager.CHEAT_PERMISSION) |
238 | 255 | public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) { |
239 | | - try { |
240 | | - ClientComponent clientComp = client.getComponent(ClientComponent.class); |
241 | | - CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class); |
242 | | - if (move != null) { |
243 | | - float prevHeight = move.height; |
244 | | - move.height = amount; |
245 | | - clientComp.character.saveComponent(move); |
246 | | - LocationComponent loc = client.getComponent(LocationComponent.class); |
247 | | - Vector3f currentPosition = loc.getWorldPosition(); |
248 | | - clientComp.character |
249 | | - .send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ()))); |
250 | | - physics.removeCharacterCollider(clientComp.character); |
251 | | - physics.getCharacterCollider(clientComp.character); |
252 | | - return "Height of player set to " + amount + " (was " + prevHeight + ")"; |
| 256 | + if (amount >= 1 && amount <= 25) { |
| 257 | + try { |
| 258 | + ClientComponent clientComp = client.getComponent(ClientComponent.class); |
| 259 | + CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class); |
| 260 | + CharacterComponent charComp = clientComp.character.getComponent(CharacterComponent.class); |
| 261 | + EntityRef player = clientComp.character; |
| 262 | + GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class); |
| 263 | + |
| 264 | + Prefab playerDefaults = Assets.getPrefab("engine:player").get(); |
| 265 | + CharacterMovementComponent moveDefault = playerDefaults.getComponent(CharacterMovementComponent.class); |
| 266 | + CharacterComponent characterDefault = playerDefaults.getComponent(CharacterComponent.class); |
| 267 | + |
| 268 | + if (move != null && gazeMountPointComponent != null) { |
| 269 | + float prevHeight = move.height; |
| 270 | + float defaultEyeHeight = config.getPlayer().getEyeHeight(); |
| 271 | + float foreHeadSize = moveDefault.height - defaultEyeHeight; |
| 272 | + float ratio = amount / moveDefault.height; |
| 273 | + |
| 274 | + move.height = amount; |
| 275 | + move.jumpSpeed = getJumpSpeed(ratio, moveDefault.jumpSpeed); |
| 276 | + move.stepHeight = ratio * moveDefault.stepHeight; |
| 277 | + move.distanceBetweenFootsteps = ratio * moveDefault.distanceBetweenFootsteps; |
| 278 | + move.runFactor = getRunFactor(ratio, moveDefault.runFactor); |
| 279 | + charComp.interactionRange = getInteractionRange(ratio, characterDefault.interactionRange); |
| 280 | + gazeMountPointComponent.translate.y = amount - foreHeadSize; |
| 281 | + Location.removeChild(player, gazeMountPointComponent.gazeEntity); |
| 282 | + Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY)); |
| 283 | + |
| 284 | + player.saveComponent(gazeMountPointComponent); |
| 285 | + clientComp.character.saveComponent(move); |
| 286 | + |
| 287 | + return "Height of player set to " + amount + " (was " + prevHeight + ")"; |
| 288 | + } |
| 289 | + return ""; |
| 290 | + } catch (NullPointerException e) { |
| 291 | + e.printStackTrace(); |
| 292 | + return ""; |
253 | 293 | } |
254 | | - return ""; |
255 | | - } catch (NullPointerException e) { |
256 | | - e.printStackTrace(); |
257 | | - return ""; |
| 294 | + } else { |
| 295 | + return "Invalid input. Accepted values: [1 to 25]"; |
258 | 296 | } |
259 | 297 | } |
260 | 298 |
|
|
0 commit comments