فهرست منبع

Merge pull request #1999 from Ghostuel/feat/yuehai-youxing-realm

feat: 适配月海游星结界皮肤
huangrunheng 2 هفته پیش
والد
کامیت
969433f040

+ 6 - 1
tasks/Component/Costume/costume_base.py

@@ -132,11 +132,16 @@ class CostumeBase:
             return
         # setattr(self, asset_before, asset_after)
         asset_before_object: RuleImage = getattr(self, asset_before)
-        asset_before_object.roi_front = asset_after.roi_front
+        asset_before_object.roi_front = list(asset_after.roi_front)
         if rp_roi_back:
             asset_before_object.roi_back = asset_after.roi_back
         asset_before_object.threshold = asset_after.threshold
         asset_before_object.file = asset_after.file
+        asset_before_object.method = asset_after.method
+        # A cached dispatch flag must not retain the previous skin's method.
+        for name in ('is_template_match', 'is_masked_template_match',
+                     'is_multi_scale_template_match', 'is_sift_flann'):
+            asset_before_object.__dict__.pop(name, None)
         # https://github.com/runhey/OnmyojiAutoScript/issues/1972
         asset_before_object.refresh()
 

+ 1 - 1
tasks/Component/Costume/costume_test_realm.py

@@ -62,7 +62,7 @@ if __name__ == '__main__':
     c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)
-    t.set_costume(RealmType.COSTUME_REALM_2)
+    t.set_costume(RealmType.COSTUME_REALM_DEFAULT)
     t.run()
 
 

+ 9 - 9
tasks/Component/CostumeCarpBanner/assets.py

@@ -12,28 +12,28 @@ class CostumeCarpBannerAssets:
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_1 = RuleImage(roi_front=(572,272,21,33), roi_back=(530,220,202,267), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
+	I_SHI_GROWN_1 = RuleImage(roi_front=(572,272,21,33), roi_back=(560,250,130,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
 	# 结界卡 
-	I_SHI_CARD_1 = RuleImage(roi_front=(911,262,20,33), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
+	I_SHI_CARD_1 = RuleImage(roi_front=(911,262,20,33), roi_back=(760,250,220,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
 	# 防守 
-	I_SHI_DEFENSE_1 = RuleImage(roi_front=(216,258,22,33), roi_back=(178,209,261,274), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
+	I_SHI_DEFENSE_1 = RuleImage(roi_front=(216,258,22,33), roi_back=(260,250,210,210), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
 
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_2 = RuleImage(roi_front=(585,336,21,38), roi_back=(519,212,220,281), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_grown_2.png")
+	I_SHI_GROWN_2 = RuleImage(roi_front=(585,336,21,38), roi_back=(560,250,130,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_grown_2.png")
 	# 结界卡 
-	I_SHI_CARD_2 = RuleImage(roi_front=(871,341,20,36), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_card_2.png")
+	I_SHI_CARD_2 = RuleImage(roi_front=(871,341,20,36), roi_back=(760,250,220,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_card_2.png")
 	# 防守 
-	I_SHI_DEFENSE_2 = RuleImage(roi_front=(287,343,19,38), roi_back=(178,209,261,274), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_defense_2.png")
+	I_SHI_DEFENSE_2 = RuleImage(roi_front=(287,343,19,38), roi_back=(260,250,210,210), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_defense_2.png")
 
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_3 = RuleImage(roi_front=(600,277,19,34), roi_back=(519,212,220,281), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_grown_3.png")
+	I_SHI_GROWN_3 = RuleImage(roi_front=(600,277,19,34), roi_back=(560,250,130,220), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_grown_3.png")
 	# 结界卡 
-	I_SHI_CARD_3 = RuleImage(roi_front=(899,281,21,40), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_card_3.png")
+	I_SHI_CARD_3 = RuleImage(roi_front=(899,281,21,40), roi_back=(760,250,220,220), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_card_3.png")
 	# 防守 
-	I_SHI_DEFENSE_3 = RuleImage(roi_front=(298,279,19,38), roi_back=(178,209,261,274), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_defense_3.png")
+	I_SHI_DEFENSE_3 = RuleImage(roi_front=(298,279,19,38), roi_back=(260,250,210,210), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_defense_3.png")
 
 

+ 3 - 3
tasks/Component/CostumeCarpBanner/cb1/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown_1",
     "imageName": "cb1_shi_grown_1.png",
     "roiFront": "572,272,21,33",
-    "roiBack": "530,220,202,267",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card_1",
     "imageName": "cb1_shi_card_1.png",
     "roiFront": "911,262,20,33",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense_1",
     "imageName": "cb1_shi_defense_1.png",
     "roiFront": "216,258,22,33",
-    "roiBack": "178,209,261,274",
+    "roiBack": "260,250,210,210",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "防守"

+ 3 - 3
tasks/Component/CostumeCarpBanner/cb2/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown_2",
     "imageName": "cb2_shi_grown_2.png",
     "roiFront": "585,336,21,38",
-    "roiBack": "519,212,220,281",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card_2",
     "imageName": "cb2_shi_card_2.png",
     "roiFront": "871,341,20,36",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense_2",
     "imageName": "cb2_shi_defense_2.png",
     "roiFront": "287,343,19,38",
-    "roiBack": "178,209,261,274",
+    "roiBack": "260,250,210,210",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "防守"

+ 7 - 7
tasks/Component/CostumeCarpBanner/cb3/image.json

@@ -3,8 +3,8 @@
     "itemName": "shi_grown_3",
     "imageName": "cb3_shi_grown_3.png",
     "roiFront": "600,277,19,34",
-    "roiBack": "519,212,220,281",
-    "method": "Template matching",
+    "roiBack": "560,250,130,220",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "育成"
   },
@@ -12,8 +12,8 @@
     "itemName": "shi_card_3",
     "imageName": "cb3_shi_card_3.png",
     "roiFront": "899,281,21,40",
-    "roiBack": "823,210,252,297",
-    "method": "Template matching",
+    "roiBack": "760,250,220,220",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "结界卡"
   },
@@ -21,9 +21,9 @@
     "itemName": "shi_defense_3",
     "imageName": "cb3_shi_defense_3.png",
     "roiFront": "298,279,19,38",
-    "roiBack": "178,209,261,274",
-    "method": "Template matching",
+    "roiBack": "260,250,210,210",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "防守"
   }
-]
+]

+ 8 - 8
tasks/KekkaiActivation/a/image.json

@@ -3,7 +3,7 @@
     "itemName": "a_harvest_fish4",
     "imageName": "a_a_harvest_fish4.png",
     "roiFront": "897,159,48,40",
-    "roiBack": "872,128,140,181",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "斗鱼收获奖励4星"
@@ -12,7 +12,7 @@
     "itemName": "a_harvest_exp",
     "imageName": "a_a_harvest_exp.png",
     "roiFront": "891,153,49,43",
-    "roiBack": "865,121,152,183",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "一般的收获奖励"
@@ -156,7 +156,7 @@
     "itemName": "a_harvest_kaiko_4",
     "imageName": "a_a_harvest_kaiko_4.png",
     "roiFront": "894,164,48,41",
-    "roiBack": "867,132,148,187",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "太鼓4"
@@ -165,7 +165,7 @@
     "itemName": "a_harvest_kaiko_3",
     "imageName": "a_a_harvest_kaiko_3.png",
     "roiFront": "893,163,47,42",
-    "roiBack": "865,136,148,178",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -174,7 +174,7 @@
     "itemName": "a_harvest_kaiko_6",
     "imageName": "a_a_harvest_kaiko_6.png",
     "roiFront": "898,160,45,38",
-    "roiBack": "868,129,146,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "太鼓6"
@@ -183,7 +183,7 @@
     "itemName": "a_harvest_fish_6",
     "imageName": "a_a_harvest_fish_6.png",
     "roiFront": "898,159,45,38",
-    "roiBack": "869,131,165,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "斗鱼6"
@@ -192,7 +192,7 @@
     "itemName": "a_harvest_moon_3",
     "imageName": "a_a_harvest_moon_3.png",
     "roiFront": "897,159,46,40",
-    "roiBack": "869,127,155,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "太阴3"
@@ -210,7 +210,7 @@
     "itemName": "a_harvest_fish_3",
     "imageName": "a_a_harvest_fish_3.png",
     "roiFront": "891,165,57,39",
-    "roiBack": "854,128,160,174",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "斗鱼3"

+ 8 - 8
tasks/KekkaiActivation/assets.py

@@ -31,9 +31,9 @@ class KekkaiActivationAssets:
 
 	# Image Rule Assets
 	# 斗鱼收获奖励4星 
-	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(872,128,140,181), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
+	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
 	# 一般的收获奖励 
-	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(865,121,152,183), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
+	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
 	# "结界卡" 
 	I_A_CARDS_REALM = RuleImage(roi_front=(0,0,100,100), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_cards_realm.png")
 	# description 
@@ -65,19 +65,19 @@ class KekkaiActivationAssets:
 	# description 
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
 	# 太鼓4 
-	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(867,132,148,187), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
+	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
 	# description 
-	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(865,136,148,178), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
+	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
 	# 太鼓6 
-	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(868,129,146,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
+	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
 	# 斗鱼6 
-	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(869,131,165,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
+	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
 	# 太阴3 
-	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(869,127,155,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
+	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
 	# 卸下 
 	I_A_DEMOUNT = RuleImage(roi_front=(939,575,55,47), roi_back=(903,551,107,91), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_demount.png")
 	# 斗鱼3 
-	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(854,128,160,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
+	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
 
 
 	# Image Rule Assets

+ 9 - 9
tasks/KekkaiUtilize/assets.py

@@ -38,27 +38,27 @@ class KekkaiUtilizeAssets:
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN = RuleImage(roi_front=(595,291,35,38), roi_back=(530,220,202,267), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_grown.png")
+	I_SHI_GROWN = RuleImage(roi_front=(595,291,35,38), roi_back=(560,250,130,220), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_grown.png")
 	# 结界卡 
-	I_SHI_CARD = RuleImage(roi_front=(891,300,31,55), roi_back=(823,210,252,297), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_card.png")
+	I_SHI_CARD = RuleImage(roi_front=(891,300,31,55), roi_back=(760,250,220,220), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_card.png")
 	# description 
-	I_SHI_DEFENSE = RuleImage(roi_front=(303,308,34,52), roi_back=(178,209,261,274), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_defense.png")
+	I_SHI_DEFENSE = RuleImage(roi_front=(303,308,34,52), roi_back=(260,250,210,210), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_defense.png")
 	# 收取经验(没有满的图) 
-	I_CARD_EXP = RuleImage(roi_front=(889,151,57,54), roi_back=(829,33,231,257), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_card_exp.png")
+	I_CARD_EXP = RuleImage(roi_front=(889,151,57,54), roi_back=(750,90,250,230), threshold=0.8, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_card_exp.png")
 	# 收取体力(没有满) 
-	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(744,336,395,216), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
+	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(790,285,295,240), threshold=0.7, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
 	# 收取盒子的经验(没有满) 
-	I_BOX_EXP = RuleImage(roi_front=(893,440,42,45), roi_back=(792,334,359,232), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
+	I_BOX_EXP = RuleImage(roi_front=(893,440,41,64), roi_back=(875,285,255,240), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
 	# 结界皮肤 
-	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(22,359,393,328), threshold=0.9, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
+	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(140,270,270,285), threshold=0.9, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
 	# 寄养别人的经验 
-	I_UTILIZE_EXP = RuleImage(roi_front=(583,144,58,43), roi_back=(513,43,280,309), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_utilize_exp.png")
+	I_UTILIZE_EXP = RuleImage(roi_front=(583,144,58,43), roi_back=(500,65,220,280), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_utilize_exp.png")
 	# 取出 
 	I_AP_EXTRACT = RuleImage(roi_front=(592,501,100,75), roi_back=(592,501,100,75), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_ap_extract.png")
 	# 提取 
 	I_EXP_EXTRACT = RuleImage(roi_front=(592,448,100,73), roi_back=(592,448,100,73), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_exp_extract.png")
 	# 盒子经验满 
-	I_BOX_EXP_MAX = RuleImage(roi_front=(889,430,61,64), roi_back=(796,326,405,330), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp_max.png")
+	I_BOX_EXP_MAX = RuleImage(roi_front=(889,430,61,64), roi_back=(875,285,255,240), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp_max.png")
 	# 种树活动关闭标识 
 	I_PLANT_TREE_CLOSE = RuleImage(roi_front=(777,91,36,34), roi_back=(711,52,169,125), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_plant_tree_close.png")
 

+ 14 - 14
tasks/KekkaiUtilize/realm/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown",
     "imageName": "realm_shi_grown.png",
     "roiFront": "595,291,35,38",
-    "roiBack": "530,220,202,267",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card",
     "imageName": "realm_shi_card.png",
     "roiFront": "891,300,31,55",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense",
     "imageName": "realm_shi_defense.png",
     "roiFront": "303,308,34,52",
-    "roiBack": "178,209,261,274",
+    "roiBack": "260,250,210,210",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
@@ -30,8 +30,8 @@
     "itemName": "card_exp",
     "imageName": "realm_card_exp.png",
     "roiFront": "889,151,57,54",
-    "roiBack": "829,33,231,257",
-    "method": "Template matching",
+    "roiBack": "750,90,250,230",
+    "method": "Multi-scale template matching",
     "threshold": 0.8,
     "description": "收取经验(没有满的图)"
   },
@@ -39,16 +39,16 @@
     "itemName": "box_ap",
     "imageName": "realm_box_ap.png",
     "roiFront": "815,435,57,51",
-    "roiBack": "744,336,395,216",
-    "method": "Template matching",
+    "roiBack": "790,285,295,240",
+    "method": "Multi-scale template matching",
     "threshold": 0.7,
     "description": "收取体力(没有满)"
   },
   {
     "itemName": "box_exp",
     "imageName": "realm_box_exp.png",
-    "roiFront": "893,440,42,45",
-    "roiBack": "792,334,359,232",
+    "roiFront": "893,440,41,64",
+    "roiBack": "875,285,255,240",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "收取盒子的经验(没有满)"
@@ -57,8 +57,8 @@
     "itemName": "realm_shin",
     "imageName": "realm_realm_shin.png",
     "roiFront": "175,460,54,58",
-    "roiBack": "22,359,393,328",
-    "method": "Template matching",
+    "roiBack": "140,270,270,285",
+    "method": "Multi-scale template matching",
     "threshold": 0.9,
     "description": "结界皮肤"
   },
@@ -66,7 +66,7 @@
     "itemName": "utilize_exp",
     "imageName": "realm_utilize_exp.png",
     "roiFront": "583,144,58,43",
-    "roiBack": "513,43,280,309",
+    "roiBack": "500,65,220,280",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "寄养别人的经验"
@@ -93,7 +93,7 @@
     "itemName": "box_exp_max",
     "imageName": "realm_box_exp_max.png",
     "roiFront": "889,430,61,64",
-    "roiBack": "796,326,405,330",
+    "roiBack": "875,285,255,240",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "盒子经验满"
@@ -107,4 +107,4 @@
     "threshold": 0.8,
     "description": "种树活动关闭标识"
   }
-]
+]

BIN
tasks/KekkaiUtilize/realm/realm_box_exp.png


BIN
tests/tasks/KekkaiUtilize/fixtures/collected_bottle_animals.png


BIN
tests/tasks/KekkaiUtilize/fixtures/distant_realm_elements.png


+ 220 - 0
tests/tasks/KekkaiUtilize/test_realm_multiscale.py

@@ -0,0 +1,220 @@
+"""Offline regression tests for shared realm assets and distant carp banners."""
+from copy import deepcopy
+import json
+from pathlib import Path
+import unittest
+from unittest.mock import patch
+
+import cv2
+import numpy as np
+
+from module.atom.image import RuleImage, set_roi_match_padding
+from tasks.Component.Costume.config import CarpBannerType
+from tasks.Component.Costume.costume_base import CostumeBase
+from tasks.Component.CostumeCarpBanner.assets import CostumeCarpBannerAssets
+from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
+
+ROOT = Path(__file__).resolve().parents[3]
+TARGETS = {
+    'I_SHI_GROWN': (599, 293, 45, 65),
+    'I_SHI_CARD': (777, 288, 50, 72),
+    'I_SHI_DEFENSE': (410, 288, 45, 80),
+    'I_REALM_SHIN': (308, 300, 85, 85),
+    'I_CARD_EXP': (770, 158, 70, 68),
+    'I_BOX_AP': (880, 312, 65, 65),
+    'I_BOX_EXP': (937, 312, 52, 70),
+}
+ORIGINAL_REGIONS = {
+    'I_SHI_GROWN': (519, 212, 220, 281),
+    'I_SHI_CARD': (823, 210, 252, 297),
+    'I_SHI_DEFENSE': (178, 209, 261, 274),
+    'I_REALM_SHIN': (22, 359, 393, 328),
+    'I_CARD_EXP': (829, 33, 231, 257),
+    'I_BOX_AP': (744, 336, 395, 216),
+    'I_BOX_EXP': (792, 334, 359, 232),
+}
+
+
+class Probe(CostumeBase, KekkaiUtilizeAssets):
+    """Only rule replacement is exercised; no Config or Device is created."""
+    pass
+
+
+def screenshot():
+    fixture = Path(__file__).parent / 'fixtures/distant_realm_elements.png'
+    crop = cv2.cvtColor(cv2.imdecode(np.fromfile(fixture, dtype=np.uint8), cv2.IMREAD_COLOR),
+                       cv2.COLOR_BGR2RGB)
+    image = np.zeros((720, 1280, 3), dtype=np.uint8)
+    image[150:460, 300:1000] = crop
+    return image
+
+
+def configured_rules():
+    probe = Probe()
+    for name in TARGETS:
+        setattr(probe, name, deepcopy(getattr(KekkaiUtilizeAssets, name)))
+    with patch('tasks.Component.Costume.costume_base.I18n.trans_zh_cn', return_value='carp'):
+        probe.check_costume_carpbanner(CarpBannerType.COSTUME_CARPBANNER_3)
+    return {name: getattr(probe, name) for name in TARGETS}
+
+
+class RealmMultiScaleTests(unittest.TestCase):
+    def tearDown(self):
+        set_roi_match_padding(0)
+
+    def test_all_seven_visible_elements_match_at_correct_locations(self):
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name, rule in configured_rules().items():
+                with self.subTest(padding=padding, name=name):
+                    self.assertTrue(rule.match(screenshot(), threshold=0.6 if name == 'I_BOX_EXP' else None))
+                    x, y, w, h = rule.roi_front
+                    ex, ey, ew, eh = TARGETS[name]
+                    self.assertTrue(ex <= x + w / 2 < ex + ew)
+                    self.assertTrue(ey <= y + h / 2 < ey + eh)
+                    self.assertEqual(rule.last_scale, None if name == 'I_BOX_EXP' else
+                                     (0.6 if name.startswith('I_SHI_') else 1.0))
+
+    def test_missing_target_is_not_accepted(self):
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name, rule in configured_rules().items():
+                with self.subTest(padding=padding, name=name):
+                    image = screenshot()
+                    x, y, w, h = TARGETS[name]
+                    image[y-5:y+h+5, x-5:x+w+5] = 0
+                    self.assertFalse(rule.match(image, threshold=0.6 if name == 'I_BOX_EXP' else None), (name, rule.last_score, rule.roi_front))
+
+    def test_empty_screen_has_no_matches(self):
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                self.assertFalse(rule.match(np.zeros((720, 1280, 3), dtype=np.uint8)))
+
+    def test_cross_skin_search_regions(self):
+        expected = {
+            'I_SHI_DEFENSE': (260, 250, 210, 210),
+            'I_SHI_GROWN': (560, 250, 130, 220),
+            'I_SHI_CARD': (760, 250, 220, 220),
+            'I_REALM_SHIN': (140, 270, 270, 285),
+            'I_CARD_EXP': (750, 90, 250, 230),
+            'I_BOX_AP': (790, 285, 295, 240),
+            'I_BOX_EXP': (875, 285, 255, 240),
+            'I_BOX_EXP_MAX': (875, 285, 255, 240),
+            'I_UTILIZE_EXP': (500, 65, 220, 280),
+        }
+        for name, roi in expected.items():
+            self.assertEqual(tuple(getattr(KekkaiUtilizeAssets, name).roi_back), roi)
+            if name.startswith('I_SHI_'):
+                for skin in range(1, 4):
+                    self.assertEqual(tuple(getattr(CostumeCarpBannerAssets,
+                                                  name + '_' + str(skin)).roi_back), roi)
+
+    def test_collected_bottle_does_not_match_white_animals_at_task_threshold(self):
+        fixture = Path(__file__).parent / 'fixtures/collected_bottle_animals.png'
+        crop = cv2.cvtColor(cv2.imdecode(np.fromfile(fixture, dtype=np.uint8),
+                                      cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
+        image = np.zeros((720, 1280, 3), dtype=np.uint8)
+        image[280:640, 790:1150] = crop
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name in ('I_BOX_EXP', 'I_BOX_EXP_MAX'):
+                for roi in ((875, 285, 255, 240), (790, 480, 350, 150)):
+                    rule = deepcopy(getattr(KekkaiUtilizeAssets, name))
+                    rule.roi_back = roi
+                    self.assertFalse(rule.match(image, threshold=0.6),
+                                     (name, roi, rule.last_score))
+
+    def test_bottle_click_dimensions_match_replacement_template(self):
+        rule = deepcopy(KekkaiUtilizeAssets.I_BOX_EXP)
+        height, width = rule.image.shape[:2]
+        self.assertEqual(tuple(rule.roi_front[2:]), (width, height))
+        self.assertTrue(rule.match(screenshot(), threshold=0.6))
+
+    def test_runtime_rules_keep_original_templates_and_thresholds(self):
+        defaults = {'I_REALM_SHIN': 0.9, 'I_CARD_EXP': 0.8,
+                    'I_BOX_AP': 0.7, 'I_BOX_EXP': 0.7}
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                if name.startswith('I_SHI_'):
+                    source = getattr(CostumeCarpBannerAssets, name + '_3')
+                    self.assertEqual(rule.file, source.file)
+                    self.assertEqual(rule.threshold, 0.5)
+                else:
+                    self.assertEqual(rule.file, getattr(KekkaiUtilizeAssets, name).file)
+                    self.assertEqual(rule.threshold, defaults[name])
+                self.assertEqual(rule.method, 'Template matching' if name == 'I_BOX_EXP'
+                                 else 'Multi-scale template matching')
+
+    def test_original_size_templates_remain_recognizable(self):
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                image = np.zeros((720, 1280, 3), dtype=np.uint8)
+                x, y, _, _ = rule.roi_back
+                template = rule.image
+                h, w = template.shape[:2]
+                image[y+10:y+10+h, x+10:x+10+w] = template
+                self.assertTrue(rule.match(image))
+                self.assertEqual(rule.last_scale, None if name == 'I_BOX_EXP' else 1.0)
+                self.assertEqual(rule.roi_front, [x+10, y+10, w, h])
+
+    def test_replacement_copies_method_and_clears_cached_dispatch(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        target = probe.I_SHI_GROWN
+        self.assertTrue(target.is_template_match)
+        self.assertFalse(target.is_multi_scale_template_match)
+        _ = target.image
+        source = CostumeCarpBannerAssets.I_SHI_GROWN_3
+        probe.replace_img('I_SHI_GROWN', source)
+        self.assertIs(probe.I_SHI_GROWN, target)
+        self.assertIsNone(target._image)
+        self.assertFalse(target.is_template_match)
+        self.assertTrue(target.is_multi_scale_template_match)
+        self.assertTrue(target.match(screenshot()))
+        self.assertEqual(source.roi_front, [600, 277, 19, 34])
+        self.assertIsNot(target.roi_front, source.roi_front)
+
+    def test_replacement_can_return_to_original_matching_method(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        probe.replace_img('I_SHI_GROWN', CostumeCarpBannerAssets.I_SHI_GROWN_3)
+        self.assertTrue(probe.I_SHI_GROWN.is_multi_scale_template_match)
+        probe.replace_img('I_SHI_GROWN', KekkaiUtilizeAssets.I_SHI_GROWN)
+        self.assertTrue(probe.I_SHI_GROWN.is_template_match)
+        self.assertFalse(probe.I_SHI_GROWN.is_multi_scale_template_match)
+
+    def test_replacement_can_preserve_fixed_search_region(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        original = probe.I_SHI_GROWN.roi_back
+        probe.replace_img('I_SHI_GROWN', CostumeCarpBannerAssets.I_SHI_GROWN_3,
+                          rp_roi_back=False)
+        self.assertEqual(probe.I_SHI_GROWN.roi_back, original)
+
+    def test_manual_realm_tool_references_existing_enum_members(self):
+        import ast
+        from tasks.Component.Costume.config import RealmType
+        tool = ROOT / 'tasks/Component/Costume/costume_test_realm.py'
+        tree = ast.parse(tool.read_text(encoding='utf-8'))
+        members = [node.attr for node in ast.walk(tree)
+                   if isinstance(node, ast.Attribute)
+                   and isinstance(node.value, ast.Name)
+                   and node.value.id == 'RealmType']
+        self.assertTrue(members)
+        for member in members:
+            self.assertIn(member, RealmType.__members__)
+
+    def test_generated_classes_match_json(self):
+        for rel, assets in [('tasks/KekkaiUtilize/realm/image.json', KekkaiUtilizeAssets),
+                            ('tasks/Component/CostumeCarpBanner/cb3/image.json',
+                             CostumeCarpBannerAssets)]:
+            for row in json.loads((ROOT / rel).read_text(encoding='utf-8')):
+                with self.subTest(file=rel, name=row['itemName']):
+                    rule = getattr(assets, 'I_' + row['itemName'].upper())
+                    self.assertEqual(rule.method, row['method'])
+                    self.assertEqual(tuple(rule.roi_back), tuple(map(int, row['roiBack'].split(','))))
+                    self.assertEqual(rule.threshold, row['threshold'])
+
+
+if __name__ == '__main__':
+    unittest.main()