2021-12-29 06:52:48 +00:00
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Util ;
2021-12-29 06:52:48 +00:00
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Games
2021-12-29 06:52:48 +00:00
{
2022-03-12 04:10:13 +00:00
using Scripts_KarateMan ;
2021-12-29 06:52:48 +00:00
public class KarateMan : Minigame
{
2022-03-01 08:17:06 +00:00
public enum HitType
{
Pot = 0 ,
Rock = 2 ,
Ball = 3 ,
2022-03-03 04:23:20 +00:00
CookingPot = 6 ,
Alien = 7 ,
TacoBell = 999
2022-03-01 08:17:06 +00:00
}
2022-03-03 21:16:06 +00:00
public enum HitThree
{
HitTwo ,
HitThree ,
HitThreeAlt ,
HitFour
}
2022-02-26 06:31:35 +00:00
public enum LightBulbType
{
2022-02-26 18:57:09 +00:00
Normal ,
Blue ,
Yellow ,
Custom
2022-02-26 06:31:35 +00:00
}
2022-02-26 18:27:02 +00:00
public enum BackgroundType
2022-02-26 06:31:35 +00:00
{
2022-02-26 18:57:09 +00:00
Yellow ,
2022-02-27 23:46:32 +00:00
Fuchsia ,
2022-02-26 18:57:09 +00:00
Blue ,
Red ,
Orange ,
Pink ,
Custom
2022-02-26 18:27:02 +00:00
}
2022-03-01 17:40:59 +00:00
public enum BackgroundFXType
{
None ,
2022-03-01 20:37:06 +00:00
Sunburst ,
Rings
2022-03-01 17:40:59 +00:00
}
2022-02-27 17:02:46 +00:00
public enum ShadowType
{
Tinted ,
Custom
}
2022-02-26 18:57:09 +00:00
public Color [ ] LightBulbColors ;
2022-02-26 18:27:02 +00:00
public Color [ ] BackgroundColors ;
2022-02-27 17:02:46 +00:00
public Color [ ] ShadowColors ;
2022-02-27 03:28:15 +00:00
public static Color ShadowBlendColor = new Color ( 195f / 255f , 48f / 255f , 2f / 255f ) ;
2022-02-26 06:31:35 +00:00
2022-02-14 13:48:41 +00:00
const float hitVoiceOffset = 0.042f ;
2022-01-01 18:54:17 +00:00
public GameObject Pot , Bomb ;
2021-12-30 08:26:18 +00:00
public KarateJoe KarateJoe ;
2021-12-29 06:52:48 +00:00
2022-01-20 01:48:52 +00:00
public List < Minigame . Eligible > EligibleCombos = new List < Minigame . Eligible > ( ) ;
2021-12-29 06:52:48 +00:00
public static KarateMan instance { get ; set ; }
2021-12-30 08:26:18 +00:00
public Sprite [ ] ObjectSprites ;
2022-01-03 15:15:48 +00:00
public Sprite [ ] BarrelSprites ;
2022-03-03 04:04:11 +00:00
public Sprite [ ] CookingPotSprites ;
2022-03-03 04:23:20 +00:00
public Sprite [ ] OtherSprites ;
2021-12-30 08:26:18 +00:00
2021-12-30 12:17:22 +00:00
public List < BGSpriteC > BGSprites ;
public SpriteRenderer BGSprite ;
2022-02-26 18:27:02 +00:00
public SpriteRenderer BGFXSprite ;
2022-02-27 17:02:46 +00:00
public BackgroundType BGType = BackgroundType . Yellow ;
2022-03-01 17:40:59 +00:00
public BackgroundFXType BGFXType = BackgroundFXType . None ;
2022-02-26 18:27:02 +00:00
public Color BGColor ;
2021-12-30 12:17:22 +00:00
2022-02-27 17:02:46 +00:00
public ShadowType Shadow = ShadowType . Tinted ;
public Color ShadowColor = Color . black ;
2022-01-21 07:09:32 +00:00
private float newBeat ;
2021-12-30 12:17:22 +00:00
2022-01-21 07:09:32 +00:00
public GameEvent bop = new GameEvent ( ) ;
public GameEvent prepare = new GameEvent ( ) ;
2022-01-03 22:42:43 +00:00
2022-01-19 05:40:49 +00:00
private float bgBeat ;
2022-03-03 04:04:11 +00:00
public ParticleSystem potHitEffect ;
2022-01-20 01:48:52 +00:00
public GameObject comboRef ;
2022-01-21 07:09:32 +00:00
public GameObject HIT3Ref ;
public Sprite [ ] Numbers ;
2021-12-30 12:17:22 +00:00
[System.Serializable]
public class BGSpriteC
{
public List < Sprite > Sprites ;
}
2021-12-29 06:52:48 +00:00
private void Awake ( )
{
instance = this ;
2022-02-27 17:02:46 +00:00
BGType = 0 ;
2022-02-26 18:27:02 +00:00
BGColor = BackgroundColors [ 0 ] ;
2022-02-27 17:02:46 +00:00
Shadow = 0 ;
2022-02-26 18:27:02 +00:00
}
2022-03-08 04:46:49 +00:00
public override void OnGameSwitch ( float beat )
2022-02-26 18:27:02 +00:00
{
2022-03-08 04:46:49 +00:00
base . OnGameSwitch ( beat ) ;
2022-02-27 17:02:46 +00:00
SetBackgroundColor ( ( int ) BGType , ( int ) Shadow , BGColor , ShadowColor ) ;
2021-12-29 06:52:48 +00:00
}
2022-01-20 01:48:52 +00:00
public void Combo ( float beat )
{
comboRef . GetComponent < Animator > ( ) . enabled = true ;
comboRef . GetComponent < Animator > ( ) . Play ( "comboRef" ) ;
Jukebox . PlayOneShotGame ( "karateman/barrelOutCombos" ) ;
Shoot ( beat , 0 , true , "PotCombo1" , 0 , new Vector2 ( - 0.94f , - 2.904f ) ) ;
Shoot ( beat + 0.25f , 0 , true , "PotCombo2" , 1 , new Vector2 ( - 0.94f , - 2.904f ) ) ;
Shoot ( beat + 0.5f , 0 , true , "PotCombo3" , 2 , new Vector2 ( - 0.776f , - 3.162f ) ) ;
Shoot ( beat + 0.75f , 0 , true , "PotCombo4" , 3 , new Vector2 ( 1.453f , - 3.162f ) ) ;
Shoot ( beat + 1f , 0 , true , "PotCombo5" , 4 , new Vector2 ( 0.124f , - 3.123f ) ) ;
Shoot ( beat + 1.5f , 4 , true , "PotCombo6" , 5 , new Vector2 ( - 1.333f , - 2.995f ) ) ;
2022-01-21 01:24:30 +00:00
MultiSound . Play ( new MultiSound . Sound [ ]
{
new MultiSound . Sound ( "karateman/punchy1" , beat + 1f ) ,
new MultiSound . Sound ( "karateman/punchy2" , beat + 1.25f ) ,
new MultiSound . Sound ( "karateman/punchy3" , beat + 1.5f ) ,
new MultiSound . Sound ( "karateman/punchy4" , beat + 1.75f ) ,
new MultiSound . Sound ( "karateman/ko" , beat + 2f ) ,
new MultiSound . Sound ( "karateman/pow" , beat + 2.5f )
} ) ;
2022-01-20 01:48:52 +00:00
}
2022-02-26 04:57:18 +00:00
public void Shoot ( float beat , int type , bool combo = false , string throwAnim = "" , int comboIndex = 0 , Vector2 endShadowPos = new Vector2 ( ) , UnityEngine . Color tint = default )
2022-01-20 01:48:52 +00:00
{
GameObject pot = Instantiate ( Pot ) ;
pot . transform . parent = Pot . transform . parent ;
2022-01-30 01:26:53 +00:00
if ( KarateJoe . instance . anim . IsAnimationNotPlaying ( ) )
KarateJoe . instance . SetHead ( 0 ) ;
2022-01-20 01:48:52 +00:00
Pot p = pot . GetComponent < Pot > ( ) ;
pot . SetActive ( true ) ;
p . startBeat = beat ;
p . createBeat = beat ;
p . isThrown = true ;
p . type = type ;
2022-03-03 04:23:20 +00:00
if ( type < = ObjectSprites . Length )
p . Sprite . GetComponent < SpriteRenderer > ( ) . sprite = ObjectSprites [ type ] ;
2022-01-20 01:48:52 +00:00
if ( combo )
{
p . comboIndex = comboIndex ;
p . throwAnim = throwAnim ;
p . combo = true ;
KarateJoe . currentComboPots . Add ( p ) ;
p . endShadowThrowPos = endShadowPos ;
}
else
{
p . throwAnim = "PotThrow" ;
string outSnd = "" ;
switch ( type )
{
case 0 :
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
p . hitSnd = "karateman/potHit" ;
break ;
case 1 :
outSnd = "karateman/lightbulbOut" ;
p . hitSnd = "karateman/lightbulbHit" ;
2022-02-26 04:57:18 +00:00
if ( tint ! = default & & tint ! = Color . black ) {
2022-02-26 06:31:35 +00:00
p . BulbLightSprite . SetActive ( true ) ;
p . BulbLightSprite . GetComponent < SpriteRenderer > ( ) . color = tint ;
2022-02-26 04:57:18 +00:00
}
2022-01-20 01:48:52 +00:00
break ;
case 2 :
2022-01-30 09:09:26 +00:00
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
2022-01-20 01:48:52 +00:00
p . hitSnd = "karateman/rockHit" ;
break ;
case 3 :
2022-01-30 09:09:26 +00:00
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
2022-01-20 01:48:52 +00:00
p . hitSnd = "karateman/soccerHit" ;
break ;
case 4 :
p . kick = true ;
outSnd = "karateman/barrelOutKicks" ;
p . hitSnd = "karateman/barrelBreak" ;
2022-01-21 01:24:30 +00:00
MultiSound . Play ( new MultiSound . Sound [ ]
{
2022-01-21 07:09:32 +00:00
new MultiSound . Sound ( "karateman/punchKick1" , beat + 1f ) ,
new MultiSound . Sound ( "karateman/punchKick2" , beat + 1.5f ) ,
new MultiSound . Sound ( "karateman/punchKick3" , beat + 1.75f ) ,
new MultiSound . Sound ( "karateman/punchKick4" , beat + 2.25f )
2022-01-21 01:24:30 +00:00
} ) ;
2022-01-20 01:48:52 +00:00
break ;
2022-01-25 01:02:45 +00:00
case 6 :
2022-03-03 04:04:11 +00:00
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
2022-03-03 04:23:20 +00:00
p . hitSnd = "karateman/cookingPot" ;
2022-01-25 01:02:45 +00:00
break ;
2022-03-03 04:04:11 +00:00
case 7 :
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
2022-03-03 04:23:20 +00:00
p . hitSnd = "karateman/alienHit" ;
2022-03-03 04:04:11 +00:00
break ;
2022-03-03 04:23:20 +00:00
case 999 :
p . Sprite . GetComponent < SpriteRenderer > ( ) . sprite = OtherSprites [ 0 ] ;
2022-03-03 04:04:11 +00:00
if ( Starpelly . Mathp . GetDecimalFromFloat ( beat ) = = 0f )
outSnd = "karateman/objectOut" ;
else
outSnd = "karateman/offbeatObjectOut" ;
2022-03-03 04:23:20 +00:00
p . hitSnd = "karateman/tacobell" ;
2022-03-03 04:04:11 +00:00
break ;
2022-01-20 01:48:52 +00:00
}
p . endShadowThrowPos = new Vector2 ( - 1.036f , - 2.822f ) ;
Jukebox . PlayOneShotGame ( outSnd ) ;
}
2022-03-27 18:13:13 +00:00
p . Init ( ) ;
2022-01-20 01:48:52 +00:00
}
2022-02-14 13:48:41 +00:00
List < Beatmap . Entity > cuedVoices = new List < Beatmap . Entity > ( ) ; // "Hit" voices cued in advance are stored here so they aren't called multiple times in Update().
2021-12-30 12:17:22 +00:00
private void Update ( )
{
2022-01-19 05:40:49 +00:00
if ( Conductor . instance . ReportBeat ( ref newBeat ) )
2021-12-30 12:17:22 +00:00
{
2022-02-26 18:27:02 +00:00
if ( BGFXSprite . enabled )
2021-12-30 12:17:22 +00:00
{
2022-03-01 20:37:06 +00:00
var type = ( int ) BGFXType - 1 ;
2022-01-19 05:40:49 +00:00
if ( bgBeat % 2 = = 0 )
{
2022-03-01 20:37:06 +00:00
BGFXSprite . sprite = BGSprites [ type ] . Sprites [ 0 ] ;
2022-01-19 05:40:49 +00:00
}
2021-12-30 12:17:22 +00:00
else
2022-01-19 05:40:49 +00:00
{
2022-03-01 20:37:06 +00:00
BGFXSprite . sprite = BGSprites [ type ] . Sprites [ 1 ] ;
2022-01-19 05:40:49 +00:00
}
bgBeat + + ;
2022-01-03 22:42:43 +00:00
}
2022-01-19 05:40:49 +00:00
}
2021-12-30 12:17:22 +00:00
2022-01-21 07:09:32 +00:00
if ( Conductor . instance . ReportBeat ( ref bop . lastReportedBeat , bop . startBeat % 1 ) )
2022-01-19 05:40:49 +00:00
{
2022-01-21 07:09:32 +00:00
if ( Conductor . instance . songPositionInBeats > = bop . startBeat & & Conductor . instance . songPositionInBeats < bop . startBeat + bop . length )
2022-01-03 22:42:43 +00:00
{
2022-01-21 07:09:32 +00:00
if ( KarateJoe . anim . IsAnimationNotPlaying ( ) )
2022-01-19 05:40:49 +00:00
KarateJoe . anim . Play ( "Bop" , 0 , 0 ) ;
2021-12-30 12:17:22 +00:00
}
}
2022-01-21 07:09:32 +00:00
if ( prepare . length > 0 )
{
if ( Conductor . instance . songPositionInBeats > = prepare . startBeat & & Conductor . instance . songPositionInBeats < prepare . startBeat + prepare . length )
{
if ( KarateJoe . anim . IsAnimationNotPlaying ( ) )
KarateJoe . AnimPlay ( "Prepare" ) ;
}
else
{
KarateJoe . AnimPlay ( "Idle" ) ;
prepare . length = 0 ;
}
}
2022-02-14 13:48:41 +00:00
2022-03-03 10:43:01 +00:00
if ( ! Conductor . instance . isPlaying )
return ;
2022-02-14 13:48:41 +00:00
// Call "hit" voice slightly early to account for sound offset.
var hitVoiceEvents = GameManager . instance . Beatmap . entities . FindAll ( c = > c . datamodel = = "karateman/hit3" | | c . datamodel = = "karateman/hit4" ) ;
for ( int i = 0 ; i < hitVoiceEvents . Count ; i + + )
{
var hitEvent = hitVoiceEvents [ i ] ;
var timeToEvent = hitEvent . beat - Conductor . instance . songPositionInBeats ;
if ( timeToEvent < = 1f & & timeToEvent > 0f & & ! cuedVoices . Contains ( hitEvent ) )
{
cuedVoices . Add ( hitEvent ) ;
2022-03-03 21:16:06 +00:00
var sound = "karateman/hit" ;
if ( hitEvent . type = = ( int ) KarateMan . HitThree . HitThreeAlt ) sound + = "Alt" ;
MultiSound . Play ( new MultiSound . Sound [ ] { new MultiSound . Sound ( sound , hitEvent . beat - hitVoiceOffset * Conductor . instance . songBpm / 60f ) } ) ;
2022-02-14 13:48:41 +00:00
}
}
2021-12-30 12:17:22 +00:00
}
2022-03-01 17:40:59 +00:00
public void SetBackgroundFX ( BackgroundFXType type )
2021-12-30 12:17:22 +00:00
{
2022-03-01 17:40:59 +00:00
BGFXType = type ;
2022-03-01 20:37:06 +00:00
if ( BGFXType = = BackgroundFXType . None )
2022-03-01 17:40:59 +00:00
{
BGFXSprite . enabled = false ;
}
else
{
BGFXSprite . enabled = true ;
2022-03-01 20:37:06 +00:00
BGFXSprite . sprite = BGSprites [ ( int ) type - 1 ] . Sprites [ 0 ] ;
2022-03-01 17:40:59 +00:00
}
2022-02-26 18:27:02 +00:00
}
2022-02-27 17:02:46 +00:00
public void SetBackgroundColor ( int type , int shadowType , Color backgroundColor , Color shadowColor )
2022-02-26 18:27:02 +00:00
{
2022-02-27 17:02:46 +00:00
BGType = ( BackgroundType ) type ;
BGColor = backgroundColor ;
BGSprite . color = backgroundColor ;
Shadow = ( ShadowType ) shadowType ;
ShadowColor = shadowColor ;
2021-12-30 12:17:22 +00:00
}
2022-01-03 22:42:43 +00:00
public void Bop ( float beat , float length )
2021-12-30 08:26:18 +00:00
{
2022-01-21 07:09:32 +00:00
bop . length = length ;
bop . startBeat = beat ;
2021-12-29 06:52:48 +00:00
}
2022-01-19 05:40:49 +00:00
2022-03-03 21:16:06 +00:00
public void Hit2 ( float beat )
{
MultiSound . Play ( new MultiSound . Sound [ ] { new MultiSound . Sound ( "karateman/two" , beat + 0.5f ) } ) ;
}
public void Hit3 ( float beat , bool alt = false )
2022-01-21 01:24:30 +00:00
{
2022-03-03 21:16:06 +00:00
var sound = "karateman/three" ;
if ( alt ) sound + = "Alt" ;
MultiSound . Play ( new MultiSound . Sound [ ] { new MultiSound . Sound ( sound , beat + 0.5f ) } ) ;
2022-01-21 07:09:32 +00:00
GameObject hit3 = Instantiate ( HIT3Ref , this . transform ) ;
hit3 . transform . GetChild ( 0 ) . GetChild ( 1 ) . GetComponent < SpriteRenderer > ( ) . sprite = Numbers [ 2 ] ;
BeatAction . New ( hit3 , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat + 0.5f , delegate { hit3 . transform . GetChild ( 0 ) . gameObject . SetActive ( true ) ; } ) ,
new BeatAction . Action ( beat + 4.5f , delegate { Destroy ( hit3 ) ; } )
} ) ;
}
public void Hit4 ( float beat )
{
2022-02-14 13:48:41 +00:00
MultiSound . Play ( new MultiSound . Sound [ ] { new MultiSound . Sound ( "karateman/four" , beat + 0.5f ) } ) ;
2022-01-21 07:09:32 +00:00
GameObject hit4 = Instantiate ( HIT3Ref , this . transform ) ;
hit4 . transform . GetChild ( 0 ) . GetChild ( 1 ) . GetComponent < SpriteRenderer > ( ) . sprite = Numbers [ 3 ] ;
BeatAction . New ( hit4 , new List < BeatAction . Action > ( )
{
new BeatAction . Action ( beat + 0.5f , delegate { hit4 . transform . GetChild ( 0 ) . gameObject . SetActive ( true ) ; } ) ,
new BeatAction . Action ( beat + 4.5f , delegate { Destroy ( hit4 ) ; } )
} ) ;
}
public void Prepare ( float beat , float length )
{
prepare . startBeat = beat ;
prepare . length = length ;
2022-01-21 01:24:30 +00:00
}
2022-01-19 05:40:49 +00:00
public void CreateBomb ( Transform parent , Vector2 scale , ref GameObject shadow )
{
GameObject bomb = Instantiate ( Bomb , parent ) ;
bomb . SetActive ( true ) ;
bomb . transform . localScale = scale ;
shadow . transform . parent = bomb . transform ;
shadow . transform . SetAsLastSibling ( ) ;
bomb . GetComponent < Bomb > ( ) . shadow = shadow ;
}
2022-02-27 03:28:15 +00:00
public Color GetShadowColor ( )
{
2022-02-27 17:02:46 +00:00
if ( Shadow = = ShadowType . Custom )
{
return ShadowColor ;
}
else if ( BGType < BackgroundType . Custom )
{
return ShadowColors [ ( int ) BGType ] ;
}
return Color . LerpUnclamped ( BGColor , ShadowBlendColor , 0.45f ) ;
2022-02-27 03:28:15 +00:00
}
2021-12-29 06:52:48 +00:00
}
}