Re: Checking for specific date
Posted: Tue Feb 16, 2021 4:21 pm
Tools for Daggerfall
https://forums.dfworkshop.net/
Hm... I am not sure how to do that correctly.
Code: Select all
// custom quest action for Black Horse Courier
//
// this creates a new quest action which checks if we are in a given range of days
//
// _Example_ task:
// when yearly from 15.1. to 4.5.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using DaggerfallWorkshop.Utility;
using FullSerializer;
namespace DaggerfallWorkshop.Game.Questing
{
/// <summary>
/// Raise or lower task state based on month
/// Date must be in day1.month1. to day2.month2. (like "1.8. to 15.8." for August 8th to 15th)
/// </summary>
public class YearlyFrom : ActionTemplate
{
int day1;
int day2;
int month1;
int month2;
public override string Pattern
{
get { return @"yearly from (?<day1>\d+).(?<month1>\d+). to (?<day2>\d+).(?<month2>\d+)."; }
}
public YearlyFrom(Quest parentQuest)
: base(parentQuest)
{
IsTriggerCondition = true;
IsAlwaysOnTriggerCondition = 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
YearlyFrom action = new YearlyFrom(parentQuest);
action.day1 = Parser.ParseInt(match.Groups["day1"].Value);
action.day2 = Parser.ParseInt(match.Groups["day2"].Value);
action.month1 = Parser.ParseInt(match.Groups["month1"].Value);
action.month2 = Parser.ParseInt(match.Groups["month2"].Value);
return action;
}
public override bool CheckTrigger(Task caller)
{
// Get live world time (day 1 to 30, month 1 to 12)
DaggerfallDateTime worldTime = DaggerfallUnity.Instance.WorldTime.Now;
int currentDay = worldTime.day;
int currentMonth = worldTime.month;
// Check if inside range
if ((currentDay >= day1 && currentDay <= day2) && (currentMonth >= month1 && currentMonth <= month2))
return true;
else
return false;
}
#region Serialization
[fsObject("v1")]
public struct SaveData_v1
{
public int day1;
public int day2;
public int month1;
public int month2;
}
public override object GetSaveData()
{
SaveData_v1 data = new SaveData_v1();
data.day1 = day1;
data.day2 = day2;
data.month1 = month1;
data.month2 = month2;
return data;
}
public override void RestoreSaveData(object dataIn)
{
if (dataIn == null)
return;
SaveData_v1 data = (SaveData_v1)dataIn;
day1 = data.day1;
day2 = data.day2;
month1 = data.month1;
month2 = data.month2;
}
#endregion
}
}
Code: Select all
// Black Horse Courier
using System;
using System.Collections.Generic;
using UnityEngine;
using DaggerfallConnect;
using DaggerfallConnect.Arena2;
using DaggerfallConnect.FallExe;
using DaggerfallWorkshop;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Banking;
using DaggerfallWorkshop.Game.Guilds;
using DaggerfallWorkshop.Game.Questing;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Formulas;
using DaggerfallWorkshop.Game.Items;
using DaggerfallWorkshop.Game.MagicAndEffects;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game.UserInterfaceWindows;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings;
using DaggerfallWorkshop.Utility;
namespace BlackHorseCourier
{
public class BlackHorseCourier : MonoBehaviour
{
protected static string[] placesTable =
{
"TuluneCity, 0x435d, 1, -1",
"CredenceHall, 0xc544, 1, -1",
"Camelford, 0xc545, 1, -1",
"Elizay, 0xc546, 1, -1",
"OldLysoldasFarm, 0x3FA7, 1, -1",
"PilgrimKynareth, 0x2E9E, 1, -1",
"PilgrimMara, 0x38F2, 1, -1",
"PilgrimDibella, 0x4FF4, 1, -1",
"PilgrimAkatosh, 0x57B7, 1, -1",
"PilgrimZenithar, 0x6582, 1, -1",
"PilgrimArkay, 0x6681, 1, -1",
"PilgrimStendarr, 0x67AF, 1, -1",
"PilgrimJulianos, 0x72DC, 1, -1",
};
static Mod mod;
[Invoke(StateManager.StateTypes.Start, 0)]
public static void Init(InitParams initParams)
{
mod = initParams.Mod;
var go = new GameObject(mod.Title);
go.AddComponent<BlackHorseCourier>();
}
public static void InitMod()
{
Debug.Log("Begin mod init: BlackHorseCourier");
Debug.Log("Registering quest list BlackHorseCourier");
if (!QuestListsManager.RegisterQuestList("BlackHorseCourier"))
throw new Exception("Quest list name is already in use, unable to register BlackHorseCourier quest list.");
// Add additional data into the quest machine for the quests
Debug.Log("Adding new BlackHorseCourier locations into quest places table");
QuestMachine questMachine = GameManager.Instance.QuestMachine;
questMachine.PlacesTable.AddIntoTable(placesTable);
Debug.Log("Finished mod init: BlackHorseCourier");
}
void Awake()
{
//var settings = mod.GetSettings();
// ---
InitMod();
mod.IsReady = true;
}
}
}
Code: Select all
questMachine.RegisterAction(new YearlyFrom(null));
Oh. That is easy Thank you.TheLacus wrote: ↑Wed Feb 17, 2021 3:21 pm Hi, this is how to register a new action:
While not strictly required, I'd also suggest to put all your mod code inside namespace BlackHorseCourier, inlcuding custom action.Code: Select all
questMachine.RegisterAction(new YearlyFrom(null));
Code: Select all
public override string Pattern
{
get { return @"yearly from (?<day1>\d+).(?<month1>\d+). to (?<day2>\d+).(?<month2>\d+)."; }
}
Code: Select all
public override string Pattern
{
get { return @"yearly from (?<day1>\d+)-(?<month1>\d+) to (?<day2>\d+)-(?<month2>\d+)"; }
}