[comon] ArmorEagleBonus improve

This commit is contained in:
2019-08-18 15:57:29 +03:00
parent bbf1438728
commit 2d70a5652b
2 changed files with 43 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
* bonuses
* spawn bonus by timer
* eagle armor bonus for enemy
* dota and death game types bonuses
* boat bonus
* tanks and bullets speed balancing
* game series
* network series

View File

@@ -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);
for (team in game.teams) {
if (team.eagleId > 0) {
var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
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 / 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);
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);
}
}
}
}
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, "armor")));
game.gameEventSignal.emit(CHANGE(BRICK(brickId, brickType)));
}
game.ticker.emit(function() {
for (brickId in bricks) {
game.gameEventSignal.emit(CHANGE(BRICK(brickId, "brick")));
}
}, Std.int(config.duration * 1000), '$CLASS.${eagle.id}');
}
}, Std.int(duration * 1000), '$CLASS.${eagle.id}');
}
}