I couldn't find any quest actions that measured the PC's health, so I tried to make some myself. Have in mind that I'm a total novice to C# so I copied most of the code from the LevelCompelted action.
This one is supposed to trigger a task when the player's current health is at least a certain value
Code: Select all
using System.Text.RegularExpressions;
using FullSerializer;
namespace DaggerfallWorkshop.Game.Questing
{
public class WhenHealthLevel : ActionTemplate
{
int minHealthValue;
public override string Pattern
{
get { return @"pchealth is at least (?<minHealthValue>\d+)"; }
}
public WhenHealthLevel(Quest parentQuest)
: base(parentQuest)
{
IsTriggerCondition = true;
}
public override IQuestAction CreateNew(string source, Quest parentQuest)
{
// Source must match pattern
Match match = Test(source);
if (!match.Success)
return null;
// Factory new action
WhenHealthLevel action = new WhenHealthLevel(parentQuest);
action.minHealthValue = Parser.ParseInt(match.Groups["minHealthValue"].Value);
return action;
}
public override bool CheckTrigger(Task caller)
{
return GameManager.Instance.PlayerEntity.CurrentHealth >= minHealthValue;
}
#region Serialization
[fsObject("v1")]
public struct SaveData_v1
{
public int minHealthValue;
}
public override object GetSaveData()
{
SaveData_v1 data = new SaveData_v1();
data.minHealthValue = minHealthValue;
return data;
}
public override void RestoreSaveData(object dataIn)
{
if (dataIn == null)
return;
SaveData_v1 data = (SaveData_v1)dataIn;
minHealthValue = data.minHealthValue;
}
#endregion
}
}
Code: Select all
using System.Text.RegularExpressions;
using FullSerializer;
namespace DaggerfallWorkshop.Game.Questing
{
public class WhenHealthLevelPercent : ActionTemplate
{
int minHealthValue;
public override string Pattern
{
get { return @"pchealthp is at least (?<minHealthValue>\d+)"; }
}
public WhenHealthLevelPercent(Quest parentQuest)
: base(parentQuest)
{
IsTriggerCondition = true;
}
public override IQuestAction CreateNew(string source, Quest parentQuest)
{
// Source must match pattern
Match match = Test(source);
if (!match.Success)
return null;
// Factory new action
WhenHealthLevelPercent action = new WhenHealthLevelPercent(parentQuest);
action.minHealthValue = Parser.ParseInt(match.Groups["minHealthValue"].Value);
return action;
}
public override bool CheckTrigger(Task caller)
{
return GameManager.Instance.PlayerEntity.CurrentHealthPercent >= minHealthValue;
}
#region Serialization
[fsObject("v1")]
public struct SaveData_v1
{
public int minHealthValue;
}
public override object GetSaveData()
{
SaveData_v1 data = new SaveData_v1();
data.minHealthValue = minHealthValue;
return data;
}
public override void RestoreSaveData(object dataIn)
{
if (dataIn == null)
return;
SaveData_v1 data = (SaveData_v1)dataIn;
minHealthValue = data.minHealthValue;
}
#endregion
}
}
in theory they should be working alright now.
So I wrote a little quest to test them:
Code: Select all
Quest: ACTIONTEST
DisplayName: Action test
-- Message panels
QRC:
Message: 1010
<ce> You have at least 50% health
Message: 1020
<ce> You have at least 50 health
QBN:
-- Quest start-up:
_highhealth_ task:
pchealthp is at least 50
say 1010
_highhealth2_ task:
pchealth is at least 50
say 1020