2018-09-15 22:34:53 +08:00
|
|
|
class Game{
|
|
|
|
constructor(controller, selectedSong, songData){
|
|
|
|
this.controller = controller
|
|
|
|
this.selectedSong = selectedSong
|
|
|
|
this.songData = songData
|
2018-10-12 04:24:18 +08:00
|
|
|
this.elapsedTime = 0
|
2020-03-12 12:59:28 +08:00
|
|
|
this.currentCircle = -1
|
|
|
|
this.updateCurrentCircle()
|
2018-09-15 22:34:53 +08:00
|
|
|
this.combo = 0
|
2018-10-01 15:33:43 +08:00
|
|
|
this.rules = new GameRules(this)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.globalScore = {
|
|
|
|
points: 0,
|
|
|
|
good: 0,
|
2018-10-01 15:33:43 +08:00
|
|
|
ok: 0,
|
|
|
|
bad: 0,
|
2018-09-15 22:34:53 +08:00
|
|
|
maxCombo: 0,
|
2018-09-16 01:27:53 +08:00
|
|
|
drumroll: 0,
|
2018-10-01 15:33:43 +08:00
|
|
|
gauge: 0,
|
|
|
|
title: selectedSong.title,
|
|
|
|
difficulty: this.rules.difficulty
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2020-03-05 23:58:49 +08:00
|
|
|
var combo = this.songData.circles.filter(circle => {
|
2019-02-18 00:26:46 +08:00
|
|
|
var type = circle.type
|
|
|
|
return (type === "don" || type === "ka" || type === "daiDon" || type === "daiKa") && (!circle.branch || circle.branch.active)
|
2018-09-15 22:34:53 +08:00
|
|
|
}).length
|
2020-03-05 23:58:49 +08:00
|
|
|
this.soulPoints = this.rules.soulPoints(combo)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.paused = false
|
|
|
|
this.started = false
|
|
|
|
this.mainMusicPlaying = false
|
|
|
|
this.musicFadeOut = 0
|
|
|
|
this.fadeOutStarted = false
|
|
|
|
this.currentTimingPoint = 0
|
2019-02-21 04:48:21 +08:00
|
|
|
this.branchNames = ["normal", "advanced", "master"]
|
|
|
|
this.resetSection()
|
2019-03-16 05:34:48 +08:00
|
|
|
this.gameLagSync = !this.controller.touchEnabled && !(/Firefox/.test(navigator.userAgent))
|
2018-09-22 04:31:35 +08:00
|
|
|
|
2018-09-15 22:34:53 +08:00
|
|
|
assets.songs.forEach(song => {
|
|
|
|
if(song.id == selectedSong.folder){
|
|
|
|
this.mainAsset = song.sound
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
run(){
|
|
|
|
this.timeForDistanceCircle = 2500
|
|
|
|
this.initTiming()
|
2018-10-12 04:24:18 +08:00
|
|
|
this.view = this.controller.view
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
initTiming(){
|
|
|
|
// Date when the chrono is started (before the game begins)
|
2020-03-12 12:59:28 +08:00
|
|
|
var firstCircle
|
|
|
|
for(var i = 0; i < this.songData.circles.length; i++){
|
|
|
|
firstCircle = this.songData.circles[i]
|
|
|
|
if(firstCircle.type !== "event"){
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 14:04:40 +08:00
|
|
|
if(this.controller.calibrationMode){
|
|
|
|
var offsetTime = 0
|
|
|
|
}else{
|
|
|
|
var offsetTime = Math.max(0, this.timeForDistanceCircle - (firstCircle ? firstCircle.ms : 0)) |0
|
|
|
|
}
|
2019-01-25 09:42:05 +08:00
|
|
|
if(this.controller.multiplayer){
|
|
|
|
var syncWith = this.controller.syncWith
|
|
|
|
var syncCircles = syncWith.game.songData.circles
|
|
|
|
var syncOffsetTime = Math.max(0, this.timeForDistanceCircle - syncCircles[0].ms) |0
|
|
|
|
offsetTime = Math.max(offsetTime, syncOffsetTime)
|
|
|
|
}
|
2018-10-03 17:48:18 +08:00
|
|
|
this.elapsedTime = -offsetTime
|
2018-09-15 22:34:53 +08:00
|
|
|
// The real start for the game will start when chrono will reach 0
|
2018-12-13 17:18:52 +08:00
|
|
|
this.startDate = Date.now() + offsetTime
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
update(){
|
|
|
|
this.updateTime()
|
2019-11-28 14:04:40 +08:00
|
|
|
// Main operations
|
2018-09-15 22:34:53 +08:00
|
|
|
this.updateCirclesStatus()
|
|
|
|
this.checkPlays()
|
|
|
|
// Event operations
|
|
|
|
this.whenFadeoutMusic()
|
2018-11-13 12:36:15 +08:00
|
|
|
if(this.controller.multiplayer !== 2){
|
|
|
|
this.whenLastCirclePlayed()
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
getCircles(){
|
|
|
|
return this.songData.circles
|
|
|
|
}
|
|
|
|
updateCirclesStatus(){
|
2018-10-15 06:00:40 +08:00
|
|
|
var nextSet = false
|
2019-02-18 00:26:46 +08:00
|
|
|
var ms = this.elapsedTime
|
2018-09-15 22:34:53 +08:00
|
|
|
var circles = this.songData.circles
|
2019-01-16 20:33:42 +08:00
|
|
|
var startIndex = this.currentCircle === 0 ? 0 : this.currentCircle - 1
|
2019-02-18 00:26:46 +08:00
|
|
|
var index = 0
|
2019-02-24 20:04:14 +08:00
|
|
|
|
2019-02-18 00:26:46 +08:00
|
|
|
for(var i = startIndex; i < circles.length; i++){
|
2018-10-15 06:00:40 +08:00
|
|
|
var circle = circles[i]
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle && (!circle.branch || circle.branch.active) && !circle.isPlayed){
|
2019-02-18 00:26:46 +08:00
|
|
|
var type = circle.type
|
2018-09-19 01:33:18 +08:00
|
|
|
var drumrollNotes = type === "balloon" || type === "drumroll" || type === "daiDrumroll"
|
2019-11-28 14:04:40 +08:00
|
|
|
var endTime = circle.endTime + (drumrollNotes ? 0 : this.rules.bad) + this.controller.audioLatency
|
2018-09-15 22:34:53 +08:00
|
|
|
|
2019-11-28 14:04:40 +08:00
|
|
|
if(ms >= circle.ms + this.controller.audioLatency){
|
|
|
|
if(drumrollNotes && !circle.rendaPlayed && ms < endTime + this.controller.audioLatency){
|
2018-09-22 04:31:35 +08:00
|
|
|
circle.rendaPlayed = true
|
|
|
|
if(this.rules.difficulty === "easy"){
|
2019-02-04 17:14:42 +08:00
|
|
|
assets.sounds["v_renda" + this.controller.snd].stop()
|
2019-12-25 02:10:40 +08:00
|
|
|
this.controller.playSound("v_renda")
|
2018-09-19 01:33:18 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
}
|
2020-03-01 00:50:28 +08:00
|
|
|
if(circle.daiFailed && (ms >= circle.daiFailed.ms + this.rules.daiLeniency || ms > endTime)){
|
|
|
|
this.checkScore(circle, circle.daiFailed.check)
|
|
|
|
}else if(ms > endTime){
|
2018-09-21 02:30:49 +08:00
|
|
|
if(!this.controller.autoPlayEnabled){
|
|
|
|
if(drumrollNotes){
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle.section && circle.timesHit === 0){
|
|
|
|
this.resetSection()
|
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
circle.played(-1, false)
|
2018-09-21 02:30:49 +08:00
|
|
|
this.updateCurrentCircle()
|
|
|
|
if(this.controller.multiplayer === 1){
|
2018-11-13 12:36:15 +08:00
|
|
|
var value = {
|
2019-11-28 14:04:40 +08:00
|
|
|
pace: (ms - circle.ms - this.controller.audioLatency) / circle.timesHit
|
2018-11-13 12:36:15 +08:00
|
|
|
}
|
|
|
|
if(type === "drumroll" || type === "daiDrumroll"){
|
|
|
|
value.kaAmount = circle.timesKa / circle.timesHit
|
|
|
|
}
|
|
|
|
p2.send("drumroll", value)
|
2018-09-21 02:30:49 +08:00
|
|
|
}
|
|
|
|
}else{
|
2019-02-24 23:13:41 +08:00
|
|
|
this.skipNote(circle)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.updateCurrentCircle()
|
|
|
|
}
|
|
|
|
}
|
2018-10-15 07:18:01 +08:00
|
|
|
}else if(!this.controller.autoPlayEnabled && !nextSet){
|
|
|
|
nextSet = true
|
|
|
|
this.currentCircle = i
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-02-18 00:26:46 +08:00
|
|
|
if(index++ > 1){
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-24 20:04:14 +08:00
|
|
|
|
2019-02-18 00:26:46 +08:00
|
|
|
var branches = this.songData.branches
|
|
|
|
if(branches){
|
2019-02-21 04:48:21 +08:00
|
|
|
var force = this.controller.multiplayer === 2 ? p2 : this
|
|
|
|
var measures = this.songData.measures
|
|
|
|
if(this.controller.multiplayer === 2 || force.branch){
|
|
|
|
if(!force.branchSet){
|
|
|
|
force.branchSet = true
|
|
|
|
if(branches.length){
|
|
|
|
this.setBranch(branches[0], force.branch)
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
var view = this.controller.view
|
|
|
|
var currentMeasure = view.branch
|
|
|
|
for(var i = measures.length; i--;){
|
|
|
|
var measure = measures[i]
|
|
|
|
if(measure.nextBranch && measure.ms <= ms){
|
|
|
|
currentMeasure = measure.nextBranch.active
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(view.branch !== currentMeasure){
|
2019-04-05 04:40:11 +08:00
|
|
|
if(!this.branchStatic){
|
|
|
|
view.branchAnimate = {
|
|
|
|
ms: ms,
|
|
|
|
fromBranch: view.branch
|
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
this.branchStatic = false
|
2019-02-21 04:48:21 +08:00
|
|
|
view.branch = currentMeasure
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
}
|
|
|
|
for(var i = 0; i < measures.length; i++){
|
|
|
|
var measure = measures[i]
|
|
|
|
if(measure.ms > ms){
|
|
|
|
break
|
|
|
|
}else if(measure.nextBranch && !measure.gameChecked){
|
|
|
|
measure.gameChecked = true
|
|
|
|
var branch = measure.nextBranch
|
|
|
|
if(branch.type){
|
|
|
|
var accuracy = 0
|
|
|
|
if(branch.type === "drumroll"){
|
|
|
|
if(force.branch){
|
|
|
|
var accuracy = Math.max(0, branch.requirement[force.branch])
|
2019-02-18 00:26:46 +08:00
|
|
|
}else{
|
2019-02-21 04:48:21 +08:00
|
|
|
var accuracy = this.sectionDrumroll
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
}else if(this.sectionNotes.length !== 0){
|
|
|
|
if(force.branch){
|
|
|
|
var accuracy = Math.max(0, Math.min(100, branch.requirement[force.branch]))
|
2019-02-18 00:26:46 +08:00
|
|
|
}else{
|
2019-02-21 04:48:21 +08:00
|
|
|
var accuracy = this.sectionNotes.reduce((a, b) => a + b) / this.sectionNotes.length * 100
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
if(accuracy >= branch.requirement.master){
|
|
|
|
this.setBranch(branch, "master")
|
|
|
|
}else if(accuracy >= branch.requirement.advanced){
|
|
|
|
this.setBranch(branch, "advanced")
|
|
|
|
}else{
|
|
|
|
this.setBranch(branch, "normal")
|
|
|
|
}
|
|
|
|
}else if(this.controller.multiplayer === 1){
|
|
|
|
p2.send("branch", "normal")
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-10-15 06:00:40 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-02-24 23:13:41 +08:00
|
|
|
fixNoteStream(keysDon){
|
|
|
|
var circleIsNote = circle => {
|
|
|
|
var type = circle.type
|
|
|
|
return type === "don" || type === "ka" || type === "daiDon" || type === "daiKa"
|
|
|
|
}
|
|
|
|
var correctNote = circle => {
|
|
|
|
var type = circle.type
|
|
|
|
return keysDon ? (type === "don" || type === "daiDon") : (type === "ka" || type === "daiKa")
|
|
|
|
}
|
|
|
|
var ms = this.elapsedTime
|
|
|
|
var circles = this.songData.circles
|
|
|
|
|
|
|
|
for(var i = this.currentCircle + 1; i < circles.length; i++){
|
|
|
|
var circle = circles[i]
|
2019-11-28 14:04:40 +08:00
|
|
|
var relative = ms - circle.ms - this.controller.audioLatency
|
2019-02-24 23:13:41 +08:00
|
|
|
if(!circle.branch || circle.branch.active){
|
|
|
|
if((!circleIsNote(circle) || relative < -this.rules.bad)){
|
|
|
|
break
|
|
|
|
}else if(Math.abs(relative) < this.rules.ok && correctNote(circle)){
|
|
|
|
for(var j = this.currentCircle; j < i; j++){
|
|
|
|
var circle = circles[j]
|
|
|
|
if(circle && !circle.branch || circle.branch.active){
|
|
|
|
this.skipNote(circles[j])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.currentCircle = i
|
|
|
|
return circles[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skipNote(circle){
|
2020-03-12 12:59:28 +08:00
|
|
|
if(circle.type === "event"){
|
|
|
|
return
|
|
|
|
}
|
2019-02-24 23:13:41 +08:00
|
|
|
if(circle.section){
|
|
|
|
this.resetSection()
|
|
|
|
}
|
|
|
|
circle.played(-1, circle.type === "daiDon" || circle.type === "daiKa")
|
|
|
|
this.sectionNotes.push(0)
|
|
|
|
this.controller.displayScore(0, true)
|
|
|
|
this.updateCombo(0)
|
|
|
|
this.updateGlobalScore(0, 1)
|
|
|
|
if(this.controller.multiplayer === 1){
|
|
|
|
p2.send("note", {
|
|
|
|
score: -1
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
checkPlays(){
|
|
|
|
var circles = this.songData.circles
|
|
|
|
var circle = circles[this.currentCircle]
|
2020-03-12 12:59:28 +08:00
|
|
|
if(circle && circle.type === "event"){
|
|
|
|
this.updateCurrentCircle()
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
|
2019-02-24 20:04:14 +08:00
|
|
|
if(this.controller.autoPlayEnabled){
|
|
|
|
while(circle && this.controller.autoPlay(circle)){
|
|
|
|
circle = circles[this.currentCircle]
|
|
|
|
}
|
|
|
|
return
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
var keys = this.controller.getKeys()
|
2018-09-19 01:33:18 +08:00
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
var don_l = keys["don_l"] && !this.controller.isWaiting("don_l", "score")
|
|
|
|
var don_r = keys["don_r"] && !this.controller.isWaiting("don_r", "score")
|
|
|
|
var ka_l = keys["ka_l"] && !this.controller.isWaiting("ka_l", "score")
|
|
|
|
var ka_r = keys["ka_r"] && !this.controller.isWaiting("ka_r", "score")
|
2018-09-19 01:33:18 +08:00
|
|
|
|
2019-02-24 20:04:14 +08:00
|
|
|
var checkDon = () => {
|
|
|
|
if(don_l && don_r){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["don_l", "don_r"], circle, "daiDon")
|
2019-02-24 20:04:14 +08:00
|
|
|
}else if(don_l){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["don_l"], circle, "don")
|
2019-02-24 20:04:14 +08:00
|
|
|
}else if(don_r){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["don_r"], circle, "don")
|
2019-02-24 20:04:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var checkKa = () => {
|
|
|
|
if(ka_l && ka_r){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["ka_l", "ka_r"], circle, "daiKa")
|
2019-02-24 20:04:14 +08:00
|
|
|
}else if(ka_l){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["ka_l"], circle, "ka")
|
2019-02-24 20:04:14 +08:00
|
|
|
}else if(ka_r){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.checkKey(["ka_r"], circle, "ka")
|
2019-02-24 20:04:14 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-02-24 20:04:14 +08:00
|
|
|
var keyTime = this.controller.getKeyTime()
|
|
|
|
if(keyTime["don"] >= keyTime["ka"]){
|
|
|
|
checkDon()
|
|
|
|
checkKa()
|
|
|
|
}else{
|
|
|
|
checkKa()
|
|
|
|
checkDon()
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
checkKey(keyCodes, circle, check){
|
2019-02-18 00:26:46 +08:00
|
|
|
if(circle && !circle.isPlayed){
|
2018-09-19 01:33:18 +08:00
|
|
|
if(!this.checkScore(circle, check)){
|
|
|
|
return
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
keyCodes.forEach(keyCode => {
|
|
|
|
this.controller.waitForKeyup(keyCode, "score")
|
|
|
|
})
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
checkScore(circle, check){
|
2018-10-03 17:48:18 +08:00
|
|
|
var ms = this.elapsedTime
|
2019-02-18 00:26:46 +08:00
|
|
|
var type = circle.type
|
2018-09-19 01:33:18 +08:00
|
|
|
|
|
|
|
var keysDon = check === "don" || check === "daiDon"
|
|
|
|
var keysKa = check === "ka" || check === "daiKa"
|
|
|
|
var keyDai = check === "daiDon" || check === "daiKa"
|
|
|
|
var typeDon = type === "don" || type === "daiDon"
|
|
|
|
var typeKa = type === "ka" || type === "daiKa"
|
|
|
|
var typeDai = type === "daiDon" || type === "daiKa"
|
2018-09-15 22:34:53 +08:00
|
|
|
|
2018-09-22 04:31:35 +08:00
|
|
|
var keyTime = this.controller.getKeyTime()
|
2020-03-01 00:50:28 +08:00
|
|
|
var currentTime = circle.daiFailed ? circle.daiFailed.ms : keysDon ? keyTime["don"] : keyTime["ka"]
|
2019-11-28 14:04:40 +08:00
|
|
|
var relative = currentTime - circle.ms - this.controller.audioLatency
|
2018-09-22 04:31:35 +08:00
|
|
|
|
2019-02-24 23:13:41 +08:00
|
|
|
if(relative >= this.rules.ok){
|
|
|
|
var fixedNote = this.fixNoteStream(keysDon)
|
|
|
|
if(fixedNote){
|
|
|
|
return this.checkScore(fixedNote, check)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 22:34:53 +08:00
|
|
|
if(typeDon || typeKa){
|
2018-09-22 04:31:35 +08:00
|
|
|
if(-this.rules.bad >= relative || relative >= this.rules.bad){
|
|
|
|
return true
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
var score = 0
|
|
|
|
if(keysDon && typeDon || keysKa && typeKa){
|
2018-09-22 04:31:35 +08:00
|
|
|
var circleStatus = -1
|
|
|
|
relative = Math.abs(relative)
|
|
|
|
if(relative < this.rules.good){
|
|
|
|
circleStatus = 450
|
|
|
|
}else if(relative < this.rules.ok){
|
|
|
|
circleStatus = 230
|
|
|
|
}else if(relative < this.rules.bad){
|
|
|
|
circleStatus = 0
|
|
|
|
}
|
2020-03-01 00:50:28 +08:00
|
|
|
if(typeDai && !keyDai){
|
|
|
|
if(this.controller.easierBigNotes){
|
|
|
|
// Taiko Force Lv5 can't hit both Dons at the same time, so dai offered
|
|
|
|
keyDai = true
|
|
|
|
}else if(!circle.daiFailed){
|
|
|
|
circle.daiFailed = {
|
|
|
|
ms: ms,
|
|
|
|
status: circleStatus,
|
|
|
|
check: check
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}else if(ms < circle.daiFailed.ms + this.rules.daiLeniency){
|
|
|
|
return false
|
|
|
|
}else{
|
|
|
|
circleStatus = circle.daiFailed.status
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
if(circleStatus === 230 || circleStatus === 450){
|
2018-09-15 22:34:53 +08:00
|
|
|
score = circleStatus
|
|
|
|
}
|
2018-10-25 22:18:41 +08:00
|
|
|
circle.played(score, score === 0 ? typeDai : keyDai)
|
|
|
|
this.controller.displayScore(score, false, typeDai && keyDai)
|
2018-09-15 22:34:53 +08:00
|
|
|
}else{
|
2019-02-24 20:04:14 +08:00
|
|
|
var keyTime = this.controller.getKeyTime()
|
|
|
|
var keyTimeRelative = Math.abs(keyTime.don - keyTime.ka)
|
|
|
|
if(Math.abs(relative) >= (keyTimeRelative <= 25 ? this.rules.bad : this.rules.good)){
|
|
|
|
return true
|
|
|
|
}
|
2018-10-25 22:18:41 +08:00
|
|
|
circle.played(-1, typeDai)
|
|
|
|
this.controller.displayScore(score, true, false)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
this.updateCombo(score)
|
2018-09-20 07:20:26 +08:00
|
|
|
this.updateGlobalScore(score, typeDai && keyDai ? 2 : 1, circle.gogoTime)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.updateCurrentCircle()
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle.section){
|
|
|
|
this.resetSection()
|
|
|
|
}
|
2019-02-18 00:26:46 +08:00
|
|
|
this.sectionNotes.push(score === 450 ? 1 : (score === 230 ? 0.5 : 0))
|
|
|
|
if(this.controller.multiplayer === 1){
|
2018-11-13 12:36:15 +08:00
|
|
|
var value = {
|
2018-09-15 22:34:53 +08:00
|
|
|
score: score,
|
2019-11-28 14:04:40 +08:00
|
|
|
ms: circle.ms - currentTime - this.controller.audioLatency,
|
2019-03-16 05:34:48 +08:00
|
|
|
dai: typeDai ? (keyDai ? 2 : 1) : 0
|
2018-11-13 12:36:15 +08:00
|
|
|
}
|
|
|
|
if((!keysDon || !typeDon) && (!keysKa || !typeKa)){
|
|
|
|
value.reverse = true
|
|
|
|
}
|
|
|
|
p2.send("note", value)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
}else{
|
2019-11-28 14:04:40 +08:00
|
|
|
if(circle.ms + this.controller.audioLatency > currentTime || currentTime > circle.endTime + this.controller.audioLatency){
|
2018-09-22 04:31:35 +08:00
|
|
|
return true
|
2018-09-19 01:33:18 +08:00
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
if(keysDon && type === "balloon"){
|
|
|
|
this.checkBalloon(circle)
|
2019-02-18 00:26:46 +08:00
|
|
|
if(check === "daiDon" && !circle.isPlayed){
|
2018-09-22 04:31:35 +08:00
|
|
|
this.checkBalloon(circle)
|
|
|
|
}
|
|
|
|
}else if((keysDon || keysKa) && (type === "drumroll" || type === "daiDrumroll")){
|
2018-11-13 12:36:15 +08:00
|
|
|
this.checkDrumroll(circle, keysKa)
|
2018-09-22 04:31:35 +08:00
|
|
|
if(keyDai){
|
2018-11-13 12:36:15 +08:00
|
|
|
this.checkDrumroll(circle, keysKa)
|
2018-09-22 04:31:35 +08:00
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-19 01:33:18 +08:00
|
|
|
return true
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
checkBalloon(circle){
|
|
|
|
if(circle.timesHit >= circle.requiredHits - 1){
|
|
|
|
var score = 5000
|
|
|
|
this.updateCurrentCircle()
|
|
|
|
circle.hit()
|
|
|
|
circle.played(score)
|
|
|
|
if(this.controller.multiplayer == 1){
|
|
|
|
p2.send("drumroll", {
|
2019-11-28 14:04:40 +08:00
|
|
|
pace: (this.elapsedTime - circle.ms + this.controller.audioLatency) / circle.timesHit
|
2018-09-15 22:34:53 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var score = 300
|
|
|
|
circle.hit()
|
|
|
|
}
|
2019-02-18 00:26:46 +08:00
|
|
|
this.globalScore.drumroll++
|
|
|
|
this.sectionDrumroll++
|
2018-09-15 22:34:53 +08:00
|
|
|
this.globalScore.points += score
|
2018-12-03 00:53:12 +08:00
|
|
|
this.view.setDarkBg(false)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-11-13 12:36:15 +08:00
|
|
|
checkDrumroll(circle, keysKa){
|
2018-10-08 02:58:42 +08:00
|
|
|
var ms = this.elapsedTime
|
2019-02-18 00:26:46 +08:00
|
|
|
var dai = circle.type === "daiDrumroll"
|
2018-09-15 22:34:53 +08:00
|
|
|
var score = 100
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle.section && circle.timesHit === 0){
|
|
|
|
this.resetSection()
|
|
|
|
}
|
2018-11-13 12:36:15 +08:00
|
|
|
circle.hit(keysKa)
|
2018-09-15 22:34:53 +08:00
|
|
|
var keyTime = this.controller.getKeyTime()
|
2019-02-18 00:26:46 +08:00
|
|
|
if(circle.type === "drumroll"){
|
2018-09-15 22:34:53 +08:00
|
|
|
var sound = keyTime["don"] > keyTime["ka"] ? "don" : "ka"
|
|
|
|
}else{
|
|
|
|
var sound = keyTime["don"] > keyTime["ka"] ? "daiDon" : "daiKa"
|
|
|
|
}
|
2018-09-20 07:20:26 +08:00
|
|
|
var circleAnim = new Circle({
|
|
|
|
id: 0,
|
2018-10-08 02:58:42 +08:00
|
|
|
start: ms,
|
2018-09-20 07:20:26 +08:00
|
|
|
type: sound,
|
|
|
|
txt: "",
|
|
|
|
speed: circle.speed,
|
2019-01-27 02:29:13 +08:00
|
|
|
gogoTime: circle.gogoTime,
|
|
|
|
fixedPos: document.hasFocus()
|
2018-09-20 07:20:26 +08:00
|
|
|
})
|
2018-09-19 01:33:18 +08:00
|
|
|
circleAnim.played(score, dai)
|
2018-10-08 02:58:42 +08:00
|
|
|
circleAnim.animate(ms)
|
2018-10-12 04:24:18 +08:00
|
|
|
this.view.drumroll.push(circleAnim)
|
2018-09-19 01:33:18 +08:00
|
|
|
this.globalScore.drumroll++
|
2019-02-21 04:48:21 +08:00
|
|
|
this.sectionDrumroll++
|
2018-09-19 01:33:18 +08:00
|
|
|
this.globalScore.points += score * (dai ? 2 : 1)
|
2018-12-03 00:53:12 +08:00
|
|
|
this.view.setDarkBg(false)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2020-03-12 12:59:28 +08:00
|
|
|
getLastCircle(circles){
|
|
|
|
for(var i = circles.length; i--;){
|
|
|
|
if(circles[i].type !== "event"){
|
|
|
|
return circles[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
whenLastCirclePlayed(){
|
2018-10-03 17:48:18 +08:00
|
|
|
var ms = this.elapsedTime
|
2018-11-13 12:36:15 +08:00
|
|
|
if(!this.lastCircle){
|
|
|
|
var circles = this.songData.circles
|
2020-03-12 12:59:28 +08:00
|
|
|
var circle = this.getLastCircle(circles)
|
2019-11-28 14:04:40 +08:00
|
|
|
this.lastCircle = circle ? circle.endTime : 0
|
2018-11-13 12:36:15 +08:00
|
|
|
if(this.controller.multiplayer){
|
|
|
|
var syncWith = this.controller.syncWith
|
|
|
|
var syncCircles = syncWith.game.songData.circles
|
2020-03-12 12:59:28 +08:00
|
|
|
circle = this.getLastCircle(syncCircles)
|
2019-11-28 14:04:40 +08:00
|
|
|
var syncLastCircle = circle ? circle.endTime : 0
|
2018-11-13 12:36:15 +08:00
|
|
|
if(syncLastCircle > this.lastCircle){
|
|
|
|
this.lastCircle = syncLastCircle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 14:04:40 +08:00
|
|
|
if(!this.fadeOutStarted && ms >= this.lastCircle + 2000 + this.controller.audioLatency){
|
2018-09-18 06:37:59 +08:00
|
|
|
this.fadeOutStarted = ms
|
2018-11-13 12:36:15 +08:00
|
|
|
if(this.controller.multiplayer){
|
|
|
|
this.controller.syncWith.game.fadeOutStarted = ms
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
whenFadeoutMusic(){
|
2018-09-18 06:37:59 +08:00
|
|
|
var started = this.fadeOutStarted
|
|
|
|
if(started){
|
2018-10-03 17:48:18 +08:00
|
|
|
var ms = this.elapsedTime
|
2019-03-06 05:48:30 +08:00
|
|
|
var duration = this.mainAsset ? this.mainAsset.duration : 0
|
|
|
|
var musicDuration = duration * 1000 - this.controller.offset
|
2018-09-18 06:37:59 +08:00
|
|
|
if(this.musicFadeOut === 0){
|
|
|
|
if(this.controller.multiplayer === 1){
|
2020-03-13 10:34:54 +08:00
|
|
|
var obj = this.getGlobalScore()
|
|
|
|
obj.name = account.loggedIn ? account.displayName : strings.defaultName
|
|
|
|
p2.send("gameresults", obj)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
this.musicFadeOut++
|
2018-09-18 06:37:59 +08:00
|
|
|
}else if(this.musicFadeOut === 1 && ms >= started + 1600){
|
|
|
|
this.controller.gameEnded()
|
2019-01-25 09:42:05 +08:00
|
|
|
if(!p2.session && this.controller.multiplayer === 1){
|
2018-11-02 06:05:18 +08:00
|
|
|
p2.send("gameend")
|
|
|
|
}
|
2018-09-18 06:37:59 +08:00
|
|
|
this.musicFadeOut++
|
2018-10-11 06:13:24 +08:00
|
|
|
}else if(this.musicFadeOut === 2 && (ms >= started + 8600 && ms >= musicDuration + 250)){
|
2018-09-18 06:37:59 +08:00
|
|
|
this.controller.displayResults()
|
2018-09-15 22:34:53 +08:00
|
|
|
this.musicFadeOut++
|
2018-10-11 06:13:24 +08:00
|
|
|
}else if(this.musicFadeOut === 3 && (ms >= started + 9600 && ms >= musicDuration + 1250)){
|
2018-10-06 01:03:59 +08:00
|
|
|
this.controller.clean()
|
2018-10-01 15:33:43 +08:00
|
|
|
if(this.controller.scoresheet){
|
|
|
|
this.controller.scoresheet.startRedraw()
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
playMainMusic(){
|
2018-10-11 06:13:24 +08:00
|
|
|
var ms = this.elapsedTime + this.controller.offset
|
|
|
|
if(!this.mainMusicPlaying && (!this.fadeOutStarted || ms < this.fadeOutStarted + 1600)){
|
2019-11-28 14:04:40 +08:00
|
|
|
if(this.calibrationState === "audio"){
|
|
|
|
var beatInterval = this.controller.view.beatInterval
|
|
|
|
var startAt = ms % beatInterval
|
|
|
|
var duration = this.mainAsset.duration * 1000
|
|
|
|
if(startAt < duration){
|
|
|
|
this.mainAsset.playLoop(0, false, startAt / 1000, 0, beatInterval / 1000)
|
|
|
|
}else{
|
|
|
|
this.mainAsset.playLoop((startAt - duration) / 1000, false, 0, 0, beatInterval / 1000)
|
|
|
|
}
|
|
|
|
}else if(this.controller.multiplayer !== 2 && this.mainAsset){
|
2018-09-15 22:34:53 +08:00
|
|
|
this.mainAsset.play((ms < 0 ? -ms : 0) / 1000, false, Math.max(0, ms / 1000))
|
|
|
|
}
|
|
|
|
this.mainMusicPlaying = true
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 14:04:40 +08:00
|
|
|
togglePause(forcePause, pauseMove, noSound){
|
2018-09-15 22:34:53 +08:00
|
|
|
if(!this.paused){
|
2019-11-28 14:04:40 +08:00
|
|
|
if(forcePause === false){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(!noSound){
|
|
|
|
this.controller.playSound("se_pause", 0, true)
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
this.paused = true
|
2018-12-13 17:18:52 +08:00
|
|
|
this.latestDate = Date.now()
|
2019-03-06 05:48:30 +08:00
|
|
|
if(this.mainAsset){
|
|
|
|
this.mainAsset.stop()
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
this.mainMusicPlaying = false
|
2019-11-28 14:04:40 +08:00
|
|
|
this.view.pauseMove(pauseMove || 0, true)
|
2018-11-24 00:53:29 +08:00
|
|
|
this.view.gameDiv.classList.add("game-paused")
|
2018-11-24 22:09:08 +08:00
|
|
|
this.view.lastMousemove = this.view.getMS()
|
|
|
|
this.view.cursorHidden = false
|
Custom scripting, #song=, translations
- A song can be linked directly by adding "#song=<id>" to the url, replace `<id>` with the id in the database, after loading it jumps immediately jumps to the difficulty selection
- Added tutorial translations
- Fixed song preview not playing
- Use text fallback for the logo when there are no vectors
- Increased combo cache by 1 pixel
- A custom javascript file can be loaded from config.json by defining "custom_js" value
- Added lots of events to help writing custom js files: `version-link, title-screen, language-change, song-select, song-select-move, song-select-difficulty, song-select-back, about, about-link, tutorial, import-songs, import-songs-default, session, session-start, session-end, debug, load-song, load-song-player2, load-song-unfocused, load-song-cancel, load-song-error, game-start, key-events, p2-game-end, p2-disconnected, p2-abandoned, pause, unpause, pause-restart, pause-song-select, game-lag, scoresheet, scoresheet-player2`
- Event syntax example:
```js
addEventListener("game-start", event => {
console.log("game-start", event.detail)
})
```
2019-02-14 17:32:45 +08:00
|
|
|
pageEvents.send("pause")
|
2019-11-28 14:04:40 +08:00
|
|
|
}else if(!forcePause){
|
|
|
|
if(forcePause !== false && this.calibrationState && ["audioHelp", "audioComplete", "videoHelp", "videoComplete", "results"].indexOf(this.calibrationState) !== -1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(this.calibrationState === "audioHelp" || this.calibrationState === "videoHelp"){
|
|
|
|
this.calibrationState = this.calibrationState === "audioHelp" ? "audio" : "video"
|
|
|
|
this.controller.view.pauseOptions = strings.pauseOptions
|
|
|
|
this.controller.playSound("se_don", 0, true)
|
|
|
|
}else if(!noSound){
|
|
|
|
this.controller.playSound("se_cancel", 0, true)
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
this.paused = false
|
2018-12-13 17:18:52 +08:00
|
|
|
var currentDate = Date.now()
|
2018-10-03 22:22:40 +08:00
|
|
|
this.startDate += currentDate - this.latestDate
|
|
|
|
this.sndTime = currentDate - snd.buffer.getTime() * 1000
|
2018-11-24 00:53:29 +08:00
|
|
|
this.view.gameDiv.classList.remove("game-paused")
|
2018-11-24 22:09:08 +08:00
|
|
|
this.view.pointer()
|
Custom scripting, #song=, translations
- A song can be linked directly by adding "#song=<id>" to the url, replace `<id>` with the id in the database, after loading it jumps immediately jumps to the difficulty selection
- Added tutorial translations
- Fixed song preview not playing
- Use text fallback for the logo when there are no vectors
- Increased combo cache by 1 pixel
- A custom javascript file can be loaded from config.json by defining "custom_js" value
- Added lots of events to help writing custom js files: `version-link, title-screen, language-change, song-select, song-select-move, song-select-difficulty, song-select-back, about, about-link, tutorial, import-songs, import-songs-default, session, session-start, session-end, debug, load-song, load-song-player2, load-song-unfocused, load-song-cancel, load-song-error, game-start, key-events, p2-game-end, p2-disconnected, p2-abandoned, pause, unpause, pause-restart, pause-song-select, game-lag, scoresheet, scoresheet-player2`
- Event syntax example:
```js
addEventListener("game-start", event => {
console.log("game-start", event.detail)
})
```
2019-02-14 17:32:45 +08:00
|
|
|
pageEvents.send("unpause", currentDate - this.latestDate)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
isPaused(){
|
|
|
|
return this.paused
|
|
|
|
}
|
|
|
|
updateTime(){
|
|
|
|
// Refreshed date
|
2018-10-03 17:48:18 +08:00
|
|
|
var ms = this.elapsedTime
|
2018-09-15 22:34:53 +08:00
|
|
|
if(ms >= 0 && !this.started){
|
2018-12-13 17:18:52 +08:00
|
|
|
this.startDate = Date.now()
|
2018-10-03 17:48:18 +08:00
|
|
|
this.elapsedTime = this.getAccurateTime()
|
2018-09-15 22:34:53 +08:00
|
|
|
this.started = true
|
2018-10-03 22:22:40 +08:00
|
|
|
this.sndTime = this.startDate - snd.buffer.getTime() * 1000
|
2018-09-15 22:34:53 +08:00
|
|
|
}else if(ms < 0 || ms >= 0 && this.started){
|
2018-12-13 17:18:52 +08:00
|
|
|
var currentDate = Date.now()
|
2019-03-16 05:34:48 +08:00
|
|
|
if(this.gameLagSync){
|
2018-10-06 15:23:36 +08:00
|
|
|
var sndTime = currentDate - snd.buffer.getTime() * 1000
|
|
|
|
var lag = sndTime - this.sndTime
|
|
|
|
if(Math.abs(lag) >= 50){
|
|
|
|
this.startDate += lag
|
|
|
|
this.sndTime = sndTime
|
Custom scripting, #song=, translations
- A song can be linked directly by adding "#song=<id>" to the url, replace `<id>` with the id in the database, after loading it jumps immediately jumps to the difficulty selection
- Added tutorial translations
- Fixed song preview not playing
- Use text fallback for the logo when there are no vectors
- Increased combo cache by 1 pixel
- A custom javascript file can be loaded from config.json by defining "custom_js" value
- Added lots of events to help writing custom js files: `version-link, title-screen, language-change, song-select, song-select-move, song-select-difficulty, song-select-back, about, about-link, tutorial, import-songs, import-songs-default, session, session-start, session-end, debug, load-song, load-song-player2, load-song-unfocused, load-song-cancel, load-song-error, game-start, key-events, p2-game-end, p2-disconnected, p2-abandoned, pause, unpause, pause-restart, pause-song-select, game-lag, scoresheet, scoresheet-player2`
- Event syntax example:
```js
addEventListener("game-start", event => {
console.log("game-start", event.detail)
})
```
2019-02-14 17:32:45 +08:00
|
|
|
pageEvents.send("game-lag", lag)
|
2018-10-06 15:23:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.elapsedTime = currentDate - this.startDate
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
getAccurateTime(){
|
2018-09-27 05:12:50 +08:00
|
|
|
if(this.isPaused()){
|
2018-10-03 17:48:18 +08:00
|
|
|
return this.elapsedTime
|
2018-09-27 05:12:50 +08:00
|
|
|
}else{
|
2018-12-13 17:18:52 +08:00
|
|
|
return Date.now() - this.startDate
|
2018-09-27 05:12:50 +08:00
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
getCircles(){
|
|
|
|
return this.songData.circles
|
|
|
|
}
|
|
|
|
updateCurrentCircle(){
|
2019-02-18 00:26:46 +08:00
|
|
|
var circles = this.songData.circles
|
|
|
|
do{
|
|
|
|
var circle = circles[++this.currentCircle]
|
2020-03-12 12:59:28 +08:00
|
|
|
}while(circle && (circle.branch && !circle.branch.active || circle.type === "event"))
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
getCurrentCircle(){
|
|
|
|
return this.currentCircle
|
|
|
|
}
|
|
|
|
updateCombo(score){
|
2018-09-19 01:33:18 +08:00
|
|
|
if(score !== 0){
|
2018-09-15 22:34:53 +08:00
|
|
|
this.combo++
|
|
|
|
}else{
|
|
|
|
this.combo = 0
|
|
|
|
}
|
|
|
|
if(this.combo > this.globalScore.maxCombo){
|
|
|
|
this.globalScore.maxCombo = this.combo
|
|
|
|
}
|
2019-12-25 02:10:40 +08:00
|
|
|
if(this.combo === 50 || this.combo > 0 && this.combo % 100 === 0 && this.combo <= 5000){
|
|
|
|
this.controller.playSound("v_combo_" + this.combo)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-06-21 11:17:11 +08:00
|
|
|
if (this.songData.scoremode == 2 && this.combo > 0 && this.combo % 100 == 0) {
|
|
|
|
this.globalScore.points += 10000;
|
|
|
|
}
|
2018-10-12 04:24:18 +08:00
|
|
|
this.view.updateCombo(this.combo)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
getCombo(){
|
|
|
|
return this.combo
|
|
|
|
}
|
|
|
|
getGlobalScore(){
|
|
|
|
return this.globalScore
|
|
|
|
}
|
2018-09-20 07:20:26 +08:00
|
|
|
updateGlobalScore(score, multiplier, gogoTime){
|
2018-09-15 22:34:53 +08:00
|
|
|
// Circle score
|
|
|
|
switch(score){
|
|
|
|
case 450:
|
2018-10-01 15:33:43 +08:00
|
|
|
this.globalScore.good++
|
2020-03-05 23:58:49 +08:00
|
|
|
this.globalScore.gauge += this.soulPoints.good
|
2018-09-15 22:34:53 +08:00
|
|
|
break
|
|
|
|
case 230:
|
2018-10-01 15:33:43 +08:00
|
|
|
this.globalScore.ok++
|
2020-03-05 23:58:49 +08:00
|
|
|
this.globalScore.gauge += this.soulPoints.ok
|
2018-09-15 22:34:53 +08:00
|
|
|
break
|
|
|
|
case 0:
|
2018-10-01 15:33:43 +08:00
|
|
|
this.globalScore.bad++
|
2020-03-05 23:58:49 +08:00
|
|
|
this.globalScore.gauge += this.soulPoints.bad
|
2018-09-15 22:34:53 +08:00
|
|
|
break
|
|
|
|
}
|
2019-06-21 11:17:11 +08:00
|
|
|
if (this.songData.scoremode) {
|
|
|
|
switch (score) {
|
|
|
|
case 450:
|
|
|
|
score = this.songData.scoreinit;
|
|
|
|
break;
|
|
|
|
case 230:
|
|
|
|
score = Math.floor(this.songData.scoreinit / 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-01 15:33:43 +08:00
|
|
|
// Gauge update
|
2020-03-05 23:58:49 +08:00
|
|
|
if(this.globalScore.gauge < 0){
|
2018-10-01 15:33:43 +08:00
|
|
|
this.globalScore.gauge = 0
|
2020-03-05 23:58:49 +08:00
|
|
|
}else if(this.globalScore.gauge > 10000){
|
|
|
|
this.globalScore.gauge = 10000
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
// Points update
|
2019-06-21 11:17:11 +08:00
|
|
|
if (this.songData.scoremode == 2) {
|
|
|
|
var diff_mul = 0;
|
|
|
|
if (this.combo >= 100) {
|
|
|
|
diff_mul = 8;
|
|
|
|
} else if (this.combo >= 50) {
|
|
|
|
diff_mul = 4;
|
|
|
|
} else if (this.combo >= 30) {
|
|
|
|
diff_mul = 2;
|
|
|
|
} else if (this.combo >= 10) {
|
|
|
|
diff_mul = 1;
|
|
|
|
}
|
|
|
|
score += this.songData.scorediff * diff_mul;
|
|
|
|
} else {
|
|
|
|
score += Math.max(0, Math.floor((Math.min(this.combo, 100) - 1) / 10) * (this.songData.scoremode ? this.songData.scorediff : 100));
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
|
2018-09-20 07:20:26 +08:00
|
|
|
if(gogoTime){
|
|
|
|
multiplier *= 1.2
|
|
|
|
}
|
|
|
|
this.globalScore.points += Math.floor(score * multiplier / 10) * 10
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
setBranch(currentBranch, activeName){
|
|
|
|
var pastActive = currentBranch.active
|
|
|
|
var ms = currentBranch.ms
|
|
|
|
for(var i = 0; i < this.songData.branches.length; i++){
|
|
|
|
var branch = this.songData.branches[i]
|
|
|
|
if(branch.ms >= ms){
|
|
|
|
var relevantName = activeName
|
|
|
|
var req = branch.requirement
|
|
|
|
var noNormal = req.advanced <= 0
|
|
|
|
var noAdvanced = req.master <= 0 || req.advanced >= req.master || branch.type === "accuracy" && req.advanced > 100
|
|
|
|
var noMaster = branch.type === "accuracy" && req.master > 100
|
|
|
|
if(relevantName === "normal" && noNormal){
|
|
|
|
relevantName = noAdvanced ? "master" : "advanced"
|
|
|
|
}
|
|
|
|
if(relevantName === "advanced" && noAdvanced){
|
|
|
|
relevantName = noMaster ? "normal" : "master"
|
|
|
|
}
|
|
|
|
if(relevantName === "master" && noMaster){
|
|
|
|
relevantName = noAdvanced ? "normal" : "advanced"
|
|
|
|
}
|
|
|
|
for(var j in this.branchNames){
|
|
|
|
var name = this.branchNames[j]
|
|
|
|
if(name in branch){
|
|
|
|
branch[name].active = name === relevantName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(branch === currentBranch){
|
|
|
|
activeName = relevantName
|
|
|
|
}
|
|
|
|
branch.active = relevantName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var circles = this.songData.circles
|
|
|
|
var circle = circles[this.currentCircle]
|
|
|
|
if(!circle || circle.branch === currentBranch[pastActive]){
|
|
|
|
var ms = this.elapsedTime
|
|
|
|
var closestCircle = circles.findIndex(circle => {
|
2019-11-28 14:04:40 +08:00
|
|
|
return (!circle.branch || circle.branch.active) && circle.endTime + this.controller.audioLatency >= ms
|
2019-02-21 04:48:21 +08:00
|
|
|
})
|
|
|
|
if(closestCircle !== -1){
|
|
|
|
this.currentCircle = closestCircle
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.controller.multiplayer === 1){
|
2019-02-21 04:48:21 +08:00
|
|
|
p2.send("branch", activeName)
|
2019-02-18 00:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-21 04:48:21 +08:00
|
|
|
resetSection(){
|
|
|
|
this.sectionNotes = []
|
|
|
|
this.sectionDrumroll = 0
|
|
|
|
}
|
2019-11-28 14:04:40 +08:00
|
|
|
clearKeyTime(){
|
|
|
|
var keyboard = this.controller.keyboard
|
|
|
|
for(var key in keyboard.keyTime){
|
|
|
|
keyboard.keys[key] = null
|
|
|
|
keyboard.keyTime[key] = -Infinity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
calibration(){
|
|
|
|
var view = this.controller.view
|
|
|
|
if(!this.calibrationState){
|
|
|
|
this.controller.parsedSongData.measures = []
|
|
|
|
this.calibrationProgress = {
|
|
|
|
audio: 0,
|
|
|
|
video: 0,
|
|
|
|
requirement: 40
|
|
|
|
}
|
|
|
|
this.calibrationReset("audio", true)
|
|
|
|
}
|
|
|
|
var progress = this.calibrationProgress
|
|
|
|
var state = this.calibrationState
|
|
|
|
switch(state){
|
|
|
|
case "audio":
|
|
|
|
case "video":
|
|
|
|
if(state === "audio" && !this.mainAsset){
|
2019-12-25 02:10:40 +08:00
|
|
|
this.mainAsset = assets.sounds["se_calibration"]
|
2019-11-28 14:04:40 +08:00
|
|
|
this.mainMusicPlaying = false
|
|
|
|
}
|
|
|
|
if(progress.hit >= progress.requirement){
|
|
|
|
var reduced = 0
|
|
|
|
for(var i = 2; i < progress.offsets.length; i++){
|
|
|
|
reduced += progress.offsets[i]
|
|
|
|
}
|
|
|
|
progress[state] = Math.max(0, Math.round(reduced / progress.offsets.length - 2))
|
|
|
|
this.calibrationState += "Complete"
|
|
|
|
view.pauseOptions = []
|
|
|
|
this.clearKeyTime()
|
|
|
|
this.togglePause(true, 1)
|
|
|
|
this.mainAsset = null
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case "audioComplete":
|
|
|
|
case "videoComplete":
|
|
|
|
if(Date.now() - this.latestDate > 3000){
|
|
|
|
var audioComplete = this.calibrationState === "audioComplete"
|
|
|
|
this.controller.playSound("se_pause", 0, true)
|
|
|
|
if(audioComplete){
|
|
|
|
this.calibrationReset("video")
|
|
|
|
}else{
|
|
|
|
view.pauseOptions = [
|
|
|
|
strings.calibration.retryPrevious,
|
|
|
|
strings.calibration.finish
|
|
|
|
]
|
|
|
|
}
|
|
|
|
this.calibrationState = audioComplete ? "videoHelp" : "results"
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
calibrationHit(ms){
|
|
|
|
var progress = this.calibrationProgress
|
|
|
|
var beatInterval = this.controller.view.beatInterval
|
|
|
|
var current = Math.floor((ms + 100) / beatInterval)
|
|
|
|
if(current !== progress.last){
|
|
|
|
var offset = ((ms + 100) % beatInterval) - 100
|
|
|
|
var offsets = progress.offsets
|
|
|
|
if(offsets.length >= progress.requirement){
|
|
|
|
offsets.shift()
|
|
|
|
}
|
|
|
|
offsets.push(offset)
|
|
|
|
progress.hit++
|
|
|
|
progress.last = current
|
2020-03-09 20:36:57 +08:00
|
|
|
this.globalScore.gauge = 10000 / (progress.requirement / progress.hit)
|
2019-11-28 14:04:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
calibrationReset(to, togglePause){
|
|
|
|
var view = this.controller.view
|
|
|
|
this.songData.circles = []
|
|
|
|
view.pauseOptions = [
|
|
|
|
to === "audio" ? strings.calibration.back : strings.calibration.retryPrevious,
|
|
|
|
strings.calibration.start
|
|
|
|
]
|
|
|
|
this.calibrationState = to + "Help"
|
|
|
|
var progress = this.calibrationProgress
|
|
|
|
progress.offsets = []
|
|
|
|
progress.hit = 0
|
|
|
|
progress.last = null
|
|
|
|
this.globalScore.gauge = 0
|
|
|
|
if(to === "video"){
|
|
|
|
this.clearKeyTime()
|
|
|
|
this.initTiming()
|
|
|
|
this.latestDate = this.startDate
|
|
|
|
this.elapsedTime = 0
|
|
|
|
view.ms = 0
|
|
|
|
}
|
|
|
|
if(togglePause){
|
|
|
|
this.togglePause(true, 1, true)
|
|
|
|
}else{
|
|
|
|
view.pauseMove(1, true)
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|