private static uint CreateMerchantObject(string sellerPlayerId, PlayerStore dbPlayerStore) { const string StoreResref = "player_store"; var merchant = CreateObject(ObjectType.Store, StoreResref, GetLocation(OBJECT_SELF)); SetLocalString(merchant, "SELLER_PLAYER_ID", sellerPlayerId); foreach (var item in dbPlayerStore.ItemsForSale) { if (item.Value.Price <= 0) { continue; } var deserialized = Object.Deserialize(item.Value.Data); Object.AcquireItem(merchant, deserialized); var originalBaseGPValue = Core.NWNX.Item.GetBaseGoldPieceValue(deserialized); var originalAdditionalGPValue = Core.NWNX.Item.GetAddGoldPieceValue(deserialized); SetLocalInt(deserialized, "ORIGINAL_BASE_GP_VALUE", originalBaseGPValue); SetLocalInt(deserialized, "ORIGINAL_ADDITIONAL_GP_VALUE", originalAdditionalGPValue); Core.NWNX.Item.SetBaseGoldPieceValue(deserialized, item.Value.Price); Core.NWNX.Item.SetAddGoldPieceValue(deserialized, 0); } return(merchant); }
/// <summary> /// Creates a new spawn object into its spawn area. /// Hand-placed objects are deserialized and added to the area. /// Spawn tables run their own logic to determine which object to spawn. /// </summary> /// <param name="spawnId">The ID of the spawn</param> /// <param name="detail">The details of the spawn</param> private static uint SpawnObject(Guid spawnId, SpawnDetail detail) { // Hand-placed spawns are stored as a serialized string. // Deserialize and add it to the area. if (!string.IsNullOrWhiteSpace(detail.SerializedObject)) { var deserialized = Object.Deserialize(detail.SerializedObject); var position = new Vector(detail.X, detail.Y, detail.Z); Object.AddToArea(deserialized, detail.Area, position); AssignCommand(deserialized, () => SetFacing(detail.Facing)); SetLocalString(deserialized, "SPAWN_ID", spawnId.ToString()); return(deserialized); } // Spawn tables have their own logic which must be run to determine the spawn to use. // Create the object at the stored location. else if (detail.SpawnTableId > 0) { var spawnTable = _spawnTables[detail.SpawnTableId]; var(objectType, resref) = spawnTable.GetNextSpawnResref(); // It's possible that the rules of the spawn table don't have a spawn ready to be created. // In this case, exit early. if (string.IsNullOrWhiteSpace(resref)) { return(OBJECT_INVALID); } var position = new Vector(detail.X, detail.Y, detail.Z); var location = Location(detail.Area, position, detail.Facing); var spawn = CreateObject(objectType, resref, location); SetLocalString(spawn, "SPAWN_ID", spawnId.ToString()); return(spawn); } return(OBJECT_INVALID); }
private void ListingInit(DialogPage page) { var player = GetPC(); var playerId = GetObjectUUID(player); var dbPlayerStore = DB.Get <PlayerStore>(playerId); var model = GetDataModel <Model>(); var item = dbPlayerStore.ItemsForSale[model.SelectedItemId]; void AdjustPrice(int amount) { item.Price += amount; if (item.Price <= 0) { item.Price = 1; } else if (item.Price > 999999) { item.Price = 999999; } DB.Set(playerId, dbPlayerStore); PlayerMarket.UpdateCacheEntry(playerId, dbPlayerStore); } page.Header = ColorToken.Green("Item: ") + item.StackSize + "x " + item.Name + "\n" + ColorToken.Green("Price: ") + item.Price + "\n\n" + "Please select an option."; if (model.IsConfirmingRemoveItem) { page.AddResponse(ColorToken.Red("CONFIRM REMOVE ITEM"), () => { var inWorldItem = Object.Deserialize(item.Data); Object.AcquireItem(player, inWorldItem); dbPlayerStore.ItemsForSale.Remove(model.SelectedItemId); DB.Set(playerId, dbPlayerStore); PlayerMarket.UpdateCacheEntry(playerId, dbPlayerStore); ChangePage(EditItemListPageId, false); model.IsConfirmingRemoveItem = false; }); } else { page.AddResponse(ColorToken.Red("Remove Item"), () => { model.IsConfirmingRemoveItem = true; }); } page.AddResponse("Increase by 10,000 gil", () => { AdjustPrice(10000); }); page.AddResponse("Increase by 1,000 gil", () => { AdjustPrice(1000); }); page.AddResponse("Increase by 100 gil", () => { AdjustPrice(100); }); page.AddResponse("Increase by 10 gil", () => { AdjustPrice(10); }); page.AddResponse("Increase by 1 gil", () => { AdjustPrice(1); }); page.AddResponse("Decrease by 10,000 gil", () => { AdjustPrice(-10000); }); page.AddResponse("Decrease by 1,000 gil", () => { AdjustPrice(-1000); }); page.AddResponse("Decrease by 100 gil", () => { AdjustPrice(-100); }); page.AddResponse("Decrease by 10 gil", () => { AdjustPrice(-10); }); page.AddResponse("Decrease by 1 gil", () => { AdjustPrice(-1); }); }