Re: [Mod Request] Floor type affects movement speed
Posted: Tue Feb 23, 2021 12:18 am
Here is the two mods I'm hooking into these changes to mess with them.
Here is the code from my combat mod that changes move speed based on sheath/attack state
Here is the code I use for my interactive terrain tile. This will override the combat mods values anytime a second tile is loaded since it is grabbing the previous tile number for the additive model, and not the sheath state number.
Currently, they both change values properly, including doing proper additive changes, so you scale based from the previous set movementspeed by the last code/mod. The only issue is trying to ensure there is a way to set a base speed value, so even when mods change the value using the setWalkSpeed, it won't override the base value defined by the mod on the highest load priority. This would allow dynamic scaling and allow a permanent base change for mods that need it, like my terrain mod.
Here is the code from my combat mod that changes move speed based on sheath/attack state
Code: Select all
//sets players current movement using overrides and override float values. Ensures triggered only once when setting values to save update cycles.
void movementModifier()
{
//the player isn't sheathed, idle, and restoredWalk hasn't been triggered by sheathing yet. This is default movement speed unsheathed modifier.
if(!GameManager.Instance.WeaponManager.Sheathed && AttackState == 0 && !restoredWalk)
{
walkspeed = playerSpeedChanger.GetWalkSpeed(GameManager.Instance.PlayerEntity);
playerSpeedChanger.StoreWalkSpeed();
playerSpeedChanger.SetWalkSpeed(walkspeed * .45f, true);
restoredWalk = true;
attackApplied = false;
return;
}
//if the player is attacking, is unsheathed, and hasn't already had movement modifier attackApplied, set walkspeed based.
if (AttackState != 0 && !GameManager.Instance.WeaponManager.Sheathed && restoredWalk && !attackApplied)
{
walkspeed = playerSpeedChanger.GetWalkSpeed(GameManager.Instance.PlayerEntity);
playerSpeedChanger.StoreWalkSpeed();
playerSpeedChanger.SetWalkSpeed(walkspeed * .01f, true);
attackApplied = true;
return;
}
//if weapon is sheathed and restore walk has been set to true, restore sheathed movement speed using the last walk speed value.
if (GameManager.Instance.WeaponManager.Sheathed && restoredWalk)
{
restoredWalk = playerSpeedChanger.RestoreWalkSpeed();
restoredWalk = false;
attackApplied = false;
Debug.Log("restore walkspeed");
return;
}
Code: Select all
// Update is called once per frame
void Update()
{
if (OnTileChange())
{
List<float> TileProperties = TileProperty(lastTile);
movementModifier(TileProperties[0]);
Debug.Log("New Ground Tile: " + lastTile.ToString() + " | " + TileProperties[0].ToString());
}
}
void movementModifier(float moveModifier)
{
//on tile change, update the current speed using an additive model to ensure it modifies based on any previous number being used.
playerSpeedChanger.SetWalkSpeed(playerSpeedChanger.GetWalkSpeed(GameManager.Instance.PlayerEntity) * moveModifier, true);
//store the new value so it can be restored and used when computed in future mod/code execution
playerSpeedChanger.StoreWalkSpeed();
}