export const generateLogs = (type, player1, player2, damage = 0) => {
const { name: name1 } = player1;
const { name: name2 } = player2;
let logMessage = type
.replace('[playerKick]', name1)
.replace('[playerDefence]', name2);
switch (type) {
case 'start':
logMessage = LOGS.start
.replace('[time]', getTime())
.replace('[player1]', name1)
.replace('[player2]', name2);
break;
case 'hit':
logMessage = `${LOGS.hit[getRandom(0, LOGS.hit.length - 1)]
.replace('[playerKick]', name1)
.replace('[playerDefence]', name2)} -${damage}
[${player2.hp} / 100]
`;
break;
case 'defence':
logMessage = LOGS.defence[getRandom(0, LOGS.defence.length - 1)]
.replace('[playerKick]', name2)
.replace('[playerDefence]', name1);
break;
case 'end':
logMessage = LOGS.end[getRandom(0, LOGS.end.length - 1)]
.replace('[playerWins]', name1)
.replace('[playerLose]', name2);
break;
case 'draw':
logMessage = LOGS.draw;
break;
default:
logMessage = '...';
}
const el = `<p>${logMessage }</p>`;
chat.insertAdjacentHTML('afterbegin', el);
return el ;
};
let logMessage = type
.replace('[playerKick]', name1)
.replace('[playerDefence]', name2);
export const generateLogs = (type, player1, player2, damage = 0) => {
const { name: name1 } = player1;
const { name: name2 } = player2;
const logMessage = type
.replace('[playerKick]', name1)
.replace('[playerDefence]', name2);
switch (type) {
case 'start':
return logMessage + LOGS.start
.replace('[time]', getTime())
.replace('[player1]', name1)
.replace('[player2]', name2);
case 'hit':
return logMessage + `${LOGS.hit[getRandom(0, LOGS.hit.length - 1)]
.replace('[playerKick]', name1)
.replace('[playerDefence]', name2)} -${damage}
[${player2.hp} / 100]
`;
case 'defence':
return logMessage + LOGS.defence[getRandom(0, LOGS.defence.length - 1)]
.replace('[playerKick]', name2)
.replace('[playerDefence]', name1);
case 'end':
return logMessage + LOGS.end[getRandom(0, LOGS.end.length - 1)]
.replace('[playerWins]', name1)
.replace('[playerLose]', name2);
case 'draw':
return logMessage + LOGS.draw;
default:
return logMessage + '...';
}
};
export const insertLogs = (logMessage) => {
const el = `<p>${logMessage}</p>`;
chat.insertAdjacentHTML('afterbegin', el);
};