Esempio n. 1
0
        public void CloneItemNoLocalStateIsNotCopied(string itemResRef)
        {
            Location startLocation = NwModule.Instance.StartingLocation;
            NwItem?  item          = NwItem.Create(itemResRef, startLocation);

            Assert.That(item, Is.Not.Null, $"Item {itemResRef} was null after creation.");
            Assert.That(item !.IsValid, Is.True, $"Item {itemResRef} was invalid after creation.");

            createdTestObjects.Add(item);

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

            testVar.Value = 9999;

            NwItem clone = item.Clone(startLocation, null, false);

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

            createdTestObjects.Add(clone);

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

            Assert.That(cloneTestVar.HasValue, Is.False, "Local variable exists on the clone with copyLocalState = false.");
            Assert.That(cloneTestVar.Value, Is.Not.EqualTo(testVar.Value), "Local variable on the cloned item matches the value of the original item.");
        }
Esempio n. 2
0
 protected override void PrepareEvent(NwPlaceable objSelf)
 {
     DisturbType   = (InventoryDisturbType)NWScript.GetInventoryDisturbType();
     Placeable     = objSelf;
     Disturber     = NWScript.GetLastDisturbed().ToNwObject <NwCreature>();
     DisturbedItem = NWScript.GetInventoryDisturbItem().ToNwObject <NwItem>();
 }
 private void ToggleItemVisibility(NwItem nwItem)
 {
     if (nwItem is not null && nwItem.IsValid)
     {
         nwItem.HiddenWhenEquipped = ++nwItem.HiddenWhenEquipped % 2;
     }
 }
Esempio n. 4
0
 public static void RemoveAllTemporaryItemProperties(this NwItem nwItem)
 {
     foreach (NWN.API.ItemProperty property in nwItem.ItemProperties.Where(x => x.DurationType == EffectDuration.Temporary))
     {
         nwItem.RemoveItemProperty(property);
     }
 }
Esempio n. 5
0
 public static void SendLootMessageToParty(this NwItem acquireItem, string message, float distance)
 {
     if (acquireItem.Possessor is NwPlayer player && !player.IsDM)
     {
         player.SendMessageToAllPartyWithinDistance(message, distance);
         player.SendServerMessage(message);
     }
 }
Esempio n. 6
0
        public void CreateItemIsCreated(string itemResRef)
        {
            Location startLocation = NwModule.Instance.StartingLocation;
            NwItem?  item          = NwItem.Create(itemResRef, startLocation);

            Assert.That(item, Is.Not.Null, $"Item {itemResRef} was null after creation.");
            Assert.That(item !.IsValid, Is.True, $"Item {itemResRef} was invalid after creation.");

            createdTestObjects.Add(item);
        }
Esempio n. 7
0
        public void CloneItemWithoutTagOriginalTagIsCopied(string itemResRef)
        {
            Location startLocation = NwModule.Instance.StartingLocation;
            NwItem?  item          = NwItem.Create(itemResRef, startLocation);

            Assert.That(item, Is.Not.Null, $"Item {itemResRef} was null after creation.");
            Assert.That(item !.IsValid, Is.True, $"Item {itemResRef} was invalid after creation.");

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

            NwItem clone = item.Clone(startLocation, null, false);

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

            createdTestObjects.Add(clone);

            Assert.That(clone.Tag, Is.EqualTo(item.Tag), "Cloned item's tag did not match the original item's.");
        }
Esempio n. 8
0
        public void CloneItemCustomTagIsApplied(string itemResRef)
        {
            Location startLocation = NwModule.Instance.StartingLocation;
            NwItem?  item          = NwItem.Create(itemResRef, startLocation);

            Assert.That(item, Is.Not.Null, $"Item {itemResRef} was null after creation.");
            Assert.That(item !.IsValid, Is.True, $"Item {itemResRef} was invalid after creation.");

            createdTestObjects.Add(item);

            string expectedNewTag = "expectedNewTag";
            NwItem clone          = item.Clone(startLocation, expectedNewTag, false);

            Assert.That(clone, Is.Not.Null, $"Item {itemResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Item {itemResRef} 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 item.");
        }
Esempio n. 9
0
        public void SerializeItemCreatesValidData(string itemResRef)
        {
            Location startLocation = NwModule.Instance.StartingLocation;
            NwItem?  item          = NwItem.Create(itemResRef, startLocation);

            Assert.That(item, Is.Not.Null, $"Item {itemResRef} was null after creation.");
            Assert.That(item !.IsValid, Is.True, $"Item {itemResRef} was invalid after creation.");

            createdTestObjects.Add(item);

            byte[]? itemData = item.Serialize();

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

            NwItem?item2 = NwItem.Deserialize(itemData !);

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

            createdTestObjects.Add(item2);

            Assert.That(item2.Area, Is.Null);
        }
Esempio n. 10
0
 public static bool CheckFit(this NwGameObject gameObject, NwItem item)
 {
     return(CheckFit(gameObject, item.BaseItemType));
 }
Esempio n. 11
0
 public static void NotifyLoot(this NwItem acquireItem) => SendLootMessageToParty(acquireItem, $"{acquireItem.Possessor.Name.ColorString(Color.PINK)} obtained {acquireItem.BaseItemType.ToString().ColorString(Color.WHITE)}.", 40);
Esempio n. 12
0
 public static bool HasTemporaryItemProperty(this NwItem nwItem) => nwItem.ItemProperties.Any(x => x.DurationType == EffectDuration.Temporary);
Esempio n. 13
0
 public static string PrintGPValueOnItem(this NwItem nwItem)
 => nwItem.PlotFlag
     ? nwItem.OriginalDescription
     : (nwItem.Description = $"{"Gold Piece Value:".ColorString(Color.YELLOW)}{nwItem.GoldValue.ToString().ColorString(Color.ORANGE)}\n\n{nwItem.OriginalDescription}");
Esempio n. 14
0
 protected override void PrepareEvent(NwObject objSelf)
 {
     Creature = (NwCreature)objSelf;
     Item     = EventsPlugin.GetEventData("ITEM").ParseObject <NwItem>();
 }
            public static void Signal(NwItem item, Location targetLocation, NwGameObject?targetObject = null)
            {
                Event nwEvent = NWScript.EventActivateItem(item, targetLocation, targetObject) !;

                NWScript.SignalEvent(NwModule.Instance, nwEvent);
            }
Esempio n. 16
0
File: Item.cs Progetto: jakkn/Anvil
 public static void SetWeight(this NwItem item, decimal weight)
 => ItemPlugin.SetWeight(item, (int)Math.Round(weight * 10.0m, MidpointRounding.ToZero));
Esempio n. 17
0
 public static void AcquireItem(this NwGameObject gameObject, NwItem item)
 {
     ObjectPlugin.AcquireItem(gameObject, item);
 }