@@ -74,25 +74,32 @@ private void InstantUpgrade(AppDbContext context)
74
74
if ( ! setting . IsInstantComplete ) return ;
75
75
var info = context . AccountsInfo . Find ( AccountId ) ;
76
76
if ( info . Gold < 2 ) return ;
77
- var currentlyBuilding = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == VillageId ) . Where ( x => x . Level != - 1 ) ;
77
+ var currentlyBuildings = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == VillageId ) . Where ( x => x . Level != - 1 ) . ToList ( ) ;
78
78
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
79
79
var tribe = context . AccountsInfo . Find ( AccountId ) . Tribe ;
80
80
if ( tribe == TribeEnums . Romans )
81
81
{
82
- if ( currentlyBuilding . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 3 : 2 ) ) return ;
82
+ if ( currentlyBuildings . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 3 : 2 ) ) return ;
83
83
}
84
84
else
85
85
{
86
- if ( currentlyBuilding . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 2 : 1 ) ) return ;
86
+ if ( currentlyBuildings . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 2 : 1 ) ) return ;
87
87
}
88
88
#elif TTWARS
89
- if ( currentlyBuilding . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 2 : 1 ) ) return ;
89
+ if ( currentlyBuildings . Count ( x => x . Level != - 1 ) < ( info . HasPlusAccount ? 2 : 1 ) ) return ;
90
90
#else
91
91
92
92
#error You forgot to define Travian version here
93
93
94
94
#endif
95
- if ( currentlyBuilding . Max ( x => x . CompleteTime ) < DateTime . Now . AddMinutes ( setting . InstantCompleteTime ) ) return ;
95
+ var notInstantBuildings = currentlyBuildings . Where ( x => x . Type . IsNotAdsUpgrade ( ) ) ;
96
+ foreach ( var building in notInstantBuildings )
97
+ {
98
+ currentlyBuildings . Remove ( building ) ;
99
+ }
100
+ if ( ! currentlyBuildings . Any ( ) ) return ;
101
+
102
+ if ( currentlyBuildings . Max ( x => x . CompleteTime ) < DateTime . Now . AddMinutes ( setting . InstantCompleteTime ) ) return ;
96
103
97
104
_taskManager . Add ( AccountId , new InstantUpgrade ( VillageId , AccountId ) ) ;
98
105
}
0 commit comments