Skip to content

Commit

Permalink
created YaridaTrainingGameMode
Browse files Browse the repository at this point in the history
  • Loading branch information
guerro323 committed Aug 16, 2020
1 parent 44141c1 commit 531a0d0
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 154 deletions.
2 changes: 1 addition & 1 deletion PataNext.Export.Desktop/Updater/SquirrelUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task checkForUpdate(bool deltaPatching = true)
else
{
notification.State = ProgressNotificationState.Cancelled;
notification.Text = "Update failed :(";
notification.Text = "Update failed :(\nRe-Downloading the full setup is recommended.";
Logger.Error(ex, "Update failed!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ protected override void OnUpdatePass()
var comboState = GameWorld.GetComponentData<GameCombo.State>(LocalEngine);

if (state.CurrentBeat < 0)
{
AudioPlayerUtility.Stop(audioPlayer);
return;
}

var targetAudio = m_LastClip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnDependenciesResolved(IEnumerable<object> dependencies)

public override bool CanUpdate()
{
return LocalEngine != default && base.CanUpdate();
return LocalEngine != default && LocalInformation.Elapsed >= TimeSpan.Zero && base.CanUpdate();
}

private EntityQuery abilityQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using StormiumTeam.GameBase.Camera.Components;
using StormiumTeam.GameBase.Roles.Components;
using StormiumTeam.GameBase.Roles.Descriptions;
using StormiumTeam.GameBase.SystemBase;
using StormiumTeam.GameBase.Time;
using StormiumTeam.GameBase.Time.Components;

Expand All @@ -61,28 +62,27 @@ public struct JInputSettings
[UpdateAfter(typeof(SetGameTimeSystem))]
[UpdateAfter(typeof(ReceiveInputDataSystem))]
[UpdateBefore(typeof(ManageComponentTagSystem))]
public class RegisterRhythmEngineInputSystem : AppSystem, IRhythmEngineSimulationPass
public class RegisterRhythmEngineInputSystem : GameAppSystem, IRhythmEngineSimulationPass
{
private InputDatabase inputDb;
private IManagedWorldTime time;

private PlayableUnitProvider playableUnitProvider;
private AbilityCollectionSystem abilityCollectionSystem;

private IScheduler scheduler;
private IScheduler scheduler;
private GameHostModule module;

private JInputSettings inputSettings;

public RegisterRhythmEngineInputSystem(WorldCollection collection) : base(collection)
{
DependencyResolver.Add(() => ref inputDb);
DependencyResolver.Add(() => ref gameWorld);
DependencyResolver.Add(() => ref time);

DependencyResolver.Add(() => ref playableUnitProvider);
DependencyResolver.Add(() => ref abilityCollectionSystem);

DependencyResolver.Add(() => ref scheduler);
DependencyResolver.Add(() => ref module);
}
Expand All @@ -93,17 +93,14 @@ public RegisterRhythmEngineInputSystem(WorldCollection collection) : base(collec
private Entity ability1Action;
private Entity ability2Action;

private GameWorld gameWorld;
private GameEntity gameEntityTest;

private int spawnInFrame;

protected override void OnDependenciesResolved(IEnumerable<object> dependencies)
{
base.OnDependenciesResolved(dependencies);

spawnInFrame = 10;

module.Storage.Subscribe((_, storage) =>
{
module.Storage.UnsubscribeCurrent();
Expand All @@ -115,13 +112,12 @@ protected override void OnDependenciesResolved(IEnumerable<object> dependencies)
private void CreateInputs(IStorage storage)
{
rhythmActionMap = new Dictionary<int, Entity>();

using var stream = new MemoryStream(storage.GetFilesAsync("input.json").Result.First().GetContentAsync().Result);
using var reader = new JsonTextReader(new StreamReader(stream));

var serializer = new JsonSerializer();
var input = serializer.Deserialize<JInputSettings>(reader);
Console.WriteLine(input.SliderSensibility);

static CInput[] ct(IEnumerable<string> map) => map.Select(str => new CInput(str)).ToArray();

Expand All @@ -130,11 +126,11 @@ private void CreateInputs(IStorage storage)
rhythmActionMap[1] = inputDb.RegisterSingle<RhythmInputAction>(new RhythmInputAction.Layout(lyt, ct(input.PonKeys)));
rhythmActionMap[2] = inputDb.RegisterSingle<RhythmInputAction>(new RhythmInputAction.Layout(lyt, ct(input.DonKeys)));
rhythmActionMap[3] = inputDb.RegisterSingle<RhythmInputAction>(new RhythmInputAction.Layout(lyt, ct(input.ChakaKeys)));

ability0Action = inputDb.RegisterSingle<PressAction>(new PressAction.Layout(lyt, ct(input.Ability0Keys)));
ability1Action = inputDb.RegisterSingle<PressAction>(new PressAction.Layout(lyt, ct(input.Ability1Keys)));
ability2Action = inputDb.RegisterSingle<PressAction>(new PressAction.Layout(lyt, ct(input.Ability2Keys)));

panningAction = inputDb.RegisterSingle<AxisAction>(new AxisAction.Layout(lyt, ct(input.PanningNegativeKeys), ct(input.PanningPositiveKeys)));

inputSettings = input;
Expand All @@ -147,140 +143,6 @@ protected override void OnUpdate()
return;
spawnInFrame = -999;

var localKitDb = new GameResourceDb<UnitKitResource, UnitKitResourceKey>(gameWorld);
var localAttachDb = new GameResourceDb<UnitAttachmentResource, UnitAttachmentResourceKey>(gameWorld);
var localEquipDb = new GameResourceDb<EquipmentResource, EquipmentResourceKey>(gameWorld);

gameEntityTest = gameWorld.CreateEntity();
gameWorld.AddComponent(gameEntityTest, new PlayerDescription());
gameWorld.AddComponent(gameEntityTest, new PlayerInputComponent());
gameWorld.AddComponent(gameEntityTest, new PlayerIsLocal());

var unitTarget = gameWorld.CreateEntity();
gameWorld.AddComponent(unitTarget, new UnitTargetDescription());
gameWorld.AddComponent(unitTarget, new Position());
gameWorld.AddComponent(unitTarget, new Relative<PlayerDescription>(gameEntityTest));

var rhythmEngine = gameWorld.CreateEntity();
gameWorld.AddComponent(rhythmEngine, new RhythmEngineDescription());
gameWorld.AddComponent(rhythmEngine, new RhythmEngineController {State = RhythmEngineState.Playing, StartTime = time.Total.Add(TimeSpan.FromSeconds(2))});
gameWorld.AddComponent(rhythmEngine, new RhythmEngineSettings {BeatInterval = TimeSpan.FromSeconds(0.5), MaxBeat = 4});
gameWorld.AddComponent(rhythmEngine, new RhythmEngineLocalState());
gameWorld.AddComponent(rhythmEngine, new RhythmEngineExecutingCommand());
gameWorld.AddComponent(rhythmEngine, new Relative<PlayerDescription>(gameEntityTest));
gameWorld.AddComponent(rhythmEngine, gameWorld.AsComponentType<RhythmEngineLocalCommandBuffer>());
gameWorld.AddComponent(rhythmEngine, gameWorld.AsComponentType<RhythmEnginePredictedCommandBuffer>());
gameWorld.AddComponent(rhythmEngine, new GameCommandState());
gameWorld.AddComponent(rhythmEngine, new IsSimulationOwned());
GameCombo.AddToEntity(gameWorld, rhythmEngine);
RhythmSummonEnergy.AddToEntity(gameWorld, rhythmEngine);

for (var i = 0; i != 1; i++)
{
var unit = playableUnitProvider.SpawnEntityWithArguments(new PlayableUnitProvider.Create
{
Statistics = new UnitStatistics
{
BaseWalkSpeed = 2,
FeverWalkSpeed = 2.2f,
MovementAttackSpeed = 3.1f,
Weight = 8.5f,
},
Direction = UnitDirection.Right
});
gameWorld.GetComponentData<Position>(unit).Value.X += 8;
gameWorld.GetComponentData<Position>(unitTarget).Value.X -= 8;

gameWorld.AddComponent(unit, new UnitCurrentKit(localKitDb.GetOrCreate(new UnitKitResourceKey("taterazay"))));
gameWorld.AddComponent(unit, new Relative<PlayerDescription>(gameEntityTest));
gameWorld.AddComponent(unit, new Relative<UnitTargetDescription>(unitTarget));
gameWorld.AddComponent(unit, new UnitEnemySeekingState());
gameWorld.AddComponent(unit, new UnitTargetOffset());
gameWorld.AddComponent(unit, new UnitTargetControlTag());

var displayedEquip = gameWorld.AddBuffer<UnitDisplayedEquipment>(unit);
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("Mask"),
Resource = localEquipDb.GetOrCreate("Masks/n_kibadda")
});
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("LeftEquipment"),
Resource = localEquipDb.GetOrCreate("Shields/default_shield")
});
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("RightEquipment"),
Resource = localEquipDb.GetOrCreate("Swords/default_sword")
});

abilityCollectionSystem.SpawnFor("march", unit);
abilityCollectionSystem.SpawnFor("backward", unit);
abilityCollectionSystem.SpawnFor("retreat", unit);
abilityCollectionSystem.SpawnFor("jump", unit);
abilityCollectionSystem.SpawnFor("party", unit);
abilityCollectionSystem.SpawnFor("charge", unit);
abilityCollectionSystem.SpawnFor("CTate.BasicDefendFrontal", unit);
abilityCollectionSystem.SpawnFor("CTate.BasicDefendStay", unit, AbilitySelection.Top);
abilityCollectionSystem.SpawnFor("CTate.EnergyField", unit);

gameWorld.AddComponent(gameEntityTest, new ServerCameraState
{
Data =
{
Mode = CameraMode.Forced,
Offset = RigidTransform.Identity,
Target = unit
}
});

gameWorld.AddComponent(unit, new Relative<RhythmEngineDescription>(rhythmEngine));
}

// No favor
for (var i = 0; i != 32; i++)
{
var unit = playableUnitProvider.SpawnEntityWithArguments(new PlayableUnitProvider.Create
{
Statistics = new UnitStatistics
{
BaseWalkSpeed = 0.75f,
FeverWalkSpeed = 0.75f,
MovementAttackSpeed = 0.75f,
Weight = 8.5f,
},
Direction = UnitDirection.Right
});

var tt = gameWorld.CreateEntity();
gameWorld.AddComponent(tt, new UnitTargetDescription());
gameWorld.AddComponent(tt, new Position());
gameWorld.GetComponentData<Position>(tt).Value.X = i * 10;

gameWorld.AddComponent(unit, new UnitCurrentKit(localKitDb.GetOrCreate(new UnitKitResourceKey("yarida"))));
gameWorld.AddComponent(unit, new UnitEnemySeekingState());
gameWorld.AddComponent(unit, new UnitTargetOffset());
gameWorld.AddComponent(unit, new Relative<UnitTargetDescription>(tt));

var displayedEquip = gameWorld.AddBuffer<UnitDisplayedEquipment>(unit);
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("Mask"),
Resource = localEquipDb.GetOrCreate("Masks/n_yarida")
});
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("RightEquipment"),
Resource = localEquipDb.GetOrCreate("Spears/default_spear")
});
displayedEquip.Add(new UnitDisplayedEquipment
{
Attachment = localAttachDb.GetOrCreate("LeftEquipment"),
Resource = localEquipDb.GetOrCreate("Masks/n_taterazay")
});
}

/*Console.WriteLine("BEGIN");
foreach (var pass in World.DefaultSystemCollection.Passes)
{
Expand Down Expand Up @@ -310,16 +172,20 @@ public void OnRhythmEngineSimulationPass()
return;

GameTime gameTime = default;
foreach (var entity in gameWorld.QueryEntityWith(stackalloc[] {gameWorld.AsComponentType<GameTime>()}))
foreach (var entity in GameWorld.QueryEntityWith(stackalloc[] {GameWorld.AsComponentType<GameTime>()}))
{
gameTime = gameWorld.GetComponentData<GameTime>(entity);
gameTime = GameWorld.GetComponentData<GameTime>(entity);
break;
}

if (gameTime.Frame == default)
return;

ref var input = ref gameWorld.GetComponentData<PlayerInputComponent>(gameEntityTest);
var query = GameWorld.QueryEntityWith(stackalloc[] {AsComponentType<PlayerInputComponent>()});
if (!query.TryGetFirst(out var playerEntity))
return;

ref var input = ref GameWorld.GetComponentData<PlayerInputComponent>(playerEntity);
input.Panning = panningAction.Get<AxisAction>().Value;

if (ability0Action.Get<PressAction>().HasBeenPressed)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using GameHost.Simulation.Features.ShareWorldState.BaseSystems;
using GameHost.Simulation.TabEcs.Interfaces;

namespace PataNext.Module.Simulation.Components.GameModes
{
public struct YaridaTrainingGameModeData : IComponentData
{
public enum EPhase
{
Waiting = 0,
March = 1,

// huehuehuehuheuheueheuheuehuheueheuheuehuehueheueheuheuheuhue
Backward = 2
}

public EPhase Phase;
public float CurrUberHeroPos;
public int YaridaOvertakeCount;

public float LastCheckpointScore;
public float LastCheckpointTime;

public class Register : RegisterGameHostComponentData<YaridaTrainingGameModeData>
{}
}
}
3 changes: 3 additions & 0 deletions PataNext.Simulation.Mixed/CustomModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public CustomModule(Entity source, Context ctxParent, GameHostModuleDescription
simulationApplication.Data.Collection.GetOrCreate(typeof(Game.RhythmEngine.Systems.GetNextCommandEngineSystem));
simulationApplication.Data.Collection.GetOrCreate(typeof(Game.RhythmEngine.Systems.ApplyCommandEngineSystem));
simulationApplication.Data.Collection.GetOrCreate(typeof(Game.RhythmEngine.Systems.RhythmEngineResizeCommandBufferSystem));

simulationApplication.Data.Collection.GetOrCreate(typeof(GameModes.YaridaTrainingGameMode));
simulationApplication.Data.Collection.GetOrCreate(typeof(GameModes.StartYaridaTrainingGameMode));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public override void OnRhythmEngineSimulationPass()
ref var executing = ref GameWorld.GetComponentData<GameCommandState>(entity);

var renderBeat = RhythmEngineUtility.GetFlowBeat(state, settings);
if (renderBeat < 0)
return;

var progressionBuffer = GameWorld.GetBuffer<RhythmEngineLocalCommandBuffer>(entity);
var predictedBuffer = GameWorld.GetBuffer<RhythmEnginePredictedCommandBuffer>(entity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GameHost.Core;
using System;
using GameHost.Core;
using GameHost.Core.Ecs;
using GameHost.Simulation.Utility.EntityQuery;
using GameHost.Worlds.Components;
Expand All @@ -25,7 +26,6 @@ public override void OnRhythmEngineSimulationPass()

foreach (var entity in GameWorld.QueryEntityWith(stackalloc[]
{
GameWorld.AsComponentType<RhythmEngineIsPlaying>(),
GameWorld.AsComponentType<RhythmEngineController>(),
GameWorld.AsComponentType<RhythmEngineLocalState>(),
GameWorld.AsComponentType<RhythmEngineSettings>()
Expand All @@ -40,11 +40,19 @@ public override void OnRhythmEngineSimulationPass()
var previousBeats = RhythmEngineUtility.GetActivationBeat(previous, settings.BeatInterval);

state.Elapsed = worldTime.Total - controller.StartTime;
if (state.Elapsed < TimeSpan.Zero && HasComponent<RhythmEngineIsPlaying>(entity))
GameWorld.RemoveComponent(entity, AsComponentType<RhythmEngineIsPlaying>());

var currentBeats = RhythmEngineUtility.GetActivationBeat(state, settings);
if (previousBeats != currentBeats)
state.NewBeatTick = (uint) gameTime.Frame;
state.CurrentBeat = currentBeats;

if (!HasComponent<RhythmEngineIsPlaying>(entity))
{
state.RecoveryActivationBeat = -1;
state.LastPressure = default;
}
}

foreach (var entity in GameWorld.QueryEntityWith(stackalloc[]
Expand Down
28 changes: 28 additions & 0 deletions PataNext.Simulation.Mixed/GameModes/StartYaridaTrainingGameMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using GameHost.Core.Ecs;

namespace PataNext.Module.Simulation.GameModes
{
public class StartYaridaTrainingGameMode : AppSystem
{
private YaridaTrainingGameMode trainingGameMode;
private int frame;

private const int targetFrame = 10;

public StartYaridaTrainingGameMode(WorldCollection collection) : base(collection)
{
DependencyResolver.Add(() => ref trainingGameMode);
}

protected override void OnUpdate()
{
base.OnUpdate();

if (frame >= 0 && frame++ > targetFrame)
{
frame = -1;
trainingGameMode.Start(64);
}
}
}
}
Loading

0 comments on commit 531a0d0

Please sign in to comment.