[comon] ArmorEagleBonus improve
This commit is contained in:
@@ -5,7 +5,7 @@ import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.Team;
|
||||
import ru.m.tankz.map.LevelMap;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using ru.m.tankz.game.GameUtil;
|
||||
@@ -14,30 +14,50 @@ class ArmorEagleBonus extends BaseBonus {
|
||||
|
||||
public static inline var CLASS = "armor.eagle";
|
||||
|
||||
private static var brickMap(default, never) = [
|
||||
[1, 1, 1, 1],
|
||||
[1, 0, 0, 1],
|
||||
[1, 0, 0, 1],
|
||||
[1, 1, 1, 1],
|
||||
];
|
||||
|
||||
override public function apply(playerId:PlayerId, game:IGame, engine:IEngine):Void {
|
||||
var team:Team = game.getTeam(playerId.team);
|
||||
if (team.eagleId > 0) {
|
||||
var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
|
||||
var center = eagle.rect.center;
|
||||
var cx:Int = Math.round(center.x / engine.map.cellWidth);
|
||||
var cy:Int = Math.round(center.y / engine.map.cellHeight);
|
||||
var bricks:Array<Int> = [];
|
||||
for (x in cx - 2...cx + 2) {
|
||||
for (y in cy - 2...cy + 2) {
|
||||
var brick = engine.map.getBrick(new Point(x, y));
|
||||
if (brick != null && brick.config.type != "none") {
|
||||
bricks.push(brick.id);
|
||||
for (team in game.teams) {
|
||||
if (team.eagleId > 0) {
|
||||
var brickType = team.id == playerId.team ? "armor" : "none";
|
||||
applyEagleArmor(team.eagleId, brickType, config.duration, game, engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getEagleBricksIds(eagle:Eagle, map:LevelMap):Array<Int> {
|
||||
var result:Array<Int> = [];
|
||||
var center = eagle.rect.center;
|
||||
var cx:Int = Math.round(center.x / map.cellWidth - brickMap.length / 2);
|
||||
var cy:Int = Math.round(center.y / map.cellHeight - brickMap[0].length / 2);
|
||||
for (x in 0...brickMap.length) {
|
||||
for (y in 0...brickMap[0].length) {
|
||||
if (brickMap[x][y] > 0) {
|
||||
var brick = map.getBrick(new Point(cx + x, cy + y));
|
||||
if (brick != null) {
|
||||
result.push(brick.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (brickId in bricks) {
|
||||
game.gameEventSignal.emit(CHANGE(BRICK(brickId, "armor")));
|
||||
}
|
||||
game.ticker.emit(function() {
|
||||
for (brickId in bricks) {
|
||||
game.gameEventSignal.emit(CHANGE(BRICK(brickId, "brick")));
|
||||
}
|
||||
}, Std.int(config.duration * 1000), '$CLASS.${eagle.id}');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function applyEagleArmor(eagleId:Int, brickType:BrickType, duration:Int, game:IGame, engine:IEngine):Void {
|
||||
var eagle:Eagle = engine.getEntity(eagleId);
|
||||
var bricks:Array<Int> = getEagleBricksIds(eagle, engine.map);
|
||||
for (brickId in bricks) {
|
||||
game.gameEventSignal.emit(CHANGE(BRICK(brickId, brickType)));
|
||||
}
|
||||
game.ticker.emit(function() {
|
||||
for (brickId in bricks) {
|
||||
game.gameEventSignal.emit(CHANGE(BRICK(brickId, "brick")));
|
||||
}
|
||||
}, Std.int(duration * 1000), '$CLASS.${eagle.id}');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user