示例#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 SetAlwaysWalk(NwCreature creature, bool forceWalk)
        {
            CNWSCreature         nativeCreature = creature.Creature;
            InternalVariableBool alwaysWalk     = InternalVariables.AlwaysWalk(creature);

            if (forceWalk)
            {
                nativeCreature.m_bForcedWalk = true.ToInt();
                alwaysWalk.Value             = true;
            }
            else
            {
                alwaysWalk.Delete();

                if (creature.ActiveEffects.Any(activeEffect => activeEffect.EffectType == EffectType.MovementSpeedDecrease))
                {
                    return;
                }

                if (!nativeCreature.m_bForcedWalk.ToBool())
                {
                    nativeCreature.UpdateEncumbranceState(false.ToInt());
                    nativeCreature.m_bForcedWalk = (nativeCreature.m_nEncumbranceState != 0).ToInt();
                }

                nativeCreature.m_bForcedWalk = false.ToInt();
            }
        }
示例#3
0
            private static OnCreatureAttack[] GetAttackEvents(void *pCreature, void *pTarget, int nAttacks)
            {
                CNWSCreature?creature = CNWSCreature.FromPointer(pCreature);
                NwGameObject?target   = CNWSObject.FromPointer(pTarget).ToNwObject <NwGameObject>();

                if (creature == null || target == null)
                {
                    return(Array.Empty <OnCreatureAttack>());
                }

                NwCreature nwCreature = creature.ToNwObject <NwCreature>() !;

                // m_nCurrentAttack points to the attack after this flurry.
                int             attackNumberOffset = creature.m_pcCombatRound.m_nCurrentAttack - nAttacks;
                CNWSCombatRound combatRound        = creature.m_pcCombatRound;

                // Create an event for each attack in the flurry
                OnCreatureAttack[] attackEvents = new OnCreatureAttack[nAttacks];
                for (int i = 0; i < nAttacks; i++)
                {
                    attackEvents[i] = GetEventData(nwCreature, target, combatRound, attackNumberOffset + i);
                }

                return(attackEvents);
            }
        //private static readonly Logger Log = LogManager.GetCurrentClassLogger();
        public static void AddBuff(this NwCreature creature)
        {
            Effect acBoost = Effect.ACIncrease(5, ACBonus.ShieldEnchantment);

            acBoost.Tag = "AC_BOOST";
            creature.ApplyEffect(EffectDuration.Permanent, acBoost);
            creature.ApplyEffect(EffectDuration.Instant, Effect.VisualEffect(VfxType.ImpAcBonus));
        }
        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"));
示例#6
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);
        }
 public static void RemoveBuff(this NwCreature creature)
 {
     foreach (Effect effect in creature.ActiveEffects)
     {
         if (effect.Tag == "AC_BOOST")
         {
             creature.RemoveEffect(effect);
         }
     }
 }
示例#8
0
 public static void AddFeat(this NwCreature creature, Feat feat, int level = 0)
 {
     if (level > 0)
     {
         CreaturePlugin.AddFeatByLevel(creature, (int)feat, level);
     }
     else
     {
         CreaturePlugin.AddFeat(creature, (int)feat);
     }
 }
        /// <summary>
        /// Gets the override that is set for the creature's damage level.<br/>
        /// </summary>
        public DamageLevelEntry?GetDamageLevelOverride(NwCreature creature)
        {
            InternalVariableInt damageLevelOverride = InternalVariables.DamageLevelOverride(creature);

            if (damageLevelOverride.HasValue)
            {
                return(NwGameTables.DamageLevelTable[damageLevelOverride.Value]);
            }

            return(null);
        }
        public void SetWalkRateCap(NwCreature creature, float?newValue)
        {
            InternalVariableFloat overrideValue = InternalVariables.WalkRateCap(creature);

            if (newValue.HasValue)
            {
                overrideValue.Value = newValue.Value;
            }
            else
            {
                overrideValue.Delete();
            }
        }
示例#11
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));
        }
示例#12
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));
        }
示例#13
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.");
        }
示例#14
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));
        }
示例#15
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));
        }
示例#16
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));
        }
示例#17
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.");
        }
示例#18
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.");
        }
示例#19
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);
        }
示例#20
0
            private static OnCreatureAttack GetEventData(NwCreature creature, NwGameObject target, CNWSCombatRound combatRound, int attackNumber)
            {
                CNWSCombatAttackData combatAttackData = combatRound.GetAttack(attackNumber);

                return(new OnCreatureAttack
                {
                    CombatAttackData = combatAttackData,
                    Attacker = creature,
                    Target = target,
                    AttackNumber = attackNumber + 1, // 1-based for backwards compatibility
                    WeaponAttackType = (WeaponAttackType)combatAttackData.m_nWeaponAttackType,
                    SneakAttack = (SneakAttack)(combatAttackData.m_bSneakAttack + (combatAttackData.m_bDeathAttack << 1)),
                    KillingBlow = combatAttackData.m_bKillingBlow.ToBool(),
                    AttackType = combatAttackData.m_nAttackType,
                    AttackRoll = combatAttackData.m_nToHitRoll,
                    AttackModifier = combatAttackData.m_nToHitMod,
                    IsRangedAttack = combatAttackData.m_bRangedAttack.ToBool(),
                    IsCoupDeGrace = combatAttackData.m_bCoupDeGrace.ToBool(),
                    IsAttackDeflected = combatAttackData.m_bAttackDeflected.ToBool(),
                    IsCriticalThreat = combatAttackData.m_bCriticalThreat.ToBool(),
                    DamageData = new DamageData <short>(combatAttackData.m_nDamage),
                    TotalDamage = combatAttackData.GetTotalDamage(),
                });
            }
示例#21
0
 public void ClearDurationOverride(NwCreature creature)
 {
     restDurationOverrides.Remove(creature);
 }
        public float?GetWalkRateCap(NwCreature creature)
        {
            InternalVariableFloat overrideValue = InternalVariables.WalkRateCap(creature);

            return(overrideValue.HasValue ? overrideValue.Value : null);
        }
 /// <summary>
 /// Sets the override that is set for the creature's damage level.<br/>
 /// </summary>
 public void SetDamageLevelOverride(NwCreature creature, DamageLevelEntry damageLevel)
 {
     InternalVariables.DamageLevelOverride(creature).Value = damageLevel.RowIndex;
 }
 /// <summary>
 /// Clears any override that is set for the creature's damage level.<br/>
 /// </summary>
 public void ClearDamageLevelOverride(NwCreature creature)
 {
     InternalVariables.DamageLevelOverride(creature).Delete();
 }
示例#25
0
 protected override void PrepareEvent(NwObject objSelf)
 {
     PartyLeader = (NwPlayer)objSelf;
     Kicked      = EventsPlugin.GetEventData("KICKED").ParseObject <NwCreature>();
 }
示例#26
0
 protected override void PrepareEvent(NwObject objSelf)
 {
     Player   = (NwPlayer)objSelf;
     Henchman = EventsPlugin.GetEventData("INVITED_BY").ParseObject <NwCreature>();
 }
示例#27
0
 public TimeSpan?GetDurationOverride(NwCreature creature)
 {
     return(restDurationOverrides.TryGetValue(creature, out int retVal) ? TimeSpan.FromMilliseconds(retVal) : null);
 }
示例#28
0
 protected override void PrepareEvent(NwPlaceable objSelf)
 {
     Placeable = objSelf;
     UsedBy    = NWScript.GetLastUsedBy().ToNwObject <NwCreature>();
 }
示例#29
0
 public void SetDurationOverride(NwCreature creature, TimeSpan duration)
 {
     restDurationOverrides[creature] = (int)Math.Round(duration.TotalMilliseconds);
 }
示例#30
0
 protected override void PrepareEvent(NwPlaceable objSelf)
 {
     Placeable = objSelf;
     Attacker  = NWScript.GetLastAttacker().ToNwObject <NwCreature>();
 }