Example #1
0
        /// <summary>
        /// 艦隊に編成されている艦娘の状態から、再出撃可能かどうかを判定します。
        /// </summary>
        /// <param name="ships">艦隊に編成されている艦娘。</param>
        internal void Update(Ship[] ships)
        {
            if (ships.Length == 0)
            {
                this.ReadyTime = null;
                this.UpdateCore();
                return;
            }

            var reason = CanReSortieReason.NoProblem;

            if (ships.Any(s => (s.HP.Current / (double)s.HP.Maximum) <= 0.5))
            {
                reason |= CanReSortieReason.Wounded;
            }

            if (ships.Any(s => s.Fuel.Current < s.Fuel.Maximum || s.Bull.Current < s.Bull.Maximum))
            {
                reason |= CanReSortieReason.LackForResources;
            }

            var min = ships.Min(x => x.Condition);
            if (min < 40)
            {
                reason |= CanReSortieReason.BadCondition;

                // コンディションの最小値が前回から変更された場合のみ、再出撃可能時刻を更新する
                // (サーバーから来るコンディション値が 3 分に 1 回しか更新されないので、毎回カウントダウンし直すと最大 3 分くらいズレる)
                if (min != this.minCondition)
                {
                    this.ReadyTime = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(40 - min));
                }
            }
            else
            {
                this.ReadyTime = null;
            }

            this.minCondition = min;
            this.Reason = reason;

            this.UpdateCore();
        }
Example #2
0
        /// <summary>
        /// 艦隊に編成されている艦娘の状態から、再出撃可能かどうかを判定します。
        /// </summary>
        /// <param name="ships">艦隊に編成されている艦娘。</param>
        internal void Update(Ship[] ships, Repairyard repairyard)
        {
            try
            {
                if (ships.Length == 0)
                {
                    this.ReadyTime = null;
                    this.UpdateCore();
                    if (this.CriticaledShips.Count > 0)
                    {
                        this.CriticalCleared(this, new EventArgs());
                        this.CriticaledShips.Clear();
                    }
                    return;
                }

                var reason = CanReSortieReason.NoProblem;

                if (ships.Any(s => s.IsBadlyDamaged))
                {
                    reason |= CanReSortieReason.Wounded;

                    // We only send out the event once, when the ships has reached critical from its previous state.
                    IEnumerable<Ship> CriticalShips = ships.Where(s => s.IsBadlyDamaged);
                    foreach (Ship s in CriticalShips)
                    {
                        if (this.CriticalCondition != null && !repairyard.CheckRepairing(s.Id) && (this.CriticaledShips.Count == 0 || (this.CriticaledShips.Count > 0 && !this.CriticaledShips[s.Id])))
                        {
                            this.CriticalCondition(this, new ShipCriticalConditionEventArgs(s));
                            this.CriticaledShips.Add(s.Id, true);
                        }
                    }

                    int RepairingCritShips = ships.Where(s => s.IsBadlyDamaged && repairyard.CheckRepairing(s.Id)).Count();

                    if (this.CriticalCleared != null && ships.Where(s => s.IsBadlyDamaged).Count() == RepairingCritShips)
                    {
                        this.CriticalCleared(this, new EventArgs());
                        this.CriticaledShips.Clear();
                    }
                }
                else if (this.CriticalCleared != null && this.CriticaledShips.Count > 0)
                {
                    this.CriticaledShips.Clear();
                    this.CriticalCleared(this, new EventArgs());
                }

                if (ships.Any(s => s.Fuel.Current < s.Fuel.Maximum || s.Bull.Current < s.Bull.Maximum))
                {
                    reason |= CanReSortieReason.LackForResources;
                }

                var min = ships.Min(x => x.Condition);
                if (min < 40)
                {
                    reason |= CanReSortieReason.BadCondition;

                    // コンディションの最小値が前回から変更された場合のみ、再出撃可能時刻を更新する
                    // (サーバーから来るコンディション値が 3 分に 1 回しか更新されないので、毎回カウントダウンし直すと最大 3 分くらいズレる)
                    if (min != this.minCondition)
                    {
                        this.ReadyTime = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(40 - min));
                    }
                }
                else
                {
                    this.ReadyTime = null;
                }

                this.minCondition = min;
                this.Reason = reason;

                this.UpdateCore();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }