Skip to content

Commit bf81d6f

Browse files
committed
Merge branch 'master' of https://github.com/jefetienne/daggerfall-unity into rightClickItem
2 parents 3bb7483 + cdfac5b commit bf81d6f

30 files changed

Lines changed: 250 additions & 192 deletions

Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ public static string Execute(params string[] args)
22132213
UnityEngine.Random.InitState(Time.frameCount);
22142214
Quest quest = GameManager.Instance.QuestListsManager.GetQuest(args[0]);
22152215
if (quest != null)
2216-
QuestMachine.Instance.InstantiateQuest(quest);
2216+
QuestMachine.Instance.StartQuest(quest);
22172217

22182218
return "Finished";
22192219
}

Assets/Scripts/API/BiogFile.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using DaggerfallWorkshop.Game.Entity;
1818
using UnityEngine;
19+
using DaggerfallWorkshop.Game;
1920
using DaggerfallWorkshop.Game.Items;
2021
using DaggerfallWorkshop.Game.Player;
2122
using DaggerfallWorkshop.Utility;
@@ -176,6 +177,7 @@ public List<string> GenerateBackstory(int classIndex)
176177
}
177178
#endregion
178179

180+
GameManager.Instance.PlayerEntity.BirthRaceTemplate = characterDocument.raceTemplate; // Need correct race set when parsing %ra macro
179181
List<string> backStory = new List<string>();
180182
TextFile.Token[] tokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(tokensStart + classIndex);
181183
MacroHelper.ExpandMacros(ref tokens, (IMacroContextProvider)this);
@@ -405,6 +407,9 @@ private static void ApplyPlayerEffect(PlayerEntity playerEntity, string effect)
405407

406408
public static void ApplyEffects(List<string> effects, PlayerEntity playerEntity)
407409
{
410+
if (effects == null)
411+
return;
412+
408413
foreach (string effect in effects)
409414
{
410415
ApplyPlayerEffect(playerEntity, effect);

Assets/Scripts/Game/EnemyMotor.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace DaggerfallWorkshop.Game
2727
[RequireComponent(typeof(CharacterController))]
2828
public class EnemyMotor : MonoBehaviour
2929
{
30+
3031
#region Member Variables
3132

3233
public float OpenDoorDistance = 2f; // Maximum distance to open door
@@ -66,7 +67,9 @@ public class EnemyMotor : MonoBehaviour
6667
int searchMult;
6768
int ignoreMaskForShooting;
6869
bool canAct;
70+
bool falls;
6971
bool flyerFalls;
72+
float lastGroundedY; // Used for fall damage
7073
float originalHeight;
7174

7275
EnemySenses senses;
@@ -75,6 +78,7 @@ public class EnemyMotor : MonoBehaviour
7578
CharacterController controller;
7679
DaggerfallMobileUnit mobile;
7780
DaggerfallEntityBehaviour entityBehaviour;
81+
EnemyBlood entityBlood;
7882
EntityEffectManager entityEffectManager;
7983
EntityEffectBundle selectedSpell;
8084
EnemyAttack attack;
@@ -103,6 +107,7 @@ void Start()
103107
mobile.Summary.Enemy.Behaviour == MobileBehaviour.Spectral;
104108
swims = mobile.Summary.Enemy.Behaviour == MobileBehaviour.Aquatic;
105109
entityBehaviour = GetComponent<DaggerfallEntityBehaviour>();
110+
entityBlood = GetComponent<EnemyBlood>();
106111
entityEffectManager = GetComponent<EntityEffectManager>();
107112
entity = entityBehaviour.Entity as EnemyEntity;
108113
attack = GetComponent<EnemyAttack>();
@@ -113,6 +118,8 @@ void Start()
113118
// Add things AI should ignore when checking for a clear path to shoot.
114119
ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast"));
115120

121+
lastGroundedY = transform.position.y;
122+
116123
// Get original height, before any height adjustments
117124
originalHeight = controller.height;
118125
}
@@ -124,6 +131,7 @@ void FixedUpdate()
124131

125132
canAct = true;
126133
flyerFalls = false;
134+
falls = false;
127135

128136
HandleParalysis();
129137
KnockbackMovement();
@@ -133,6 +141,7 @@ void FixedUpdate()
133141
UpdateTimers();
134142
if (canAct)
135143
TakeAction();
144+
ApplyFallDamage();
136145
UpdateToIdleOrMoveAnim();
137146
OpenDoors();
138147
HeightAdjust();
@@ -276,6 +285,7 @@ void ApplyGravity()
276285
if (!flies && !swims && !IsLevitating && !controller.isGrounded)
277286
{
278287
controller.SimpleMove(Vector3.zero);
288+
falls = true;
279289

280290
// Only cancel movement if actually falling. Sometimes mobiles can get stuck where they are !isGrounded but SimpleMove(Vector3.zero) doesn't help.
281291
// Allowing them to continue and attempt a Move() frees them, but we don't want to allow that if we can avoid it so they aren't moving
@@ -285,7 +295,10 @@ void ApplyGravity()
285295
}
286296

287297
if (flyerFalls && flies && !IsLevitating)
298+
{
288299
controller.SimpleMove(Vector3.zero);
300+
falls = true;
301+
}
289302
}
290303

291304
/// <summary>
@@ -1278,6 +1291,39 @@ void UpdateToIdleOrMoveAnim()
12781291
lastPosition = transform.position;
12791292
}
12801293

1294+
void ApplyFallDamage()
1295+
{
1296+
// Assuming the same formula is used for the player and enemies
1297+
const float fallingDamageThreshold = 5.0f;
1298+
const float HPPerMetre = 5f;
1299+
1300+
if (controller.isGrounded)
1301+
{
1302+
// did enemy just land?
1303+
if (falls)
1304+
{
1305+
float fallDistance = lastGroundedY - transform.position.y;
1306+
if (fallDistance > fallingDamageThreshold)
1307+
{
1308+
int damage = (int)(HPPerMetre * (fallDistance - fallingDamageThreshold));
1309+
1310+
EnemyEntity enemyEntity = entityBehaviour.Entity as EnemyEntity;
1311+
enemyEntity.DecreaseHealth(damage);
1312+
1313+
if (entityBlood)
1314+
{
1315+
// Like in classic, falling enemies bleed at the center. It must hurt the center of mass ;)
1316+
entityBlood.ShowBloodSplash(0, transform.position);
1317+
}
1318+
1319+
DaggerfallUI.Instance.DaggerfallAudioSource.PlayClipAtPoint((int)SoundClips.FallDamage, FindGroundPosition());
1320+
}
1321+
}
1322+
1323+
lastGroundedY = transform.position.y;
1324+
}
1325+
}
1326+
12811327
/// <summary>
12821328
/// Open doors that are in the way.
12831329
/// </summary>

Assets/Scripts/Game/Entities/PlayerEntity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ void HandleStartingCrimeGuildQuests()
14641464
{
14651465
thievesGuildRequirementTally = InviteSent;
14661466
timeForThievesGuildLetter = 0;
1467-
Questing.QuestMachine.Instance.InstantiateQuest(ThievesGuild.InitiationQuestName, ThievesGuild.FactionId);
1467+
Questing.QuestMachine.Instance.StartQuest(ThievesGuild.InitiationQuestName, ThievesGuild.FactionId);
14681468
}
14691469
if (darkBrotherhoodRequirementTally != InviteSent
14701470
&& timeForDarkBrotherhoodLetter > 0
@@ -1473,7 +1473,7 @@ void HandleStartingCrimeGuildQuests()
14731473
{
14741474
darkBrotherhoodRequirementTally = InviteSent;
14751475
timeForDarkBrotherhoodLetter = 0;
1476-
Questing.QuestMachine.Instance.InstantiateQuest(DarkBrotherhood.InitiationQuestName, DarkBrotherhood.FactionId);
1476+
Questing.QuestMachine.Instance.StartQuest(DarkBrotherhood.InitiationQuestName, DarkBrotherhood.FactionId);
14771477
}
14781478
}
14791479

Assets/Scripts/Game/MagicAndEffects/Effects/Enchanting/ExtraSpellPts.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public override EnchantmentSettings[] GetEnchantmentSettings()
6464
return enchantments.ToArray();
6565
}
6666

67+
public override void Resume(EntityEffectManager.EffectSaveData_v1 effectData, EntityEffectManager manager, DaggerfallEntityBehaviour caster = null)
68+
{
69+
base.Resume(effectData, manager, caster);
70+
71+
ConstantEffect();
72+
}
73+
6774
#region Payloads
6875

6976
/// <summary>

Assets/Scripts/Game/MagicAndEffects/Effects/Special/LycanthropyEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public override void StartQuest(bool isCureQuest)
401401
return;
402402

403403
// Start the cure quest
404-
QuestMachine.Instance.InstantiateQuest(cureQuestName);
404+
QuestMachine.Instance.StartQuest(cureQuestName);
405405
}
406406
}
407407

Assets/Scripts/Game/MagicAndEffects/Effects/Special/VampirismEffect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public override void StartQuest(bool isCureQuest)
218218
if (isCureQuest)
219219
{
220220
if (DFRandom.random_range_inclusive(10, 100) < 30)
221-
QuestMachine.Instance.InstantiateQuest("$CUREVAM");
221+
QuestMachine.Instance.StartQuest("$CUREVAM");
222222
}
223223
else if (hasStartedInitialVampireQuest)
224224
{
@@ -237,12 +237,12 @@ public override void StartQuest(bool isCureQuest)
237237
reputation,
238238
GameManager.Instance.PlayerEntity.Level);
239239
if (offeredQuest != null)
240-
QuestMachine.Instance.InstantiateQuest(offeredQuest);
240+
QuestMachine.Instance.StartQuest(offeredQuest);
241241
}
242242
}
243243
else if (DFRandom.random_range_inclusive(1, 100) < 50)
244244
{
245-
QuestMachine.Instance.InstantiateQuest("P0A01L00");
245+
QuestMachine.Instance.StartQuest("P0A01L00");
246246
hasStartedInitialVampireQuest = true;
247247
}
248248
}

Assets/Scripts/Game/MagicAndEffects/EntityEffectBroker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ void RegisterCustomEffectDemo()
191191

192192
void Update()
193193
{
194-
// Don't tick if lastGameMinute not set (pre-init)
195-
if (lastGameMinute == 0)
194+
// Don't tick if lastGameMinute not set (pre-init) or game loading
195+
// Note: Effect system must be able to update while game is paused but game time still passes, e.g. rest or fast travel
196+
if (lastGameMinute == 0 || SaveLoadManager.Instance.LoadInProgress)
196197
return;
197198

198199
// Every game minute passing is another magic round, so work out how many minutes have passed

Assets/Scripts/Game/MobilePersonMotor.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void SeekingTile()
311311

312312
// Get current and target weights
313313
int currentWeight = GetCurrentNavPositionWeight();
314-
int targetWeight = localWeights[(int)currentDirection];
314+
int targetWeight = IsDirectionClear(currentDirection) ? localWeights[(int)currentDirection] : 0;
315315

316316
// A small chance to randomly change direction - this keeps the movement shuffled
317317
if (Random.Range(0f, 1f) < randomChangeChance)
@@ -322,7 +322,7 @@ void SeekingTile()
322322
{
323323
// Try to move in any valid random direction
324324
int randomDirection = Random.Range(0, localWeights.Length);
325-
if (localWeights[randomDirection] == 0)
325+
if (localWeights[randomDirection] == 0 || !IsDirectionClear((MobileDirection)randomDirection))
326326
return;
327327

328328
SetFacing((MobileDirection)randomDirection);
@@ -340,7 +340,7 @@ void SeekingTile()
340340
System.Random rand = new System.Random();
341341
foreach (int i in Enumerable.Range(0, 3).OrderBy(x => rand.Next(3)))
342342
{
343-
if (localWeights[i] > bestWeight)
343+
if (localWeights[i] > bestWeight && IsDirectionClear((MobileDirection)i))
344344
{
345345
bestWeight = localWeights[i];
346346
bestDirection = (MobileDirection)i;
@@ -404,6 +404,18 @@ private MobilePersonAsset FindMobilePersonAsset()
404404
return mobilePersonAsset;
405405
}
406406

407+
// Check for geometry in the way (stairs,...)
408+
bool IsDirectionClear(MobileDirection direction)
409+
{
410+
Vector3 tempTargetScenePosition = cityNavigation.WorldToScenePosition(cityNavigation.NavGridToWorldPosition(GetNextNavPosition(direction)));
411+
// Aim low to better detect stairs
412+
tempTargetScenePosition.y += 0.1f;
413+
Ray ray = new Ray(transform.position, tempTargetScenePosition - transform.position);
414+
bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition));
415+
// Debug.DrawRay(transform.position, tempTargetScenePosition - transform.position, collision ? Color.red : Color.green, 1f);
416+
return !collision;
417+
}
418+
407419
void SetTargetPosition()
408420
{
409421
// Get target position on navgrid and in world

Assets/Scripts/Game/Questing/Item.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ public override void SetResource(string line)
203203
else
204204
throw new Exception(string.Format("Could not create Item from line {0}", line));
205205

206-
// add conversation topics from anyInfo command tag
207-
AddConversationTopics();
208206
}
209207
}
210208

@@ -372,40 +370,6 @@ DaggerfallUnityItem CreateGold(int rangeLow, int rangeHigh)
372370
return result;
373371
}
374372

375-
376-
void AddConversationTopics()
377-
{
378-
List<TextFile.Token[]> anyInfoAnswers = null;
379-
List<TextFile.Token[]> anyRumorsAnswers = null;
380-
if (this.InfoMessageID != -1)
381-
{
382-
Message message = this.ParentQuest.GetMessage(this.InfoMessageID);
383-
anyInfoAnswers = new List<TextFile.Token[]>();
384-
if (message != null)
385-
{
386-
for (int i = 0; i < message.VariantCount; i++)
387-
{
388-
TextFile.Token[] tokens = message.GetTextTokensByVariant(i, false); // do not expand macros here (they will be expanded just in time by TalkManager class)
389-
anyInfoAnswers.Add(tokens);
390-
}
391-
}
392-
393-
message = this.ParentQuest.GetMessage(this.RumorsMessageID);
394-
anyRumorsAnswers = new List<TextFile.Token[]>();
395-
if (message != null)
396-
{
397-
for (int i = 0; i < message.VariantCount; i++)
398-
{
399-
TextFile.Token[] tokens = message.GetTextTokensByVariant(i, false); // do not expand macros here (they will be expanded just in time by TalkManager class)
400-
anyRumorsAnswers.Add(tokens);
401-
}
402-
}
403-
}
404-
405-
string key = this.Symbol.Name;
406-
GameManager.Instance.TalkManager.AddQuestTopicWithInfoAndRumors(this.ParentQuest.UID, this, key, TalkManager.QuestInfoResourceType.Thing, anyInfoAnswers, anyRumorsAnswers);
407-
}
408-
409373
#endregion
410374

411375
#region Serialization

0 commit comments

Comments
 (0)