ActionsApi.activateSuperWeapon(type, tile, tile2?)方法說明與使用範例
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/1195
以下摘錄展示了 ActionsApi 與超級武器相關的定義,其中 activateSuperWeapon
是關鍵方法:
resumeProduction(queueType: QueueType): void;
queueForProduction(queueType: QueueType, objName: string, objType: ObjectType, quantity: number): void;
unqueueFromProduction(queueType: QueueType, objName: string, objType: ObjectType, quantity: number): void;
activateSuperWeapon(type: SuperWeaponType, tile: {
rx: number;
ry: number;
}, tile2?: {
rx: number;
ry: number;
}): void;
orderUnits(unitIds: number[], orderType: OrderType): void;
超級武器類型列舉如下:
export declare enum SuperWeaponType {
MultiMissile = 0,
IronCurtain = 1,
LightningStorm = 2,
ChronoSphere = 3,
ChronoWarp = 4,
ParaDrop = 5,
AmerParaDrop = 6
}
超級武器的資料結構及狀態:
export declare interface SuperWeaponData {
playerName: string;
type: SuperWeaponType;
status: SuperWeaponStatus;
timerSeconds: number;
}
export declare enum SuperWeaponStatus {
Charging = 0,
Paused = 1,
Ready = 2
}
GameApi 提供 getAllSuperWeaponData()
用於查詢所有玩家的超級武器充能情況:
getVisibleUnits(playerName: string, type: "self" | "allied" | "hostile" | "enemy", filter?: (r: TechnoRules) => boolean): number[];
getGameObjectData(objId: number): GameObjectData | undefined;
getUnitData(unitId: number): UnitData | undefined;
getAllSuperWeaponData(): SuperWeaponData[];
在官方 API 的 README 中,建立遊戲時可以透過 superWeapons
參數控制是否啟用超級武器:
const game = await cdapi.createGame({
agents: [
new ExampleBot("AgentRed", "Americans"),
new ExampleBot("AgentBlue", "French")
],
buildOffAlly: false,
cratesAppear: false,
credits: 10000,
gameMode: cdapi.getAvailableGameModes(mapName)[0],
gameSpeed: 5,
mapName,
mcvRepacks: true,
shortGame: true,
superWeapons: false,
unitCount: 10
});
activateSuperWeapon
方法解析
activateSuperWeapon(type, tile, tile2?)
用於在遊戲中觸發超級武器的釋放。
參數說明:
-
type
:SuperWeaponType
列舉值,指定要使用的超級武器類型(如多管導彈、磁暴風暴、超時空等)。 -
tile
:{rx: number, ry: number}
,表示目標瓦片座標(real/world 座標),與MapApi.getTile(rx, ry)
使用相同的座標系。 -
tile2?
:某些超級武器需要第二個座標(例如超時空移動要指定起點與終點)。此參數可選,在不需要時可省略。
範例流程
查詢超級武器狀態
const swData = game.getAllSuperWeaponData();
const mySW = swData.find(d => d.playerName === botName && d.type === SuperWeaponType.MultiMissile);
if (!mySW || mySW.status !== SuperWeaponStatus.Ready) {
return; // 未就緒
}
選擇目標瓦片
// 假設我們選擇敵方基地中心
const targetTile = game.mapApi.getTile(enemyBase.rx, enemyBase.ry)!;
發動超級武器
actionsApi.activateSuperWeapon(
SuperWeaponType.MultiMissile,
{ rx: targetTile.rx, ry: targetTile.ry }
);
若使用 ChronoSphere
或 ChronoWarp
,可傳入第二個 tile2
參數表示目標地點。
存檔/結束
其他流程與普通命令相同(見 README 中的基本用法)。
總結
透過 GameApi.getAllSuperWeaponData()
可以檢查自己或敵人的超級武器充能狀態,
再配合 ActionsApi.activateSuperWeapon()
在需要的座標發起攻擊或執行特殊效果。
此方法使機器人能夠在適當的時機主動使用多管導彈、鐵幕、磁暴風暴等超級武器,提高作戰效率。
→返回《@chronodivide/game-api 使用教學與完整 API 對照表》
This article was last edited at