Skip to content

Commit 52cf64e

Browse files
committed
feat: add recur form
1 parent 22a2094 commit 52cf64e

File tree

4 files changed

+83
-39
lines changed

4 files changed

+83
-39
lines changed

src/lib/get-fullname.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Clan } from './clan/clan'
44
import { i18n } from './i18n/text'
55
import { getRole, ROLES } from './roles'
66
import { EquippmentLevel } from './rpg/equipment-level'
7-
7+
// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class// TODO Rewrite to class
88
/**
99
* Gets displayable the role of this player
1010
*

src/modules/survival/menu.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Player } from '@minecraft/server'
2-
import { BUTTON } from 'lib'
2+
import { BUTTON, doNothing } from 'lib'
33
import { achievementsForm, achievementsFormName } from 'lib/achievements/command'
44
import { clanMenu } from 'lib/clan/menu'
55
import { Core } from 'lib/extensions/core'
@@ -15,6 +15,8 @@ import { baseMenu } from 'modules/places/base/base-menu'
1515
import { wiki } from 'modules/wiki/wiki'
1616
import { Anarchy } from '../places/anarchy/anarchy'
1717
import { Spawn } from '../places/spawn'
18+
import { speedrunForm } from './speedrun/target'
19+
import { recurForm } from './recurring-events'
1820

1921
function tp(
2022
player: Player,
@@ -58,6 +60,14 @@ Menu.form = form((f, { player, self }) => {
5860
.button(i18n.nocolor`§bВики`, BUTTON.search, wiki.show)
5961
.button(achievementsFormName(player), 'textures/blocks/gold_block', achievementsForm)
6062
.button(i18n.nocolor`§7Настройки`, BUTTON.settings, () => playerSettingsMenu(player, self))
63+
.button(i18n`Еще`, BUTTON['>'], secondPage)
64+
})
65+
66+
const secondPage = form(f => {
67+
f.title(Core.name, '§c§u§s§r')
68+
f.button(i18n`Цели`, BUTTON['?'], speedrunForm)
69+
f.button(i18n`Лидеры`, BUTTON['?'], doNothing)
70+
f.button(i18n`События`, BUTTON['?'], recurForm)
6171
})
6272

6373
Join.onMoveAfterJoin.subscribe(({ player, firstJoin }) => {
Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { TicksPerSecond, world } from '@minecraft/server'
1+
import { Player, TicksPerSecond, world } from '@minecraft/server'
22
import { MinecraftEffectTypes, MinecraftEffectTypesUnion } from '@minecraft/vanilla-data'
3-
import { ms } from 'lib'
3+
import { doNothing, ms, RoadRegion } from 'lib'
4+
import { form } from 'lib/form/new'
5+
import { i18n } from 'lib/i18n/text'
46
import { DurationalRecurringEvent } from 'lib/recurring-event'
7+
import { RegionEvents } from 'lib/region/events'
58
import later from 'lib/utils/later'
69

710
// TODO Add settings for players to not apply effects on them
@@ -10,30 +13,61 @@ import later from 'lib/utils/later'
1013
// TODO Add menu to the survival menu
1114
// TODO Add chat notification
1215

13-
for (const { effectType, startingOn } of [
14-
{ effectType: 'Haste', startingOn: 1 },
15-
{ effectType: 'HealthBoost', startingOn: 4 },
16-
] satisfies {
17-
effectType: MinecraftEffectTypesUnion
18-
startingOn: number
19-
}[]) {
20-
new DurationalRecurringEvent(
21-
`effect${effectType}`,
22-
later.parse.recur().every(5).hour().startingOn(startingOn),
23-
ms.from('min', 10),
24-
() => ({}),
25-
(_, ctx) => {
26-
ctx.temp.system.runInterval(
27-
() => {
28-
for (const player of world.getAllPlayers())
29-
player.addEffect(MinecraftEffectTypes[effectType], TicksPerSecond * 3, {
30-
amplifier: 2,
31-
showParticles: false,
32-
})
33-
},
34-
`effect${effectType}`,
35-
TicksPerSecond * 2,
36-
)
37-
},
38-
)
16+
class RecurringEffect {
17+
static all: RecurringEffect[] = []
18+
19+
readonly event: DurationalRecurringEvent
20+
21+
constructor(
22+
readonly effectType: MinecraftEffectTypesUnion,
23+
readonly startingOn: number,
24+
filter?: (p: Player) => boolean,
25+
readonly amplifier = 2,
26+
) {
27+
RecurringEffect.all.push(this)
28+
this.event = new DurationalRecurringEvent(
29+
`effect${effectType}`,
30+
later.parse.recur().every(5).hour().startingOn(startingOn),
31+
ms.from('min', 10),
32+
() => ({}),
33+
(_, ctx) => {
34+
for (const player of world.getAllPlayers()) {
35+
player.success(i18n.success`Событие! ${effectType} силой ${amplifier} на ${10} минут`)
36+
}
37+
ctx.temp.system.runInterval(
38+
() => {
39+
for (const player of world.getAllPlayers()) {
40+
if (filter && !filter(player)) continue
41+
42+
player.addEffect(MinecraftEffectTypes[effectType], TicksPerSecond * 3, {
43+
amplifier,
44+
showParticles: false,
45+
})
46+
}
47+
},
48+
`effect${effectType}`,
49+
TicksPerSecond * 2,
50+
)
51+
},
52+
)
53+
}
3954
}
55+
56+
new RecurringEffect('Haste', 1)
57+
new RecurringEffect('HealthBoost', 2)
58+
new RecurringEffect(
59+
'Speed',
60+
3,
61+
p => RegionEvents.playerInRegionsCache.get(p)?.some(e => e instanceof RoadRegion) ?? false,
62+
4,
63+
)
64+
65+
export const recurForm = form(f => {
66+
f.title(i18n`События`)
67+
for (const event of RecurringEffect.all) {
68+
f.button(
69+
event.effectType + ' ' + (event.amplifier + 1) + '\n' + event.event.getNextOccurances(1)[0]?.toHHMM(),
70+
doNothing,
71+
)
72+
}
73+
})

src/modules/survival/speedrun/target.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Player } from '@minecraft/server'
22
import { InventoryInterval, ScoreboardDB } from 'lib'
33
import { defaultLang } from 'lib/assets/lang'
44
import { form } from 'lib/form/new'
5-
import { i18n } from 'lib/i18n/text'
5+
import { i18n, i18nShared } from 'lib/i18n/text'
66
import { BaseItem } from 'modules/places/base/base'
77

88
export enum SpeedRunTarget {
@@ -13,18 +13,18 @@ export enum SpeedRunTarget {
1313
MillionOfMoney = 'MillionOfMoney',
1414
}
1515

16-
const speedRunNames: Record<SpeedRunTarget, Text> = {
17-
[SpeedRunTarget.AllAchievements]: i18n`Все достижения`,
18-
[SpeedRunTarget.GetBaseItem]: i18n`Получить базу`,
19-
[SpeedRunTarget.AllQuests]: i18n`Все задания`,
20-
[SpeedRunTarget.MillionOfMoney]: i18n`1.000.000 монет`,
21-
[SpeedRunTarget.FullNetheriteArmor]: i18n`Полная незеритовая броня`,
16+
const speedRunNames: Record<SpeedRunTarget, SharedText> = {
17+
[SpeedRunTarget.AllAchievements]: i18nShared`Все достижения`,
18+
[SpeedRunTarget.GetBaseItem]: i18nShared`Получить базу`,
19+
[SpeedRunTarget.AllQuests]: i18nShared`Все задания`,
20+
[SpeedRunTarget.MillionOfMoney]: i18nShared`1.000.000 монет`,
21+
[SpeedRunTarget.FullNetheriteArmor]: i18nShared`Полная незеритовая броня`,
2222
}
2323

2424
const objectives: Record<SpeedRunTarget, ScoreboardDB> = Object.fromEntries(
2525
Object.entriesStringKeys(speedRunNames).map(([target, name]) => {
2626
const key = `${target[0]?.toLowerCase()}${target.slice(1)}SpeedRun`
27-
ScoreboardDB.defineName(key, name.to(defaultLang))
27+
ScoreboardDB.defineName(key, name)
2828
return [target, new ScoreboardDB(key, name.to(defaultLang))]
2929
}),
3030
)
@@ -72,7 +72,7 @@ InventoryInterval.slots.subscribe(({ player, slot }) => {
7272
}
7373
})
7474

75-
const speedrunForm = form((f, { player }) => {
75+
export const speedrunForm = form((f, { player }) => {
7676
f.title('Speedrun')
7777
f.body(
7878
i18n`Вы можете выбрать одну из категорий ниже для спидрана. Время считается только когда вы находитесь на анархии, т.е. пока вы оффлайн время не считается. Ваше время на анархии сейчас: ${i18n.hhmmss(player.scores.anarchyOnlineTime * 2.5)}`,

0 commit comments

Comments
 (0)