2022-05-01 18:22:00 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games.Loaders
|
|
|
|
{
|
|
|
|
using static Minigames;
|
|
|
|
public static class NtrCoinLoader
|
|
|
|
{
|
|
|
|
public static Minigame AddGame(EventCaller eventCaller)
|
|
|
|
{
|
2023-03-12 22:20:28 +00:00
|
|
|
return new Minigame("coinToss", "Coin Toss", "f9ec3b", false, false, new List<GameAction>()
|
2022-05-01 18:22:00 +00:00
|
|
|
{
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("toss", "Toss Coin")
|
2022-05-01 21:49:55 +00:00
|
|
|
{
|
2022-09-10 12:56:26 +00:00
|
|
|
function = delegate { CoinToss.instance.TossCoin(eventCaller.currentEntity.beat, eventCaller.currentEntity["type"], eventCaller.currentEntity["toggle"]); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 7,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2022-09-12 15:50:59 +00:00
|
|
|
new Param("type", CoinToss.CoinVariation.Default, "Variation", "Special Coin Variations"),
|
2022-08-21 03:13:52 +00:00
|
|
|
new Param("toggle", false, "Audience Reaction", "Enable Audience Reaction"),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("set background color", "Set Background Color")
|
2022-05-06 20:23:52 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; CoinToss.instance.ChangeBackgroundColor(e["colorA"], 0f); CoinToss.instance.ChangeBackgroundColor(e["colorB"], 0f, true); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", CoinToss.defaultBgColor, "Background Color", "The background color to change to"),
|
|
|
|
new Param("colorB", CoinToss.defaultFgColor, "Foreground Color", "The foreground color to change to")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new GameAction("fade background color", "Fade Background Color")
|
2022-05-06 20:23:52 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; CoinToss.instance.FadeBackgroundColor(e["colorA"], e["colorB"], e.length); CoinToss.instance.FadeBackgroundColor(e["colorC"], e["colorD"], e.length, true); },
|
2022-08-21 03:13:52 +00:00
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", Color.white, "BG Start Color", "The starting color in the fade"),
|
|
|
|
new Param("colorB", CoinToss.defaultBgColor, "BG End Color", "The ending color in the fade"),
|
|
|
|
new Param("colorC", Color.white, "FG Start Color", "The starting color in the fade"),
|
|
|
|
new Param("colorD", CoinToss.defaultFgColor, "FG End Color", "The ending color in the fade")
|
|
|
|
}
|
|
|
|
},
|
2022-05-06 20:23:52 +00:00
|
|
|
|
2022-07-10 02:20:30 +00:00
|
|
|
//left in for backwards-compatibility, but cannot be placed
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("set foreground color", "")
|
2022-07-10 02:20:30 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; CoinToss.instance.ChangeBackgroundColor(e["colorA"], 0f, true); },
|
2022-08-21 03:13:52 +00:00
|
|
|
defaultLength = 0.5f,
|
|
|
|
parameters = new List<Param>
|
|
|
|
|
|
|
|
{
|
|
|
|
new Param("colorA", CoinToss.defaultFgColor, "Foreground Color", "The foreground color to change to")
|
2022-07-10 02:42:28 +00:00
|
|
|
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
|
|
|
hidden = true
|
|
|
|
},
|
2022-07-10 02:42:28 +00:00
|
|
|
|
2022-08-21 03:13:52 +00:00
|
|
|
new GameAction("fade foreground color", "")
|
2022-07-10 02:42:28 +00:00
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; CoinToss.instance.FadeBackgroundColor(e["colorA"], e["colorB"], e.length, true); },
|
2022-08-21 03:13:52 +00:00
|
|
|
resizable = true,
|
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
|
|
|
new Param("colorA", Color.white, "Start Color", "The starting color in the fade"),
|
|
|
|
new Param("colorB", CoinToss.defaultFgColor, "End Color", "The ending color in the fade")
|
|
|
|
},
|
|
|
|
hidden = true
|
|
|
|
},
|
2022-06-12 19:32:00 +00:00
|
|
|
},
|
|
|
|
new List<string>() {"ntr", "aim"},
|
|
|
|
"ntrcoin", "en",
|
|
|
|
new List<string>() {}
|
|
|
|
);
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace HeavenStudio.Games
|
|
|
|
{
|
2022-05-03 20:36:55 +00:00
|
|
|
//using Scripts_CoinToss;
|
2022-05-01 18:22:00 +00:00
|
|
|
public class CoinToss : Minigame
|
|
|
|
{
|
|
|
|
|
2022-05-01 22:24:07 +00:00
|
|
|
//Right now, you can only throw one coin at a time.
|
|
|
|
//..Which makes sense, you only have one coin in the original game
|
|
|
|
|
|
|
|
//Though it would need a bit of code rewrite to make it work with multiple coins
|
|
|
|
|
2022-05-01 18:22:00 +00:00
|
|
|
public static CoinToss instance { get; set; }
|
|
|
|
|
2022-05-06 20:23:52 +00:00
|
|
|
private static Color _defaultBgColor;
|
|
|
|
public static Color defaultBgColor
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
ColorUtility.TryParseHtmlString("#F7F742", out _defaultBgColor);
|
|
|
|
return _defaultBgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Color _defaultFgColor;
|
|
|
|
public static Color defaultFgColor
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
ColorUtility.TryParseHtmlString("#FFFF83", out _defaultFgColor);
|
|
|
|
return _defaultFgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Header("Backgrounds")]
|
|
|
|
public SpriteRenderer fg;
|
|
|
|
public SpriteRenderer bg;
|
|
|
|
|
|
|
|
Tween bgColorTween;
|
|
|
|
Tween fgColorTween;
|
2022-05-01 21:49:55 +00:00
|
|
|
|
2022-05-01 18:22:00 +00:00
|
|
|
[Header("Animators")]
|
|
|
|
public Animator handAnimator;
|
|
|
|
|
2022-05-06 20:23:52 +00:00
|
|
|
public Boolean isThrowing;
|
|
|
|
|
|
|
|
public bool audienceReacting;
|
|
|
|
|
2022-05-03 20:36:55 +00:00
|
|
|
public PlayerActionEvent coin;
|
|
|
|
|
2022-09-10 12:56:26 +00:00
|
|
|
public enum CoinVariation
|
|
|
|
{
|
|
|
|
Default,
|
|
|
|
Cowbell,
|
|
|
|
}
|
|
|
|
|
2022-05-01 18:22:00 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2022-05-01 22:24:07 +00:00
|
|
|
isThrowing = false;
|
2022-05-03 20:36:55 +00:00
|
|
|
|
|
|
|
coin = null;
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-05-03 20:36:55 +00:00
|
|
|
//nothing
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
{
|
2022-05-03 20:36:55 +00:00
|
|
|
//nothing
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 12:56:26 +00:00
|
|
|
public void TossCoin(float beat, int type, bool audienceReacting)
|
2022-05-01 18:22:00 +00:00
|
|
|
{
|
2022-05-03 20:36:55 +00:00
|
|
|
if (coin != null) return;
|
|
|
|
|
2022-05-01 22:24:07 +00:00
|
|
|
//Play sound and animations
|
2022-05-01 18:22:00 +00:00
|
|
|
Jukebox.PlayOneShotGame("coinToss/throw");
|
|
|
|
handAnimator.Play("Throw", 0, 0);
|
2022-05-01 22:24:07 +00:00
|
|
|
//Game state says the hand is throwing the coin
|
2022-05-01 18:22:00 +00:00
|
|
|
isThrowing = true;
|
2022-05-01 20:10:00 +00:00
|
|
|
|
2022-09-10 12:56:26 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case (int) CoinToss.CoinVariation.Cowbell:
|
2022-09-12 15:50:59 +00:00
|
|
|
//this was intentional. it was to avoid the throw and cowbells to go offbeat.
|
|
|
|
Jukebox.PlayOneShotGame("coinToss/cowbell1");
|
|
|
|
MultiSound.Play(new MultiSound.Sound[] {
|
2022-09-10 13:38:51 +00:00
|
|
|
new MultiSound.Sound("coinToss/cowbell2", beat + 1f, offset: 0.01f),
|
|
|
|
new MultiSound.Sound("coinToss/cowbell1", beat + 2f, offset: 0.01f),
|
|
|
|
new MultiSound.Sound("coinToss/cowbell2", beat + 3f, offset: 0.01f),
|
2022-09-12 15:50:59 +00:00
|
|
|
new MultiSound.Sound("coinToss/cowbell1", beat + 4f, offset: 0.01f),
|
2022-09-10 13:38:51 +00:00
|
|
|
new MultiSound.Sound("coinToss/cowbell2", beat + 5f, offset: 0.01f),
|
2022-09-12 15:50:59 +00:00
|
|
|
new MultiSound.Sound("coinToss/cowbell1", beat + 6f, offset: 0.01f),
|
2022-09-10 12:56:26 +00:00
|
|
|
});
|
2022-09-12 15:50:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-03 20:36:55 +00:00
|
|
|
this.audienceReacting = audienceReacting;
|
2022-05-01 21:49:55 +00:00
|
|
|
|
2022-05-04 16:42:06 +00:00
|
|
|
coin = ScheduleInput(beat, 6f, InputType.STANDARD_DOWN, CatchSuccess, CatchMiss, CatchEmpty);
|
2022-05-06 20:05:19 +00:00
|
|
|
//coin.perfectOnly = true;
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 02:05:04 +00:00
|
|
|
public void TossCoin(float beat)
|
|
|
|
{
|
|
|
|
if (coin != null) return;
|
|
|
|
|
|
|
|
//Play sound and animations
|
|
|
|
Jukebox.PlayOneShotGame("coinToss/throw");
|
|
|
|
handAnimator.Play("Throw", 0, 0);
|
|
|
|
//Game state says the hand is throwing the coin
|
|
|
|
isThrowing = true;
|
|
|
|
this.audienceReacting = false;
|
|
|
|
|
|
|
|
coin = ScheduleInput(beat, 6f, InputType.STANDARD_DOWN, CatchSuccess, CatchMiss, CatchEmpty);
|
|
|
|
//coin.perfectOnly = true;
|
|
|
|
}
|
|
|
|
|
2022-05-06 20:05:19 +00:00
|
|
|
public void CatchSuccess(PlayerActionEvent caller, float state)
|
2022-05-01 20:10:00 +00:00
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("coinToss/catch");
|
2022-09-03 06:09:23 +00:00
|
|
|
if(this.audienceReacting) Jukebox.PlayOneShot("applause");
|
2022-05-01 20:10:00 +00:00
|
|
|
handAnimator.Play("Catch_success", 0, 0);
|
|
|
|
|
2022-05-03 20:36:55 +00:00
|
|
|
isThrowing = false;
|
2022-05-01 20:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 20:05:19 +00:00
|
|
|
public void CatchMiss(PlayerActionEvent caller)
|
2022-05-01 20:10:00 +00:00
|
|
|
{
|
2022-09-03 06:09:23 +00:00
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
if(this.audienceReacting) Jukebox.PlayOneShot("audience/disappointed");
|
2022-05-01 21:49:55 +00:00
|
|
|
handAnimator.Play("Pickup", 0, 0);
|
|
|
|
|
2022-05-01 22:24:07 +00:00
|
|
|
isThrowing = false;
|
2022-05-01 21:49:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 20:05:19 +00:00
|
|
|
public void CatchEmpty(PlayerActionEvent caller)
|
2022-05-01 21:49:55 +00:00
|
|
|
{
|
|
|
|
handAnimator.Play("Catch_empty", 0, 0);
|
|
|
|
isThrowing = false;
|
2022-05-03 20:36:55 +00:00
|
|
|
|
|
|
|
coin.CanHit(false);
|
2022-05-01 20:10:00 +00:00
|
|
|
}
|
2022-05-06 20:23:52 +00:00
|
|
|
|
|
|
|
public void ChangeBackgroundColor(Color color, float beats, bool isFg = false)
|
|
|
|
{
|
|
|
|
var seconds = Conductor.instance.secPerBeat * beats;
|
|
|
|
|
|
|
|
if(!isFg)
|
|
|
|
{
|
|
|
|
if (bgColorTween != null)
|
|
|
|
bgColorTween.Kill(true);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (fgColorTween != null)
|
|
|
|
fgColorTween.Kill(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (seconds == 0)
|
|
|
|
{
|
|
|
|
if(!isFg) bg.color = color;
|
|
|
|
if (isFg) fg.color = color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!isFg) bgColorTween = bg.DOColor(color, seconds);
|
|
|
|
if(isFg) fgColorTween = fg.DOColor(color, seconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FadeBackgroundColor(Color start, Color end, float beats, bool isFg = false)
|
|
|
|
{
|
|
|
|
ChangeBackgroundColor(start, 0f, isFg);
|
|
|
|
ChangeBackgroundColor(end, beats, isFg);
|
|
|
|
}
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
}
|