Skip to content

pjc0247/Nventory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nventory

Your serverless inventory that actually works

Deploy

firebase deploy

API

AddItem

await Nventory.AddItem("legendary-sword", new {
    Attack = 10,
    Speed = 5
});

Unique item and Consumables

Since we have generalized the interfaces to fit most of games, there're no unique items in Nventory.
Every item has its quantity and can be counted more than 2.
We don't have native support for it, you should implement your own stuffs.
Good news, it's pretty simple.

Unique equipments
Think about equipments, they cannot be stacked in most cases even if they have excatly same options.
GUID would be the best practice for this case.
Even if you add 2 swords, they never be stacked.

var key = $"sword.{(new Guid()).ToString()}";

await Nventory.AddItem(key, sword);

Consumables with variants
In some cases, consumables also have options.
Please see example below:

{
    "grade": "good",
    "heal" : 10
},
{
    "grade": "poor",
    "heal" : 5
}

Each items can be stacked with same options.
You may carry 2 good bananas, 3 poor bananas and so on.

In this case, just use GetHashCode method.

var key = $"banana.{banana.GetHashCode()}";

await Nventory.AddItem(key, banana);

Consumables without variantes
Nothing to do!

UpdateItem
Creates or Replaces item with given data.
(Always overwrites the item include quantity.)

await Nventory.UpdateItem("banana", banana);

ConsumeItem

await Nventory.ConsumeItem("banana", 1);

GetItem

await Nventory.GetItem("banana");
await Nventory.GetAllItems();

Subscription with Nventory

You can implement period-specific items in few lines.

// Add subscription
await Nventory.AddItem(
    "one-year-premium",
    new {},
    Nventory.OneYear);
// Check premium status
var item = await Nventory.GetItem("one-year-premium");
if (item == null)   
    Console.WriteLine("Your are not a premium member");
else
    Console.WriteLine("Welcome customer!");

Security considerations

If you don't care about Hackers

It's okay, most of singleplay games doesn't care about manipulations.
Just use Nventory for online storage. All items will be avaliable on any devices.

If you care about Securities

You should not use AddItem or UpdateItem on client. Items are always issued by server.
ConsumeItem is safe, it's always decreasing the quantity.

Most important part is firestore rules.
Hackers still have write access to your databases unless you blocked it.

{
    // firestore rules goes here
}

About

Your serverless inventory that actually works

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published