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."); }
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; } }
public static void RemoveAllTemporaryItemProperties(this NwItem nwItem) { foreach (NWN.API.ItemProperty property in nwItem.ItemProperties.Where(x => x.DurationType == EffectDuration.Temporary)) { nwItem.RemoveItemProperty(property); } }
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); } }
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); }
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."); }
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."); }
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); }
public static bool CheckFit(this NwGameObject gameObject, NwItem item) { return(CheckFit(gameObject, item.BaseItemType)); }
public static void NotifyLoot(this NwItem acquireItem) => SendLootMessageToParty(acquireItem, $"{acquireItem.Possessor.Name.ColorString(Color.PINK)} obtained {acquireItem.BaseItemType.ToString().ColorString(Color.WHITE)}.", 40);
public static bool HasTemporaryItemProperty(this NwItem nwItem) => nwItem.ItemProperties.Any(x => x.DurationType == EffectDuration.Temporary);
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}");
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); }
public static void SetWeight(this NwItem item, decimal weight) => ItemPlugin.SetWeight(item, (int)Math.Round(weight * 10.0m, MidpointRounding.ToZero));
public static void AcquireItem(this NwGameObject gameObject, NwItem item) { ObjectPlugin.AcquireItem(gameObject, item); }