2022-11-19 12:58:07 +00:00
|
|
|
const BaseCharacter = require("./BaseCharacter");
|
|
|
|
|
|
|
|
window.ATK_CHARACTER_STATE = {
|
|
|
|
Idle1: [0, "Idle1"],
|
|
|
|
Walking: [1, "Walking"],
|
|
|
|
Atk1: [2, "Atk1"],
|
2022-11-23 04:30:30 +00:00
|
|
|
Atked1: [3, "Atked1"],
|
2022-11-19 12:58:07 +00:00
|
|
|
};
|
|
|
|
|
2022-11-20 13:07:45 +00:00
|
|
|
window.ATK_CHARACTER_STATE_ARR = [];
|
|
|
|
for (let k in window.ATK_CHARACTER_STATE) {
|
|
|
|
window.ATK_CHARACTER_STATE_ARR.push(window.ATK_CHARACTER_STATE[k]);
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:58:07 +00:00
|
|
|
cc.Class({
|
|
|
|
extends: BaseCharacter,
|
|
|
|
properties: {
|
|
|
|
animNode: {
|
|
|
|
type: cc.Node,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ctor() {
|
2022-11-20 10:53:33 +00:00
|
|
|
this.speciesName = null;
|
2022-11-22 09:12:51 +00:00
|
|
|
this.hp = 100;
|
|
|
|
this.maxHp = 100;
|
|
|
|
this.framesToRecover = 0;
|
2022-11-20 10:53:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setSpecies(speciesName) {
|
|
|
|
this.speciesName = speciesName;
|
|
|
|
this.effAnimNode = this.animNode.getChildByName(this.speciesName);
|
|
|
|
this.animComp = this.effAnimNode.getComponent(dragonBones.ArmatureDisplay);
|
|
|
|
this.animComp.playAnimation(ATK_CHARACTER_STATE.Idle1[1]);
|
|
|
|
this.effAnimNode.active = true;
|
2022-11-19 12:58:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
BaseCharacter.prototype.onLoad.call(this);
|
|
|
|
},
|
|
|
|
|
2022-11-23 07:04:32 +00:00
|
|
|
updateCharacterAnim(newScheduledDirection, rdfPlayer, forceAnimSwitch) {
|
|
|
|
if (0 == rdfPlayer.framesToRecover) {
|
|
|
|
// Update directions
|
|
|
|
if (forceAnimSwitch || null == this.activeDirection || (null != newScheduledDirection && (newScheduledDirection.dx != this.activeDirection.dx || newScheduledDirection.dy != this.activeDirection.dy))) {
|
|
|
|
this.activeDirection = newScheduledDirection;
|
|
|
|
if (this.animComp && this.animComp.node) {
|
|
|
|
if (0 > newScheduledDirection.dx) {
|
|
|
|
this.animComp.node.scaleX = (-1.0);
|
|
|
|
} else if (0 < newScheduledDirection.dx) {
|
|
|
|
this.animComp.node.scaleX = (1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-19 12:58:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 07:04:32 +00:00
|
|
|
// Update per character state
|
|
|
|
let newCharacterState = rdfPlayer.characterState;
|
|
|
|
const newAnimName = window.ATK_CHARACTER_STATE_ARR[newCharacterState][1];
|
|
|
|
if (newAnimName != this.animComp.animationName) {
|
|
|
|
this.animComp.playAnimation(newAnimName);
|
|
|
|
// console.log(`JoinIndex=${this.joinIndex}, Resetting anim to ${newAnimName}, dir changed: (${oldDx}, ${oldDy}) -> (${newScheduledDirection.dx}, ${newScheduledDirection.dy})`);
|
2022-11-19 12:58:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|