CoreGameplay

This commit is contained in:
ThomasCharester committed 2025-11-21 20:27:11 +03:00
1 parent 5da64a7b3d
commit 388773129d
96 files changed
+4037 -2489

No files matched your search

@@ -1,16 +1,23 @@
using System.Globalization;
using System.Reflection.Emit;
using Code.App.StateMachine;
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Camera.CameraStates;
using Code.Gameplay.Character.Core;
using Code.Gameplay.Orders.Order;
using Code.Gameplay.Orders.Order;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
using Code.Scenes.SceneEnvironments;
using Code.StateMachine;
using Code.UI;
using Code.UI.Panels;
using Cysharp.Threading.Tasks;
using Reflex.Core;
using Reflex.Extensions;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
@@ -18,13 +25,13 @@ using UnityEngine.SceneManagement;
namespace Code.App.AppStates
{
public class GameplayState : BaseState<AppStateMachineContext>
{
// DEBUG
private Transform _testSFXTransform;
// DEBUG
{
private PlayerHealth _playerHealth;
private PlayerMoney _playerMoney;
private IScoreService _scoreService;
private IOrderService _orderService;
private CharacterProvider _playerCharacter;
@@ -45,87 +52,101 @@ namespace Code.App.AppStates
Context.InputService.EnableMap(ActionMappings.Gameplay);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveMoney);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveOrderDEBUG);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, RecieveOrderDEBUG);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, DeliverOrderDEBUG);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, RoomPassedDEBUG);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, Tube);
// Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
WaitForSceneToLoad();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private async UniTask WaitForPlayerCharacterLoad() => _playerCharacter = await Context.PlayerFactory.CreatePlayer();
private async UniTaskVoid WaitForSceneToLoad()
{
{
await Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.Gameplay);
await UniTask.WhenAll(
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.Gameplay),
Context.UIService.AsyncSwitchPanelTo(UIPanel.Gameplay),
// TODO
Context.AudioFactory.WarmGameplayMusic(),
Context.AudioFactory.WarmSFX(),
Context.AudioFactory.WarmDispatcher(),
// TODO
WaitForPlayerArmsToInitialize(),
WaitForPlayerCharacterLoad()
);
);
MusicInitialize();
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Peaceful);
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Action);
Container sceneContainer = SceneManager.GetActiveScene().GetSceneContainer();
var sceneEnvironment = ((GameplaySceneEnvironment)SceneManager.GetActiveScene()
.GetSceneContainer().Resolve<CurrentSceneEnvironment>());
GameplaySceneEnvironment sceneEnvironment = SceneEnvironmentVariables(sceneContainer);
_testSFXTransform = sceneEnvironment.debugSfxTarget;
PlayerInitialize(sceneEnvironment);
_playerCharacter.Teleport(sceneEnvironment.playerSpawnPoint.position, sceneEnvironment.playerSpawnPoint.rotation);
UIInitialize();
((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
CameraInitialize();
InputServiceInitialize();
GameplayServicesInitialize(sceneContainer);
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(_playerCharacter.GetFollowTransform());
Context.InputService.EnableMap(ActionMappings.Gameplay);
_tickEnabled = true;
Context.UIService.LoadingScreen.Hide();
}
private void OnCharacterSpawn(CharacterProvider characterProvider)
{
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(_playerCharacter.GetFollowTransform());
}
private void PlayDebugSFX(InputAction.CallbackContext context)
{
Context.AudioService.PlaySFX(SFXSounds.Crowbar, _testSFXTransform.position);
}
private void PlayDebugDispatcher(InputAction.CallbackContext context)
{
Context.AudioService.PlayDispatcher(DispatcherSounds.AhFreeman);
}
private void GiveHealth(InputAction.CallbackContext context)
{
_playerHealth.GetDamage(-1);
}
private async UniTask WaitForPlayerArmsToInitialize() => _armsMesh = await Context.PlayerFactory.CreateArms(Context.CameraStateMachine.Camera.transform);
private void LooseHealth(InputAction.CallbackContext context)
{
_playerHealth.GetDamage(1);
private void OrderGiven(float time)
{
}
private void GiveMoney(InputAction.CallbackContext context)
private void OrderRecieved(float time)
{
_playerMoney.GiveMoney(100);
((GameplayPanel)(Context.UIService.CurrentPanel)).SummonDispatcher();
Context.AudioService.PlayDispatcher((DispatcherSounds)Random.Range((int)DispatcherSounds.Recieve1,(int)DispatcherSounds.Recieve2));
}
private void LooseMoney(InputAction.CallbackContext context)
{
_playerMoney.LooseMoney(100);
((GameplayPanel)(Context.UIService.CurrentPanel)).CloseDispatcher();
private void OrderDelivered(int score, float time)
{
if(time < 0f) Context.AudioService.PlayDispatcher((DispatcherSounds)Random.Range((int)DispatcherSounds.Late1,(int)DispatcherSounds.Late2));
_playerMoney.GiveMoney(score);
}
// DEBUG
private void GiveOrderDEBUG(InputAction.CallbackContext context)
{
_orderService.OrderGive();
}
private void RecieveOrderDEBUG(InputAction.CallbackContext context)
{
_orderService.OrderRecieved();
}
private void DeliverOrderDEBUG(InputAction.CallbackContext context)
{
_orderService.OrderDelivered();
}
private void RoomPassedDEBUG(InputAction.CallbackContext context)
{
_orderService.RoomPassed();
}
private OrderDispenser _debugTube;
private void Tube(InputAction.CallbackContext context)
{
_debugTube.ThrowOrder();
}
// DEBUG
private bool _tickEnabled;
public override void Tick()
{
if (!_tickEnabled) return;
// TODO ГРЯЗь
_gameplayPanel.Timer.text = ((int)_orderService.DecreaseTimer(Time.deltaTime)).ToString(CultureInfo.CurrentCulture);
}
private void EndGame()
@@ -139,21 +160,71 @@ namespace Code.App.AppStates
_playerHealth = null;
_playerMoney = null;
_tickEnabled = false;
Context.PlayerFactory.ReleasePlayer(_playerCharacter);
_playerCharacter = null;
Context.PlayerFactory.ReleaseArms(_armsMesh);
_armsMesh = null;
Context.InputService.DisableMap(ActionMappings.Gameplay);
Context.AudioService.GladlyAskToStopMusic(MusicType.Action, callback: Context.AudioFactory.ReleaseActionMusic);
Context.AudioService.GladlyAskToStopMusic(MusicType.Peaceful, callback: Context.AudioFactory.ReleasePeacefulMusic);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveOrderDEBUG);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, RecieveOrderDEBUG);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, DeliverOrderDEBUG);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, RoomPassedDEBUG);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, Tube);
// Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
base.ExitState();
}
private void InputServiceInitialize()
{
Context.InputService.EnableMap(ActionMappings.Gameplay);
}
private void CameraInitialize()
{
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(_playerCharacter.GetFollowTransform());
}
private GameplayPanel _gameplayPanel;
private ArmsMeshProvider _armsMesh;
private void UIInitialize()
{
_gameplayPanel = (GameplayPanel)Context.UIService.CurrentPanel;
_gameplayPanel.Initialize(_playerMoney, _playerHealth);
}
private void MusicInitialize()
{
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Peaceful);
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Action);
}
private void PlayerInitialize(GameplaySceneEnvironment sceneEnvironment)
{
_playerCharacter.Teleport(sceneEnvironment.playerSpawnPoint.position, sceneEnvironment.playerSpawnPoint.rotation);
_playerCharacter.PlayerAnimator.SetAnimator(_armsMesh.ArmsAnimator);
}
private void GameplayServicesInitialize(Container sceneContainer)
{
_scoreService = sceneContainer.Resolve<IScoreService>();
_orderService = sceneContainer.Resolve<IOrderService>();
_orderService.OnOrderGiven += OrderGiven;
_orderService.OnOrderRecieved += OrderRecieved;
_orderService.OnOrderDelivered += OrderDelivered;
}
private GameplaySceneEnvironment SceneEnvironmentVariables(Container sceneContainer)
{
var sceneEnvironment = (GameplaySceneEnvironment)sceneContainer.Resolve<CurrentSceneEnvironment>();
_debugTube = sceneEnvironment.debugTube;
return sceneEnvironment;
}
}
}