2022-05-01 18:22:00 +00:00
|
|
|
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-04-02 02:28:23 +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
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
function = delegate { CoinToss.instance.TossCoin(eventCaller.currentEntity.beat, eventCaller.currentEntity["type"], eventCaller.currentEntity["toggle"]); },
|
|
|
|
defaultLength = 7,
|
2022-08-21 03:13:52 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("type", CoinToss.CoinVariation.Default, "Variation", "Choose the version of the cue to play."),
|
|
|
|
new Param("toggle", false, "Audience Reaction", "Toggle if there should be cheering or booing after the cue."),
|
2022-08-21 03:13:52 +00:00
|
|
|
}
|
|
|
|
},
|
2024-01-15 02:04:10 +00:00
|
|
|
new GameAction("fade background color", "Background Appearance")
|
2022-05-06 20:23:52 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity;
|
|
|
|
CoinToss.instance.BackgroundColor(e.beat, e.length, e["colorStart"], e["colorEnd"], e["colorStartF"], e["colorEndF"], e["ease"]); },
|
2023-10-29 19:44:47 +00:00
|
|
|
resizable = true,
|
2023-08-12 03:30:03 +00:00
|
|
|
defaultLength = 4f,
|
2022-08-21 03:13:52 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2024-01-15 02:04:10 +00:00
|
|
|
new Param("colorStart", CoinToss.defaultBgColor, "BG Start Color", "Set the color for the outer ring at the start of the event."),
|
|
|
|
new Param("colorEnd", CoinToss.defaultBgColor, "BG End Color", "Set the color for the outer ring at the end of the event."),
|
|
|
|
new Param("colorStartF", CoinToss.defaultBgColor, "FG Start Color", "Set the color for the inner oval at the start of the event."),
|
|
|
|
new Param("colorEndF", CoinToss.defaultBgColor, "FG End Color", "Set the color for the inner oval at the end of the event."),
|
|
|
|
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing for the action.")
|
2023-10-29 19:44:47 +00:00
|
|
|
}
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
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
|
2023-08-12 03:30:03 +00:00
|
|
|
new GameAction("set background color", "Set Background Color")
|
2022-07-10 02:42:28 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
function = delegate { var e = eventCaller.currentEntity; CoinToss.instance.BackgroundColor(e.beat, e.length, e["colorA"], e["colorA"], e["colorB"], e["colorB"], (int)Util.EasingFunction.Ease.Instant); },
|
|
|
|
defaultLength = 0.5f,
|
2022-08-21 03:13:52 +00:00
|
|
|
parameters = new List<Param>()
|
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
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")
|
|
|
|
},
|
|
|
|
hidden = true
|
2022-08-21 03:13:52 +00:00
|
|
|
},
|
2022-06-12 19:32:00 +00:00
|
|
|
},
|
2023-10-29 19:44:47 +00:00
|
|
|
new List<string>() { "ntr", "aim" },
|
2022-06-12 19:32:00 +00:00
|
|
|
"ntrcoin", "en",
|
2023-10-29 19:44:47 +00:00
|
|
|
new List<string>() { }
|
2022-06-12 19:32:00 +00:00
|
|
|
);
|
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
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
public static PlayerInput.InputAction InputAction_TouchFlick =
|
|
|
|
new("NtrCoinTouchFlick", new int[] { IAEmptyCat, IAFlickCat, IAEmptyCat },
|
|
|
|
IA_Empty, IA_TouchFlick, IA_Empty);
|
|
|
|
|
2022-05-01 18:22:00 +00:00
|
|
|
public static CoinToss instance { get; set; }
|
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
public static Color defaultBgColor = new Color(0.97f, 0.97f, 0.26f);
|
|
|
|
public static Color defaultFgColor = new Color(1f, 1f, 0.51f);
|
2023-10-29 19:44:47 +00:00
|
|
|
|
2022-05-06 20:23:52 +00:00
|
|
|
|
|
|
|
[Header("Backgrounds")]
|
|
|
|
public SpriteRenderer fg;
|
|
|
|
public SpriteRenderer bg;
|
|
|
|
|
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
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
BackgroundColorUpdate();
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 03:30:03 +00:00
|
|
|
private void Update()
|
2022-05-01 18:22:00 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
BackgroundColorUpdate();
|
2023-10-29 19:44:47 +00:00
|
|
|
|
|
|
|
if (coin != null && (!coin.canHit) && PlayerInput.GetIsAction(InputAction_TouchFlick))
|
|
|
|
{
|
|
|
|
coin.CanHit(true);
|
|
|
|
isThrowing = true;
|
|
|
|
handAnimator.Play("Throw_empty", 0, 0);
|
|
|
|
}
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
public override void OnPlay(double beat) => PersistColor(beat);
|
|
|
|
public override void OnGameSwitch(double beat) => PersistColor(beat);
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void TossCoin(double 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
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("coinToss/throw");
|
2022-05-01 18:22:00 +00:00
|
|
|
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)
|
2023-10-29 19:44:47 +00:00
|
|
|
{
|
|
|
|
case (int)CoinVariation.Cowbell:
|
|
|
|
//this was intentional. it was to avoid the throw and cowbells to go offbeat.
|
|
|
|
SoundByte.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
|
|
|
});
|
2023-10-29 19:44:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-03 20:36:55 +00:00
|
|
|
this.audienceReacting = audienceReacting;
|
2022-05-01 21:49:55 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
coin = ScheduleInput(beat, 6f, InputAction_BasicPress, CatchSuccess, CatchMiss, CatchEmpty);
|
2022-05-06 20:05:19 +00:00
|
|
|
//coin.perfectOnly = true;
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 20:05:19 +00:00
|
|
|
public void CatchSuccess(PlayerActionEvent caller, float state)
|
2022-05-01 20:10:00 +00:00
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShotGame("coinToss/catch");
|
2023-10-29 19:44:47 +00:00
|
|
|
if (this.audienceReacting) SoundByte.PlayOneShot("applause");
|
2022-05-01 20:10:00 +00:00
|
|
|
handAnimator.Play("Catch_success", 0, 0);
|
|
|
|
|
2023-10-29 19:44:47 +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
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("miss");
|
2023-10-29 19:44:47 +00:00
|
|
|
if (this.audienceReacting) SoundByte.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
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
private ColorEase bgColorEase = new(defaultBgColor);
|
|
|
|
private ColorEase bgFColorEase = new(defaultBgColor);
|
2023-08-12 03:30:03 +00:00
|
|
|
|
2024-03-04 03:50:46 +00:00
|
|
|
// call this in update
|
2023-08-12 03:30:03 +00:00
|
|
|
private void BackgroundColorUpdate()
|
2022-05-06 20:23:52 +00:00
|
|
|
{
|
2024-03-04 03:50:46 +00:00
|
|
|
bg.color = bgColorEase.GetColor();
|
|
|
|
fg.color = bgFColorEase.GetColor();
|
2023-08-12 03:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, Color colorStartSetF, Color colorEndSetF, int ease)
|
|
|
|
{
|
2024-03-04 03:50:46 +00:00
|
|
|
bgColorEase = new ColorEase(beat, length, colorStartSet, colorEndSet, ease);
|
|
|
|
bgFColorEase = new ColorEase(beat, length, colorStartSetF, colorEndSetF, ease);
|
2023-08-12 03:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//call this in OnPlay(double beat) and OnGameSwitch(double beat)
|
|
|
|
private void PersistColor(double beat)
|
|
|
|
{
|
|
|
|
var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("coinToss", new string[] { "fade background color" }).FindAll(x => x.beat < beat);
|
|
|
|
if (allEventsBeforeBeat.Count > 0)
|
2022-05-06 20:23:52 +00:00
|
|
|
{
|
2023-08-12 03:30:03 +00:00
|
|
|
allEventsBeforeBeat.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case
|
|
|
|
var lastEvent = allEventsBeforeBeat[^1];
|
|
|
|
BackgroundColor(lastEvent.beat, lastEvent.length, lastEvent["colorStart"], lastEvent["colorEnd"], lastEvent["colorStartF"], lastEvent["colorEndF"], lastEvent["ease"]);
|
2022-05-06 20:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-01 18:22:00 +00:00
|
|
|
}
|
|
|
|
}
|