Esempio n. 1
0
        public void CloneCreatureWithLocalStateIsCopied(string creatureResRef)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(creatureResRef, startLocation);

            Assert.That(creature, Is.Not.Null, $"Creature {creatureResRef} was null after creation.");
            Assert.That(creature !.IsValid, Is.True, $"Creature {creatureResRef} was invalid after creation.");

            createdTestObjects.Add(creature);

            LocalVariableInt testVar = creature.GetObjectVariable <LocalVariableInt>("test");

            testVar.Value = 9999;

            NwCreature clone = creature.Clone(startLocation);

            Assert.That(clone, Is.Not.Null, $"Creature {creatureResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Creature {creatureResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            LocalVariableInt cloneTestVar = clone.GetObjectVariable <LocalVariableInt>("test");

            Assert.That(cloneTestVar.HasValue, Is.True, "Local variable did not exist on the clone with copyLocalState = true.");
            Assert.That(cloneTestVar.Value, Is.EqualTo(testVar.Value), "Local variable on the cloned creature did not match the value of the original creature.");
        }
        public void GetMissingPersistentVariablePropertiesValid(string variableName)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(StandardResRef.Creature.nw_bandit001, startLocation);

            Assert.That(creature, Is.Not.Null);
            createdTestObjects.Add(creature !);

            VariableAssert(false, default, creature !.GetObjectVariable <PersistentVariableBool>(variableName + "bool"));
Esempio n. 3
0
        public void CreateCreatureIsCreated(string creatureResRef)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(creatureResRef, startLocation);

            Assert.That(creature, Is.Not.Null, $"Creature {creatureResRef} was null after creation.");
            Assert.That(creature !.IsValid, Is.True, $"Creature {creatureResRef} was invalid after creation.");

            createdTestObjects.Add(creature);
        }
Esempio n. 4
0
        public void GetFeatRemainingUsesReturnsValidValue()
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(StandardResRef.Creature.tanarukk, startLocation);

            Assert.That(creature, Is.Not.Null, "Creature was null after creation.");
            Assert.That(creature !.IsValid, Is.True, "Creature was invalid after creation.");

            createdTestObjects.Add(creature);

            NwFeat?feat = NwFeat.FromFeatType(Feat.BarbarianRage);

            Assert.That(creature.GetFeatRemainingUses(feat !), Is.EqualTo(1));
        }
Esempio n. 5
0
        public void ExtractLocStringReturnsValidData()
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(StandardResRef.Creature.nw_bandit001, startLocation);

            Assert.That(creature, Is.Not.Null);
            Assert.That(creature !.IsValid, Is.True);

            createdTestObjects.Add(creature);

            string firstName = creature.OriginalFirstName;
            string lastName  = creature.OriginalLastName;

            Assert.That(firstName, Is.EqualTo(string.Empty));
            Assert.That(lastName, Is.EqualTo(string.Empty));
        }
Esempio n. 6
0
        public void SetFeatRemainingUsesCorrectlyUpdatesState(byte uses)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(StandardResRef.Creature.tanarukk, startLocation);

            Assert.That(creature, Is.Not.Null, "Creature was null after creation.");
            Assert.That(creature !.IsValid, Is.True, "Creature was invalid after creation.");

            createdTestObjects.Add(creature);
            NwFeat?feat = NwFeat.FromFeatType(Feat.BarbarianRage);

            Assert.That(feat, Is.Not.Null, "Could not get feat.");

            creature.SetFeatRemainingUses(feat !, uses);

            Assert.That(creature.GetFeatRemainingUses(feat !), Is.EqualTo(Math.Min(uses, creature.GetFeatTotalUses(feat !))), "Remaining feat uses was not updated after being set.");
            Assert.That(creature.HasFeatPrepared(feat !), Is.EqualTo(uses > 0), "Creature incorrectly assumes the feat is/is not available.");
        }
Esempio n. 7
0
        public async Task QueueCreatureActionIsQueued()
        {
            NwCreature?creature = NwCreature.Create(StandardResRef.Creature.nw_bandit001, NwModule.Instance.StartingLocation);

            Assert.That(creature, Is.Not.Null);

            createdTestObjects.Add(creature !);

            bool  actionExecuted = false;
            await creature !.AddActionToQueue(() =>
            {
                actionExecuted = true;
            });

            await NwTask.WaitUntil(() => actionExecuted);

            Assert.That(actionExecuted, Is.EqualTo(true));
        }
Esempio n. 8
0
        public async Task WaitForObjectContextEntersCorrectContext()
        {
            NwModule module = NwModule.Instance;

            await module.WaitForObjectContext();

            Assert.That(NWScript.OBJECT_SELF.ToNwObject(), Is.EqualTo(module));

            NwCreature?creature = NwCreature.Create(StandardResRef.Creature.nw_bandit001, NwModule.Instance.StartingLocation);

            Assert.That(creature, Is.Not.Null);

            createdTestObjects.Add(creature !);

            await creature !.WaitForObjectContext();

            Assert.That(NWScript.OBJECT_SELF.ToNwObject(), Is.EqualTo(creature));
        }
Esempio n. 9
0
        public void CloneCreatureWithoutTagOriginalTagIsCopied(string creatureResRef)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(creatureResRef, startLocation);

            Assert.That(creature, Is.Not.Null, $"Creature {creatureResRef} was null after creation.");
            Assert.That(creature !.IsValid, Is.True, $"Creature {creatureResRef} was invalid after creation.");

            createdTestObjects.Add(creature);
            creature.Tag = "expectedNewTag";

            NwCreature clone = creature.Clone(startLocation, null, false);

            Assert.That(clone, Is.Not.Null, $"Creature {creatureResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Creature {creatureResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            Assert.That(clone.Tag, Is.EqualTo(creature.Tag), "Cloned creature's tag did not match the original creature's.");
        }
Esempio n. 10
0
        public void CloneCreatureCustomTagIsApplied(string creatureResRef)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(creatureResRef, startLocation);

            Assert.That(creature, Is.Not.Null, $"Creature {creatureResRef} was null after creation.");
            Assert.That(creature !.IsValid, Is.True, $"Creature {creatureResRef} was invalid after creation.");

            createdTestObjects.Add(creature);

            string     expectedNewTag = "expectedNewTag";
            NwCreature clone          = creature.Clone(startLocation, expectedNewTag, false);

            Assert.That(clone, Is.Not.Null, $"Creature {creatureResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Creature {creatureResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            Assert.That(clone.Tag, Is.EqualTo(expectedNewTag), "Tag defined in clone method was not applied to the cloned creature.");
        }
Esempio n. 11
0
        public void SetDamageLevelOverrideChangesDamageLevel(int damageLevelIndex)
        {
            Location startLocation = NwModule.Instance.StartingLocation;

            NwCreature?creature = NwCreature.Create(StandardResRef.Creature.nw_bandit001, startLocation);

            Assert.That(creature, Is.Not.Null, "Creature was null after creation.");

            createdTestObjects.Add(creature !);

            Assert.That(creature !.DamageLevel.RowIndex, Is.EqualTo(NwGameTables.DamageLevelTable[0].RowIndex)); // Uninjured

            DamageLevelEntry damageLevel = NwGameTables.DamageLevelTable[damageLevelIndex];

            DamageLevelOverrideService.SetDamageLevelOverride(creature, damageLevel);

            Assert.That(DamageLevelOverrideService.GetDamageLevelOverride(creature)?.RowIndex, Is.EqualTo(damageLevel.RowIndex));
            Assert.That(creature.GetDamageLevelOverride()?.RowIndex, Is.EqualTo(damageLevel.RowIndex));
            Assert.That(creature.DamageLevel.RowIndex, Is.EqualTo(damageLevel.RowIndex));
        }
Esempio n. 12
0
        public void SerializeCreatureCreatesValidData(string creatureResRef)
        {
            Location   startLocation = NwModule.Instance.StartingLocation;
            NwCreature?creature      = NwCreature.Create(creatureResRef, startLocation);

            Assert.That(creature, Is.Not.Null, $"Creature {creatureResRef} was null after creation.");
            Assert.That(creature !.IsValid, Is.True, $"Creature {creatureResRef} was invalid after creation.");

            createdTestObjects.Add(creature);

            byte[]? creatureData = creature.Serialize();

            Assert.That(creatureData, Is.Not.Null);
            Assert.That(creatureData, Has.Length.GreaterThan(0));

            NwCreature?creature2 = NwCreature.Deserialize(creatureData !);

            Assert.That(creature2, Is.Not.Null);
            Assert.That(creature2 !.IsValid, Is.True);

            createdTestObjects.Add(creature2);

            Assert.That(creature2.Area, Is.Null);
        }