3535
3636 searchAllItemAllowedExpandFields = []string {"type" , "image_urls" , "level" }
3737
38- mountAllowedExpandFields = []string {"effects" }
38+ mountAllowedExpandFields = []string {"effects" }
39+
40+ // Equipment item type IDs that represent mounts
41+ mountEquipmentTypeIds = map [int ]bool {
42+ 242 : true ,
43+ 245 : true ,
44+ 247 : true ,
45+ }
3946 setAllowedExpandFields = utils .Concat (mountAllowedExpandFields , []string {"equipment_ids" })
4047 itemAllowedExpandFields = utils .Concat (mountAllowedExpandFields , []string {"recipe" , "description" , "conditions" , "pods" })
4148 equipmentAllowedExpandFields = utils .Concat (itemAllowedExpandFields , []string {"range" , "parent_set" , "is_weapon" , "critical_hit_probability" , "critical_hit_bonus" , "max_cast_per_turn" , "ap_cost" })
@@ -211,8 +218,8 @@ func ListMounts(w http.ResponseWriter, r *http.Request) {
211218 txn := database .Db .Txn (false )
212219 defer txn .Abort ()
213220
214- it , err := txn .Get (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "mounts " ), "id" )
215- if err != nil || it == nil {
221+ equipIt , err := txn .Get (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "equipment " ), "id" )
222+ if err != nil || equipIt == nil {
216223 e .WriteNotFoundResponse (w , "No mounts found." )
217224 return
218225 }
@@ -221,10 +228,13 @@ func ListMounts(w http.ResponseWriter, r *http.Request) {
221228 utils .RequestsMountsList .Inc ()
222229
223230 var mounts []APIMount
224- for obj := it .Next (); obj != nil ; obj = it .Next () {
225- p := obj .(* mapping.MappedMultilangMount )
231+ for obj := equipIt .Next (); obj != nil ; obj = equipIt .Next () {
232+ p := obj .(* mapping.MappedMultilangItemUnity )
233+ if ! mountEquipmentTypeIds [p .Type .ItemTypeId ] {
234+ continue
235+ }
226236 if filterFamilyName != "" {
227- if ! strings .EqualFold (p .FamilyName [lang ], filterFamilyName ) {
237+ if ! strings .EqualFold (p .Type . Name [lang ], filterFamilyName ) {
228238 continue
229239 }
230240 }
@@ -234,12 +244,11 @@ func ListMounts(w http.ResponseWriter, r *http.Request) {
234244 e .WriteInvalidFilterResponse (w , "filter[family.id] is not a number." )
235245 return
236246 }
237- if p .FamilyId != filterFamilyId {
247+ if p .Type . ItemTypeId != filterFamilyId {
238248 continue
239249 }
240250 }
241- mount := RenderMountListEntry (p , lang )
242-
251+ mount := RenderEquipmentAsMountListEntry (p , lang )
243252 if expansions .Has ("effects" ) {
244253 effects := RenderEffects (& p .Effects , lang )
245254 if len (effects ) != 0 {
@@ -837,19 +846,17 @@ func SearchMounts(w http.ResponseWriter, r *http.Request) {
837846 }
838847 itemId := int (hit .Id )
839848
840- raw , err := txn .First (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "mounts " ), "id" , itemId )
849+ raw , err := txn .First (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "equipment " ), "id" , itemId )
841850 if err != nil {
842851 e .WriteServerErrorResponse (w , "Could not read database: " + err .Error ())
843852 return
844853 }
845-
846854 if raw == nil {
847855 e .WriteNotFoundResponse (w , fmt .Sprintf ("Could not find %s with ID %s in database" , "mount" , strconv .Itoa (itemId )))
848856 return
849857 }
850-
851- item := raw .(* mapping.MappedMultilangMount )
852- mounts = append (mounts , RenderMountListEntry (item , lang ))
858+ item := raw .(* mapping.MappedMultilangItemUnity )
859+ mounts = append (mounts , RenderEquipmentAsMountListEntry (item , lang ))
853860 }
854861
855862 utils .WriteCacheHeader (& w )
@@ -1061,7 +1068,7 @@ func SearchAllIndices(w http.ResponseWriter, r *http.Request) {
10611068
10621069 searchChans := make ([]chan []ApiAllSearchResultScore , 0 )
10631070
1064- indicesHasItem := parsedIndices .Has ("items-equipment" ) || parsedIndices .Has ("items-consumables" ) || parsedIndices .Has ("items-resources" ) || parsedIndices .Has ("items-quest_items" ) || parsedIndices .Has ("items-cosmetics" )
1071+ indicesHasItem := parsedIndices .Has ("items-equipment" ) || parsedIndices .Has ("items-consumables" ) || parsedIndices .Has ("items-resources" ) || parsedIndices .Has ("items-quest_items" ) || parsedIndices .Has ("items-cosmetics" ) || parsedIndices . Has ( "mounts" )
10651072 needItemSearch := parsedIndices .Size () == 0 || indicesHasItem
10661073 if needItemSearch {
10671074 itemRetChan := make (chan []ApiAllSearchResultScore )
@@ -1129,7 +1136,8 @@ func SearchAllIndices(w http.ResponseWriter, r *http.Request) {
11291136 }
11301137
11311138 // search_index filter
1132- if ! parsedIndices .Has (itemType ) {
1139+ isMountItem := mountEquipmentTypeIds [item .Type .ItemTypeId ]
1140+ if ! parsedIndices .Has (itemType ) && ! (parsedIndices .Has ("mounts" ) && isMountItem ) {
11331141 continue
11341142 }
11351143
@@ -1252,84 +1260,6 @@ func SearchAllIndices(w http.ResponseWriter, r *http.Request) {
12521260 }()
12531261 }
12541262
1255- needMountSearch := false
1256- mountIncluded := additiveTypesExceptions .Has ("mount" )
1257- notExcluded = ! removedTypesExceptions .Has ("mount" )
1258- noIndexGiven = parsedIndices .Size () == 0 && notExcluded
1259- if noIndexGiven {
1260- needMountSearch = true
1261- } else if parsedIndices .Size () != 0 && ! parsedIndices .Has ("mounts" ) { // index given but no set
1262- needMountSearch = false
1263- } else {
1264- needMountSearch = mountIncluded && notExcluded
1265- }
1266-
1267- if needMountSearch {
1268- mountIndexUid := fmt .Sprintf ("%s-mounts-%s" , utils .CurrentRedBlueVersionStr (database .Version .Search ), lang )
1269- mountIndex := client .Index (mountIndexUid )
1270- mountRetChan := make (chan []ApiAllSearchResultScore )
1271- searchChans = append (searchChans , mountRetChan )
1272- go func () {
1273- request := & meilisearch.SearchRequest {
1274- Limit : searchLimit * 3 ,
1275- ShowRankingScoreDetails : true ,
1276- }
1277-
1278- var searchResp * meilisearch.SearchResponse
1279- if searchResp , err = mountIndex .Search (query , request ); err != nil {
1280- e .WriteServerErrorResponse (w , "Failed to search for query: " + err .Error ())
1281- mountRetChan <- nil
1282- return
1283- }
1284-
1285- mounts := make ([]ApiAllSearchResultScore , 0 )
1286- for _ , hitRaw := range searchResp .Hits {
1287- indexed := Hit {}
1288- err = hitRaw .DecodeInto (& indexed )
1289- if err != nil {
1290- e .WriteServerErrorResponse (w , "Could not decode hit: " + err .Error ())
1291- return
1292- }
1293-
1294- score := indexed .ScoreDetails .Words .Score * wordScoreWeight + indexed .ScoreDetails .Typo .Score * typoScoreWeight
1295-
1296- mountId := int (indexed .Id )
1297-
1298- txn := database .Db .Txn (false )
1299- raw , err := txn .First (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "mounts" ), "id" , mountId )
1300- if err != nil {
1301- e .WriteServerErrorResponse (w , "Could not read database: " + err .Error ())
1302- mountRetChan <- nil
1303- return
1304- }
1305-
1306- if raw == nil {
1307- e .WriteServerErrorResponse (w , fmt .Sprintf ("Could not find %s with ID %s in database" , "mount" , strconv .Itoa (mountId )))
1308- mountRetChan <- nil
1309- return
1310- }
1311-
1312- item := raw .(* mapping.MappedMultilangMount )
1313-
1314- result := ApiAllSearchResult {
1315- Name : item .Name [lang ],
1316- Id : item .AnkamaId ,
1317- Type : ApiAllSearchResultType {
1318- NameId : "mounts" ,
1319- },
1320- ItemFields : nil ,
1321- }
1322-
1323- mounts = append (mounts , ApiAllSearchResultScore {
1324- Result : result ,
1325- Score : score ,
1326- })
1327- }
1328-
1329- mountRetChan <- mounts
1330- }()
1331- }
1332-
13331263 // wait for all search results and merge them into one slice
13341264 var merged []ApiAllSearchResultScore
13351265
@@ -1580,21 +1510,25 @@ func GetSingleMountHandler(w http.ResponseWriter, r *http.Request) {
15801510 txn := database .Db .Txn (false )
15811511 defer txn .Abort ()
15821512
1583- raw , err := txn .First (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "mounts " ), "id" , ankamaId )
1513+ raw , err := txn .First (fmt .Sprintf ("%s-%s" , utils .CurrentRedBlueVersionStr (database .Version .MemDb ), "equipment " ), "id" , ankamaId )
15841514 if err != nil {
15851515 e .WriteServerErrorResponse (w , "Could not read database: " + err .Error ())
15861516 return
15871517 }
1588-
15891518 if raw == nil {
15901519 e .WriteNotFoundResponse (w , fmt .Sprintf ("Could not find %s with ID %s in database" , "mount" , strconv .Itoa (ankamaId )))
15911520 return
15921521 }
1522+ item := raw .(* mapping.MappedMultilangItemUnity )
1523+ if ! mountEquipmentTypeIds [item .Type .ItemTypeId ] {
1524+ e .WriteNotFoundResponse (w , fmt .Sprintf ("Could not find %s with ID %s in database" , "mount" , strconv .Itoa (ankamaId )))
1525+ return
1526+ }
15931527
15941528 utils .RequestsTotal .Inc ()
15951529 utils .RequestsMountsSingle .Inc ()
15961530
1597- mount := RenderMount ( raw .( * mapping. MappedMultilangMount ) , lang )
1531+ mount := RenderEquipmentAsMount ( item , lang )
15981532 utils .WriteCacheHeader (& w )
15991533 err = json .NewEncoder (w ).Encode (mount )
16001534 if err != nil {
0 commit comments