Refactoring

This commit is contained in:
2026-03-29 23:23:33 +02:00
parent 43d61fcf16
commit 8a602bd2db
124 changed files with 1313 additions and 758 deletions
@@ -11,18 +11,20 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatTabsModule } from '@angular/material/tabs';
import { ListErrorsComponent, GuildwarAttackComponent, GuildwarDefenceComponent } from 'src/app/components/shared';
import { Errors, HWActivityStat, HWGuildClan, HWMember, HWMemberStat, HWWeekStat } from 'src/app/core/models';
import { UtilitiesService } from 'src/app/core/services';
import { CardContainerComponent, ListErrorsComponent, GuildwarAttackComponent, GuildwarDefenceComponent } from '@components/shared';
import { CardColors, Errors, HWActivityStat, HWGuildClan, HWMember } from '@models';
import { ClanViewModel, MembersViewModel } from '@viewmodels/herowars';
import { HWClanService, HWMemberService, UtilitiesService } from '@services';
import { MAX_CLAN_MEMBERS } from '@constants';
import guildData from 'src/files-data/hw-guild-data.json'; // page Membres
import guildStatistics from 'src/files-data/hw-guild-statistics.json'; // page Overview -> Statistics
import guildData from '@data/hw-guild-data.json'; // page Membres
import guildStatistics from '@data/hw-guild-statistics.json'; // page Overview -> Statistics
@Component({
selector: 'app-herowars-guildwar',
standalone: true,
imports: [
DatePipe, DecimalPipe, FormsModule, ListErrorsComponent,
DatePipe, DecimalPipe, FormsModule, CardContainerComponent, ListErrorsComponent,
MatButtonModule, MatCardModule, MatDividerModule, MatFormFieldModule,
MatIconModule, MatInputModule, MatTabsModule,
GuildwarAttackComponent, GuildwarDefenceComponent
@@ -44,151 +46,76 @@ import guildStatistics from 'src/files-data/hw-guild-statistics.json'; // page O
]
})
export class HerowarsGuildwarComponent implements OnInit {
public destroyRef = inject(DestroyRef);
public title = 'Guild War';
public subtitle = 'Log';
public description = 'Tools in working progress.';
public colors: CardColors = { background: 'bg-raspberry', text: 'text-bg-primary' };
public errors: Errors = { errors: {} };
public destroyRef = inject(DestroyRef);
public now = new Date();
public daysToWarn = 1;
public maxClanMembers = MAX_CLAN_MEMBERS;
public clanLoaded = false;
public membersLoaded = false;
public clanViewModel: ClanViewModel = {} as ClanViewModel;
public membersViewModel: MembersViewModel = {} as MembersViewModel;
private _guildClan: HWGuildClan = {} as HWGuildClan;
private _guildMembers: HWMember[] = [];
private _guildInfo: HWActivityStat = {} as HWActivityStat;
constructor(
private _titleService: Title,
private _utilitiesService: UtilitiesService
private _utilitiesService: UtilitiesService,
private _clanService: HWClanService,
private _memberService: HWMemberService
) { }
ngOnInit() {
this._titleService.setTitle(this.title);
}
private _resetActivity(): HWActivityStat {
const activity: HWActivityStat = { activity: 0, prestige: 0, titanite: 0, war: 0, adventure: 0, gifts: 0, score: 0, scoreGifts: 0, warGifts: 0, rewards: 0 };
return activity;
getClanViewModel(): ClanViewModel {
return this.clanViewModel;
}
private _importMembers() {
try {
const oneDayInSec = (24 * 60 * 60);
const daysToKick = parseInt(guildData.clan.daysToKick);
this.daysToWarn = (parseInt(guildData.clan.daysToKick) / 2);
for (const data of Object.entries(guildData.clan.members)) {
const member: HWMember = {} as HWMember;
Object.assign(member, data[1]);
if (guildData.clan.warriors.indexOf(parseInt(member.id)) !== -1) {
member.champion = true;
} else {
member.champion = false;
}
member.heroes = { power: 0, teams: []};
member.titans = { power: 0, teams: []};
this._guildMembers.push(member);
}
this._guildMembers.map((data) => {
const last = new Date((parseInt(data.lastLoginTime) * 1000));
const exp = new Date(last.getTime() + ((daysToKick * oneDayInSec) * 1000));
const diff = Math.floor(((exp.getTime() - this.now.getTime()) / 1000));
const daysLeft = Math.floor((diff / oneDayInSec));
let timeLeft = diff;
if (daysLeft >= 1) {
timeLeft = (diff - (daysLeft * oneDayInSec));
}
data.inactivity = {
daysLeft: daysLeft,
timeLeft: timeLeft,
dropDelay: `${daysLeft}d, ${this._utilitiesService.secondsToDuration(timeLeft)}`,
dropDate: Math.floor((exp.getTime() / 1000))
};
data.raids = [];
data.raidsInfo = {
variationAvg: 0,
variationSum: 0
};
data.stat = {} as HWMemberStat;
let index = guildData.membersStat.findIndex(stat => stat.userId === data.id);
if (index !== -1) {
delete (guildData.membersStat[index] as {userId?: string}).userId;
Object.assign(data.stat, guildData.membersStat[index]);
//data.stat = guildData.membersStat[index];
}
index = guildStatistics.stat.findIndex(stat => stat.id === data.id);
if (index !== -1) {
delete (guildStatistics.stat[index] as {id?: string}).id;
const stat: HWWeekStat = {} as HWWeekStat;
Object.assign(stat, guildStatistics.stat[index]);
data.weekStat = stat;
data.adventureSum = guildStatistics.stat[index].adventureStat.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
data.clanGiftsSum = guildStatistics.stat[index].clanGifts.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
data.clanWarSum = guildStatistics.stat[index].clanWarStat.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
this._guildClan.sumTotal.adventure += data.adventureSum;
this._guildClan.sumTotal.gifts += data.clanGiftsSum;
this._guildClan.sumTotal.war += data.clanWarSum;
}
getMembersViewModel(): MembersViewModel {
return this.membersViewModel;
}
data.score = (data.stat.dungeonActivitySum + data.stat.activitySum + data.stat.prestigeSum);
data.warGifts = (((this._guildClan.giftsCount / 2) * ((data.clanWarSum * 10) / 100)) / 20);
this._guildClan.todayTotal.activity += data.stat.todayActivity;
this._guildClan.todayTotal.prestige += data.stat.todayPrestige;
this._guildClan.todayTotal.titanite += data.stat.todayDungeonActivity;
this._guildClan.todayTotal.score += (data.stat.todayDungeonActivity + data.stat.todayActivity + data.stat.todayPrestige);
this._guildClan.sumTotal.activity += data.stat.activitySum;
this._guildClan.sumTotal.prestige += data.stat.prestigeSum;
this._guildClan.sumTotal.titanite += data.stat.dungeonActivitySum;
this._guildClan.sumTotal.score += data.score;
this._guildClan.sumTotal.warGifts += data.warGifts;
data.scoreGifts = 0;
data.rewards = 0;
return data;
});
this._guildClan.sumTotal.scoreGifts = (this._guildClan.giftsCount - Math.floor(this._guildClan.sumTotal.warGifts));
this._guildClan.todayAverages.activity = (this._guildClan.todayTotal.activity / this._guildMembers.length);
this._guildClan.todayAverages.prestige = (this._guildClan.todayTotal.prestige / this._guildMembers.length);
this._guildClan.todayAverages.titanite = (this._guildClan.todayTotal.titanite / this._guildMembers.length);
this._guildClan.todayAverages.score = (this._guildClan.todayTotal.score / this._guildMembers.length);
this._guildClan.sumAverages.activity = (this._guildClan.sumTotal.activity / this._guildMembers.length);
this._guildClan.sumAverages.prestige = (this._guildClan.sumTotal.prestige / this._guildMembers.length);
this._guildClan.sumAverages.titanite = (this._guildClan.sumTotal.titanite / this._guildMembers.length);
this._guildClan.sumAverages.war = (this._guildClan.sumTotal.war / 20);
this._guildClan.sumAverages.adventure = (this._guildClan.sumTotal.adventure / this._guildMembers.length);
this._guildClan.sumAverages.gifts = (this._guildClan.sumTotal.gifts / this._guildMembers.length);
this._guildClan.sumAverages.score = (this._guildClan.sumTotal.score / this._guildMembers.length);
this._guildMembers.map((data) => {
data.scoreGifts = ((data.score / this._guildClan.sumTotal.score) * this._guildClan.sumTotal.scoreGifts);
data.rewards = Math.floor((data.scoreGifts + data.warGifts));
this._guildClan.sumTotal.rewards += data.rewards;
return data;
});
this._guildClan.sumAverages.rewards = (this._guildClan.sumTotal.rewards / this._guildMembers.length);
console.log(this._guildClan);
console.log(this._guildMembers);
} catch (error) {
console.error(error);
getColors(color = 'megna'): CardColors {
if (color === 'accent') {
this.colors = { background: 'bg-accent', text: 'text-navy' };
} else if (color === 'raspberry') {
this.colors = { background: 'bg-raspberry', text: 'text-bg-primary' };
} else {
this.colors = { background: 'bg-megna', text: 'text-bg-primary' };
}
}
getClan(): HWGuildClan {
return this._guildClan;
return this.colors;
}
loadClan(): void {
Object.assign(this._guildClan, guildData.clan);
this._guildClan.sumAverages = this._resetActivity();
this._guildClan.sumTotal = this._resetActivity();
this._guildClan.todayAverages = this._resetActivity();
this._guildClan.todayTotal = this._resetActivity();
this._guildClan = this._clanService.loadClan();
this.clanViewModel = new ClanViewModel(this._guildClan);
this.clanLoaded = true;
}
loadData(): void {
this._guildClan = this._clanService.loadClan();
this._guildMembers = this._memberService.loadMembers(this._guildClan);
this._guildClan = this._clanService.loadClanStats(this._guildClan, this._guildMembers);
this.daysToWarn = (parseInt(this._guildClan.daysToKick) / 2);
this.clanViewModel = new ClanViewModel(this._guildClan);
this.clanLoaded = true;
this.membersViewModel = new MembersViewModel(this._guildMembers);
this.membersLoaded = true;
console.log(this._guildClan);
console.log(this._guildMembers);
}
loadMembers(): void {
this._importMembers();
this._guildMembers = this._memberService.loadMembers(this._guildClan);
this.membersViewModel = new MembersViewModel(this._guildMembers);
this._guildClan = this._clanService.loadClanStats(this._guildClan, this._guildMembers);
this.membersLoaded = true;
}
@@ -198,10 +125,12 @@ export class HerowarsGuildwarComponent implements OnInit {
syncClan(): void {
console.log(this._guildClan);
console.log(guildData);
}
syncMembers(): void {
console.log(this._guildMembers);
console.log(guildStatistics);
}
}