Page 2 of 2

Re: [Mod Request] Floor type affects movement speed

Posted: Tue Feb 23, 2021 12:18 am
by l3lessed
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

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;
            }
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.

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();
    }
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.

Re: [Mod Request] Floor type affects movement speed

Posted: Tue Feb 23, 2021 10:10 pm
by l3lessed
Well, everything above is largely useless and overcomplicated as usual for my first pass. After going at the above approach for an afternoon, it is clear this is a dumb approach.

After thinking about it more, I decided using a list that stores the values modders are injecting and manipulating and hooking it to a for loop to properly loop and compute each subsequent speed adjustment value would be best and easiest and provide most accurate and sturdy speed scaling property.

It will consist of a list that contains float values; devs will push the value into it and then remove it when done with their move modifier effect. Each time the list updates or the base speed updates, the setSpeed will kick the for loop into gear and start sequently applying each modifier, starting with the base value and first modifier then going to the following modifier and the following updated current speed. At the end of the loop, we should have the proper modified speed.