HeavenStudio/Assets/Scripts/Games/KarateMan/KarateManJoe.cs
AstrlJelly 6051b6c3f4
Karate Man Additions Part 1 (#559)
* starting out with adding so many things

* voiceless kicks and combos (that one was easy)
* queuing objects/specials
* starting on cutting out the voice
 -i was using MultiSound.Delete() but i found it very inconsistent and janky so im switching to a check of the next block and if it should cut out the voice
* got rid of basically all of the static variables in favor of checking the last color blocks
 -also means that the bg and object colors getting held over between remixes shouldn't happen anymore
* removed all of the super backwards compatibility
 -im almost certain these blocks are only available in .tengoku files though, so nobody should have any issues

* convert karateman to karateMan

* conversion stuff start
* voice cutting fully works and is consistent now

color conversion isn't working, but ill fix it eventually
background color isn't working rn either, and moving to the new system has caused a lot of errors

* it compiles now

this Background Appearance block got hands ‼️
working on converting everything to the new bg color system
this will be so annoying to build a RiqUpdater for.

* bunch of small stuff

i got this done while i was at a cabin

* bg still broken :(

* unconvert karateman from karateMan, bg finally works

well. bg ALMOST finally works
i'll be doing the fx stuff after, and ill combine it with the flow block

* bg nearly done

* i just might give up on bg compatibility

i tried for like an hour and a half to convert it but i couldn't.
minenice might be able to but idk.

* background + lightbulb stuffs

* FINALLY got old bg blocks updating + better bulb sfx

store the keys of the objects in the dictionary that i want to remove, create the properties, then remove all of the objects using the keys.

bulbs use a method that lets any sfx go through for the throw and hit, which means custom lightbulb cues 😃

moved all queuing into one list, then a foreach checks the datamodel of each riqentity in the list

camera bug fixed (call update in awake and start)

recolorable barrels lol

* and with that, it's finished!

added backwards compatibility for bg fx and fixed the particles (oops i forgot to assign them in the inspector

* fixed a bug

the warning would not go away if you dragged the playback bar behind a warning cuz it wasn't checking for the beginning of a warning block

* oops forgot to remove a debug log
2023-10-07 18:14:06 +00:00

383 lines
14 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_KarateMan
{
public class KarateManJoe : MonoBehaviour
{
public Animator anim;
public Animator FaceAnim;
public GameEvent bop = new GameEvent();
public SpriteRenderer[] Shadows;
public Color BombGlowTint;
double bombGlowStart = double.MinValue;
float bombGlowLength = 0f;
float bombGlowIntensity = 0f;
const float bombGlowRatio = 1f;
double lastPunchTime = double.MinValue;
double lastComboMissTime = double.MinValue;
double lastUpperCutTime = double.MinValue;
public bool inCombo = false;
public bool lockedInCombo = false;
public bool comboWaiting = false;
int inComboId = -1;
int shouldComboId = -1;
public void SetComboId(int id) { inComboId = id; }
public void SetShouldComboId(int id) { shouldComboId = id; }
public int GetComboId() { return inComboId; }
public int GetShouldComboId() { return shouldComboId; }
public bool wantKick = false;
public bool inKick = false;
double lastChargeTime = double.MinValue;
double unPrepareTime = double.MinValue;
double noNuriJabTime = double.MinValue;
bool canEmote = false;
public int wantFace = 0;
public bool inSpecial { get { return inCombo || lockedInCombo ||
Conductor.instance.GetPositionFromBeat(lastChargeTime, 2.75f) <= 0.25f || inNuriLock; } }
public bool inNuriLock { get { return (Conductor.instance.songPositionInBeatsAsDouble >= noNuriJabTime && Conductor.instance.songPositionInBeatsAsDouble < noNuriJabTime + 1f); } }
private void Update()
{
var cond = Conductor.instance;
if (cond.songPositionInBeatsAsDouble < bombGlowStart)
{
bombGlowIntensity = 1f;
}
else
{
float glowProg = cond.GetPositionFromBeat(bombGlowStart, bombGlowLength);
bombGlowIntensity = 1f - glowProg;
if (cond.songPositionInBeatsAsDouble >= bombGlowStart + bombGlowLength)
{
bombGlowStart = double.MinValue;
bombGlowLength = 0f;
}
}
UpdateJoeColour();
if (canEmote && wantFace >= 0)
{
SetFaceExpressionForced(wantFace);
if (wantFace == (int) KarateMan.KarateManFaces.Surprise) wantFace = -1;
}
if (cond.songPositionInBeatsAsDouble >= noNuriJabTime && cond.songPositionInBeatsAsDouble < noNuriJabTime + 1f)
{
anim.DoScaledAnimation("JabNoNuri", noNuriJabTime, 1f);
bop.startBeat = noNuriJabTime + 1f;
}
else if (cond.songPositionInBeatsAsDouble >= noNuriJabTime + 1f && noNuriJabTime != double.MinValue)
{
bop.startBeat = noNuriJabTime + 1f;
noNuriJabTime = double.MinValue;
}
if (unPrepareTime != double.MinValue && cond.songPositionInBeatsAsDouble >= unPrepareTime)
{
unPrepareTime = double.MinValue;
anim.speed = 1f;
anim.Play("Beat", -1, 0);
}
if (cond.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1, false) && cond.songPositionInBeatsAsDouble > bop.startBeat && cond.songPositionInBeatsAsDouble < bop.startBeat + bop.length && cond.songPositionInBeatsAsDouble >= unPrepareTime && !inCombo)
{
Bop();
}
if (inCombo && shouldComboId == -2)
{
float missProg = cond.GetPositionFromBeat(lastComboMissTime, 3f);
if (missProg >= 0f && missProg < 1f)
{
anim.DoScaledAnimation("LowKickMiss", lastComboMissTime, 3f);
bop.startBeat = lastComboMissTime + 3f;
}
else if (missProg >= 1f)
{
anim.speed = 1f;
bop.startBeat = lastComboMissTime + 3f;
lastComboMissTime = double.MinValue;
inCombo = false;
inComboId = -1;
shouldComboId = -1;
}
}
if (inKick)
{
float chargeProg = cond.GetPositionFromBeat(lastChargeTime, 2.75f);
if (chargeProg >= 0f && chargeProg < 1f)
{
anim.DoScaledAnimation("ManCharge", lastChargeTime, 2.75f);
bop.startBeat = lastChargeTime + 1.75f;
}
else if (chargeProg >= 1f)
{
anim.speed = 1f;
bop.startBeat = lastChargeTime + 1.75f;
lastChargeTime = double.MinValue;
inKick = false;
}
}
if (PlayerInput.Pressed(true) && !inSpecial)
{
if (!KarateMan.instance.IsExpectingInputNow(InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN))
{
Punch(1);
SoundByte.PlayOneShotGame("karateman/swingNoHit", forcePlay: true);
}
}
if (PlayerInput.AltPressed() && KarateMan.IsComboEnable && !inSpecial)
{
if (!KarateMan.instance.IsExpectingInputNow(InputType.STANDARD_ALT_DOWN))
{
//start a forced-fail combo sequence
ForceFailCombo(cond.songPositionInBeatsAsDouble);
KarateMan.instance.ScoreMiss(2);
}
}
else if (PlayerInput.AltPressedUp())
{
if (!KarateMan.instance.IsExpectingInputNow(InputType.STANDARD_ALT_UP))
{
if (inComboId != -1 && !lockedInCombo)
{
inComboId = -1;
}
}
}
if ((!GameManager.instance.autoplay) && (PlayerInput.PressedUp(true) && !PlayerInput.Pressing(true)))
{
if (wantKick)
{
//stopped holding, don't charge
wantKick = false;
}
else if (inKick && cond.GetPositionFromBeat(lastChargeTime, 2.75f) <= 0.5f && !KarateMan.instance.IsExpectingInputNow(InputType.STANDARD_UP | InputType.DIRECTION_UP))
{
Kick(cond.songPositionInBeatsAsDouble);
SoundByte.PlayOneShotGame("karateman/swingKick", forcePlay: true);
}
}
}
public void Bop()
{
anim.speed = 1f;
anim.Play("Beat", -1, 0);
lastChargeTime = double.MinValue;
}
public bool Punch(int forceHand = 0)
{
if (GameManager.instance.currentGame != "karateman") return false;
var cond = Conductor.instance;
bool straight = false;
anim.speed = 1f;
unPrepareTime = double.MinValue;
lastChargeTime = double.MinValue;
inKick = false;
switch (forceHand)
{
case 0:
if (cond.songPositionInBeatsAsDouble - lastPunchTime < 0.25f + (Minigame.JustLateTime() - 1f))
{
lastPunchTime = double.MinValue;
anim.DoScaledAnimationAsync("Straight", 0.5f);
straight = true;
}
else
{
lastPunchTime = cond.songPositionInBeatsAsDouble;
anim.DoScaledAnimationAsync("Jab", 0.5f);
}
break;
case 1:
anim.DoScaledAnimationAsync("Jab", 0.5f);
break;
case 2:
anim.DoScaledAnimationAsync("Straight", 0.5f);
straight = true;
break;
case 3:
lastPunchTime = double.MinValue;
anim.DoNormalizedAnimation("JabNoNuri");
noNuriJabTime = cond.songPositionInBeatsAsDouble;
break;
}
bop.startBeat = cond.songPositionInBeatsAsDouble + 0.5f;
return straight; //returns what hand was used to punch the object
}
public void ComboSequence(int seq)
{
if (GameManager.instance.currentGame != "karateman") return;
var cond = Conductor.instance;
bop.startBeat = cond.songPositionInBeatsAsDouble + 1f;
unPrepareTime = double.MinValue;
switch (seq)
{
case 0:
anim.Play("LowJab", -1, 0);
break;
case 1:
anim.Play("LowKick", -1, 0);
break;
case 2:
anim.DoScaledAnimationAsync("BackHand", 0.5f);
comboWaiting = true;
break;
case 3:
anim.DoScaledAnimationAsync("UpperCut", 0.5f);
lockedInCombo = false;
comboWaiting = false;
break;
case 4:
anim.Play("ToReady", -1, 0);
bop.startBeat = cond.songPositionInBeatsAsDouble + 0.5f;
lockedInCombo = false;
comboWaiting = false;
break;
default:
break;
}
}
public void ComboMiss(double beat)
{
var cond = Conductor.instance;
lastComboMissTime = beat;
bop.startBeat = beat + 3f;
unPrepareTime = double.MinValue;
anim.DoNormalizedAnimation("LowKickMiss");
}
public void ForceFailCombo(double beat)
{
if (inCombo) return;
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { Punch(1); inCombo = true; inComboId = -1; shouldComboId = -1;}),
new BeatAction.Action(beat + 0.25f, delegate { Punch(2); }),
new BeatAction.Action(beat + 0.5f, delegate { ComboSequence(0); }),
new BeatAction.Action(beat + 0.75f, delegate { shouldComboId = -2; ComboMiss(beat + 0.75f); }),
});
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("karateman/swingNoHit", beat),
new MultiSound.Sound("karateman/swingNoHit_Alt", beat + 0.25f),
new MultiSound.Sound("karateman/swingNoHit_Alt", beat + 0.5f),
new MultiSound.Sound("karateman/comboMiss", beat + 0.75f),
}, forcePlay: true);
}
public void StartKickCharge(double beat)
{
wantKick = true;
unPrepareTime = double.MinValue;
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate {
if (wantKick)
{
wantKick = false;
inKick = true;
lastChargeTime = beat;
bop.startBeat = beat + 1.75f;
}
})
});
}
public void Kick(double beat)
{
if (!inKick) return;
//play the kick animation and reset stance
anim.speed = 1f;
bop.startBeat = beat + 1f;
unPrepareTime = double.MinValue;
lastChargeTime = double.MinValue;
inKick = false;
anim.DoScaledAnimationAsync("ManKick", 0.5f);
}
public void MarkCanEmote()
{
canEmote = true;
}
public void MarkNoEmote()
{
canEmote = false;
}
public void UpdateJoeColour()
{
Color mainCol = KarateMan.instance.BodyColor;
Color highlightCol = KarateMan.instance.HighlightColor;
if (bombGlowIntensity > 0)
{
highlightCol = Color.LerpUnclamped(highlightCol, mainCol, bombGlowIntensity);
mainCol = Color.LerpUnclamped(mainCol, BombGlowTint, bombGlowIntensity * bombGlowRatio);
}
KarateMan.instance.MappingMaterial.SetColor("_ColorAlpha", mainCol);
KarateMan.instance.MappingMaterial.SetColor("_ColorBravo", new Color(1, 0, 0, 1));
KarateMan.instance.MappingMaterial.SetColor("_ColorDelta", highlightCol);
}
public void Prepare(double beat, float length)
{
anim.speed = 0f;
anim.Play("Beat", -1, 0);
unPrepareTime = beat + length;
}
public void SetFaceExpressionForced(int face)
{
FaceAnim.DoScaledAnimationAsync("Face" + face.ToString("D2"));
}
public void SetFaceExpression(int face, bool ignoreCheck = false)
{
wantFace = face;
if (canEmote || ignoreCheck)
FaceAnim.DoScaledAnimationAsync("Face" + face.ToString("D2"));
}
public void ApplyBombGlow()
{
bombGlowStart = double.MaxValue;
bombGlowLength = 0f;
bombGlowIntensity = 1f;
}
public void RemoveBombGlow(double beat, float length = 0.5f)
{
if (double.IsNaN(bombGlowIntensity)) return;
bombGlowStart = beat;
bombGlowLength = length;
bombGlowIntensity = 0f;
}
}
}