コード例 #1
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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.");
        }
コード例 #2
0
        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"));
コード例 #3
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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);
        }
コード例 #4
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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));
        }
コード例 #5
0
ファイル: NativeUtilsTests.cs プロジェクト: nwn-dotnet/Anvil
        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));
        }
コード例 #6
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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.");
        }
コード例 #7
0
ファイル: NwObjectTests.cs プロジェクト: nwn-dotnet/Anvil
        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));
        }
コード例 #8
0
ファイル: NwObjectTests.cs プロジェクト: nwn-dotnet/Anvil
        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));
        }
コード例 #9
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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.");
        }
コード例 #10
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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.");
        }
コード例 #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));
        }
コード例 #12
0
ファイル: NwCreatureTests.cs プロジェクト: nwn-dotnet/Anvil
        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);
        }