forked from Shardstone/trail-into-darkness
Work on hooking the character system into the character creation
This commit is contained in:
@@ -3,7 +3,7 @@ using ZLinq;
|
||||
|
||||
namespace Nox.Game {
|
||||
public interface ICharacterFactory {
|
||||
CharacterDefinition CreateCustomProtagonist(CustomCharacterCreationRequest request);
|
||||
CharacterDefinition CreateProtagonist(CharacterCreationRequest request);
|
||||
CharacterDefinition CreateFromTemplate(CharacterTemplate template, CharacterRole role = CharacterRole.Companion);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class CustomCharacterCreationRequest : IEntityDefinition {
|
||||
public sealed class CharacterCreationRequest : IEntityDefinition {
|
||||
public Guid Id { get; set; } = Guid.Empty;
|
||||
public string Name { get; set; }
|
||||
public CharacterRace Race { get; set; }
|
||||
@@ -64,7 +64,7 @@ namespace Nox.Game {
|
||||
this.modifiersFactory = modifiersFactory ?? throw new ArgumentNullException(nameof(modifiersFactory));
|
||||
}
|
||||
|
||||
public CharacterDefinition CreateCustomProtagonist(CustomCharacterCreationRequest request) {
|
||||
public CharacterDefinition CreateProtagonist(CharacterCreationRequest request) {
|
||||
if(request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Nox.Game {
|
||||
public static class DefaultCharacterSystemsFactory {
|
||||
public static class CharacterSystemsFactory {
|
||||
public static ICharacterSystems Create(
|
||||
PartySettings partySettings,
|
||||
StarterCharacterSettings starterCharacterSettings,
|
||||
PerksRegistry perksRegistry,
|
||||
CharacterRegistry characterRegistry,
|
||||
@@ -13,7 +14,7 @@ namespace Nox.Game {
|
||||
ICharacterAttributesFactory attributesFactory = new CharacterAttributesFactory(modifierResolver);
|
||||
ICharacterStatsFactory statsFactory = new CharacterStatsFactory(starterCharacterSettings, modifierResolver);
|
||||
ICharacterFactory characterFactory = new CharacterFactory(attributesFactory, statsFactory, perkFactory, modifiersFactory);
|
||||
IPartyFactory partyFactory = new PartyFactory(starterCharacterSettings);
|
||||
IPartyFactory partyFactory = new PartyFactory(partySettings, starterCharacterSettings);
|
||||
|
||||
return new CharacterSystems(perkFactory, modifiersFactory, modifierResolver, characterFactory, partyFactory);
|
||||
}
|
||||
@@ -1,52 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Nox.Game {
|
||||
public class PartyCreatorModel {
|
||||
private readonly ICharacterFactory characterFactory;
|
||||
private readonly IPartyFactory partyFactory;
|
||||
private readonly DefaultPartySettings defaultPartySettings;
|
||||
public PartyCreatorModel(ICharacterFactory characterFactory, IPartyFactory partyFactory, DefaultPartySettings defaultPartySettings) {
|
||||
private readonly List<CharacterCreationRequest> characterCreationRequests;
|
||||
private readonly PartySettings partySettings;
|
||||
|
||||
public PartyCreatorModel(ICharacterFactory characterFactory,
|
||||
IPartyFactory partyFactory,
|
||||
List<CharacterCreationRequest> characterCreationRequests,
|
||||
PartySettings partySettings) {
|
||||
this.characterFactory = characterFactory;
|
||||
this.partyFactory = partyFactory;
|
||||
this.defaultPartySettings = defaultPartySettings;
|
||||
this.characterCreationRequests = characterCreationRequests;
|
||||
this.partySettings = partySettings;
|
||||
}
|
||||
public PartyDefinition CreatePartyForNewRun(int companionCount) {
|
||||
var protagonist = characterFactory.CreateCustomProtagonist(new CustomCharacterCreationRequest {
|
||||
Name = "John Doe",
|
||||
Attributes = new EntityAttributes {
|
||||
attributes = new[] {
|
||||
new Attribute(AttributeType.Might, 3),
|
||||
new Attribute(AttributeType.Reflex, 3),
|
||||
new Attribute(AttributeType.Knowledge, 3),
|
||||
new Attribute(AttributeType.Perception, 3)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var rookAttributes = new EntityAttributes {
|
||||
attributes = new[] {
|
||||
new Attribute(AttributeType.Might, 6),
|
||||
new Attribute(AttributeType.Knowledge, 2),
|
||||
new Attribute(AttributeType.Perception, 2),
|
||||
new Attribute(AttributeType.Reflex, 4)
|
||||
}
|
||||
};
|
||||
|
||||
CharacterTemplate[] companionTemplates = {
|
||||
new() {
|
||||
Name = "Rook",
|
||||
Attributes = rookAttributes,
|
||||
Perks = new PerksData(){
|
||||
perks = new List<PerkDefinition>()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var companions = new List<CharacterDefinition>();
|
||||
for(var i = 0; i < companionCount && i < companionTemplates.Length; i++) {
|
||||
companions.Add(characterFactory.CreateFromTemplate(companionTemplates[i], CharacterRole.Companion));
|
||||
public PartyDefinition CreatePartyForNewRun() {
|
||||
if(characterCreationRequests.Count > partySettings.maxPartySize) {
|
||||
throw new System.ArgumentException("Too many characters requested.");
|
||||
}
|
||||
|
||||
var protagonist = characterFactory.CreateProtagonist(characterCreationRequests.Find(r => r.Role == CharacterRole.Protagonist));
|
||||
var companions = characterCreationRequests.FindAll(r => r.Role != CharacterRole.Protagonist).Select(r => characterFactory.CreateProtagonist(r));
|
||||
return partyFactory.Create(protagonist, companions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
public sealed class PartyFactory : IPartyFactory {
|
||||
private readonly PartySettings partySettings;
|
||||
private readonly StarterCharacterSettings starterCharacterSettings;
|
||||
|
||||
public PartyFactory(StarterCharacterSettings starterCharacterSettings) {
|
||||
public PartyFactory(PartySettings partySettings, StarterCharacterSettings starterCharacterSettings) {
|
||||
this.partySettings = partySettings;
|
||||
this.starterCharacterSettings = starterCharacterSettings;
|
||||
}
|
||||
|
||||
@@ -20,7 +22,7 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
var party = new PartyDefinition {
|
||||
maxPartySize = starterCharacterSettings.maxPartySize <= 0 ? int.MaxValue : starterCharacterSettings.maxPartySize
|
||||
maxPartySize = partySettings.maxPartySize <= 0 ? int.MaxValue : partySettings.maxPartySize
|
||||
};
|
||||
|
||||
var protagonistClone = protagonist.Clone();
|
||||
|
||||
@@ -5,22 +5,25 @@ using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
[CreateAssetMenu(fileName = "DefaultPartySettings", menuName = "Nox/Database/Entities/Default Party Settings")]
|
||||
public class DefaultPartySettings : ScriptableObject {
|
||||
public class PartySettings : ScriptableObject {
|
||||
[Header("Party System Defaults")]
|
||||
public int maxPartySize = 4;
|
||||
|
||||
[Header("This will be default starting set")]
|
||||
public string startingSetId;
|
||||
public string testStartingSetId;
|
||||
|
||||
[Header("Party Definition Sets")]
|
||||
public List<PartyDefinitionSet> partyDefinitionSets;
|
||||
public List<PartyDefinitionSet> testPartyDefinitionSets;
|
||||
|
||||
[Header("Testing Party Definition Sets")]
|
||||
public StarterCharacterSettings starterCharacterSettings;
|
||||
public StarterCharacterSettings testStarterCharacterSettings;
|
||||
|
||||
private void OnValidate() {
|
||||
if(String.IsNullOrEmpty(startingSetId)) {
|
||||
if(String.IsNullOrEmpty(testStartingSetId)) {
|
||||
Debug.LogError("DefaultPartySettings: startingSetId cannot be null or empty");
|
||||
return;
|
||||
}
|
||||
foreach(var partyDefinitionSet in partyDefinitionSets) {
|
||||
foreach(var partyDefinitionSet in testPartyDefinitionSets) {
|
||||
var partyDefinition = partyDefinitionSet.partyDefinition;
|
||||
if(partyDefinition == null) {
|
||||
return;
|
||||
@@ -32,8 +35,8 @@ namespace Nox.Game {
|
||||
}
|
||||
}
|
||||
|
||||
if(partyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet) != null) {
|
||||
var testingSet = partyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet);
|
||||
if(testPartyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet) != null) {
|
||||
var testingSet = testPartyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet);
|
||||
ApplyClassAndRacialBonuses(testingSet);
|
||||
}
|
||||
|
||||
@@ -47,9 +50,9 @@ namespace Nox.Game {
|
||||
private void ApplyClassAndRacialBonuses(PartyDefinitionSet testingSet) {
|
||||
var partyDefinition = testingSet.partyDefinition;
|
||||
foreach(var member in partyDefinition.members) {
|
||||
var baseSettings = starterCharacterSettings.defaultEntityAttributes;
|
||||
var classAttributes = starterCharacterSettings.classBonuses.AsValueEnumerable().FirstOrDefault(c => c.@class == member.Class)?.bonusAttributes;
|
||||
var racialAttributes = starterCharacterSettings.racialBonuses.AsValueEnumerable().FirstOrDefault(rb => rb.race == member.Race)?.bonusAttributes;
|
||||
var baseSettings = testStarterCharacterSettings.defaultEntityAttributes;
|
||||
var classAttributes = testStarterCharacterSettings.classBonuses.AsValueEnumerable().FirstOrDefault(c => c.@class == member.Class)?.bonusAttributes;
|
||||
var racialAttributes = testStarterCharacterSettings.racialBonuses.AsValueEnumerable().FirstOrDefault(rb => rb.race == member.Race)?.bonusAttributes;
|
||||
if (classAttributes != null && racialAttributes != null) {
|
||||
member.Attributes += baseSettings + classAttributes + racialAttributes;
|
||||
}
|
||||
@@ -14,9 +14,6 @@ namespace Nox.Game {
|
||||
[Header("General Racial Bonuses and Perks per Class")]
|
||||
public RacialBonuses [] racialBonuses;
|
||||
public ClassBonuses [] classBonuses;
|
||||
|
||||
[Header("Party System Defaults")]
|
||||
public int maxPartySize = 4;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Nox.Game {
|
||||
|
||||
gameDataState.activeSessionId = latestSession.sessionId;
|
||||
gameDataState.savedPartyPosition = saveData.partyPosition.ToVector3();
|
||||
gameDataState.ActiveParty = saveData.partyDefinition;
|
||||
gameDataState.ActiveParty = saveData.activeParty;
|
||||
adventureData = saveData.adventureData;
|
||||
|
||||
if(gameLogStore != null && saveData.gameLogData != null) {
|
||||
@@ -59,7 +59,7 @@ namespace Nox.Game {
|
||||
public AdventureData adventureData;
|
||||
|
||||
// Party
|
||||
public PartyDefinition partyDefinition;
|
||||
public PartyDefinition activeParty;
|
||||
public SerializableVector3 partyPosition;
|
||||
|
||||
// In-game log
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Nox.Game {
|
||||
public NoxSavedDataSet CaptureNoxSaveData() {
|
||||
return new NoxSavedDataSet {
|
||||
activePlayMode = PlayMode.Adventure,
|
||||
partyDefinition = partyDefinition,
|
||||
activeParty = partyDefinition,
|
||||
partyPosition = partyRef ? SerializableVector3.FromVector3(partyRef.transform.position) : SerializableVector3.Zero
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
using Jovian.SaveSystem;
|
||||
using Nox.Core;
|
||||
using Nox.Game;
|
||||
using Nox.Game.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nox.UI {
|
||||
public class CharacterCreationView : IMenuView {
|
||||
// we need prefab reference from the menu view, character creation data, save system, modifier calculation, gamemode state to start the game
|
||||
// party creation data/system,
|
||||
public CharacterCreationView(CharacterCreationReference characterCreationReference, MenuGameStateData menuGameStateData) {
|
||||
characterCreationReference.startGameButton.onClick.AddListener(() => menuGameStateData.startGameRequests?.Invoke(PlayMode.Adventure));
|
||||
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 List<CharacterCreationRequest> characterCreationRequests;
|
||||
|
||||
public CharacterCreationView(
|
||||
CharacterCreationReference characterCreationReference,
|
||||
MenuGameStateData menuGameStateData,
|
||||
ISaveSystem saveSystem,
|
||||
GameDataState gameDataState,
|
||||
PartySettings partySettings,
|
||||
ICharacterSystems characterSystems) {
|
||||
SaveSystem = saveSystem;
|
||||
this.characterCreationReference = characterCreationReference;
|
||||
this.menuGameStateData = menuGameStateData;
|
||||
this.gameDataState = gameDataState;
|
||||
this.partySettings = partySettings;
|
||||
this.characterSystems = characterSystems;
|
||||
|
||||
}
|
||||
|
||||
public void Initialize() {
|
||||
throw new System.NotImplementedException();
|
||||
characterCreationReference.startGameButton.onClick.AddListener(() => menuGameStateData.startGameRequests?.Invoke(PlayMode.Adventure));
|
||||
}
|
||||
|
||||
public void CreateParty() {
|
||||
var partyCreatorModel = new PartyCreatorModel(characterSystems.CharacterFactory, characterSystems.PartyFactory, characterCreationRequests, partySettings);
|
||||
var party = partyCreatorModel.CreatePartyForNewRun();
|
||||
gameDataState.ActiveParty = party;
|
||||
}
|
||||
|
||||
public void Tick() {
|
||||
|
||||
Reference in New Issue
Block a user