-
Notifications
You must be signed in to change notification settings - Fork 324
/
JournalNote.cs
84 lines (68 loc) · 2.14 KB
/
JournalNote.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Hazelnut
// Contributors:
//
using System.Collections.Generic;
using System.Text.RegularExpressions;
using DaggerfallConnect.Arena2;
using FullSerializer;
namespace DaggerfallWorkshop.Game.Questing.Actions
{
/// <summary>
/// Adds a text entry to the player journal as a note.
/// </summary>
public class JournalNote : ActionTemplate
{
int id;
public override string Pattern
{
get { return @"journal note (?<id>\d+)"; }
}
public JournalNote(Quest parentQuest)
: base(parentQuest)
{
allowRearm = false;
}
public override IQuestAction CreateNew(string source, Quest parentQuest)
{
// Source must match pattern
Match match = Test(source);
if (!match.Success)
return null;
// Factory new note
JournalNote note = new JournalNote(parentQuest);
note.id = Parser.ParseInt(match.Groups["id"].Value);
return note;
}
public override void Update(Task caller)
{
Message message = ParentQuest.GetMessage(id);
GameManager.Instance.PlayerEntity.Notebook.AddNote(new List<TextFile.Token>(message.GetTextTokens()));
SetComplete();
}
#region Serialization
[fsObject("v1")]
public struct SaveData_v1
{
public int id;
}
public override object GetSaveData()
{
SaveData_v1 data = new SaveData_v1();
data.id = id;
return data;
}
public override void RestoreSaveData(object dataIn)
{
if (dataIn == null)
return;
SaveData_v1 data = (SaveData_v1)dataIn;
id = data.id;
}
#endregion
}
}