@@ -907,37 +907,49 @@ protected virtual async Task OnDedicatedExited(SpringBattleContext springBattleC
907907
908908 private void discussionTimer_Elapsed ( object sender , ElapsedEventArgs e )
909909 {
910- discussionTimer . Stop ( ) ;
911- var poll = new CommandPoll ( this , false , false , true ) ;
912- poll . PollEnded += MapVoteEnded ;
913- var options = new List < PollOption > ( ) ;
914- for ( int i = 0 ; i < NumberOfMapChoices ; i ++ )
910+ try
915911 {
916- Resource map ;
917- if ( i < NumberOfMapChoices / 2 )
918- {
919- map = MapPicker . GetRecommendedMap ( GetContext ( ) , MinimalMapSupportLevel , MapRatings . GetMapRanking ( ) . TakeWhile ( x => x . Percentile < 0.2 ) . Select ( x => x . Map ) . AsQueryable ( ) ) ; //choose at least 50% popular maps
920- }
921- else
912+ discussionTimer . Stop ( ) ;
913+ var poll = new CommandPoll ( this , false , false , true ) ;
914+ poll . PollEnded += MapVoteEnded ;
915+ var options = new List < PollOption > ( ) ;
916+ List < int > pickedMaps = new List < int > ( ) ;
917+ using ( var db = new ZkDataContext ( ) )
922918 {
923- map = MapPicker . GetRecommendedMap ( GetContext ( ) , ( MinimalMapSupportLevel < MapSupportLevel . Featured ) ? MapSupportLevel . Supported : MinimalMapSupportLevel ) ;
924- }
925- options . Add ( new PollOption ( )
926- {
927- Name = map . InternalName ,
928- URL = $ "{ GlobalConst . BaseSiteUrl } /Maps/Detail/{ map . ResourceID } ",
929- ResourceID = map . ResourceID ,
930- Action = async ( ) =>
919+ for ( int i = 0 ; i < NumberOfMapChoices ; i ++ )
931920 {
932- var cmd = new CmdMap ( ) . Create ( ) ;
933- cmd . Arm ( this , null , map . ResourceID . ToString ( ) ) ;
934- if ( cmd . Access == BattleCommand . AccessType . NotIngame && spring . IsRunning ) return ;
935- if ( cmd . Access == BattleCommand . AccessType . Ingame && ! spring . IsRunning ) return ;
936- await cmd . ExecuteArmed ( this , null ) ;
921+ Resource map ;
922+ if ( i < NumberOfMapChoices / 2 )
923+ {
924+ map = MapPicker . GetRecommendedMap ( GetContext ( ) , MinimalMapSupportLevel , MapRatings . GetMapRanking ( ) . TakeWhile ( x => x . Percentile < 0.2 ) . Select ( x => x . Map ) . Where ( x => ! pickedMaps . Contains ( x . ResourceID ) ) . AsQueryable ( ) ) ; //choose at least 50% popular maps
925+ }
926+ else
927+ {
928+ map = MapPicker . GetRecommendedMap ( GetContext ( ) , ( MinimalMapSupportLevel < MapSupportLevel . Featured ) ? MapSupportLevel . Supported : MinimalMapSupportLevel , db . Resources . Where ( x => ! pickedMaps . Contains ( x . ResourceID ) ) ) ;
929+ }
930+ pickedMaps . Add ( map . ResourceID ) ;
931+ options . Add ( new PollOption ( )
932+ {
933+ Name = map . InternalName ,
934+ URL = $ "{ GlobalConst . BaseSiteUrl } /Maps/Detail/{ map . ResourceID } ",
935+ ResourceID = map . ResourceID ,
936+ Action = async ( ) =>
937+ {
938+ var cmd = new CmdMap ( ) . Create ( ) ;
939+ cmd . Arm ( this , null , map . ResourceID . ToString ( ) ) ;
940+ if ( cmd . Access == BattleCommand . AccessType . NotIngame && spring . IsRunning ) return ;
941+ if ( cmd . Access == BattleCommand . AccessType . Ingame && ! spring . IsRunning ) return ;
942+ await cmd . ExecuteArmed ( this , null ) ;
943+ }
944+ } ) ;
937945 }
938- } ) ;
946+ }
947+ StartVote ( new CmdMap ( ) . GetIneligibilityReasonFunc ( this ) , options , null , "Choose the next map" , poll , MapVoteTime ) ;
948+ }
949+ catch ( Exception ex )
950+ {
951+ Trace . TraceError ( "Error creating map poll: " + ex ) ;
939952 }
940- StartVote ( new CmdMap ( ) . GetIneligibilityReasonFunc ( this ) , options , null , "Choose the next map" , poll , MapVoteTime ) ;
941953 }
942954
943955 private void MapVoteEnded ( object sender , PollOutcome e )
0 commit comments