1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var SideralObject_1 = require("./../SideralObject");
|
14 | var SideralObject_2 = require("./../SideralObject");
|
15 | var Tool_1 = require("./../Tool");
|
16 |
|
17 |
|
18 |
|
19 | var Skill = (function (_super) {
|
20 | __extends(Skill, _super);
|
21 |
|
22 | |
23 |
|
24 |
|
25 | function Skill() {
|
26 | var _this = _super.call(this) || this;
|
27 | |
28 |
|
29 |
|
30 | _this.hitboxProps = {};
|
31 | |
32 |
|
33 |
|
34 | _this.duration = 0;
|
35 | |
36 |
|
37 |
|
38 | _this.durationType = Tool_1.Enum.DURATION_TYPE.MS;
|
39 | |
40 |
|
41 |
|
42 | _this.preparation = 0;
|
43 | |
44 |
|
45 |
|
46 | _this.preparationType = Tool_1.Enum.DURATION_TYPE.MS;
|
47 | |
48 |
|
49 |
|
50 | _this.reload = 0;
|
51 | |
52 |
|
53 |
|
54 | _this.reloadType = Tool_1.Enum.DURATION_TYPE.MS;
|
55 | |
56 |
|
57 |
|
58 | _this.unstoppable = true;
|
59 | |
60 |
|
61 |
|
62 | _this.movable = true;
|
63 | |
64 |
|
65 |
|
66 |
|
67 | _this.active = false;
|
68 | |
69 |
|
70 |
|
71 |
|
72 | _this.ready = true;
|
73 | _this.timers = _this.add(new SideralObject_2.TimerManager());
|
74 | _this.signals.preparationStart = new Tool_1.SignalEvent();
|
75 | _this.signals.preparationUpdate = new Tool_1.SignalEvent();
|
76 | _this.signals.preparationComplete = new Tool_1.SignalEvent();
|
77 | _this.signals.skillStart = new Tool_1.SignalEvent();
|
78 | _this.signals.skillUpdate = new Tool_1.SignalEvent();
|
79 | _this.signals.skillComplete = new Tool_1.SignalEvent();
|
80 | _this.signals.reloadStart = new Tool_1.SignalEvent();
|
81 | _this.signals.reloadUpdate = new Tool_1.SignalEvent();
|
82 | _this.signals.reloadComplete = new Tool_1.SignalEvent();
|
83 | return _this;
|
84 | }
|
85 |
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | Skill.prototype.addHitbox = function (hitbox, hitboxProps) {
|
93 | if (hitboxProps === void 0) { hitboxProps = {}; }
|
94 | var x = typeof hitboxProps.x === "undefined" ? this.owner.props.x : hitboxProps.x, y = typeof hitboxProps.y === "undefined" ? this.owner.props.y : hitboxProps.y;
|
95 | delete hitboxProps.x;
|
96 | delete hitboxProps.y;
|
97 | hitboxProps.owner = this.owner;
|
98 | return this.owner.context.scene.spawn(hitbox, x, y, Object.assign({}, hitboxProps));
|
99 | };
|
100 | |
101 |
|
102 |
|
103 |
|
104 | Skill.prototype.run = function (params) {
|
105 | var _this = this;
|
106 | if (params === void 0) { params = {}; }
|
107 | var startSkill = function () {
|
108 | Object.assign(_this, params);
|
109 | _this.signals.preparationComplete.dispatch();
|
110 | _this.timers.addTimer("skill", _this.timers.getDuration(_this.duration, _this.durationType, _this.animation && _this.owner.sprite.getAnimation(_this.animation)), _this._onSkillComplete.bind(_this), {
|
111 | init: _this.signals.skillStart.dispatch.bind(_this),
|
112 | update: _this.updateSkill.bind(_this)
|
113 | });
|
114 | if (_this.animation) {
|
115 | try {
|
116 | _this.owner.sprite.setAnimation(_this.animation, true);
|
117 | }
|
118 | catch (e) {
|
119 | throw Error(e);
|
120 | }
|
121 | }
|
122 | if (_this.hitboxClass) {
|
123 | _this.hitbox = _this.addHitbox(new (_this.hitboxClass)(), _this.hitboxProps);
|
124 | }
|
125 | };
|
126 | this.active = true;
|
127 | this.ready = !this.unstoppable;
|
128 | if (this.preparation) {
|
129 | this.timers.addTimer("preparation", this.timers.getDuration(this.preparation, this.preparationType), startSkill.bind(this), {
|
130 | init: this.signals.preparationStart.dispatch.bind(this),
|
131 | update: this.signals.preparationUpdate.dispatch.bind(this)
|
132 | });
|
133 | }
|
134 | else {
|
135 | startSkill();
|
136 | }
|
137 | };
|
138 | |
139 |
|
140 |
|
141 | Skill.prototype.stop = function () {
|
142 | this.active = false;
|
143 | this.timers.removeAllTimer();
|
144 | };
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | Skill.prototype.updateSkill = function (tick, value, ratio, duration) {
|
154 | if (!this.movable) {
|
155 | this.owner.props.vy = this.owner.props.accelY = 0;
|
156 | this.owner.props.vx = this.owner.props.accelX = 0;
|
157 | }
|
158 | this.signals.skillUpdate.dispatch(tick, value, ratio, duration);
|
159 | };
|
160 | |
161 |
|
162 |
|
163 |
|
164 | Skill.prototype._onSkillComplete = function () {
|
165 | var _this = this;
|
166 | this.signals.skillComplete.dispatch(this);
|
167 | if (this.reload) {
|
168 | this.timers.addTimer("reload", this.timers.getDuration(this.reload, this.reloadType), function () {
|
169 | _this.ready = true;
|
170 | _this.signals.reloadComplete.dispatch;
|
171 | }, {
|
172 | update: this.signals.reloadUpdate.dispatch.bind(this)
|
173 | });
|
174 | }
|
175 | this.ready = !this.reload;
|
176 | if (this.hitbox) {
|
177 | this.hitbox.kill();
|
178 | this.hitbox = null;
|
179 | }
|
180 | };
|
181 | return Skill;
|
182 | }(SideralObject_1.SideralObject));
|
183 | exports.Skill = Skill;
|