Ejemplo n.º 1
0
        public UnitViewModel(AppConfig config, MainViewModel mvm)
        {
            m_config = config;
            m_mvm = mvm;

            SendToSlotCommand = new DelegateCommand<string>(SendToSlot, x => SelectedIdol != null);
            SaveCommand = new DelegateCommand(Save, () => !string.IsNullOrEmpty(UnitName));
            DeleteCommand = new DelegateCommand(Delete, () => Units.Contains(SelectedUnit));
            MoveToSlotCommand = new DelegateCommand<string>(MoveToSlot, CanMoveToSlot);
            ResetSlotCommand = new DelegateCommand<string>(ResetSlot, CanResetSlot);
            HighlightCommand = new DelegateCommand<string>(Highlight, CanHighlight);
            CopyIidCommand = new DelegateCommand(CopyIid, () => SelectedIdol != null);
            SetGuestCenterCommand = new DelegateCommand(SetGuestCenter, () => SelectedIdol != null);
            CopyIidFromSlotCommand = new DelegateCommand<string>(CopyIidFromSlot);
            SetGuestCenterFromSlotCommand = new DelegateCommand<string>(SetGuestCenterFromSlot);

            Idols = new ListCollectionView(m_config.OwnedIdols);
            Filter = new IdolFilter(config, Idols, false);
            Filter.SetConfig(config.UnitIdolFilterConfig);

            Units = m_config.Units;

            TemporalUnit = new Unit();
            SelectedUnit = Units.FirstOrDefault();

            foreach (var option in config.UnitIdolSortOptions)
            {
                Idols.SortDescriptions.Add(option.ToSortDescription());
            }
        }
Ejemplo n.º 2
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            if(e.Property==DataContextProperty)
            {
                if(e.NewValue!=null && e.NewValue is Unit)
                {
                    m_unit = e.NewValue as Unit;
                }

                if (e.OldValue != null)
                {
                    (e.OldValue as INotifyPropertyChanged).PropertyChanged -= SkillTimeline_PropertyChanged;
                    var u = e.OldValue as Unit;
                    UnregisterProperptyChanged(u.Slot1);
                    UnregisterProperptyChanged(u.Slot2);
                    UnregisterProperptyChanged(u.Slot3);
                    UnregisterProperptyChanged(u.Slot4);
                    UnregisterProperptyChanged(u.Slot5);
                }

                if (e.NewValue != null)
                {
                    (e.NewValue as INotifyPropertyChanged).PropertyChanged += SkillTimeline_PropertyChanged;
                    var u = e.NewValue as Unit;
                    RegisterProperptyChanged(u.Slot1);
                    RegisterProperptyChanged(u.Slot2);
                    RegisterProperptyChanged(u.Slot3);
                    RegisterProperptyChanged(u.Slot4);
                    RegisterProperptyChanged(u.Slot5);
                }

                LoadSlots();
            }
            else if(e.Property==SimulationResultProperty)
            {
                if(e.NewValue!=null)
                {
                    m_triggeredSkills = (e.NewValue as SimulationResult).TriggeredSkills.GroupBy(x => x.Who.Oid).ToDictionary(x=>x.Key,x=>x.ToArray());
                }
                else
                {
                    m_triggeredSkills = new Dictionary<int, TriggeredSkill[]>();
                }
                LoadSlots();
            }
            base.OnPropertyChanged(e);
        }
Ejemplo n.º 3
0
        private int CalculateLife(Unit unit, Idol guest)
        {
            if(unit==null)
            {
                return 0;
            }

            var life = 0;
            var centerEffect = unit.Center?.CenterEffect is CenterEffect.LifeUp ? (CenterEffect.LifeUp)unit.Center.CenterEffect : null;
            var guestCenterEffect = guest?.CenterEffect is CenterEffect.LifeUp ? (CenterEffect.LifeUp)guest.CenterEffect : null;

            foreach (var idol in unit.Slots.Cast<IIdol>().Concat(Enumerable.Repeat(guest,1)))
            {
                if (idol == null) continue;

                var rate = 1.0;
                if (centerEffect!=null && centerEffect.Targets.HasFlag(idol.Category) == true)
                {
                    rate += centerEffect.Rate;
                }
                if (guestCenterEffect != null && guestCenterEffect.Targets.HasFlag(idol.Category) == true)
                {
                    rate += guestCenterEffect.Rate;
                }
                life += (int)Math.Ceiling(idol.Life * rate);
            }
            return life;
        }
Ejemplo n.º 4
0
 public void CopyFrom(Unit unit)
 {
     Name = unit.Name;
     Slot1 = unit.Slot1;
     Slot2 = unit.Slot2;
     Slot3 = unit.Slot3;
     Slot4 = unit.Slot4;
     Slot5 = unit.Slot5;
 }
Ejemplo n.º 5
0
 private void Delete()
 {
     Units.Remove(SelectedUnit);
     SelectedUnit = Units.FirstOrDefault();
     if (SelectedUnit == null)
     {
         TemporalUnit = new Unit();
     }
     m_config.Save();
 }