Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Vitals while HUDVitals is not Active #2593

Open
Jagget opened this issue Feb 22, 2024 · 2 comments
Open

Changing Vitals while HUDVitals is not Active #2593

Jagget opened this issue Feb 22, 2024 · 2 comments

Comments

@Jagget
Copy link
Collaborator

Jagget commented Feb 22, 2024

Calling

GameManager.Instance.PlayerEntity.CurrentHealth = 32;

When the UI is not in the main HUD status, it does not change the HUD vitals indicator.

Steps to reproduce:

  • Create a new custom Quest Action
  • Call CurrentHealth update in the Action.Update() callback.
  • The amount of Health will change, but the HUD will not react.
@Jagget
Copy link
Collaborator Author

Jagget commented Feb 22, 2024

Action example:

public class ReducePlayerHealth : ActionTemplate
{
    private int _percent;
    private int _amount;

    public ReducePlayerHealth(Quest parentQuest) : base(parentQuest)
    {
    }

    public override string Pattern => @"reduce player health by (?<percent>\d+)|reduce player health on (?<amount>\d+)";

    public override IQuestAction CreateNew(string source, Quest parentQuest)
    {
        Match match = Test(source);

        if (!match.Success) return null;

        var percentGroup = match.Groups["percent"];
        var amountGroup = match.Groups["amount"];

        return new ReducePlayerHealth(parentQuest)
        {
            _percent = percentGroup.Success ? Parser.ParseInt(match.Groups["percent"].Value) : 0,
            _amount = amountGroup.Success ? Parser.ParseInt(match.Groups["amount"].Value) : 0,
        };
    }

    public override void Update(Task _)
    {
        PlayerEntity player = GameManager.Instance.PlayerEntity;

        var health = 0;
        if (_percent > 0)
            health = (int)(player.CurrentHealth - player.MaxHealth / 100f * _percent);

        if (_amount > 0)
            health = player.CurrentHealth - _amount;

        if (health < 1) health = 1;

        player.CurrentHealth = health;
        SetComplete();
    }

    public override object GetSaveData()
    {
        return new SaveData_v1
        {
            percent = _percent,
            amount = _amount,
        };
    }

    public override void RestoreSaveData(object dataIn)
    {
        if (dataIn == null) return;

        var data = (SaveData_v1)dataIn;

        _percent = data.percent;
        _amount = data.amount;
    }

    [FullSerializer.fsObject("v1")]
    private struct SaveData_v1
    {
        public int percent;
        public int amount;
    }
}

Quest example:

Quest: INDAFACE
DisplayName: In da face

QRC:
QuestComplete:  [1004]
I got in da face for money.

QBN:
Item _reward_ gold
start task _damaged_
  
_damaged_ task:
  reduce player health on 5

_sold_ task:
  when _damaged_
  give pc _reward_
  end quest

@John-Leitch
Copy link

Entirely new to unity so forgive any mistakes. Based on my assessment, here's what seems to be occurring:

Between the question completion and the reward, the game is unpaused for a tick. VitalsChangeDetector.UpdateDeltas is called as expected, calculating VitalsChangeDetector.HealthLost from previousHealth and currentHealth, then updating previousHealth. However, because the quest is completed, a DaggerfallUIMessages.dfuiOpenInventoryWindow is posted to DaggerfallUI, pushing a DaggerfallInventoryWindow to the top of the UI. No longer part of the topmost window, the HUDVitals is not updated in that tick. When the inventory is closed and the game is once again unpaused, VitalsChangeDetector.UpdateDeltas doesn't catch the change in health because previousHealth was set the previous tick.

If nobody is averse to the idea, I could contribute a patch for this in the next day or two. It may take a couple rounds of CR as I'm still ramping up on unity and this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants