You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
6.1 KiB
167 lines
6.1 KiB
|
1 week ago
|
import { _decorator, Component, Node, Label, instantiate, ProgressBar } from 'cc';
|
||
|
|
import { BattleDataManager, SaveBattleDataType } from './BattleDataManager';
|
||
|
|
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
|
||
|
|
import { GPath, GBundle } from '../../game/ConfigRes';
|
||
|
|
import { Sprite } from 'cc';
|
||
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
// 定义武器伤害统计接口
|
||
|
|
interface WeaponDamage {
|
||
|
|
[weaponId: number]: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
@ccclass('DamageStatistics')
|
||
|
|
export class DamageStatistics extends Component {
|
||
|
|
@property(Node)
|
||
|
|
damageLayout: Node = null;
|
||
|
|
|
||
|
|
@property(Node)
|
||
|
|
damageSingleItem: Node = null;
|
||
|
|
|
||
|
|
/**对怪物造成的总伤害 */
|
||
|
|
allDamageNum: number = 0;
|
||
|
|
|
||
|
|
/**存储各武器的伤害统计,键为weaponId,值为伤害值 */
|
||
|
|
private weaponDamageMap = new Map<number, number>()
|
||
|
|
/**存储各武器阶段性伤害统计 */
|
||
|
|
private weaponPartialDamageMap = new Map<number, number>()
|
||
|
|
private curWeaponIdArr: number[] = []
|
||
|
|
private isLayoutActive: boolean = false;
|
||
|
|
|
||
|
|
getWeaponDamageMap(): Map<number, number> {
|
||
|
|
return this.weaponDamageMap
|
||
|
|
}
|
||
|
|
/**获取武器阶段性伤害统计 */
|
||
|
|
getWeaponPartialDamageMap(): Map<number, number> {
|
||
|
|
return this.weaponPartialDamageMap
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onEnable(): void {
|
||
|
|
GEvent.Ins.on(GEvent.ShowLevelSpine, this.refreshSkillNum, this);
|
||
|
|
}
|
||
|
|
protected onDisable(): void {
|
||
|
|
GEvent.Ins.off(GEvent.ShowLevelSpine, this.refreshSkillNum, this);
|
||
|
|
}
|
||
|
|
start() {
|
||
|
|
|
||
|
|
}
|
||
|
|
showDamageLayout() {
|
||
|
|
this.isLayoutActive = !this.isLayoutActive
|
||
|
|
this.damageLayout.opacity = this.isLayoutActive ? 255 : 0
|
||
|
|
}
|
||
|
|
/**刷新显示技能数量 */
|
||
|
|
refreshSkillNum() {
|
||
|
|
this.damageLayout.children.forEach(item => {
|
||
|
|
let weaponId = item['weaponId'] as number
|
||
|
|
let skillNum = gg.game.CurentBattle.getWeaponSkillNum(weaponId)
|
||
|
|
item.getChildByName('skillNumStr').getComponent(Label).string = `${skillNum}`
|
||
|
|
})
|
||
|
|
}
|
||
|
|
/**刷新武器列表layout */
|
||
|
|
refreshWeaponListLayout(weaponIds: number[]) {
|
||
|
|
// // 清空现有项
|
||
|
|
// this.damageLayout.destroyAllChildren();
|
||
|
|
weaponIds.forEach(weaponId => {
|
||
|
|
if (!this.curWeaponIdArr.includes(weaponId)) {
|
||
|
|
// 武器已被添加,初始化伤害统计
|
||
|
|
this.weaponDamageMap.set(weaponId, 0);
|
||
|
|
this.weaponPartialDamageMap.set(weaponId, 0);
|
||
|
|
// 创建显示项
|
||
|
|
this.createDamageItem(weaponId);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
this.curWeaponIdArr = weaponIds
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 创建单个武器伤害显示项
|
||
|
|
* @param weaponId 武器ID
|
||
|
|
* @param weaponName 武器名称
|
||
|
|
* @param damage 伤害值
|
||
|
|
*/
|
||
|
|
private createDamageItem(weaponId: number): void {
|
||
|
|
let config: ITableWeapon2 = gg.data.project.getWeaponData(weaponId)
|
||
|
|
let itemData = gg.data.table.getItemData(config.itemID)
|
||
|
|
if (!this.weaponDamageMap.has(weaponId)) {
|
||
|
|
this.weaponDamageMap.set(weaponId, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
const item = instantiate(this.damageSingleItem);
|
||
|
|
item.active = true;
|
||
|
|
item.parent = this.damageLayout;
|
||
|
|
//item.getChildByName('itemSpr').getComponent(SpriteLoad).setSprite(GPath.DamageStatistics(`底${config.quality}`), GBundle.);
|
||
|
|
item.getChildByName('iconSpr').getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items);
|
||
|
|
item.getChildByName('skillNumStr').getComponent(Label).string = `0`
|
||
|
|
item.getChildByName('weaponStr').getComponent(Label).string = config.name
|
||
|
|
item.getChildByName('progressStr').getComponent(Label).string = `0%`
|
||
|
|
item.getChildByName('rateProgress').getComponent(Sprite).fillRange = 0
|
||
|
|
item.getChildByName('cdProgress').getComponent(Sprite).fillRange = 0
|
||
|
|
item.attr({ weaponId: weaponId })
|
||
|
|
}
|
||
|
|
/**刷新武器cd进度 */
|
||
|
|
freshWeaponCD(weaponId: number, cd: number, remainingTime: number) {
|
||
|
|
let progress = remainingTime / cd
|
||
|
|
let item = this.damageLayout.children.find(child => child['weaponId'] === weaponId);
|
||
|
|
if (!item) return;
|
||
|
|
let progressSpr = item.getChildByName('cdProgress').getComponent(Sprite);
|
||
|
|
if (cd <= 0.3) {
|
||
|
|
progressSpr.fillRange = 1
|
||
|
|
} else {
|
||
|
|
progressSpr.fillRange = progress
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 更新指定武器的伤害统计
|
||
|
|
* @param weaponId 武器ID
|
||
|
|
* @param damage 新增的伤害值
|
||
|
|
*/
|
||
|
|
public updateWeaponDamage(weaponId: number, damage: number): void {
|
||
|
|
if (weaponId < 0 || damage <= 0) return;
|
||
|
|
|
||
|
|
// 更新武器伤害统计
|
||
|
|
if (!this.weaponDamageMap.has(weaponId)) {
|
||
|
|
this.weaponDamageMap.set(weaponId, 0);
|
||
|
|
}
|
||
|
|
if (!this.weaponPartialDamageMap.has(weaponId)) {
|
||
|
|
this.weaponPartialDamageMap.set(weaponId, 0);
|
||
|
|
}
|
||
|
|
this.weaponDamageMap.set(weaponId, this.weaponDamageMap.get(weaponId) + damage);
|
||
|
|
this.weaponPartialDamageMap.set(weaponId, this.weaponPartialDamageMap.get(weaponId) + damage);
|
||
|
|
|
||
|
|
// 更新总伤害
|
||
|
|
this.allDamageNum += damage;
|
||
|
|
for (let weaponItem of this.damageLayout.children) {
|
||
|
|
let weaponId = weaponItem['weaponId']
|
||
|
|
let progressSpr = weaponItem.getChildByName('rateProgress').getComponent(Sprite);
|
||
|
|
let rate = this.weaponDamageMap.get(weaponId) / this.allDamageNum
|
||
|
|
progressSpr.fillRange = rate
|
||
|
|
weaponItem.getChildByName('progressStr').getComponent(Label).string = `${(rate * 100).toFixed(1)}%`
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 重置所有伤害统计
|
||
|
|
*/
|
||
|
|
public resetDamageStatistics(): void {
|
||
|
|
this.curWeaponIdArr = []
|
||
|
|
this.weaponDamageMap.clear();
|
||
|
|
this.weaponPartialDamageMap.clear();
|
||
|
|
this.allDamageNum = 0;
|
||
|
|
|
||
|
|
// 清空显示
|
||
|
|
if (this.damageLayout) {
|
||
|
|
this.damageLayout.destroyAllChildren();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 重置阶段性武器伤害统计
|
||
|
|
*/
|
||
|
|
public resetWeaponPartialDamageMap(): void {
|
||
|
|
this.weaponPartialDamageMap.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|