親愛度システムの小さな改修

This commit is contained in:
syuilo 2021-01-03 14:50:17 +09:00
parent d3bd478723
commit 1195867b2c
2 changed files with 33 additions and 5 deletions

View file

@ -172,6 +172,11 @@ export default class 藍 {
if (data.userId == this.account.id) return; // 自分は弾く
this.onReceiveMessage(new Message(this, data, true));
});
// 通知
mainStream.on('notification', data => {
this.onNotification(data);
});
//#endregion
// Install modules
@ -277,6 +282,22 @@ export default class 藍 {
}
}
@autobind
private onNotification(notification: any) {
switch (notification.type) {
// リアクションされたら親愛度を少し上げる
// TODO: リアクション取り消しをよしなにハンドリングする
case 'reaction': {
const friend = new Friend(this, { user: notification.user });
friend.incLove(0.1);
break;
}
default:
break;
}
}
@autobind
private crawleTimer() {
const timers = this.timers.find();

View file

@ -101,7 +101,7 @@ export default class Friend {
}
@autobind
public incLove() {
public incLove(amount = 1) {
const today = getDate();
if (this.doc.lastLoveIncrementedAt != today) {
@ -112,20 +112,25 @@ export default class Friend {
if (this.doc.lastLoveIncrementedAt == today && (this.doc.todayLoveIncrements || 0) >= 3) return;
if (this.doc.love == null) this.doc.love = 0;
this.doc.love++;
this.doc.love += amount;
// 最大 100
if (this.doc.love > 100) this.doc.love = 100;
this.doc.lastLoveIncrementedAt = today;
this.doc.todayLoveIncrements = (this.doc.todayLoveIncrements || 0) + 1;
this.doc.todayLoveIncrements = (this.doc.todayLoveIncrements || 0) + amount;
this.save();
this.ai.log(`💗 ${this.userId} +${amount}`);
}
@autobind
public decLove() {
public decLove(amount = 1) {
// 親愛度MAXなら下げない
if (this.doc.love === 100) return;
if (this.doc.love == null) this.doc.love = 0;
this.doc.love--;
this.doc.love -= amount;
// 最低 -30
if (this.doc.love < -30) this.doc.love = -30;
@ -136,6 +141,8 @@ export default class Friend {
}
this.save();
this.ai.log(`💢 ${this.userId} -${amount}`);
}
@autobind