public void SetExtensionTimers(SMTimer timer) { if (timer.DurationSeconds > 60 || (timer.DurationSeconds == 60 && timer.DurationTicks > 0)) { int extensionNum = (timer.DurationSeconds / 60) - 1; SMTimer extension; if (extensionNum >= extensionTimers.Count) { // Make a new extension timer, linked to by the previous one // We assume we're only 1 above, if not, a lot of things are probably wrong everywhere - these have to go in order extension = new SMTimer() { InternalId = extensionTimers.Count, DurationSeconds = 60 }; if (extensionNum > 0) { extensionTimers[extensionNum - 1].LinkedTimers.Add(extension); } extensionTimers.Add(extension); } else { extension = extensionTimers[extensionNum]; } // Link the existing extension timer to this one extension.LinkedTimers.Add(timer); timer.DurationSeconds = timer.DurationSeconds % 60; } }
// Meant to be called after a tote is assigned of course public void SetStartTimerForNote(SMNote note) { // These will have to be the same note and everything...which is handled by being the same tote // This will basically never have anything in it except in very rare cases var availableTimers = startTimers.Where(t => t.Totehead.InternalId == note.totehead.InternalId && t.DurationTicks + t.DurationSeconds * 40 == note.startTicks && t.AttachedNotes.All(an => an.durationTicks == note.durationTicks)); SMTimer timer; if (availableTimers.Count() == 0) { timer = new SMTimer() { DurationTicks = note.startTicks, Totehead = note.totehead, InternalId = startTimers.Count }; startTimers.Add(timer); } else { timer = availableTimers.First(); } note.startTimer = timer; timer.AttachedNotes.Add(note); SetExtensionTimers(timer); }
// Meant to be called after a tote is assigned of course public void SetDurationTimerForNote(SMNote note) { //var availableTimers = durationTimers.Where(t => t.Totehead.InternalId == note.totehead.InternalId && t.DurationTicks + t.DurationSeconds*40 == note.durationTicks && t.AttachedNotes.All(an => an.startTicks + an.durationTicks < note.startTicks - 3 || note.startTicks + note.durationTicks < an.startTicks - 3)); var availableTimers = new List <SMTimer>(); // Always make a new timer, we can't re-use circuits SMTimer timer; if (availableTimers.Count() == 0) { timer = new SMTimer() { DurationTicks = note.durationTicks, Totehead = note.totehead, InternalId = durationTimers.Count }; durationTimers.Add(timer); } else { timer = availableTimers.First(); } note.durationTimer = timer; timer.AttachedNotes.Add(note); SetExtensionTimers(timer); }