forked from Shardstone/trail-into-darkness
118 lines
5.2 KiB
C#
118 lines
5.2 KiB
C#
using Jovian.InGameLogging;
|
|
using Jovian.InGameLogging.UI;
|
|
using Jovian.Logger;
|
|
using Jovian.SaveSystem;
|
|
using Nox.Core;
|
|
using Nox.Game;
|
|
using Nox.Game.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using PlayMode = Nox.Core.PlayMode;
|
|
|
|
namespace Nox.UI {
|
|
public class CharacterCreationView : IGameLifecycle, IMenuView {
|
|
public ISaveSystem SaveSystem { get; }
|
|
private readonly CharacterCreationReference characterCreationReference;
|
|
private readonly MenuGameStateData menuGameStateData;
|
|
private readonly GameDataState gameDataState;
|
|
private readonly PartySettings partySettings;
|
|
private readonly ICharacterSystems characterSystems;
|
|
private readonly PortraitsHolder portraitsHolder;
|
|
|
|
private List<CharacterCreationRequest> characterCreationRequests;
|
|
private Action canStartCheck;
|
|
private GameLogView gameLogView;
|
|
private InGameLogger inGameLogger;
|
|
|
|
public CharacterCreationView(CharacterCreationReference characterCreationReference,
|
|
MenuGameStateData menuGameStateData,
|
|
ISaveSystem saveSystem,
|
|
GameDataState gameDataState,
|
|
PartySettings partySettings,
|
|
ICharacterSystems characterSystems,
|
|
PortraitsHolder portraitsHolder) {
|
|
SaveSystem = saveSystem;
|
|
this.characterCreationReference = characterCreationReference;
|
|
this.menuGameStateData = menuGameStateData;
|
|
this.gameDataState = gameDataState;
|
|
this.partySettings = partySettings;
|
|
this.characterSystems = characterSystems;
|
|
this.portraitsHolder = portraitsHolder;
|
|
}
|
|
|
|
public void Initialize() {
|
|
var store = new GameLogStore(500);
|
|
gameLogView = characterCreationReference.gameLogView;
|
|
gameLogView.Initialize(store);
|
|
inGameLogger = new InGameLogger(store, LogChannel.CharacterCreation);
|
|
inGameLogger.Enable();
|
|
|
|
canStartCheck = () => {
|
|
var canStart = characterCreationRequests is { Count: > 0 };
|
|
characterCreationReference.startGameButton.interactable = canStart;
|
|
};
|
|
|
|
characterCreationReference.startGameButton.interactable = false;
|
|
characterCreationReference.startGameButton.onClick.AddListener(() => {
|
|
Hide();
|
|
menuGameStateData.startGameRequests?.Invoke(PlayMode.Adventure);
|
|
});
|
|
characterCreationReference.backButton.onClick.AddListener(Hide);
|
|
characterCreationReference.backButtonCenter.onClick.AddListener(Hide);
|
|
characterCreationReference.acceptButton.onClick.AddListener(() => {
|
|
if(characterCreationRequests == null || characterCreationRequests.Count == 0) {
|
|
GlobalLogger.LogWarning("No characters selected. Creating party from the test party definition sets", LogCategory.GameLogic);
|
|
var randomIndex = UnityEngine.Random.Range(0, partySettings.testPartyDefinitionSets.Count - 1);
|
|
var protagonist = partySettings.testPartyDefinitionSets[randomIndex].partyDefinition.Protagonist;
|
|
characterCreationRequests = new List<CharacterCreationRequest> {
|
|
new() {
|
|
Id = Guid.NewGuid(),
|
|
Name = protagonist.Name,
|
|
Race = protagonist.Race,
|
|
Class = protagonist.Class,
|
|
Role = CharacterRole.Protagonist,
|
|
Attributes = protagonist.Attributes,
|
|
Stats = protagonist.Stats,
|
|
Perks = protagonist.Perks,
|
|
Modifiers = protagonist.Modifiers
|
|
}
|
|
};
|
|
}
|
|
CreateParty();
|
|
canStartCheck.Invoke();
|
|
});
|
|
|
|
}
|
|
|
|
private void CreateParty() {
|
|
var partyCreatorModel = new PartyCreatorModel(characterSystems.CharacterFactory, characterSystems.PartyFactory, characterCreationRequests, partySettings);
|
|
var party = partyCreatorModel.CreatePartyForNewRun();
|
|
gameDataState.ActiveParty = party;
|
|
|
|
inGameLogger.Log("Character Creation Results:");
|
|
inGameLogger.Log($"Protagonist: {party.Protagonist.Name}", "#FFBF00");
|
|
inGameLogger.Log($"Protagonist Race: {party.Protagonist.Race}");
|
|
inGameLogger.Log($"Protagonist Class: {party.Protagonist.Class}");
|
|
inGameLogger.Log($"Companions: {party.Companions.Count}");
|
|
inGameLogger.Log($"{party.Protagonist.Attributes}");
|
|
inGameLogger.Log($"{party.Protagonist.Stats}");
|
|
inGameLogger.Log($"{party.Protagonist.Perks}");
|
|
inGameLogger.Log($"{party.Protagonist.Modifiers}");
|
|
}
|
|
|
|
public void Tick() {
|
|
return;
|
|
}
|
|
public void Show() {
|
|
characterCreationReference.gameObject.SetActive(true);
|
|
}
|
|
public void Hide() {
|
|
characterCreationReference.gameObject.SetActive(false);
|
|
}
|
|
public void Dispose() {
|
|
inGameLogger.Disable();
|
|
}
|
|
}
|
|
}
|