{"size": 1944, "ext": "js", "max_stars_repo_path": "src/ai/MinionPlayer.js", "max_stars_repo_name": "Phoenix3214/MultiOgar", "max_stars_repo_stars_event_min_datetime": "2018-04-10T21:55:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-15T05:50:34.000Z", "max_issues_repo_path": "src/ai/MinionPlayer.js", "max_issues_repo_name": "Phoenix3214/MultiOgar", "max_issues_repo_issues_event_min_datetime": "2019-04-14T22:08:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-23T15:12:46.000Z", "max_forks_repo_path": "src/ai/MinionPlayer.js", "max_forks_repo_name": "Phoenix3214/MultiOgar", "max_forks_repo_forks_event_min_datetime": "2018-03-28T19:31:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-04T13:04:56.000Z"}
{"max_stars_count": 4, "max_issues_count": 6, "max_forks_count": 12, "avg_line_length": 37.3846153846, "max_line_length": 101, "alphanum_fraction": 0.6141975309}
'use strict';
const PlayerTracker = require("../PlayerTracker");

function MinionPlayer() {
    PlayerTracker.apply(this, Array.prototype.slice.call(arguments));
    this.isMi = true;
}

module.exports = MinionPlayer;

MinionPlayer.prototype = new PlayerTracker;

MinionPlayer.prototype.checkConnection = function() {
    if (this.gameServer.config.minionSameColor) {
        this.color = this.owner.color;
        this.cells.forEach(function(item) {
            item.color = this.owner.color;
        }, this);
    }
    if (this.socket.isCloseReq) {
        for (;this.cells.length;) this.gameServer.removeNode(this.cells[0]);
        return void (this.isRemoved = true);
    }
    if (!this.cells.length) {
        this.gameServer.gameMode.onPlayerSpawn(this.gameServer, this);
        if (!this.cells.length) this.socket.close();
    }
    if (this.owner.socket.isConnected === false || !this.owner.minion.control) this.socket.close();
    this.frozen = this.owner.minion.frozen;
    if (this.owner.minion.split) this.socket.packetHandler.pressSpace = true;
    if (this.owner.minion.eject) this.socket.packetHandler.pressW = true;
    if (this.owner.minion.follow) this.mouse = this.owner.centerPos;
    else this.mouse = this.owner.mouse;
    if (this.owner.minion.collect) {
        this.viewNodes = [];
        var self = this;
        this.gameServer.quadTree.find(this.viewBox, function(item) {
            if (item.cell.cellType === 1 || item.cell.cellType === 3) self.viewNodes.push(item.cell);
        });
        var bestDist = 1 / 0; // Infinite
        for (var i in this.viewNodes) {
            var node = this.viewNodes[i],
                dx = this.cells[0].position.x - node.position.x,
                dy = this.cells[0].position.y - node.position.y;
            if (dx * dx + dy * dy < bestDist) {
                bestDist = dx * dx + dy * dy;
                this.mouse = node.position;
            }
        }
    }
};
