@@ -17,97 +17,100 @@ public PlanManager(IDbContextFactory<AppDbContext> contextFactory)
17
17
public void Add ( int index , PlanTask task )
18
18
{
19
19
Check ( index ) ;
20
- using var context = _contextFactory . CreateDbContext ( ) ;
21
- // check wall
22
- if ( task . Building . IsWall ( ) )
20
+ if ( task . Type == Enums . PlanTypeEnums . General )
23
21
{
24
- var village = context . Villages . Find ( index ) ;
25
- var tribe = context . AccountsInfo . Find ( village . AccountId ) . Tribe ;
26
- var wall = tribe . GetWall ( ) ;
27
- if ( task . Building != wall ) task . Building = wall ;
28
- }
22
+ using var context = _contextFactory . CreateDbContext ( ) ;
23
+ // check wall
24
+ if ( task . Building . IsWall ( ) )
25
+ {
26
+ var village = context . Villages . Find ( index ) ;
27
+ var tribe = context . AccountsInfo . Find ( village . AccountId ) . Tribe ;
28
+ var wall = tribe . GetWall ( ) ;
29
+ if ( task . Building != wall ) task . Building = wall ;
30
+ }
29
31
30
- // check building can build muiltiple times (warehouse, ganary, ...)
31
- if ( task . Building . IsMultipleAllow ( ) )
32
- {
33
- var villageBuildings = context . VillagesBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
34
- var building = villageBuildings . Where ( x => x . Type == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
35
- if ( building is null )
32
+ // check building can build muiltiple times (warehouse, ganary, ...)
33
+ if ( task . Building . IsMultipleAllow ( ) )
36
34
{
37
- var currentBuildings = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
38
- var currentBuilding = currentBuildings . Where ( x => x . Type == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
39
- if ( currentBuilding is null )
35
+ var villageBuildings = context . VillagesBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
36
+ var building = villageBuildings . Where ( x => x . Type == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
37
+ if ( building is null )
40
38
{
41
- var planTasks = GetList ( index ) ;
42
- var planTask = planTasks . Where ( x => x . Building == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
43
- if ( planTask is not null )
39
+ var currentBuildings = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
40
+ var currentBuilding = currentBuildings . Where ( x => x . Type == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
41
+ if ( currentBuilding is null )
42
+ {
43
+ var planTasks = GetList ( index ) ;
44
+ var planTask = planTasks . Where ( x => x . Building == task . Building ) . OrderByDescending ( x => x . Level ) . FirstOrDefault ( ) ;
45
+ if ( planTask is not null )
46
+ {
47
+ if ( task . Location != planTask . Location && planTask . Level != planTask . Building . GetMaxLevel ( ) )
48
+ {
49
+ task . Location = planTask . Location ;
50
+ }
51
+ }
52
+ }
53
+ else
44
54
{
45
- if ( task . Location != planTask . Location && planTask . Level != planTask . Building . GetMaxLevel ( ) )
55
+ if ( task . Location != currentBuilding . Location && currentBuilding . Level != currentBuilding . Type . GetMaxLevel ( ) )
46
56
{
47
- task . Location = planTask . Location ;
57
+ task . Location = currentBuilding . Location ;
48
58
}
49
59
}
50
60
}
51
61
else
52
62
{
53
- if ( task . Location != currentBuilding . Location && currentBuilding . Level != currentBuilding . Type . GetMaxLevel ( ) )
63
+ if ( task . Location != building . Id && building . Level != building . Type . GetMaxLevel ( ) )
54
64
{
55
- task . Location = currentBuilding . Location ;
65
+ task . Location = building . Id ;
56
66
}
57
67
}
58
68
}
59
69
else
60
70
{
61
- if ( task . Location != building . Id && building . Level != building . Type . GetMaxLevel ( ) )
71
+ if ( task . Building . IsResourceField ( ) )
62
72
{
63
- task . Location = building . Id ;
73
+ var villageBuilding = context . VillagesBuildings . Where ( x => x . VillageId == index ) . FirstOrDefault ( x => x . Id == task . Location ) ;
74
+ // different type village ( 4446 import to 3337 for example )
75
+ // now i just ignore the different resource field
76
+ if ( villageBuilding is null || villageBuilding . Type != task . Building ) return ;
64
77
}
65
- }
66
- }
67
- else
68
- {
69
- if ( task . Building . IsResourceField ( ) )
70
- {
71
- var villageBuilding = context . VillagesBuildings . Where ( x => x . VillageId == index ) . FirstOrDefault ( x => x . Id == task . Location ) ;
72
- // different type village ( 4446 import to 3337 for example )
73
- // now i just ignore the different resource field
74
- if ( villageBuilding is null || villageBuilding . Type != task . Building ) return ;
75
- }
76
- else
77
- {
78
- var villageBuildings = context . VillagesBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
79
- var building = villageBuildings . FirstOrDefault ( x => x . Type == task . Building ) ;
80
- if ( building is null )
78
+ else
81
79
{
82
- var currentBuildings = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
83
- var currentBuilding = currentBuildings . FirstOrDefault ( x => x . Type == task . Building ) ;
84
- if ( currentBuilding is null )
80
+ var villageBuildings = context . VillagesBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
81
+ var building = villageBuildings . FirstOrDefault ( x => x . Type == task . Building ) ;
82
+ if ( building is null )
85
83
{
86
- var planTasks = GetList ( index ) ;
87
- var planTask = planTasks . FirstOrDefault ( x => x . Building == task . Building ) ;
88
- if ( planTask is not null )
84
+ var currentBuildings = context . VillagesCurrentlyBuildings . Where ( x => x . VillageId == index ) . ToList ( ) ;
85
+ var currentBuilding = currentBuildings . FirstOrDefault ( x => x . Type == task . Building ) ;
86
+ if ( currentBuilding is null )
89
87
{
90
- if ( task . Location != planTask . Location )
88
+ var planTasks = GetList ( index ) ;
89
+ var planTask = planTasks . FirstOrDefault ( x => x . Building == task . Building ) ;
90
+ if ( planTask is not null )
91
91
{
92
- task . Location = planTask . Location ;
92
+ if ( task . Location != planTask . Location )
93
+ {
94
+ task . Location = planTask . Location ;
95
+ }
96
+ }
97
+ }
98
+ else
99
+ {
100
+ if ( task . Location != currentBuilding . Location )
101
+ {
102
+ task . Location = currentBuilding . Location ;
93
103
}
94
104
}
95
105
}
96
106
else
97
107
{
98
- if ( task . Location != currentBuilding . Location )
108
+ if ( task . Location != building . Id )
99
109
{
100
- task . Location = currentBuilding . Location ;
110
+ task . Location = building . Id ;
101
111
}
102
112
}
103
113
}
104
- else
105
- {
106
- if ( task . Location != building . Id )
107
- {
108
- task . Location = building . Id ;
109
- }
110
- }
111
114
}
112
115
}
113
116
0 commit comments