Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/valheimPlus/ValheimPlus
Browse files Browse the repository at this point in the history
 into development
  • Loading branch information
nxPublic committed Jun 9, 2021
2 parents 85d8bb7 + 93236a0 commit ab2b081
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 207 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,4 @@ Please see [CONTRIBUTING.md](/CONTRIBUTING.md) for details on compiling V+ for d
* Thomas 'Aeluwas#2855' B. - https://github.com/exscape
* Nick 'baconparticles' P. - https://github.com/baconparticles
* An 'Hachidan' N. - https://github.com/ahnguyen09
* Abra - https://github.com/Abrackadabra
155 changes: 64 additions & 91 deletions ValheimPlus/AdvancedBuildingMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ namespace ValheimPlus
class ABM
{
// Status
public static bool isActive = false;
public static bool isActive;

// Player Instance
private static Player PlayerInstance;

// Control Flags
static bool controlFlag = false;
static bool shiftFlag = false;
static bool altFlag = false;
static bool controlFlag;
static bool shiftFlag;
static bool altFlag;

// Exit flags
public static bool exitOnNextIteration = false;
static bool blockDefaultFunction = false;
public static bool exitOnNextIteration;
static bool blockDefaultFunction;

static private Piece component;
private static Piece component;

//Modification Speeds
static float gDistance = 2;
static float gScrollDistance = 2;
// Modification Speeds
const float BASE_TRANSLATION_DISTANCE = (float) 0.1; // 1/10th of a 1m pole
const float BASE_ROTATION_ANGLE_DEGREES = 3;

static float currentModificationSpeed = 1;
const float MIN_MODIFICATION_SPEED = 1;
const float MAX_MODIFICATION_SPEED = 30;

// Save and Load object rotation
static Quaternion savedRotation = new Quaternion();
static Quaternion savedRotation;

public static void Run(ref Player __instance)
{
Expand Down Expand Up @@ -64,10 +68,7 @@ public static void Run(ref Player __instance)

if (isActive && component == null)
{
if (isActive)
{
exitMode();
}
exitMode();

return;
}
Expand All @@ -86,8 +87,10 @@ public static void Run(ref Player __instance)
// Check if Build Mode && Correct build mode
if (isInBuildMode() && IsHoeOrTerrainTool(selectedPrefab()))
{
if(isActive)
if (isActive)
{
exitMode();
}

return;
}
Expand All @@ -100,7 +103,7 @@ public static void Run(ref Player __instance)
exitMode();
}

ABM.isRunning();
isRunning();

// DO WORK WHEN ALREADY STARTED
listenToHotKeysAndDoWork();
Expand All @@ -123,59 +126,42 @@ private static void listenToHotKeysAndDoWork()
// CONTROL PRESSED
if (Input.GetKeyDown(KeyCode.LeftControl)) { controlFlag = true; }
if (Input.GetKeyUp(KeyCode.LeftControl)) { controlFlag = false; }

// SHIFT PRESSED
if (Input.GetKeyDown(KeyCode.LeftShift)) { shiftFlag = true; }
if (Input.GetKeyUp(KeyCode.LeftShift)) { shiftFlag = false; }
changeModificationSpeeds(shiftFlag);

// SHIFT PRESSED
float distance;
float scrollDistance;

if (shiftFlag)
{
distance = gDistance * 3;
scrollDistance = gScrollDistance * 3;
}
else
{
distance = gDistance;
scrollDistance = gScrollDistance;
}

// LEFT ALT PRESSED
if (Input.GetKeyDown(KeyCode.LeftAlt)) { altFlag = true; }
if (Input.GetKeyUp(KeyCode.LeftAlt)) { altFlag = false; }

changeModificationSpeed();

if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.copyObjectRotation)) {
if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.copyObjectRotation))
{
savedRotation = component.transform.rotation;
}
if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.pasteObjectRotation))
{
component.transform.rotation = savedRotation;
}


var currentRotationAngleDegrees = BASE_ROTATION_ANGLE_DEGREES * currentModificationSpeed;
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
Quaternion rotation;
if (controlFlag)
{
rX++;
rotation = Quaternion.Euler(component.transform.eulerAngles.x + (scrollDistance * (float)rX), component.transform.eulerAngles.y, component.transform.eulerAngles.z); // forward to backwards
rotation = Quaternion.Euler(component.transform.eulerAngles.x + (currentRotationAngleDegrees * rX), component.transform.eulerAngles.y, component.transform.eulerAngles.z); // forward to backwards
}
else if (altFlag)
{
rZ++;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y, component.transform.eulerAngles.z + (currentRotationAngleDegrees * rZ)); // diagonal
}
else
{
if (altFlag)
{
rZ++;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y, component.transform.eulerAngles.z + (scrollDistance * (float)rZ)); // diagonal
}
else
{
rY++;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y + (scrollDistance * (float)rY), component.transform.eulerAngles.z); // left<->right
}
rY++;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y + (currentRotationAngleDegrees * rY), component.transform.eulerAngles.z); // left<->right
}
component.transform.rotation = rotation;
}
Expand All @@ -185,55 +171,52 @@ private static void listenToHotKeysAndDoWork()
if (controlFlag)
{
rX--;
rotation = Quaternion.Euler(component.transform.eulerAngles.x + (scrollDistance * (float)rX), component.transform.eulerAngles.y, component.transform.eulerAngles.z); // forward to backwards
rotation = Quaternion.Euler(component.transform.eulerAngles.x + (currentRotationAngleDegrees * rX), component.transform.eulerAngles.y, component.transform.eulerAngles.z); // forward to backwards
}
else if (altFlag)
{
rZ--;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y, component.transform.eulerAngles.z + (currentRotationAngleDegrees * rZ)); // diagonal
}
else
{
if (altFlag)
{
rZ--;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y, component.transform.eulerAngles.z + (scrollDistance * (float)rZ)); // diagonal
}
else
{
rY--;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y + (scrollDistance * (float)rY), component.transform.eulerAngles.z); // left<->right
}
rY--;
rotation = Quaternion.Euler(component.transform.eulerAngles.x, component.transform.eulerAngles.y + (currentRotationAngleDegrees * rY), component.transform.eulerAngles.z); // left<->right
}

component.transform.rotation = rotation;
}


var currentTranslationDistance = BASE_TRANSLATION_DISTANCE * currentModificationSpeed;
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (controlFlag)
{
component.transform.Translate(Vector3.up * distance * Time.deltaTime);
component.transform.Translate(Vector3.up * currentTranslationDistance);
}
else
{
component.transform.Translate(Vector3.forward * distance * Time.deltaTime);
component.transform.Translate(Vector3.forward * currentTranslationDistance);
}
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (controlFlag)
{
component.transform.Translate(Vector3.down * distance * Time.deltaTime);
component.transform.Translate(Vector3.down * currentTranslationDistance);
}
else
{
component.transform.Translate(Vector3.back * distance * Time.deltaTime);
component.transform.Translate(Vector3.back * currentTranslationDistance);
}
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
component.transform.Translate(Vector3.left * distance * Time.deltaTime);
component.transform.Translate(Vector3.left * currentTranslationDistance);
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
component.transform.Translate(Vector3.right * distance * Time.deltaTime);
component.transform.Translate(Vector3.right * currentTranslationDistance);
}

try
Expand All @@ -245,10 +228,8 @@ private static void listenToHotKeysAndDoWork()
}
}

private static bool isValidPlacement()
private static void isValidPlacement()
{
bool water = component.m_waterPiece || component.m_noInWater;

PlayerInstance.m_placementStatus = 0;

if (component.m_groundOnly || component.m_groundPiece || component.m_cultivatedGroundOnly)
Expand Down Expand Up @@ -276,7 +257,7 @@ private static bool isValidPlacement()
}
}

if (component.m_onlyInTeleportArea && !EffectArea.IsPointInsideArea(component.transform.position, EffectArea.Type.Teleport, 0f))
if (component.m_onlyInTeleportArea && !EffectArea.IsPointInsideArea(component.transform.position, EffectArea.Type.Teleport))
{
PlayerInstance.m_placementStatus = Player.PlacementStatus.NoTeleportArea;
}
Expand All @@ -291,7 +272,7 @@ private static bool isValidPlacement()

float radius = component.GetComponent<PrivateArea>() ? component.GetComponent<PrivateArea>().m_radius : 0f;

if (!PrivateArea.CheckAccess(PlayerInstance.m_placementGhost.transform.position, radius, true))
if (!PrivateArea.CheckAccess(PlayerInstance.m_placementGhost.transform.position, radius))
{
PlayerInstance.m_placementStatus = Player.PlacementStatus.PrivateZone;
}
Expand All @@ -303,8 +284,6 @@ private static bool isValidPlacement()
{
component.SetInvalidPlacementHeightlight(false);
}

return true;
}

private static void startMode()
Expand Down Expand Up @@ -379,34 +358,28 @@ private static void isRunning()
}
}

private static void changeModificationSpeeds(bool isShiftPressed)
private static void changeModificationSpeed()
{
float incValue = 1;
float speedDelta = 1;
if (shiftFlag)
incValue = 10;

if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.increaseScrollSpeed))
{
if ((gScrollDistance - incValue) < 360)
gScrollDistance += incValue;
speedDelta = 10;
}

if ((gDistance - incValue) < 360)
gDistance += incValue;
if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.increaseScrollSpeed))
{
currentModificationSpeed = Mathf.Clamp(currentModificationSpeed + speedDelta, MIN_MODIFICATION_SPEED,
MAX_MODIFICATION_SPEED);

notifyUser("Modification Speed: " + gDistance);
Debug.Log("Modification Speed: " + gDistance);
notifyUser("Modification Speed: " + currentModificationSpeed);
}

if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.decreaseScrollSpeed))
{
if((gScrollDistance-incValue) > 0)
gScrollDistance = gScrollDistance - incValue;

if ((gDistance - incValue) > 0)
gDistance = gDistance - incValue;
currentModificationSpeed = Mathf.Clamp(currentModificationSpeed - speedDelta, MIN_MODIFICATION_SPEED,
MAX_MODIFICATION_SPEED);

notifyUser("Modification Speed: " + gDistance);
Debug.Log("Modification Speed: " + gDistance);
notifyUser("Modification Speed: " + currentModificationSpeed);
}
}
}
Expand Down
Loading

0 comments on commit ab2b081

Please sign in to comment.