var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
// TypeScript file
var Goods = (function (_super) {
    __extends(Goods, _super);
    function Goods(goodsID, itemID) {
        var _this = _super.call(this) || this;
        _this.isHad = false;
        _this.id = goodsID;
        _this.itemID = itemID;
        _this.once(egret.Event.ADDED_TO_STAGE, _this.init, _this);
        return _this;
    }
    Goods.prototype.init = function () {
        this.armature = DBManager.buildArmature("item" + this.id);
        this.icon = this.armature.display;
        this.icon.scaleX = 2;
        this.icon.scaleY = 2;
        dragonBones.WorldClock.clock.add(this.armature);
        this.addChild(this.icon);
        this.armature.animation.play("normal", 0);
        this.touchEnabled = true;
        this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTapHandler, this);
    };
    Goods.prototype.dispose = function () {
        this.touchEnabled = false;
        this.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTapHandler, this);
        dragonBones.WorldClock.clock.remove(this.armature);
        this.armature.dispose();
    };
    Goods.prototype.onTapHandler = function (e) {
        e.stopPropagation();
        this.armature.animation.play("found", 1);
        var self = this;
        this.armature.addEventListener(dragonBones.AnimationEvent.COMPLETE, function f(e) {
            e.currentTarget.animation.play("normal");
            e.currentTarget.removeEventListener(dragonBones.AnimationEvent.COMPLETE, f, this);
            if (!self.isHad) {
                self.isHad = true;
                if (self.itemID > 0) {
                    if (userGameData.package.indexOf(self.itemID) == -1) {
                        // let item = RES.getRes("items_json")["items"][self.itemID];
                        var item = Game.instance.getItemObj(self.itemID);
                        if (item) {
                            talk.setTalk("\u83B7\u5F97  " + item.name, function () {
                                Game.instance.addPackageItem(self.itemID);
                                packageList.addID(self.itemID);
                            });
                        }
                    }
                }
            }
        }, this);
    };
    return Goods;
}(egret.DisplayObjectContainer));
__reflect(Goods.prototype, "Goods");
//# sourceMappingURL=Goods.js.map