internal void FollowPath(Vector2D weaponPos, IMovementPath path) { if (!IsWalkingEnabled) { return; } if (!currentWaypoint.HasValue || currentWaypoint.Value.DistanceTo(weaponPos) < WAYPOINT_RADIUS) { currentWaypoint = path.NextPoint; Api.Logger.Dev("Automaton: Next waypoint is " + currentWaypoint); } if (!currentWaypoint.HasValue) { Api.Logger.Error("Automaton: Failed to get next waypoint"); return; } Vector2D diff = currentWaypoint.Value - weaponPos; var moveModes = CharacterMoveModesHelper.CalculateMoveModes(diff) | CharacterMoveModes.ModifierRun; // Running will yield us more LP/minute (by miniscule amount, though) var command = new CharacterInputUpdate(moveModes, 0); // Ugh, too lazy to look for usages to understand whether `0` is "up" or "right". Probably "right", but I won't mess with trigonometry, forgive me. ((PlayerCharacter)CurrentCharacter.ProtoCharacter).ClientSetInput(command); }
protected void ServerSetMobInput( ICharacter character, Vector2F movementDirection, double rotationAngleRad) { var movementDirectionNormalized = new Vector2D( ClampDirection(movementDirection.X), ClampDirection(movementDirection.Y)).Normalized; var moveSpeed = character.SharedGetFinalStatValue(StatName.MoveSpeed); moveSpeed *= ProtoTile.SharedGetTileMoveSpeedMultiplier(character.Tile); Server.Characters.SetMoveSpeed(character, moveSpeed); var moveVelocity = movementDirectionNormalized * moveSpeed; Server.Characters.SetVelocity(character, moveVelocity); var statePublic = GetPublicState(character); statePublic.AppliedInput.Set( new CharacterInput() { MoveModes = CharacterMoveModesHelper.CalculateMoveModes(movementDirectionNormalized), RotationAngleRad = (float)rotationAngleRad, }, moveSpeed); double ClampDirection(double dir) { const double directionThreshold = 0.1; if (dir > directionThreshold) { return(1); } if (dir < -directionThreshold) { return(-1); } return(0); } }
protected void ServerSetMobInput( ICharacter character, Vector2F movementDirection, double rotationAngleRad) { var movementDirectionNormalized = new Vector2D( ClampDirection(movementDirection.X), ClampDirection(movementDirection.Y)).Normalized; double moveSpeed; if (movementDirection.X != 0 && movementDirection.Y != 0) { moveSpeed = character.SharedGetFinalStatValue(StatName.MoveSpeed); moveSpeed *= ProtoTile.SharedGetTileMoveSpeedMultiplier(character.Tile); } else { moveSpeed = 0; } Server.World.SetDynamicObjectMoveSpeed(character, moveSpeed); var moveAcceleration = movementDirectionNormalized * this.PhysicsBodyAccelerationCoef * moveSpeed; Server.World.SetDynamicObjectPhysicsMovement(character, moveAcceleration, targetVelocity: moveSpeed); var statePublic = GetPublicState(character); statePublic.AppliedInput.Set( new CharacterInput() { MoveModes = CharacterMoveModesHelper.CalculateMoveModes(movementDirectionNormalized), RotationAngleRad = (float)rotationAngleRad, }, moveSpeed);