[client] update ResultFrame
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
typedef Type = Dynamic;
|
||||
|
||||
typedef GameType = String;
|
||||
|
||||
typedef TeamId = String;
|
||||
@@ -36,6 +34,10 @@ abstract PlayerId(Array<Dynamic>) {
|
||||
return index - other.index;
|
||||
}
|
||||
|
||||
public function format():String {
|
||||
return index > -1 ? '${team} #${index}' : team;
|
||||
}
|
||||
|
||||
@:from static public inline function fromArray(value:Array<Dynamic>):PlayerId {
|
||||
return new PlayerId(value[0], value[1]);
|
||||
}
|
||||
@@ -79,3 +81,10 @@ abstract PackId(Array<Dynamic>) {
|
||||
typedef LevelId = Int;
|
||||
|
||||
typedef PresetId = Int;
|
||||
|
||||
abstract Score(Int) from Int to Int {
|
||||
|
||||
public function new(value:Int) this = value;
|
||||
|
||||
public inline function format():String return '${this}$';
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ typedef TankConfig = {
|
||||
@:optinal var hits:Int;
|
||||
@:optinal var upgrade:TankType;
|
||||
@:optinal var downgrade:TankType;
|
||||
@:optinal var score:Null<Int>;
|
||||
@:optinal var score:Null<Score>;
|
||||
}
|
||||
|
||||
typedef BonusConfig = {
|
||||
@@ -137,7 +137,7 @@ class Config {
|
||||
|
||||
private var brickMap:Map<BrickType, BrickConfig>;
|
||||
private var brickMapByIndex:Map<Int, BrickConfig>;
|
||||
private var tankMap:Map<TankType, TankConfig>;
|
||||
private var tankMap:Map<String, TankConfig>;
|
||||
private var presetsMap:Map<PresetId, GamePreset>;
|
||||
private var bonusMap:Map<BonusType, BonusConfig>;
|
||||
private var teamsMap:Map<TeamId, TeamConfig>;
|
||||
|
||||
@@ -4,6 +4,7 @@ import haxework.color.Color;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class Tank extends MobileEntity {
|
||||
@@ -16,6 +17,8 @@ class Tank extends MobileEntity {
|
||||
public var protect(default, default):Bool;
|
||||
public var freezing(default, default):Bool;
|
||||
|
||||
public var info(get, null):TankInfo;
|
||||
|
||||
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) {
|
||||
super(id, rect, config.speed, Direction.RIGHT);
|
||||
this.protect = false;
|
||||
@@ -35,6 +38,17 @@ class Tank extends MobileEntity {
|
||||
return value;
|
||||
}
|
||||
|
||||
private function get_info():TankInfo {
|
||||
return {
|
||||
type: config.type,
|
||||
skin: config.skin,
|
||||
hits: hits,
|
||||
bonus: bonus,
|
||||
color: color,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
override public function move(direction:Direction):Void {
|
||||
if (!freezing) {
|
||||
super.move(direction);
|
||||
|
||||
@@ -42,13 +42,7 @@ class EventUtil {
|
||||
}
|
||||
|
||||
public static function buildTankSpawn(tank:Tank):GameEvent {
|
||||
return SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, {
|
||||
type:tank.config.type,
|
||||
hits:tank.hits,
|
||||
bonus:tank.bonus,
|
||||
color:tank.color,
|
||||
name:tank.name,
|
||||
}));
|
||||
return SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, tank.info));
|
||||
}
|
||||
|
||||
public static function buildBonusSpawn(bonus:Bonus):GameEvent {
|
||||
|
||||
@@ -20,6 +20,7 @@ typedef Result = {
|
||||
|
||||
typedef TankInfo = {
|
||||
var type:TankType;
|
||||
var skin:String;
|
||||
var hits:Int;
|
||||
var bonus:Bool;
|
||||
var color:Color;
|
||||
|
||||
@@ -11,6 +11,7 @@ import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState.FragTarget;
|
||||
import ru.m.tankz.game.Spawner;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.Timer;
|
||||
@@ -240,7 +241,11 @@ class GameRunner extends Game implements EngineListener {
|
||||
case [BULLET(bullet), EAGLE(eagle)]:
|
||||
if (!eagle.death) {
|
||||
if (!eagle.protect) {
|
||||
gameEventSignal.emit(DESTROY(EAGLE(eagle.id, buildShot(bullet, eagle.score))));
|
||||
var score = eagle.config.score;
|
||||
if (score != null && eagle.team == bullet.playerId.team) {
|
||||
score = Math.round(score * -0.5);
|
||||
}
|
||||
gameEventSignal.emit(DESTROY(EAGLE(eagle.id, buildShot(bullet, score))));
|
||||
}
|
||||
gameEventSignal.emit(DESTROY(BULLET(bullet.id)));
|
||||
}
|
||||
@@ -388,11 +393,19 @@ class GameRunner extends Game implements EngineListener {
|
||||
case SPAWN(EAGLE(id, rect, teamId)):
|
||||
var team = getTeam(teamId);
|
||||
team.eagleId = id;
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
getPlayer(playerId).state.tank = info;
|
||||
case SPAWN(BULLET(_, _, playerId, _)):
|
||||
getPlayer(playerId).bullets++;
|
||||
case DESTROY(EAGLE(id, shot)):
|
||||
var eagle:Eagle = engine.getEntity(id);
|
||||
eagle.death = true;
|
||||
var shooter = getPlayer(cast(engine.getEntity(shot.tankId), Tank).playerId);
|
||||
shooter.state.frags.push({
|
||||
playerId: new PlayerId(eagle.team, -1),
|
||||
target: EAGLE(eagle.color),
|
||||
score: shot.score,
|
||||
});
|
||||
if (shot.score != null) {
|
||||
var tank:Tank = engine.getEntity(shot.tankId);
|
||||
changeScore(tank.playerId, shot.score);
|
||||
@@ -419,9 +432,14 @@ class GameRunner extends Game implements EngineListener {
|
||||
if (tank.bonus && shot.bulletId != null) {
|
||||
spawnBonus();
|
||||
}
|
||||
var shooter = getPlayer(cast(engine.getEntity(shot.tankId), Tank).playerId);
|
||||
shooter.state.frags.push({
|
||||
playerId: player.id,
|
||||
target: TANK(tank.info),
|
||||
score: shot.score,
|
||||
});
|
||||
if (shot.score != null) {
|
||||
var shooterTank:Tank = engine.getEntity(shot.tankId);
|
||||
changeScore(shooterTank.playerId, shot.score);
|
||||
changeScore(shooter.id, shot.score);
|
||||
}
|
||||
engine.destroy(id);
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
|
||||
@@ -5,39 +5,43 @@ import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
enum FragTarget {
|
||||
TANK(tank:TankInfo);
|
||||
EAGLE(color:Color);
|
||||
}
|
||||
|
||||
typedef Frag = {
|
||||
var playerId:PlayerId;
|
||||
var target:FragTarget;
|
||||
var score:Score;
|
||||
}
|
||||
|
||||
class State {
|
||||
public var score:Int;
|
||||
public var frags:Int;
|
||||
public var shots:Int;
|
||||
public var hits:Int;
|
||||
public var frags:Array<Frag>;
|
||||
|
||||
public function new() {
|
||||
score = 0;
|
||||
frags = 0;
|
||||
shots = 0;
|
||||
hits = 0;
|
||||
frags = [];
|
||||
}
|
||||
|
||||
public function add(state:State) {
|
||||
score += state.score;
|
||||
frags += state.frags;
|
||||
shots += state.shots;
|
||||
hits += state.hits;
|
||||
frags = frags.concat(state.frags);
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
score = 0;
|
||||
frags = 0;
|
||||
shots = 0;
|
||||
hits = 0;
|
||||
frags = [];
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerState extends State {
|
||||
public var id:PlayerId;
|
||||
public var tank:TankType;
|
||||
public var tank:TankInfo;
|
||||
public var color:Color;
|
||||
public var name:String;
|
||||
public var life:Int;
|
||||
|
||||
Reference in New Issue
Block a user