"use strict";
cc._RF.push(module, '2bf4dXY+rJG37abLKiCEh7s', 'Block');
// Script/Block.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GameData_1 = require("./GameData");
var GameManager_1 = require("./GameManager");
var Notification_1 = require("./tool/Notification");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var NewClass = /** @class */ (function (_super) {
    __extends(NewClass, _super);
    function NewClass() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.label = null;
        _this.text = 'hello';
        return _this;
    }
    // LIFE-CYCLE CALLBACKS:
    NewClass.prototype.onLoad = function () {
        this.node.getComponent(cc.PolygonCollider).enabled = true;
        this.speed = 10;
        this.num = 0;
        this.move = false;
        if (this.node.name.length > 6) {
            this.num = parseInt(this.node.name.substring(5, 7));
        }
        else
            this.num = parseInt(this.node.name.substring(5, 6));
        this.speed = GameData_1.default._instance.BLOCK_INFO[this.num - 1].speed;
        this.init();
    };
    NewClass.prototype.start = function () {
    };
    NewClass.prototype.init = function () {
        var _this = this;
        var speedTemp = this.speed;
        this.getSpeed();
        if (this.num > GameData_1.default._instance.GM_INFO.blockScale) {
            if (this.speed < GameData_1.default._instance.LEVEL_INFO.slowSpeed)
                this.speed = GameData_1.default._instance.LEVEL_INFO.slowSpeed;
        }
        else {
            if (this.speed < GameData_1.default._instance.LEVEL_INFO.fastSpeed)
                this.speed = GameData_1.default._instance.LEVEL_INFO.fastSpeed;
        }
        if (this.speed > speedTemp)
            this.speed = speedTemp;
        if (this.num != 13 && !GameData_1.default._instance.GM_INFO.probation) {
            GameData_1.default._instance.CLICK_DATA.block = this.num;
            GameData_1.default._instance.CLICK_DATA.speed = this.speed;
            this.getDifficulty();
            GameManager_1.default._instance.Air2.push(this.speed);
            if (GameManager_1.default._instance.Air2.length > 99) {
                console.log("被限制后", GameManager_1.default._instance.Air2);
            }
        }
        else {
            if (GameManager_1.default._instance.block) {
                var random = parseInt(Math.random() * 3 + "") + 1;
                this.speed = GameManager_1.default._instance.block.getComponent("Block").speed + random;
            }
            this.node.getComponent(cc.PolygonCollider).enabled = false;
            this.node.getComponent(cc.BoxCollider).enabled = false;
            GameData_1.default._instance.CLICK_DATA.fakeSpeed = this.speed;
        }
        this.move = true;
        this.tween =
            cc.tween(this.node)
                .to(this.speed, { x: -this.node.x })
                .call(function () {
                _this.move = false;
            })
                .start();
    };
    NewClass.prototype.getSpeed = function () {
        //先加范围  厚的
        var reduceSpeed = GameData_1.default._instance.LEVEL_INFO.reduceSpeed;
        if (reduceSpeed > 35)
            reduceSpeed = 35;
        reduceSpeed = parseInt(Math.random() * reduceSpeed + "");
        var random = Math.random() * 10;
        var max = 1;
        if (GameData_1.default._instance.LEVEL_INFO.speed < 1.3)
            max = 9;
        else if (GameData_1.default._instance.LEVEL_INFO.speed < 1.5)
            max = 7;
        else if (GameData_1.default._instance.LEVEL_INFO.speed < 1.8)
            max = 5;
        else if (GameData_1.default._instance.LEVEL_INFO.speed < 2)
            max = 3;
        if (random > max)
            reduceSpeed = -reduceSpeed;
        //先乘以系数
        this.speed = this.speed / GameData_1.default._instance.LEVEL_INFO.speed;
        this.speed = parseInt(this.speed * 10 / 10 + "");
        //后减去随机值 
        reduceSpeed = parseInt(reduceSpeed * 10 / 10 + "");
        this.speed = this.speed - reduceSpeed / 10;
        if (this.num != 13) {
            GameManager_1.default._instance.Air.push(this.speed);
            if (GameManager_1.default._instance.Air.length == 99) {
                console.log("初始数据", GameManager_1.default._instance.Air);
            }
        }
    };
    NewClass.prototype.getDifficulty = function () {
        var difficulty1 = 0;
        var sudu = Math.abs(this.speed - GameManager_1.default._instance.oldSpeed);
        difficulty1 = (sudu / 10 + 1) * (11 - this.speed);
        if (difficulty1 <= 1)
            difficulty1 = 1;
        else if (difficulty1 >= 7)
            difficulty1 = 7;
        var difficulty2 = 0;
        if (this.node.width < 180)
            difficulty2 = 0;
        else if (this.node.width < 199)
            difficulty2 = 0.5;
        else
            difficulty2 = 1;
        var difficulty3 = 0;
        if (GameManager_1.default._instance.interfere == true) {
            difficulty3 = 1;
        }
        var difficulty4 = 0;
        if (this.num > 6) {
            difficulty4 = 1;
        }
        GameManager_1.default._instance.oldSpeed = this.speed;
        this.difficulty = 0;
        this.difficulty = difficulty1 + difficulty2 + difficulty3 + difficulty4;
        this.difficulty = parseInt(this.difficulty * 10 + "");
        GameData_1.default._instance.CLICK_DATA.difficulty = this.difficulty / 10;
        GameManager_1.default._instance.difficultyArray += GameData_1.default._instance.CLICK_DATA.difficulty;
        if (GameData_1.default._instance.CLICK_DATA.difficulty > GameData_1.default._instance.GM_INFO.difficultyMax)
            GameData_1.default._instance.GM_INFO.difficultyMax = GameData_1.default._instance.CLICK_DATA.difficulty;
    };
    NewClass.prototype.setScore = function (fen) {
        var score = 0;
        var difficulty = this.difficulty / 10;
        var layer = GameData_1.default._instance.LEVEL_INFO.layer;
        var doubleHit = GameData_1.default._instance.LEVEL_INFO.doubleHit;
        score = parseInt(fen * difficulty * layer * doubleHit + "");
        Notification_1.Notification.emit("addScore", score);
    };
    NewClass.prototype.hide = function () {
        var _this = this;
        cc.tween(this.node)
            .to(0.2, { opacity: 0 })
            .call(function () {
            _this.node.active = false;
            _this.node.removeFromParent();
            _this.node = null;
        })
            .start();
    };
    NewClass.prototype.onCollisionEnter = function (other, self) {
        if (GameManager_1.default._instance) {
            if (GameManager_1.default._instance.over == true) {
                return;
            }
        }
        if (other.node.name == "Player") {
            var max = self.name.length;
            var ColliderName = other.name.substring(6, max);
            if (this.move == true) {
                if (this.tween) {
                    this.tween.stop();
                }
            }
        }
    };
    NewClass.prototype.update = function (dt) {
    };
    __decorate([
        property(cc.Label)
    ], NewClass.prototype, "label", void 0);
    __decorate([
        property
    ], NewClass.prototype, "text", void 0);
    NewClass = __decorate([
        ccclass
    ], NewClass);
    return NewClass;
}(cc.Component));
exports.default = NewClass;

cc._RF.pop();