Note Miss Event + Bug Fix

This commit is contained in:
NeeEoo
2023-07-10 00:17:21 +02:00
parent 6e52f80c9b
commit 3daab89d13
4 changed files with 160 additions and 20 deletions
@@ -0,0 +1,138 @@
package funkin.backend.scripting.events;
import funkin.game.Note;
import funkin.game.Character;
final class NoteMissEvent extends CancellableEvent {
@:dox(hide) public var animCancelled:Bool = false;
@:dox(hide) public var deleteNote:Bool = true;
@:dox(hide) public var stunned:Bool = true;
@:dox(hide) public var resetCombo:Bool = true;
@:dox(hide) public var playMissSound:Bool = true;
/**
* Note that has been missed
*/
public var note:Note;
public var score:Int;
public var misses:Int;
public var muteVocals:Bool;
/**
* The amount of health that'll be gained from missing that note. If called from `onPlayerMiss`, the value will be negative.
*/
public var healthGain:Float;
public var missSound:String;
public var missVolume:Float;
public var ghostMiss:Bool;
public var gfSad:Bool;
public var gfSadAnim:String;
public var forceGfAnim:Bool;
/**
* Whenever the animation should be forced to play.
*/
public var forceAnim:Bool;
/**
* Suffix of the animation. "miss" for miss notes, "-alt" for alt notes, "" for normal ones.
*/
public var animSuffix:String;
/**
* Character that pressed the note.
*/
public var character(get, set):Character;
/**
* Characters that pressed the note.
*/
public var characters:Array<Character>;
/**
* Whenever the Character is a player
*/
public var playerID:Int;
/**
* Note Type name (null if default note)
*/
public var noteType:String;
/**
* Direction of the press (0 = Left, 1 = Down, 2 = Up, 3 = Right)
*/
public var direction:Int;
/**
* Accuracy gained from pressing this note. From 0 to 1. null means no accuracy is gained.
*/
public var accuracy:Null<Float>;
/**
* Prevents the miss sound from played.
*/
public function preventMissSound() {
playMissSound = false;
}
@:dox(hide)
public function cancelMissSound() {preventMissSound();}
/**
* Prevents the combo from being reset.
*/
public function preventResetCombo() {
resetCombo = false;
}
@:dox(hide)
public function cancelResetCombo() {preventResetCombo();}
/**
* Prevents the default sing animation from being played.
*/
public function preventStunned() {
stunned = false;
}
@:dox(hide)
public function cancelStunned() {preventStunned();}
/**
* Prevents the default sing animation from being played.
*/
public function preventAnim() {
animCancelled = true;
}
@:dox(hide)
public function cancelAnim() {preventAnim();}
/**
* Prevents the note from being deleted.
*/
public function preventDeletion() {
deleteNote = false;
}
@:dox(hide)
public function cancelDeletion() {preventDeletion();}
/**
* Prevents the vocals volume from being set to 1 after pressing the note.
*/
public function preventVocalsUnmute() {
muteVocals = true;
}
@:dox(hide)
public function cancelVocalsUnmute() {preventVocalsUnmute();}
/**
* Prevents the vocals volume from being muted in case its a parameter of `onPlayerMiss`
*/
public function preventVocalsMute() {
muteVocals = false;
}
@:dox(hide)
public function cancelVocalsMute() {preventVocalsMute();}
private inline function get_character()
return characters[0];
private function set_character(char:Character) {
characters = [char];
return char;
}
}
@@ -22,7 +22,7 @@ class ScriptsMacro {
// OTHER LIBRARIES & STUFF
"away3d", "flx3d", #if sys "sys", #end "openfl.net",
"funkin.backend.system.net",
"hxcodec.flixel", "hxcodec.openfl", "hxcodec.lime",
#if VIDEO_CUTSCENES "hxcodec.flixel", "hxcodec.openfl", "hxcodec.lime", #end
// BASE HAXE
"DateTools", "EReg", "Lambda", "StringBuf", "haxe.crypto", "haxe.display", "haxe.exceptions", "haxe.extern", "scripting"
])
+18 -16
View File
@@ -1371,21 +1371,22 @@ class PlayState extends MusicBeatState
var directionID:Null<Int> = note == null ? direction : note.strumID;
if (playerID == null || directionID == null || playerID == -1) return;
var event:NoteHitEvent = scripts.event("onPlayerMiss", EventManager.get(NoteHitEvent).recycle(true, false, false, note, strumLines.members[playerID].characters, true, note != null ? note.noteType : null, "", "", "", directionID, -10, 0, note != null ? -0.0475 : -0.04, "shit"));
var event:NoteMissEvent = scripts.event("onPlayerMiss", EventManager.get(NoteMissEvent).recycle(note, -10, 1, muteVocalsOnMiss, note != null ? -0.0475 : -0.04, Paths.soundRandom('missnote', 1, 3), FlxG.random.float(0.1, 0.2), note == null, combo > 5, "sad", true, true, "miss", strumLines.members[playerID].characters, playerID, note != null ? note.noteType : null, directionID, 0));
strumLine.onMiss.dispatch(event);
if (event.cancelled) return;
if (strumLine != null) strumLine.addHealth(event.healthGain);
if (gf != null && combo > 5 && gf.hasAnimation('sad'))
gf.playAnim('sad', event.forceAnim, MISS);
combo = 0;
if (gf != null && event.gfSad && gf.hasAnimation(event.gfSadAnim))
gf.playAnim(event.gfSadAnim, event.forceGfAnim, MISS);
songScore -= 10;
misses++;
if (event.resetCombo) combo = 0;
FlxG.sound.play(Paths.soundRandom('missnote', 1, 3), FlxG.random.float(0.1, 0.2));
songScore += event.score;
misses += event.misses;
if (muteVocalsOnMiss) vocals.volume = 0;
if (event.playMissSound) FlxG.sound.play(event.missSound, event.missVolume);
if (event.muteVocals) vocals.volume = 0;
if (event.accuracy != null) {
accuracyPressedNotes++;
@@ -1394,16 +1395,17 @@ class PlayState extends MusicBeatState
updateRating();
}
for(char in event.characters) {
if (char == null) continue;
if (!event.animCancelled) {
for(char in event.characters) {
if (char == null) continue;
char.stunned = true;
char.playSingAnim(directionID, "miss", MISS);
if(event.stunned) char.stunned = true;
char.playSingAnim(directionID, event.animSuffix, MISS, event.forceAnim);
}
}
if (strumLine != null && note != null) {
if (event.deleteNote && strumLine != null && note != null)
strumLine.deleteNote(note);
}
}
@:dox(hide)
@@ -1450,7 +1452,7 @@ class PlayState extends MusicBeatState
var event:NoteHitEvent;
if (strumLine != null && !strumLine.cpu)
event = scripts.event("onPlayerHit", EventManager.get(NoteHitEvent).recycle(false, !note.isSustainNote, !note.isSustainNote, note, strumLine.characters, true, note.noteType, note.animSuffix.getDefault(strumLine.altAnim ? "-alt" : ""), "game/score/", "", note.strumID, score, note.isSustainNote ? null : accuracy, note.noteData > 0 ? 0.023 : 0.004, daRating, Options.splashesEnabled && !note.isSustainNote && daRating == "sick"));
event = scripts.event("onPlayerHit", EventManager.get(NoteHitEvent).recycle(false, !note.isSustainNote, !note.isSustainNote, note, strumLine.characters, true, note.noteType, note.animSuffix.getDefault(strumLine.altAnim ? "-alt" : ""), "game/score/", "", note.strumID, score, note.isSustainNote ? null : accuracy, 0.023, daRating, Options.splashesEnabled && !note.isSustainNote && daRating == "sick"));
else
event = scripts.event("onDadHit", EventManager.get(NoteHitEvent).recycle(false, false, false, note, strumLine.characters, false, note.noteType, note.animSuffix.getDefault(strumLine.altAnim ? "-alt" : ""), "game/score/", "", note.strumID, 0, null, 0, daRating, false));
strumLine.onHit.dispatch(event);
@@ -1465,7 +1467,7 @@ class PlayState extends MusicBeatState
updateRating();
}
if (event.countAsCombo) combo++;
if (event.showRating || (event.showRating == null && event.player))
{
displayCombo(event);
+3 -3
View File
@@ -17,11 +17,11 @@ class StrumLine extends FlxTypedGroup<Strum> {
*/
public var onHit:FlxTypedSignal<NoteHitEvent->Void> = new FlxTypedSignal<NoteHitEvent->Void>();
/**
* Signal that triggers whenever a note is missed. Similar to onPlayerMiss and onDadMiss, except strumline specific.
* Signal that triggers whenever a note is missed. Similar to onPlayerMiss, except strumline specific.
* To add a listener, do
* `strumLine.onMiss.add(function(e:NoteHitEvent) {});`
* `strumLine.onMiss.add(function(e:NoteMissEvent) {});`
*/
public var onMiss:FlxTypedSignal<NoteHitEvent->Void> = new FlxTypedSignal<NoteHitEvent->Void>();
public var onMiss:FlxTypedSignal<NoteMissEvent->Void> = new FlxTypedSignal<NoteMissEvent->Void>();
/**
* Signal that triggers whenever a note is being updated. Similar to onNoteUpdate, except strumline specific.
* To add a listener, do