96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
const DoubleLinkedList = require("../Utility/DoubleLinkedList");
|
|
|
|
class EntityGroup {
|
|
constructor(info) {
|
|
this.id = info.id;
|
|
this.mapIDs = Array.isArray(info.mapIDs) ? info.mapIDs : [];
|
|
this.structure = info.structure;
|
|
this.entitySettings = info.entitySettings;
|
|
this.members = new DoubleLinkedList();
|
|
this.leaders = new DoubleLinkedList();
|
|
this.isSummonPossible = true;
|
|
this.predefinedArea = info.predefinedArea ? info.predefinedArea : {
|
|
x: 1000,
|
|
y: 1000,
|
|
width: 750,
|
|
height: 750
|
|
};
|
|
};
|
|
|
|
setAreaPosition(position) {
|
|
this.predefinedArea.x = position.x;
|
|
this.predefinedArea.y = position.y;
|
|
}
|
|
|
|
getEntitySetting(groupMemberTypeID) {
|
|
const entitySetting = this.entitySettings[groupMemberTypeID];
|
|
|
|
return entitySetting ? entitySetting : {
|
|
speed: 600,
|
|
respawnTime: 0
|
|
};
|
|
}
|
|
|
|
cancelRespawn() {
|
|
if (!this.isSummonPossible) return;
|
|
|
|
this.members.each((key, value) => {
|
|
value.cancelEvent(8);
|
|
|
|
return true;
|
|
});
|
|
|
|
this.isSummonPossible = false;
|
|
}
|
|
|
|
default() {
|
|
this.members.clearEach(() => null);
|
|
this.leaders.clearEach(() => null);
|
|
|
|
this.isSummonPossible = true;
|
|
}
|
|
|
|
isDefeated() {
|
|
let deadEntitiesCount = 0;
|
|
|
|
this.members.each((key, value) => {
|
|
if (!value.isAlive) deadEntitiesCount++;
|
|
|
|
return true;
|
|
});
|
|
|
|
this.leaders.each((key, value) => {
|
|
if (!value.isAlive) deadEntitiesCount++;
|
|
|
|
return true;
|
|
});
|
|
|
|
return this.structure.length === deadEntitiesCount || (this.members.isEmpty() && this.leaders.isEmpty());
|
|
}
|
|
|
|
addMember(entity) {
|
|
this.members.addItem(entity.id, entity);
|
|
}
|
|
|
|
addLeader(entity) {
|
|
this.leaders.addItem(entity.id, entity);
|
|
}
|
|
|
|
isLeader(id) {
|
|
return this.leaders.hasElement(id);
|
|
}
|
|
|
|
isLeaderAlive() {
|
|
let isAlive = false;
|
|
|
|
this.leaders.each(function (key, value) {
|
|
isAlive = value.isAlive;
|
|
|
|
return !value.isAlive;
|
|
});
|
|
|
|
return isAlive;
|
|
}
|
|
};
|
|
|
|
module.exports = EntityGroup; |