Example #1
0
        public static void MarketTerminalDisturbed()
        {
            if (GetInventoryDisturbType() != DisturbType.Added)
            {
                return;
            }

            var player        = GetLastDisturbed();
            var playerId      = GetObjectUUID(player);
            var dbPlayer      = DB.Get <Player>(playerId);
            var dbPlayerStore = DB.Get <PlayerStore>(playerId);
            var item          = GetInventoryDisturbItem();
            var itemId        = GetObjectUUID(item);
            var serialized    = Object.Serialize(item);
            var listingLimit  = 5 + dbPlayer.SeedProgress.Rank * 5;

            if (dbPlayerStore.ItemsForSale.Count >= listingLimit || // Listing limit reached.
                GetBaseItemType(item) == BaseItem.Gold ||           // Gold can't be listed.
                string.IsNullOrWhiteSpace(GetResRef(item)) ||       // Items without resrefs can't be listed.
                GetHasInventory(item))                              // Bags and other containers can't be listed.
            {
                Item.ReturnItem(player, item);
                SendMessageToPC(player, "This item cannot be listed.");
                return;
            }

            dbPlayerStore.ItemsForSale.Add(itemId, new PlayerStoreItem
            {
                Data      = serialized,
                Name      = GetName(item),
                Price     = 0,
                StackSize = GetItemStackSize(item)
            });

            DB.Set(playerId, dbPlayerStore);
            DestroyObject(item);

            SendMessageToPC(player, $"Listing limit: {dbPlayerStore.ItemsForSale.Count} / {5 + dbPlayer.SeedProgress.Rank * 5}");
        }
Example #2
0
        /// <summary>
        /// When the module loads, spawns are located in all areas. Details about those spawns are stored
        /// into the cached data.
        /// </summary>
        public static void StoreSpawns()
        {
            for (var area = GetFirstArea(); GetIsObjectValid(area); area = GetNextArea())
            {
                for (var obj = GetFirstObjectInArea(area); GetIsObjectValid(obj); obj = GetNextObjectInArea(area))
                {
                    var type     = GetObjectType(obj);
                    var position = GetPosition(obj);
                    var facing   = GetFacing(obj);
                    var id       = Guid.NewGuid();

                    // Hand-placed creature information is stored and the actual NPC is destroyed so it can be spawned by the system.
                    if (type == ObjectType.Creature)
                    {
                        _spawns.Add(id, new SpawnDetail
                        {
                            SerializedObject = Object.Serialize(obj),
                            X      = position.X,
                            Y      = position.Y,
                            Z      = position.Z,
                            Facing = facing,
                            Area   = area,
                            RespawnDelayMinutes = 5
                        });

                        // Add this entry to the spawns by area cache.
                        if (!_allSpawnsByArea.ContainsKey(area))
                        {
                            _allSpawnsByArea[area] = new List <Guid>();
                        }

                        _allSpawnsByArea[area].Add(id);

                        DestroyObject(obj);
                    }
                    // Waypoints with a spawn table ID
                    else if (type == ObjectType.Waypoint)
                    {
                        var spawnTableId = GetLocalInt(obj, "SPAWN_TABLE_ID");
                        if (spawnTableId > 0)
                        {
                            if (!_spawnTables.ContainsKey(spawnTableId))
                            {
                                Log.Write(LogGroup.Error, $"Waypoint has an invalid spawn table Id. ({spawnTableId}) is not defined. Do you have the right spawn table Id?");
                                continue;
                            }

                            var spawnTable = _spawnTables[spawnTableId];
                            _spawns.Add(id, new SpawnDetail
                            {
                                SpawnTableId        = spawnTableId,
                                X                   = position.X,
                                Y                   = position.Y,
                                Z                   = position.Z,
                                Facing              = facing,
                                Area                = area,
                                RespawnDelayMinutes = spawnTable.RespawnDelayMinutes
                            });

                            // Add this entry to the spawns by area cache.
                            if (!_allSpawnsByArea.ContainsKey(area))
                            {
                                _allSpawnsByArea[area] = new List <Guid>();
                            }

                            _allSpawnsByArea[area].Add(id);
                        }
                    }
                }
            }
        }