-
Notifications
You must be signed in to change notification settings - Fork 398
Expand file tree
/
Copy pathVampirismEffect.cs
More file actions
482 lines (402 loc) · 17.5 KB
/
VampirismEffect.cs
File metadata and controls
482 lines (402 loc) · 17.5 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
// 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: Gavin Clayton (interkarma@dfworkshop.net)
// Contributors: Allofich, Hazelnut
//
// Notes:
//
using UnityEngine;
using FullSerializer;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Utility;
using DaggerfallWorkshop.Game.UserInterfaceWindows;
using DaggerfallWorkshop.Game.Questing;
using DaggerfallWorkshop.Game.Items;
using DaggerfallConnect.Arena2;
using DaggerfallWorkshop.Utility;
using DaggerfallConnect;
using DaggerfallConnect.Utility;
using Wenzil.Console;
namespace DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects
{
/// <summary>
/// Stage two curse effect for vampirism deployed after stage one infection completed.
/// Handles buffs and other long-running vampire effects.
/// Note: This effect should only be assigned to player entity by stage one disease effect or classic character import.
/// </summary>
public class VampirismEffect : RacialOverrideEffect
{
#region Fields
public const string VampirismCurseKey = "Vampirism-Curse";
const int paperDollWidth = 110;
const int paperDollHeight = 184;
RaceTemplate compoundRace;
VampireClans vampireClan = VampireClans.Lyrezi;
uint lastTimeFed;
bool hasStartedInitialVampireQuest;
DFSize backgroundFullSize = new DFSize(125, 198);
Rect backgroundSubRect = new Rect(8, 7, paperDollWidth, paperDollHeight);
Texture2D backgroundTexture;
#endregion
#region Constructors
public VampirismEffect()
{
VampireConsoleCommands.RegisterCommands();
}
#endregion
#region Overrides
public VampireClans VampireClan
{
get { return vampireClan; }
set { vampireClan = value; }
}
public override RaceTemplate CustomRace
{
get { return GetCompoundRace(); }
}
public override void SetProperties()
{
properties.Key = VampirismCurseKey;
properties.ShowSpellIcon = false;
bypassSavingThrows = true;
}
public override void Start(EntityEffectManager manager, DaggerfallEntityBehaviour caster = null)
{
base.Start(manager, caster);
// Create compound vampire race from birth race
CreateCompoundRace();
// Get vampire clan from stage one disease
// Otherwise start as Lyrezi by default if no infection found
// Note: Classic save import will start this effect and set correct clan after load
VampirismInfection infection = (VampirismInfection)GameManager.Instance.PlayerEffectManager.FindIncumbentEffect<VampirismInfection>();
if (infection != null)
vampireClan = infection.InfectionVampireClan;
// Considered well fed on first start
UpdateSatiation();
// Our dark transformation is complete - cure everything on player (including stage one disease)
GameManager.Instance.PlayerEffectManager.CureAll();
// Refresh head texture after effect starts
DaggerfallUI.RefreshLargeHUDHeadTexture();
}
public override void Resume(EntityEffectManager.EffectSaveData_v1 effectData, EntityEffectManager manager, DaggerfallEntityBehaviour caster = null)
{
base.Resume(effectData, manager, caster);
// Refresh head texture after effect resumes
DaggerfallUI.RefreshLargeHUDHeadTexture();
}
public override void ConstantEffect()
{
base.ConstantEffect();
// Get peered entity gameobject
DaggerfallEntityBehaviour entityBehaviour = GetPeeredEntityBehaviour(manager);
if (!entityBehaviour)
return;
// Assign constant state changes for vampires
entityBehaviour.Entity.IsImmuneToDisease = true;
entityBehaviour.Entity.IsImmuneToParalysis = true;
entityBehaviour.Entity.MinMetalToHit = WeaponMaterialTypes.Silver;
}
public override void MagicRound()
{
base.MagicRound();
ApplyVampireAdvantages();
}
public override bool GetCustomPaperDollBackgroundTexture(PlayerEntity playerEntity, out Texture2D textureOut)
{
const string vampBackground = "SCBG08I0.IMG";
// Background is cut into sub-texture and cached on first call
if (!backgroundTexture)
{
Texture2D texture = ImageReader.GetTexture(vampBackground, 0, 0, false);
backgroundTexture = ImageReader.GetSubTexture(texture, backgroundSubRect, backgroundFullSize);
}
textureOut = backgroundTexture;
return true;
}
public override bool GetCustomHeadImageData(PlayerEntity entity, out ImageData imageDataOut)
{
const string vampHeads = "VAMP00I0.CIF";
// Vampires have a limited set of heads, one per birth race and gender
// Does not follow same selection rules as standard racial head images
int index;
switch (entity.Gender)
{
default:
case Genders.Male:
index = 8 + entity.BirthRaceTemplate.ID - 1;
break;
case Genders.Female:
index = entity.BirthRaceTemplate.ID - 1;
break;
}
imageDataOut = ImageReader.GetImageData(vampHeads, index, 0, true);
return true;
}
public override bool GetCustomRaceGenderAttackSoundData(PlayerEntity entity, out SoundClips soundClipOut)
{
const int chanceOfBarkSound = 20;
switch (entity.Gender)
{
default:
case Genders.Male:
soundClipOut = Dice100.SuccessRoll(chanceOfBarkSound) ? SoundClips.EnemyVampireBark : SoundClips.EnemyVampireAttack;
break;
case Genders.Female:
soundClipOut = Dice100.SuccessRoll(chanceOfBarkSound) ? SoundClips.EnemyFemaleVampireBark : SoundClips.EnemyFemaleVampireAttack;
break;
}
return true;
}
public override void OnWeaponHitEntity(PlayerEntity playerEntity, DaggerfallEntity targetEntity = null)
{
// Player just needs to strike enemy with any weapon (including melee) to register a feeding strike
UpdateSatiation();
}
public override bool CheckFastTravel(PlayerEntity playerEntity)
{
if (DaggerfallUnity.Instance.WorldTime.Now.IsDay)
{
DaggerfallMessageBox mb = new DaggerfallMessageBox(DaggerfallUI.Instance.UserInterfaceManager);
mb.PreviousWindow = DaggerfallUI.Instance.UserInterfaceManager.TopWindow;
mb.ClickAnywhereToClose = true;
mb.SetText(TextManager.Instance.GetLocalizedText("sunlightDamageFastTravelDay"));
mb.Show();
return false;
}
return true;
}
public override bool CheckStartRest(PlayerEntity playerEntity)
{
const int notSatedTextID = 36;
if (!IsSatiated())
{
DaggerfallMessageBox mb = new DaggerfallMessageBox(DaggerfallUI.Instance.UserInterfaceManager);
mb.PreviousWindow = DaggerfallUI.Instance.UserInterfaceManager.TopWindow;
mb.ClickAnywhereToClose = true;
mb.SetTextTokens(notSatedTextID);
mb.Show();
return false;
}
return true;
}
public override void StartQuest(bool isCureQuest)
{
// More about vampire clan quests can found here:
// https://en.uesp.net/wiki/Daggerfall:Quests#Vampire_Clans
if (isCureQuest)
{
if (DFRandom.random_range_inclusive(10, 100) < 30)
QuestMachine.Instance.StartQuest("$CUREVAM");
}
else if (hasStartedInitialVampireQuest)
{
// Get an appropriate quest for player's level?
if (DFRandom.random_range_inclusive(1, 100) < 50)
{
// Get the regional vampire clan faction id for affecting reputation on success/failure, and current rep
int factionId = (int)vampireClan;
int reputation = GameManager.Instance.PlayerEntity.FactionData.GetReputation(factionId);
// Select a quest at random from appropriate pool
Quest offeredQuest = GameManager.Instance.QuestListsManager.GetGuildQuest(
FactionFile.GuildGroups.Vampires,
MembershipStatus.Member,
factionId,
reputation,
GameManager.Instance.PlayerEntity.Level);
if (offeredQuest != null)
QuestMachine.Instance.StartQuest(offeredQuest);
}
}
else if (DFRandom.random_range_inclusive(1, 100) < 50)
{
QuestMachine.Instance.StartQuest("P0A01L00");
hasStartedInitialVampireQuest = true;
}
}
public override void End()
{
base.End();
// Get peered entity gameobject
DaggerfallEntityBehaviour entityBehaviour = GetPeeredEntityBehaviour(manager);
if (!entityBehaviour)
return;
// Remove player metal immunity
entityBehaviour.Entity.MinMetalToHit = WeaponMaterialTypes.Iron;
// Refresh head texture after effect ends
DaggerfallUI.RefreshLargeHUDHeadTexture();
}
#endregion
#region Public Methods
/// <summary>
/// Sets vampire thirst sated from current point in time.
/// </summary>
public void UpdateSatiation()
{
lastTimeFed = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime();
}
/// <summary>
/// Gets whether vampire thirst is satiated.
/// </summary>
public bool IsSatiated()
{
return DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime() - lastTimeFed <= DaggerfallDateTime.MinutesPerDay;
}
/// <summary>
/// Cure vampirism and allow this racial override effect to expire.
/// Game time is raised by one minute so effect payload expires almost immediately.
/// </summary>
public void CureVampirism()
{
forcedRoundsRemaining = 0;
ResignAsIncumbent();
DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.RaiseTime(60);
GameManager.Instance.PlayerEntity.PreviousVampireClan = vampireClan;
GameManager.Instance.PlayerEntity.DeleteTaggedSpells(PlayerEntity.vampireSpellTag);
EndVampireQuests();
}
/// <summary>
/// Gets name of vampire clan from Races text database.
/// </summary>
public string GetClanName()
{
return TextManager.Instance.GetLocalizedText(vampireClan.ToString().ToLower());
}
#endregion
#region Private Methods
void CreateCompoundRace()
{
// Clone birth race and assign custom settings
// New compound races will retain almost everything from birth race
compoundRace = GameManager.Instance.PlayerEntity.BirthRaceTemplate.Clone();
compoundRace.Name = TextManager.Instance.GetLocalizedText("vampire");
// Set special vampire flags
compoundRace.ImmunityFlags |= DFCareer.EffectFlags.Paralysis;
compoundRace.ImmunityFlags |= DFCareer.EffectFlags.Disease;
compoundRace.SpecialAbilities |= DFCareer.SpecialAbilityFlags.SunDamage;
compoundRace.SpecialAbilities |= DFCareer.SpecialAbilityFlags.HolyDamage;
}
RaceTemplate GetCompoundRace()
{
// Create compound race if one doesn't already exist
if (compoundRace == null)
CreateCompoundRace();
return compoundRace;
}
void ApplyVampireAdvantages()
{
// Set stat mods to all but INT
const int statModAmount = 20;
SetStatMod(DFCareer.Stats.Strength, statModAmount);
SetStatMod(DFCareer.Stats.Willpower, statModAmount);
SetStatMod(DFCareer.Stats.Agility, statModAmount);
SetStatMod(DFCareer.Stats.Endurance, statModAmount);
SetStatMod(DFCareer.Stats.Personality, statModAmount);
SetStatMod(DFCareer.Stats.Speed, statModAmount);
SetStatMod(DFCareer.Stats.Luck, statModAmount);
// Set skill mods
const int skillModAmount = 30;
SetSkillMod(DFCareer.Skills.Jumping, skillModAmount);
SetSkillMod(DFCareer.Skills.Running, skillModAmount);
SetSkillMod(DFCareer.Skills.Stealth, skillModAmount);
SetSkillMod(DFCareer.Skills.CriticalStrike, skillModAmount);
SetSkillMod(DFCareer.Skills.Climbing, skillModAmount);
SetSkillMod(DFCareer.Skills.HandToHand, skillModAmount);
// Set clan stat mods
if (vampireClan == VampireClans.Anthotis)
SetStatMod(DFCareer.Stats.Intelligence, statModAmount);
}
void EndVampireQuests()
{
const string prefix = "P0";
ulong[] quests = QuestMachine.Instance.GetAllActiveQuests();
foreach (ulong id in quests)
{
Quest quest = QuestMachine.Instance.GetQuest(id);
if (quest != null && quest.QuestName.StartsWith(prefix))
QuestMachine.Instance.TombstoneQuest(quest);
}
}
#endregion
#region Serialization
[fsObject("v1")]
public struct CustomSaveData_v1
{
public RaceTemplate compoundRace;
public VampireClans vampireClan;
public uint lastTimeFed;
public bool hasStartedInitialVampireQuest;
}
public override object GetSaveData()
{
CustomSaveData_v1 data = new CustomSaveData_v1();
data.compoundRace = compoundRace;
data.vampireClan = vampireClan;
data.lastTimeFed = lastTimeFed;
data.hasStartedInitialVampireQuest = hasStartedInitialVampireQuest;
return data;
}
public override void RestoreSaveData(object dataIn)
{
if (dataIn == null)
return;
CustomSaveData_v1 data = (CustomSaveData_v1)dataIn;
compoundRace = data.compoundRace;
vampireClan = data.vampireClan;
lastTimeFed = data.lastTimeFed;
hasStartedInitialVampireQuest = data.hasStartedInitialVampireQuest;
}
#endregion
#region Console Commands
public static class VampireConsoleCommands
{
public static void RegisterCommands()
{
try
{
ConsoleCommandsDatabase.RegisterCommand(FeedMe.name, FeedMe.description, FeedMe.usage, FeedMe.Execute);
ConsoleCommandsDatabase.RegisterCommand(CureMe.name, CureMe.description, CureMe.usage, CureMe.Execute);
}
catch (System.Exception ex)
{
DaggerfallUnity.LogMessage(ex.Message, true);
}
}
private static class FeedMe
{
public static readonly string name = "vamp_feedme";
public static readonly string description = "Vampire thirst becomes sated.";
public static readonly string usage = "vamp_feedme";
public static string Execute(params string[] args)
{
if (GameManager.Instance.PlayerEffectManager.HasVampirism())
{
(GameManager.Instance.PlayerEffectManager.GetRacialOverrideEffect() as VampirismEffect).UpdateSatiation();
return "Your thirst has been sated.";
}
else
return "Player is not a vampire.";
}
}
private static class CureMe
{
public static readonly string name = "vamp_cureme";
public static readonly string description = "Player is cured of vampirism effect at start of next magic round (1 game minute).";
public static readonly string usage = "vamp_cureme";
public static string Execute(params string[] args)
{
if (GameManager.Instance.PlayerEffectManager.HasVampirism())
{
GameManager.Instance.PlayerEffectManager.EndVampirism();
return "You have been cured of vampirism.";
}
else
return "Player is not a vampire.";
}
}
}
#endregion
}
}