Exemplo n.º 1
0
 public static void Serialize(string filepath, Inventories inventory)
 {
     using (var file = File.Create(filepath))
     {
         Serializer.Serialize(file, inventory);
         file.Flush();
     }
 }
Exemplo n.º 2
0
        public static byte[] Serialize(Inventories inventories)
        {
            MemoryStream stream = new MemoryStream();

            Serializer.Serialize<Inventories>(stream, inventories);

            stream.Seek(0, SeekOrigin.Begin);

            return stream.ToArray();
        }
Exemplo n.º 3
0
 public void SetInventories(Inventories inventories)
 {
     if (inventories != null)
     {
         _inventories.Clear();
         _inventories.AddRange(inventories.Items);
     }
 }
Exemplo n.º 4
0
 public void OnInventoriesReceived(Game game, Inventories inventories)
 {
     PBGameState.ProcessEvent((c) => c.OnInventoriesReceived(this, inventories));
 }
Exemplo n.º 5
0
        public Inventories GetInventories(string userid)
        {
            Inventories inventories = new Inventories();

            try
            {
                MongoServer server = MongoServer.Create(DbSettings.ConnectionString);

                MongoDatabase db = server.GetDatabase(DbConstants.DbNameGame, Credentials, new SafeMode(true));
                MongoCollection<BsonDocument> coll = db.GetCollection(DbConstants.CollectionNameInventory);
                QueryDocument query = new QueryDocument("userid", userid);
                var cursor = coll.Find(query);

                foreach (BsonDocument item in cursor)
                {
                    ObjectId id = item["_id"].AsObjectId;
                    var code = item["code"].AsString;
                    var name = item["name"].AsString;
                    float weight = item["weight"].IsDouble ? (float)item["weight"].AsDouble : float.Parse(item["weight"].AsString);
                    var description = item["description"].AsString;

                    GameItem gameItem = new GameItem(id.ToString(), code, name, weight, description);
                    inventories.Items.Add(gameItem);
                }

                server.Disconnect();
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }

            return inventories;
        }
Exemplo n.º 6
0
 public void OnInventoryFetched(Inventories inventories)
 {
     if (this.Listener.IsDebugLogEnabled)
     {
         this.Listener.LogDebug(this, string.Format("Inventory Fetched: {0} items", inventories.Items.Count));
     }
     this.listener.OnInventoriesReceived(this, inventories);
 }
Exemplo n.º 7
0
    public override void OnInventoriesReceived(GameControllerBase mainGame, Inventories inventories)
    {
        base.OnInventoriesReceived(mainGame, inventories);

        InventoryEngine.Instance.SetInventories(inventories);
    }