Beispiel #1
0
        /// <summary>
        /// find last of same type and reason
        ///if found, inster after
        ///if not
        ///..find any of higher type of this reson, insert before
        ///..if not found, find any lower and insert after
        ///..fallback - append to end
        /// </summary>
        /// <param name="rt"></param>
        /// <returns></returns>
        private int FindIndexToInsert(RewardType rt)
        {
            int indexToInsert;
            var rewardsList = RewardsEditor.Select(r => r.Reward).ToList();
            int index       = RewardsEditor.Where(r => r.Reward.Type == rt)
                              .Select(r => rewardsList.IndexOf(r.Reward))
                              .OrderByDescending(i => i)
                              .DefaultIfEmpty(-1)
                              .FirstOrDefault();

            if (index > -1)
            {
                indexToInsert = index + 1;
            }
            else
            {
                index = RewardsEditor.Where(r => (int)r.Reward.Type > (int)rt)
                        .Select(r => rewardsList.IndexOf(r.Reward))
                        .OrderBy(i => i)
                        .DefaultIfEmpty(-1)
                        .FirstOrDefault();
                if (index > -1)
                {
                    indexToInsert = index;
                }
                else
                {
                    index = RewardsEditor.Where(r => (int)r.Reward.Type < (int)rt)
                            .Select(r => rewardsList.IndexOf(r.Reward))
                            .OrderByDescending(i => i)
                            .DefaultIfEmpty(-1)
                            .FirstOrDefault();
                    if (index > -1)
                    {
                        indexToInsert = index + 1;
                    }
                    else
                    {
                        indexToInsert = -1;
                    }
                }
            }

            return(indexToInsert);
        }
        internal void DeleteReward(object obj)
        {
            Reward reward = obj as Reward;

            if (reward != null)
            {
                if ((reward.Reason != rewardReason) ||
                    (RewardsEditor.Where(r => r.Reward.Type == reward.Type).Count() > 1) //more than one current type
                    )
                {
                    this.rewards.Remove(obj as Reward);
                }
                else
                {
                    reward.Quantity = 0;
                    if (reward.CardInstance != null)
                    {
                        reward.CardInstance.Card = Card.Unknown;
                    }
                }
            }
            RefreshRewardLists();
        }