Beispiel #1
0
        public static ObservableCollection <MageKnightData> GetUserInventory(Guid userId)
        {
            SqlConnection connection = MKUserDataDB.GetConnection();
            string        selectStatement
                = "SELECT UserId, MageId, Quantity " +
                  "FROM UserInventory " +
                  "WHERE UserId = @UserId";

            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@UserId", userId);

            try
            {
                bool isDuplicate = false;
                connection.Open();
                UserData user = new UserData();
                ObservableCollection <MageKnightData> models = new ObservableCollection <MageKnightData>();
                SqlDataReader reader = selectCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult);
                while (reader.Read())
                {
                    int  quantity = Int32.Parse(reader["Quantity"].ToString());
                    Guid mageId   = Guid.Parse(reader["MageId"].ToString());
                    for (int i = 0; i < quantity; i++)
                    {
                        models.Add(MageDB.GetMageKnight(mageId));
                    }
                }

                connection.Close();

                return(models);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                connection.Close();
            }

            return(null);
        }
Beispiel #2
0
        protected override bool UpdateInternal(IUpdatableUser model, UserAddedMageToInventory message)
        {
            if (message.UserId != model.Id)
            {
                return(false);
            }

            MageKnightData magedata = MageDB.GetMageKnight(message.Id);
            var            mage     = this.ModelFactoryResolver.GetFactory <IUpdatableMageKnight>().Create();

            mage.Faction    = magedata.Faction;
            mage.FrontArc   = magedata.FrontArc;
            mage.Id         = magedata.Id;
            mage.Index      = magedata.Index;
            mage.ModelImage = magedata.ModelImage;
            mage.Name       = magedata.Name;
            mage.PointValue = magedata.PointValue;
            mage.Range      = magedata.Range;
            mage.Rank       = magedata.Rank;
            mage.Set        = magedata.Set;
            var dial = this.ModelFactoryResolver.GetFactory <IUpdatableDial>().Create();

            foreach (var click in magedata.Dial.Clicks)
            {
                var query = this.ModelFactoryResolver.GetFactory <IUpdatableClick>().Create();
                query.Attack  = this.ModelFactoryResolver.GetFactory <IUpdatableStat>().Create();
                query.Speed   = this.ModelFactoryResolver.GetFactory <IUpdatableStat>().Create();
                query.Defense = this.ModelFactoryResolver.GetFactory <IUpdatableStat>().Create();
                query.Damage  = this.ModelFactoryResolver.GetFactory <IUpdatableStat>().Create();

                query.Attack.Value     = click.Attack.Value;
                query.Attack.Ability   = click.Attack.Ability;
                query.Attack.StatType  = click.Attack.StatType;
                query.Speed.Value      = click.Speed.Value;
                query.Speed.Ability    = click.Speed.Ability;
                query.Speed.StatType   = click.Speed.StatType;
                query.Defense.Value    = click.Defense.Value;
                query.Defense.Ability  = click.Defense.Ability;
                query.Defense.StatType = click.Defense.StatType;
                query.Damage.Value     = click.Damage.Value;
                query.Damage.Ability   = click.Damage.Ability;
                query.Damage.StatType  = click.Damage.StatType;
                query.Index            = click.Index;

                foreach (var stat in click.Stats)
                {
                    var statQuery = this.ModelFactoryResolver.GetFactory <IUpdatableStat>().Create();
                    statQuery.Ability  = stat.Ability;
                    statQuery.Value    = stat.Value;
                    statQuery.StatType = stat.StatType;
                    query.Stats.Add(statQuery);
                }

                dial.Clicks.Add(query);
            }

            dial.ClickIndex = magedata.Dial.ClickIndex;
            dial.Click      = dial.Clicks.First();
            dial.Name       = magedata.Dial.Name;
            mage.Dial       = dial;
            model.Inventory.Add(mage);
            return(true);
        }