onNewRound checks whether the election duration has elapsed and auto-ends if so. When no election is active, it checks whether any zone's election cycle period has elapsed and starts a new election if so.
(e events.Event)
| 720 | // When no election is active, it checks whether any zone's election cycle period |
| 721 | // has elapsed and starts a new election if so. |
| 722 | func (m *ElectionsModule) onNewRound(e events.Event) events.ListenerReturn { |
| 723 | if m.state.ActiveElection != nil { |
| 724 | gd := gametime.GetDate(m.state.ActiveElection.StartRound) |
| 725 | endRound := gd.AddPeriod(m.electionDuration()) |
| 726 | |
| 727 | if util.GetRoundCount() >= endRound { |
| 728 | m.endElection(nil) |
| 729 | } |
| 730 | return events.Continue |
| 731 | } |
| 732 | |
| 733 | cyclePeriod := m.electionCyclePeriod() |
| 734 | if cyclePeriod == `` { |
| 735 | return events.Continue |
| 736 | } |
| 737 | |
| 738 | now := util.GetRoundCount() |
| 739 | for zoneKey, winner := range m.state.Winners { |
| 740 | if winner.LastElectionRound == 0 { |
| 741 | continue |
| 742 | } |
| 743 | gd := gametime.GetDate(winner.LastElectionRound) |
| 744 | nextElectionRound := gd.AddPeriod(cyclePeriod) |
| 745 | if now < nextElectionRound { |
| 746 | continue |
| 747 | } |
| 748 | m.state.ActiveElection = &Election{ |
| 749 | Title: winner.Title, |
| 750 | Zone: zoneKey, |
| 751 | StartRound: now, |
| 752 | Votes: make(map[int]int), |
| 753 | } |
| 754 | daysLeft := m.daysRemaining() |
| 755 | msg := electionAlert( |
| 756 | fmt.Sprintf(`A new election has started for "<ansi fg="white-bold">%s</ansi>."`, winner.Title), |
| 757 | `Type <ansi fg="command">help elections</ansi> to find out more about it.`, |
| 758 | `Cast your vote at the nearest polling location.`, |
| 759 | fmt.Sprintf(`The election ends in <ansi fg="white-bold">%s</ansi>!`, daysLeft), |
| 760 | ) |
| 761 | broadcastAlert(msg) |
| 762 | break |
| 763 | } |
| 764 | |
| 765 | return events.Continue |
| 766 | } |
| 767 | |
| 768 | // onPurchase adds the tax portion of a purchase to the zone coffer and |
| 769 | // notifies the buyer. evt.Cost is the tax-inclusive total charged by buy.go |
nothing calls this directly
no test coverage detected