1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Data . Entity ;
44using System . Diagnostics ;
@@ -24,11 +24,11 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
2424 {
2525 var mode = context . Mode ;
2626
27- var commProfiles = new LuaTable ( ) ;
27+ var commProfiles = new LuaTable ( ) ;
2828 var db = new ZkDataContext ( ) ;
2929
3030 // calculate to whom to send extra comms
31- var accountIDsWithExtraComms = new List < int > ( ) ;
31+ var accountIDsWithExtraComms = new Dictionary < int , int > ( ) ;
3232 if ( mode == AutohostMode . Planetwars || mode == AutohostMode . GameFFA || mode == AutohostMode . Teams )
3333 {
3434 var groupedByTeam = context . Players . Where ( x => ! x . IsSpectator ) . GroupBy ( x => x . AllyID ) . OrderByDescending ( x => x . Count ( ) ) ;
@@ -40,10 +40,23 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
4040 var cnt = biggest . Count ( ) - other . Count ( ) ;
4141 if ( cnt > 0 )
4242 {
43- foreach ( var a in
44- other . Select ( x => db . Accounts . First ( y => y . AccountID == x . LobbyID ) )
45- . OrderByDescending ( x => x . GetRating ( RatingCategory . Casual ) . Elo )
46- . Take ( cnt ) ) accountIDsWithExtraComms . Add ( a . AccountID ) ;
43+ // example case: 3 players on this team, 8 players on largest team
44+ // 5 bonus comms to dole out to this team
45+ // per_player = 1 (integer result of 5/3)
46+ // remainder: 2, so now cnt = 2
47+ // iterate over all players in this team
48+ // first player: cnt == 2, >0 so we give him a second extra comm
49+ // second player: cnt == 1, >0 so same deal
50+ // from now on cnt <= 0 so the remaining 3 players only get the one extra comm
51+ int per_player = cnt / other . Count ( ) ;
52+ cnt = cnt % other . Count ( ) ;
53+ foreach ( var a in other
54+ . Select ( x => db . Accounts . First ( y => y . AccountID == x . LobbyID ) )
55+ . OrderByDescending ( x => x . GetRating ( RatingCategory . Casual ) . Elo ) )
56+ {
57+ accountIDsWithExtraComms . Add ( a . AccountID , per_player + ( cnt > 0 ? 1 : 0 ) ) ;
58+ cnt -- ;
59+ }
4760 }
4861 }
4962 }
@@ -100,7 +113,7 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
100113 // write player custom keys (level, elo, is muted, etc.)
101114 foreach ( var p in context . Players )
102115 {
103- var user = db . Accounts . Where ( x=> x . AccountID == p . LobbyID ) . Include ( x=> x . RelalationsByOwner ) . FirstOrDefault ( ) ;
116+ var user = db . Accounts . Where ( x => x . AccountID == p . LobbyID ) . Include ( x => x . RelalationsByOwner ) . FirstOrDefault ( ) ;
104117 if ( user != null )
105118 {
106119 var userParams = new Dictionary < string , string > ( ) ;
@@ -125,7 +138,7 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
125138 . Where ( x => x . GetRating ( context . ApplicableRating ) . Elo > user . GetRating ( context . ApplicableRating ) . Elo )
126139 . Count ( )
127140 . ToString ( ) ;
128-
141+
129142 userParams [ "icon" ] = user . GetIconName ( ) ;
130143 userParams [ "avatar" ] = user . Avatar ;
131144 userParams [ "badges" ] = string . Join ( "," , user . GetBadges ( ) ) ;
@@ -136,9 +149,9 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
136149 var userSpecChatBlocked = Punishment . GetActivePunishment ( user . AccountID , null , null , x => x . BanSpecChat ) != null ; ;
137150 userParams [ "can_spec_chat" ] = userSpecChatBlocked ? "0" : "1" ;
138151
139- userParams [ "ignored" ] = string . Join ( "," , user . RelalationsByOwner . Where ( x => x . Relation == Relation . Ignore ) . Select ( x=> x . Target . Name ) ) ;
140- userParams [ "friends" ] = string . Join ( "," , user . RelalationsByOwner . Where ( x => x . Relation == Relation . Friend ) . Select ( x=> x . Target . Name ) ) ;
141-
152+ userParams [ "ignored" ] = string . Join ( "," , user . RelalationsByOwner . Where ( x => x . Relation == Relation . Ignore ) . Select ( x => x . Target . Name ) ) ;
153+ userParams [ "friends" ] = string . Join ( "," , user . RelalationsByOwner . Where ( x => x . Relation == Relation . Friend ) . Select ( x => x . Target . Name ) ) ;
154+
142155 if ( ! p . IsSpectator )
143156 {
144157 // set valid PW structure attackers
@@ -147,7 +160,7 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
147160 userParams [ "pwRank" ] = ( user . AccountRolesByAccountID . Where (
148161 x =>
149162 ! x . RoleType . IsClanOnly &&
150- ( x . RoleType . RestrictFactionID == null || x . RoleType . RestrictFactionID == user . FactionID ) ) . OrderBy ( x=> x . RoleType . DisplayOrder ) . Select ( x => ( int ? ) x . RoleType . DisplayOrder ) . FirstOrDefault ( ) ?? 999 ) . ToString ( ) ;
163+ ( x . RoleType . RestrictFactionID == null || x . RoleType . RestrictFactionID == user . FactionID ) ) . OrderBy ( x => x . RoleType . DisplayOrder ) . Select ( x => ( int ? ) x . RoleType . DisplayOrder ) . FirstOrDefault ( ) ?? 999 ) . ToString ( ) ;
151164
152165
153166 var allied = user . Faction != null && defender != null && user . Faction != defender &&
@@ -161,10 +174,10 @@ public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingConte
161174 userParams [ "pwInstructions" ] = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( GetPwInstructions ( planet , user , db , attacker ) ) ) ;
162175 }
163176
164- if ( accountIDsWithExtraComms . Contains ( user . AccountID ) ) userParams [ "extracomm" ] = "1" ;
177+ if ( accountIDsWithExtraComms . ContainsKey ( user . AccountID ) ) userParams [ "extracomm" ] = accountIDsWithExtraComms [ user . AccountID ] . ToString ( ) ;
165178
166179 var commProfileIDs = new LuaTable ( ) ;
167- var userCommandersBanned = Punishment . GetActivePunishment ( user . AccountID , null , null , x => x . BanCommanders ) != null ;
180+ var userCommandersBanned = Punishment . GetActivePunishment ( user . AccountID , null , null , x => x . BanCommanders ) != null ;
168181 if ( ! userCommandersBanned )
169182 {
170183 // set up commander data
@@ -304,7 +317,7 @@ private static string GetPwInstructions(Planet planet, Account user, ZkDataConte
304317 var ipBase = GlobalConst . BaseInfluencePerBattle ;
305318 var ipShips = planet . GetEffectiveShipIpBonus ( attacker ) ;
306319 var ipDefs = planet . GetEffectiveIpDefense ( ) ;
307- var attackerWinLoseCc = ( ipShips + ipBase - ipDefs ) * GlobalConst . PlanetWarsAttackerWinLoseCcMultiplier ;
320+ var attackerWinLoseCc = ( ipShips + ipBase - ipDefs ) * GlobalConst . PlanetWarsAttackerWinLoseCcMultiplier ;
308321 var attackerLoseKillCc = ( ipShips + ipBase - ipDefs ) * GlobalConst . PlanetWarsDefenderWinKillCcMultiplier ;
309322
310323 attackerWinLoseCc = Math . Max ( attackerWinLoseCc , 0 ) ;
@@ -360,7 +373,7 @@ private static string GetPwInstructions(Planet planet, Account user, ZkDataConte
360373 ipBase + ipShips - ipDefs ,
361374 ipBase ,
362375 ipShips ,
363- ipDefs ,
376+ ipDefs ,
364377 attacker ? . Shortcut ,
365378 attackerWinLoseCc ) ;
366379
0 commit comments