コード例 #1
0
 public void AddInventoryAmount(UserInventoryViewModel inventory, string item, int amount)
 {
     if (!this.IsCurrencyRankExempt)
     {
         this.SetInventoryAmount(inventory, item, this.GetInventoryAmount(inventory, item) + amount);
     }
 }
コード例 #2
0
 public void SubtractInventoryAmount(UserInventoryViewModel inventory, string item, int amount)
 {
     if (!this.IsCurrencyRankExempt)
     {
         this.SetInventoryAmount(inventory, item, Math.Max(this.GetInventoryAmount(inventory, item) - amount, 0));
     }
 }
コード例 #3
0
 public void SetInventoryAmount(UserInventoryViewModel inventory, string itemName, int amount)
 {
     if (inventory.Items.ContainsKey(itemName))
     {
         UserInventoryItemViewModel item          = inventory.Items[itemName];
         UserInventoryDataViewModel inventoryData = this.GetInventory(inventory);
         inventoryData.Amounts[itemName] = Math.Min(amount, item.HasMaxAmount ? item.MaxAmount : inventoryData.Inventory.DefaultMaxAmount);
     }
 }
コード例 #4
0
        public UserDataViewModel(DbDataReader dataReader, IChannelSettings settings)
            : this(uint.Parse(dataReader["ID"].ToString()), dataReader["UserName"].ToString())
        {
            this.ViewingMinutes = int.Parse(dataReader["ViewingMinutes"].ToString());

            if (dataReader.ColumnExists("CurrencyAmounts"))
            {
                Dictionary <Guid, int> currencyAmounts = JsonConvert.DeserializeObject <Dictionary <Guid, int> >(dataReader["CurrencyAmounts"].ToString());
                if (currencyAmounts != null)
                {
                    foreach (var kvp in currencyAmounts)
                    {
                        if (settings.Currencies.ContainsKey(kvp.Key))
                        {
                            this.SetCurrencyAmount(settings.Currencies[kvp.Key], kvp.Value);
                        }
                    }
                }
            }

            if (dataReader.ColumnExists("InventoryAmounts"))
            {
                Dictionary <Guid, Dictionary <string, int> > inventoryAmounts = JsonConvert.DeserializeObject <Dictionary <Guid, Dictionary <string, int> > >(dataReader["InventoryAmounts"].ToString());
                if (inventoryAmounts != null)
                {
                    foreach (var kvp in inventoryAmounts)
                    {
                        if (settings.Inventories.ContainsKey(kvp.Key))
                        {
                            UserInventoryViewModel inventory = settings.Inventories[kvp.Key];
                            this.InventoryAmounts[inventory] = new UserInventoryDataViewModel(this, inventory, kvp.Value);
                        }
                    }
                }
            }

            if (dataReader.ColumnExists("CustomCommands") && !string.IsNullOrEmpty(dataReader["CustomCommands"].ToString()))
            {
                this.CustomCommands.AddRange(SerializerHelper.DeserializeFromString <List <ChatCommand> >(dataReader["CustomCommands"].ToString()));
            }

            if (dataReader.ColumnExists("Options") && !string.IsNullOrEmpty(dataReader["Options"].ToString()))
            {
                JObject optionsJObj = JObject.Parse(dataReader["Options"].ToString());
                if (optionsJObj.ContainsKey("EntranceCommand") && optionsJObj["EntranceCommand"] != null)
                {
                    this.EntranceCommand = SerializerHelper.DeserializeFromString <CustomCommand>(optionsJObj["EntranceCommand"].ToString());
                }
                this.IsSparkExempt        = this.GetOptionValue <bool>(optionsJObj, "IsSparkExempt");
                this.IsCurrencyRankExempt = this.GetOptionValue <bool>(optionsJObj, "IsCurrencyRankExempt");
                this.GameWispUserID       = this.GetOptionValue <uint>(optionsJObj, "GameWispUserID");
                this.PatreonUserID        = this.GetOptionValue <string>(optionsJObj, "PatreonUserID");
                this.ModerationStrikes    = this.GetOptionValue <uint>(optionsJObj, "ModerationStrikes");
                this.CustomTitle          = this.GetOptionValue <string>(optionsJObj, "CustomTitle");
            }
        }
コード例 #5
0
        public int GetInventoryAmount(UserInventoryViewModel inventory, string item)
        {
            UserInventoryDataViewModel inventoryData = this.GetInventory(inventory);

            if (inventoryData.Amounts.ContainsKey(item))
            {
                return(inventoryData.Amounts[item]);
            }
            return(0);
        }
コード例 #6
0
 public void ResetInventoryAmount(UserInventoryViewModel inventory)
 {
     this.InventoryAmounts[inventory] = new UserInventoryDataViewModel(this, inventory);
 }
コード例 #7
0
 public bool HasInventoryAmount(UserInventoryViewModel inventory, string item, int amount)
 {
     return(this.IsCurrencyRankExempt || this.GetInventoryAmount(inventory, item) >= amount);
 }
コード例 #8
0
 public UserInventoryDataViewModel GetInventory(UserInventoryViewModel inventory)
 {
     return(this.InventoryAmounts.GetValueIfExists(inventory, new UserInventoryDataViewModel(this, inventory)));
 }
コード例 #9
0
 public UserInventoryDataViewModel(UserDataViewModel user, UserInventoryViewModel inventory, IDictionary <string, int> amounts)
 {
     this.User      = user;
     this.Inventory = inventory;
     this.Amounts   = new Dictionary <string, int>(amounts);
 }
コード例 #10
0
 public UserInventoryDataViewModel(UserDataViewModel user, UserInventoryViewModel inventory) : this(user, inventory, new Dictionary <string, int>())
 {
 }