Skip to content

Commit 1b49875

Browse files
committed
buff调整,增强buff效果,增加buff查看器
1 parent 032823f commit 1b49875

12 files changed

Lines changed: 754 additions & 127 deletions

File tree

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from .game_api import GameAPI, GameAPIError
2-
from .models import Location, TargetsQueryParam, Actor
2+
from .models import Location, TargetsQueryParam, Actor,MapQueryResult,FrozenActor,ControlPoint,ControlPointQueryResult,MatchInfoQueryResult,PlayerBaseInfo,ScreenInfoResult
33

44
__all__ = [
55
'GameAPI',
66
'GameAPIError',
77
'Location',
88
'TargetsQueryParam',
9-
'Actor'
9+
'Actor',
10+
'MapQueryResult',
11+
'FrozenActor',
12+
'ControlPoint',
13+
'ControlPointQueryResult',
14+
'MatchInfoQueryResult',
15+
'PlayerBaseInfo',
16+
'ScreenInfoResult'
1017
]

Copilot/openra_ai/OpenRA_Copilot_Library/game_api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@ def move_units_by_direction(self, actors: List[Actor], direction: str, distance:
416416
except Exception as e:
417417
raise GameAPIError("MOVE_UNITS_ERROR", "移动单位时发生错误: {0}".format(str(e)))
418418

419-
def move_units_by_path(self, actors: List[Actor], path: List[Location]) -> None:
419+
def move_units_by_path(self, actors: List[Actor], path: List[Location], attack_move: bool = False) -> None:
420420
'''沿路径移动单位
421421
422422
Args:
423423
actors (List[Actor]): 要移动的Actor列表
424424
path (List[Location]): 移动路径
425-
425+
attack_move (bool): 是否为攻击性移动
426426
Raises:
427427
GameAPIError: 当移动命令执行失败时
428428
'''
@@ -431,7 +431,8 @@ def move_units_by_path(self, actors: List[Actor], path: List[Location]) -> None:
431431
try:
432432
response = self._send_request('move_actor', {
433433
"targets": {"actorId": [actor.actor_id for actor in actors]},
434-
"path": [point.to_dict() for point in path]
434+
"path": [point.to_dict() for point in path],
435+
"isAttackMove": 1 if attack_move else 0
435436
})
436437
self._handle_response(response, "移动单位失败")
437438
except GameAPIError:
@@ -742,6 +743,7 @@ def attack_target(self, attacker: Actor, target: Actor) -> bool:
742743
result = self._handle_response(response, "攻击命令执行失败")
743744
return response.get("status", 0) > 0
744745
except GameAPIError as e:
746+
print(response)
745747
if e.code == "COMMAND_EXECUTION_ERROR":
746748
return False
747749
raise
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# 这个是一个示例文件,展示了如何使用OpenRA_Copilot_Library库,尽可能详细的包含了库中的所有功能,可以作为参考
2+
3+
# 该代码对应了一个基础的开局行为:展开基地车,建造电厂,兵营,各种基本单位,然后步兵探索地图,飞机探索地图,同时发展了我的科技,建造了各种部队,最后进攻敌方基地
4+
5+
import sys
6+
import os
7+
import time
8+
import json
9+
import random
10+
11+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
12+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
14+
15+
16+
import OpenRA_Copilot_Library as OpenRA
17+
from OpenRA_Copilot_Library import *
18+
19+
api = OpenRA.GameAPI("localhost")
20+
21+
# 展开基地车
22+
23+
# api.deploy_mcv_and_wait(wait_time=1.0)
24+
# print("基地车已展开完毕")
25+
26+
# # 建造电厂和兵营
27+
# api.ensure_can_build_wait("电厂")
28+
# build = api.produce_wait("电厂", 1, True)
29+
# api.ensure_can_build_wait("矿场")
30+
# build = api.produce_wait("矿场", 1, True)
31+
# # 因为电厂本来就是兵营前置了,所以先电厂后兵营
32+
# api.ensure_can_build_wait("兵营")
33+
# build = api.produce_wait("兵营", 1, True)
34+
35+
36+
# if api.ensure_can_produce_unit("步兵"):
37+
# print("开始生产3个步兵...")
38+
# wtank = api.produce("步兵", 5)
39+
# api.wait(wtank)
40+
# else:
41+
# raise RuntimeError("无法生产防空车")
42+
43+
# # # # 蓝噪声算法,用于探索地图
44+
# def _shadow_points(mapinfo: MapQueryResult, step, exponly=True):
45+
# W, H = mapinfo.MapWidth -2 , mapinfo.MapHeight -2
46+
# StartX, StartY = 2, 2
47+
# vis = mapinfo.IsVisible
48+
# exp = mapinfo.IsExplored
49+
# if exponly: # 备选:完全未探明的
50+
# pts = [Location(x, y) for y in range(StartY, H, step)
51+
# for x in range(StartX, H, step) if not exp[x][y]]
52+
# else:
53+
# pts = [Location(x, y) for y in range(StartY, W, step)
54+
# for x in range(StartX, H, step) if not vis[x][y]]
55+
# return pts
56+
57+
58+
# def explore(api: GameAPI, unit: list[Actor], mapinfo: MapQueryResult, r=18, per_unit=4, spacing=4, step=2):
59+
# if not unit:
60+
# return
61+
# all_shadow = _shadow_points(mapinfo, step)
62+
# if not all_shadow:
63+
# return
64+
65+
# taken = [] # 全局蓝噪声约束
66+
# batch = []
67+
68+
# for u in unit:
69+
# api.update_actor(u)
70+
# upos = u.position
71+
# local = [p for p in all_shadow if p.manhattan_distance(upos) <= r]
72+
# if not local:
73+
# local = [
74+
# p for p in all_shadow if p.manhattan_distance(upos) <= 2*r]
75+
# if not local:
76+
# continue
77+
# # 远且分散优先
78+
# random.shuffle(local)
79+
# local.sort(key=lambda p: min([p.manhattan_distance(q)
80+
# for q in taken] or [1e9]), reverse=True)
81+
82+
# picks = []
83+
# for i in range(per_unit):
84+
# last = None
85+
# if last:
86+
# local.sort(key=lambda p: 2 * min([p.manhattan_distance(q)
87+
# for q in taken] or [1e9]) - p.manhattan_distance(last), reverse=True)
88+
# picked = False
89+
# for p in local:
90+
# if len(picks) >= per_unit:
91+
# picked = True
92+
# break
93+
# if all(p.manhattan_distance(q) >= spacing for q in picks) and all(p.manhattan_distance(q) >= spacing for q in taken):
94+
# picks.append(p)
95+
# taken.append(p)
96+
# picked = True
97+
# last = p
98+
# if not picked:
99+
# r += 5
100+
# local = [
101+
# p for p in all_shadow if p.manhattan_distance(upos) <= r]
102+
# i -= 1
103+
104+
# api.move_units_by_path([u], picks, attack_move=True)
105+
106+
# infantry_list = api.query_actor(
107+
# TargetsQueryParam(type=["步兵"], faction="自己"))
108+
# api.form_group(infantry_list, group_id=1)
109+
# mapinfo = api.map_query()
110+
111+
# explore(api, infantry_list, mapinfo)
112+
113+
# api.ensure_can_build_wait("机场")
114+
# api.produce("核电厂", 1, auto_place_building=True)
115+
# api.produce("矿场", 1, auto_place_building=True)
116+
# api.produce("防空车", 5)
117+
# api.produce("修理中心", 1, auto_place_building=True)
118+
# api.produce_wait("机场", 1)
119+
# api.produce("车间", 1, auto_place_building=True)
120+
# api.produce("步兵", 10)
121+
# time.sleep(1)
122+
# api.produce_wait("Yak", 3)
123+
# api.produce("矿车", 2)
124+
# api.produce("核电厂", 1,auto_place_building=True)
125+
# api.produce("修理厂", 1,auto_place_building=True)
126+
# api.produce("科技中心", 1,auto_place_building=True)
127+
128+
129+
# # 再探索一下
130+
# infantry_list = api.query_actor(
131+
# TargetsQueryParam(type=["步兵"], faction="自己"))
132+
# mapinfo = api.map_query()
133+
# explore(api, infantry_list, mapinfo, r=28)
134+
135+
136+
# # 飞机探索就大一点
137+
# inti_r = 48
138+
# enemy_base = None
139+
# for i in range(5):
140+
# aircraft_list = api.query_actor(TargetsQueryParam(type=["Yak"], faction="自己"))
141+
# mapinfo = api.map_query()
142+
# explore(api, aircraft_list, mapinfo, r=inti_r,
143+
# per_unit=4, spacing=10, step=8)
144+
# for x in range(40):
145+
# enemy = api.query_actor(TargetsQueryParam(type=[""], faction="敌方"))
146+
# for unit in enemy:
147+
# if unit.type == "基地" or unit.type == "建造厂":
148+
# enemy_base = unit
149+
# break
150+
# if enemy_base:
151+
# break
152+
# time.sleep(0.5)
153+
# inti_r += 20
154+
155+
# # 建造"矿场"、"车间"以便生产载具
156+
# api.produce("步兵", 5)
157+
# api.produce("火箭兵", 5)
158+
# api.produce("重坦", 3)
159+
# api.produce("V2", 3)
160+
# api.produce("天启坦克", 3)
161+
162+
if enemy_base:
163+
battle_unit = api.query_actor(
164+
TargetsQueryParam(type=["战斗单位"], faction="自己"))
165+
api.move_units_by_location(
166+
battle_unit, enemy_base.position, attack_move=True)
167+
168+
# time.sleep(30)
169+
170+
enemy = api.query_actor(TargetsQueryParam(type=[""], faction="敌方"))
171+
for unit in enemy:
172+
if unit.type == "基地" or unit.type == "建造厂":
173+
enemy_base = unit
174+
break
175+
176+
for i in range(2000):
177+
if enemy_base:
178+
battle_unit = api.query_actor(
179+
TargetsQueryParam(type=["战斗单位"], faction="自己"))
180+
print(battle_unit)
181+
api.move_units_by_location(
182+
battle_unit, enemy_base.position, attack_move=True)
183+
for unit in battle_unit:
184+
api.update_actor(unit)
185+
print(unit.position.manhattan_distance(enemy_base.position))
186+
if unit.position.manhattan_distance(enemy_base.position) <= 5:
187+
api.attack_target(unit, enemy_base)
188+
if not battle_unit:
189+
break
190+
else:
191+
enemy = api.query_actor(TargetsQueryParam(type=[""], faction="敌方"))
192+
for unit in enemy:
193+
if unit.type == "基地" or unit.type == "建造厂":
194+
enemy_base = unit
195+
break
196+
time.sleep(0.1 )

Copilot/openra_ai/OpenRA_Copilot_Library/tests/real_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def main():
412412
time.sleep(0.1)
413413

414414
for i in range(100):
415-
test_deploy_miner(game_api)
415+
test_control_point_operations(game_api)
416416
time.sleep(1)
417417

418418

0 commit comments

Comments
 (0)