forked from Shardstone/trail-into-darkness
updated linq calls to zero allocation zlinq
This commit is contained in:
@@ -14,7 +14,9 @@
|
|||||||
"Bash(grep -E \"\\\\.cs$\")",
|
"Bash(grep -E \"\\\\.cs$\")",
|
||||||
"Bash(ls -la /d/repos/trail-into-darkness/Assets/Database/Entities/*.asset)",
|
"Bash(ls -la /d/repos/trail-into-darkness/Assets/Database/Entities/*.asset)",
|
||||||
"Bash(grep -r \"CharacterBaseSettings\\\\|PerkRegistry\\\\|CharacterRegistry\" /d/repos/trail-into-darkness/Assets/AddressableAssetsData --include=*.yaml --include=*.asset)",
|
"Bash(grep -r \"CharacterBaseSettings\\\\|PerkRegistry\\\\|CharacterRegistry\" /d/repos/trail-into-darkness/Assets/AddressableAssetsData --include=*.yaml --include=*.asset)",
|
||||||
"Bash(grep -l \"bc14507c6a9500d4eac9e684e289d084\" /d/repos/trail-into-darkness/Assets/**/*.meta)"
|
"Bash(grep -l \"bc14507c6a9500d4eac9e684e289d084\" /d/repos/trail-into-darkness/Assets/**/*.meta)",
|
||||||
|
"mcp__plugin_context7_context7__resolve-library-id",
|
||||||
|
"mcp__plugin_context7_context7__query-docs"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Nox.Platform;
|
|||||||
using Nox.Game.UI;
|
using Nox.Game.UI;
|
||||||
using Jovian.SaveSystem;
|
using Jovian.SaveSystem;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AddressableAssets;
|
using UnityEngine.AddressableAssets;
|
||||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
@@ -56,7 +56,7 @@ namespace Nox.Core {
|
|||||||
public void EnterGameState() {
|
public void EnterGameState() {
|
||||||
if(gameDataState.ActivePlayMode == PlayMode.None) {
|
if(gameDataState.ActivePlayMode == PlayMode.None) {
|
||||||
var sceneReference = Object.FindFirstObjectByType<SceneReference>();
|
var sceneReference = Object.FindFirstObjectByType<SceneReference>();
|
||||||
if(bootstrapSettings.gameModeData.Any(g => g.playMode == sceneReference.playMode)) {
|
if(bootstrapSettings.gameModeData.AsValueEnumerable().Any(g => g.playMode == sceneReference.playMode)) {
|
||||||
gameDataState.ChangePlayMode(sceneReference.playMode);
|
gameDataState.ChangePlayMode(sceneReference.playMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
public interface ICharacterAttributesFactory {
|
public interface ICharacterAttributesFactory {
|
||||||
@@ -16,12 +16,12 @@ namespace Nox.Game {
|
|||||||
public EntityAttributes Create(IEntityDefinition entityDefinition) {
|
public EntityAttributes Create(IEntityDefinition entityDefinition) {
|
||||||
var attributes = entityDefinition.Attributes;
|
var attributes = entityDefinition.Attributes;
|
||||||
|
|
||||||
if(attributes.attributes.Any(a => a.value <= 0)) {
|
if(attributes.attributes.AsValueEnumerable().Any(a => a.value <= 0)) {
|
||||||
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
|
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EntityAttributes {
|
return new EntityAttributes {
|
||||||
attributes = attributes.attributes
|
attributes = attributes.attributes.AsValueEnumerable()
|
||||||
.Select(a => {
|
.Select(a => {
|
||||||
var modifiers = modifierResolver.CollectModifiers(entityDefinition, a.attribute);
|
var modifiers = modifierResolver.CollectModifiers(entityDefinition, a.attribute);
|
||||||
return new Attribute(a.attribute, modifierResolver.Resolve(a.value, modifiers));
|
return new Attribute(a.attribute, modifierResolver.Resolve(a.value, modifiers));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
public interface ICharacterFactory {
|
public interface ICharacterFactory {
|
||||||
@@ -118,7 +118,7 @@ namespace Nox.Game {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var perkId in perkData.perks.Distinct()) {
|
foreach(var perkId in perkData.perks.AsValueEnumerable().Distinct()) {
|
||||||
perkFactory.TryAddPerk(character, perkId.Id);
|
perkFactory.TryAddPerk(character, perkId.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ namespace Nox.Game {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var modifierId in modifiersData.modifiers.Distinct()) {
|
foreach(var modifierId in modifiersData.modifiers.AsValueEnumerable().Distinct()) {
|
||||||
modifiersFactory.TryAddModifier(character, modifierId.Id);
|
modifiersFactory.TryAddModifier(character, modifierId.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
public interface ICharacterStatsFactory {
|
public interface ICharacterStatsFactory {
|
||||||
@@ -18,7 +18,7 @@ namespace Nox.Game {
|
|||||||
public EntityStats Create(IEntityDefinition entityDefinition) {
|
public EntityStats Create(IEntityDefinition entityDefinition) {
|
||||||
var attributes = entityDefinition.Attributes;
|
var attributes = entityDefinition.Attributes;
|
||||||
|
|
||||||
if(attributes.attributes.Any(a => a.value <= 0)) {
|
if(attributes.attributes.AsValueEnumerable().Any(a => a.value <= 0)) {
|
||||||
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
|
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
@@ -32,8 +32,8 @@ namespace Nox.Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(partyDefinitionSets.FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet) != null) {
|
if(partyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet) != null) {
|
||||||
var testingSet = partyDefinitionSets.FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet);
|
var testingSet = partyDefinitionSets.AsValueEnumerable().FirstOrDefault(pds => pds.id == partyDefinitionSet.id && pds.isTestingSet);
|
||||||
ApplyClassAndRacialBonuses(testingSet);
|
ApplyClassAndRacialBonuses(testingSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ namespace Nox.Game {
|
|||||||
var partyDefinition = testingSet.partyDefinition;
|
var partyDefinition = testingSet.partyDefinition;
|
||||||
foreach(var member in partyDefinition.members) {
|
foreach(var member in partyDefinition.members) {
|
||||||
var baseSettings = starterCharacterSettings.defaultEntityAttributes;
|
var baseSettings = starterCharacterSettings.defaultEntityAttributes;
|
||||||
var classAttributes = starterCharacterSettings.classBonuses.FirstOrDefault(c => c.@class == member.Class)?.bonusAttributes;
|
var classAttributes = starterCharacterSettings.classBonuses.AsValueEnumerable().FirstOrDefault(c => c.@class == member.Class)?.bonusAttributes;
|
||||||
var racialAttributes = starterCharacterSettings.racialBonuses.FirstOrDefault(rb => rb.race == member.Race)?.bonusAttributes;
|
var racialAttributes = starterCharacterSettings.racialBonuses.AsValueEnumerable().FirstOrDefault(rb => rb.race == member.Race)?.bonusAttributes;
|
||||||
if (classAttributes != null && racialAttributes != null) {
|
if (classAttributes != null && racialAttributes != null) {
|
||||||
member.Attributes += baseSettings + classAttributes + racialAttributes;
|
member.Attributes += baseSettings + classAttributes + racialAttributes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
@@ -81,9 +81,9 @@ namespace Nox.Game {
|
|||||||
|
|
||||||
public static EntityAttributes operator +(EntityAttributes a, EntityAttributes b) {
|
public static EntityAttributes operator +(EntityAttributes a, EntityAttributes b) {
|
||||||
return new EntityAttributes {
|
return new EntityAttributes {
|
||||||
attributes = a.attributes
|
attributes = a.attributes.AsValueEnumerable()
|
||||||
.Select(attr => {
|
.Select(attr => {
|
||||||
var match = b.attributes?.FirstOrDefault(attr2 => attr2.attribute == attr.attribute);
|
var match = b.attributes?.AsValueEnumerable().FirstOrDefault(attr2 => attr2.attribute == attr.attribute);
|
||||||
return new Attribute(attr.attribute, attr.value + (match?.value ?? 0));
|
return new Attribute(attr.attribute, attr.value + (match?.value ?? 0));
|
||||||
})
|
})
|
||||||
.ToArray()
|
.ToArray()
|
||||||
@@ -91,7 +91,7 @@ namespace Nox.Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int GetValue(AttributeType attributeType) {
|
public int GetValue(AttributeType attributeType) {
|
||||||
return attributes.First(attr => attr.attribute == attributeType).value;
|
return attributes.AsValueEnumerable().First(attr => attr.attribute == attributeType).value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,10 @@ namespace Nox.Game {
|
|||||||
public Stat[] stats;
|
public Stat[] stats;
|
||||||
|
|
||||||
public int GetValue(StatType statType) {
|
public int GetValue(StatType statType) {
|
||||||
var match = stats?.FirstOrDefault(stat => stat.stat == statType);
|
if(stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var match = stats.AsValueEnumerable().FirstOrDefault(stat => stat.stat == statType);
|
||||||
return match?.value ?? 0;
|
return match?.value ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,20 +128,20 @@ namespace Nox.Game {
|
|||||||
Race = Race,
|
Race = Race,
|
||||||
Class = Class,
|
Class = Class,
|
||||||
Attributes = new EntityAttributes {
|
Attributes = new EntityAttributes {
|
||||||
attributes = Attributes?.attributes?.Select(a => new Attribute(a.attribute, a.value)).ToArray()
|
attributes = Attributes?.attributes?.AsValueEnumerable().Select(a => new Attribute(a.attribute, a.value)).ToArray()
|
||||||
},
|
},
|
||||||
Stats = new EntityStats {
|
Stats = new EntityStats {
|
||||||
stats = Stats?.stats?.Select(s => new Stat(s.stat, s.value)).ToArray()
|
stats = Stats?.stats?.AsValueEnumerable().Select(s => new Stat(s.stat, s.value)).ToArray()
|
||||||
},
|
},
|
||||||
Perks = new PerksData {
|
Perks = new PerksData {
|
||||||
perks = Perks?.perks?.Select(p => new PerkDefinition {
|
perks = Perks?.perks?.AsValueEnumerable().Select(p => new PerkDefinition {
|
||||||
Id = p.Id,
|
Id = p.Id,
|
||||||
Name = p.Name,
|
Name = p.Name,
|
||||||
Modifiers = p.Modifiers
|
Modifiers = p.Modifiers
|
||||||
}).ToList() ?? new()
|
}).ToList() ?? new()
|
||||||
},
|
},
|
||||||
Modifiers = new ModifiersData {
|
Modifiers = new ModifiersData {
|
||||||
modifiers = Modifiers?.modifiers?.Select(m => new ModifierDefinition {
|
modifiers = Modifiers?.modifiers?.AsValueEnumerable().Select(m => new ModifierDefinition {
|
||||||
Id = m.Id,
|
Id = m.Id,
|
||||||
Name = m.Name,
|
Name = m.Name,
|
||||||
StatType = m.StatType,
|
StatType = m.StatType,
|
||||||
@@ -159,9 +162,9 @@ namespace Nox.Game {
|
|||||||
public List<CharacterDefinition> members = new();
|
public List<CharacterDefinition> members = new();
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public CharacterDefinition Protagonist => members.FirstOrDefault(m => m.Role == CharacterRole.Protagonist);
|
public CharacterDefinition Protagonist => members.AsValueEnumerable().FirstOrDefault(m => m.Role == CharacterRole.Protagonist);
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IReadOnlyList<CharacterDefinition> Companions => members.Where(m => m.Role == CharacterRole.Companion).ToList();
|
public IReadOnlyList<CharacterDefinition> Companions => members.AsValueEnumerable().Where(m => m.Role == CharacterRole.Companion).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using Jovian.InspectorTools;
|
|||||||
using Jovian.Logger;
|
using Jovian.Logger;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
@@ -61,7 +61,7 @@ namespace Nox.Game {
|
|||||||
return modifiersRegistry.modifiersData.modifiers;
|
return modifiersRegistry.modifiersData.modifiers;
|
||||||
}
|
}
|
||||||
public IModifier GetById(Guid modifierId) {
|
public IModifier GetById(Guid modifierId) {
|
||||||
return modifiersRegistry.modifiersData.modifiers.FirstOrDefault(m => m.Id == modifierId);
|
return modifiersRegistry.modifiersData.modifiers.AsValueEnumerable().FirstOrDefault(m => m.Id == modifierId);
|
||||||
}
|
}
|
||||||
public IReadOnlyCollection<IModifier> GetModifiersFor(IEntityDefinition character) {
|
public IReadOnlyCollection<IModifier> GetModifiersFor(IEntityDefinition character) {
|
||||||
return character.Modifiers.modifiers;
|
return character.Modifiers.modifiers;
|
||||||
@@ -76,7 +76,7 @@ namespace Nox.Game {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(character.Modifiers.modifiers.Any(p => p != null && p.Id == modifierId)) {
|
if(character.Modifiers.modifiers.AsValueEnumerable().Any(p => p != null && p.Id == modifierId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
|
|
||||||
@@ -26,34 +26,40 @@ namespace Nox.Game {
|
|||||||
return baseValue;
|
return baseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var grouped = modifiers
|
float flatSum = 0f;
|
||||||
.Where(m => m != null && m.Operation != ModifierOperation.None)
|
float addSum = 0f;
|
||||||
.GroupBy(m => m.Operation)
|
float pctSum = 0f;
|
||||||
.ToDictionary(g => g.Key, g => g.ToList());
|
var mulValues = new List<float>();
|
||||||
|
var hasFlat = false;
|
||||||
|
|
||||||
float result = baseValue;
|
foreach(var m in modifiers) {
|
||||||
|
if(m == null || m.Operation == ModifierOperation.None) {
|
||||||
// 1. Flat — if any flat modifiers exist, they replace the base entirely
|
continue;
|
||||||
if(grouped.TryGetValue(ModifierOperation.Flat, out var flatMods)) {
|
|
||||||
result = flatMods.Sum(m => m.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Addition — sum all additive bonuses
|
|
||||||
if(grouped.TryGetValue(ModifierOperation.Addition, out var addMods)) {
|
|
||||||
result += addMods.Sum(m => m.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Percentage — summed into one multiplier: result * (1 + totalPercent / 100)
|
|
||||||
if(grouped.TryGetValue(ModifierOperation.Percentage, out var pctMods)) {
|
|
||||||
var totalPercent = pctMods.Sum(m => m.Value);
|
|
||||||
result *= 1f + (totalPercent / 100f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Multiplication — each factor applied sequentially
|
|
||||||
if(grouped.TryGetValue(ModifierOperation.Multiplication, out var mulMods)) {
|
|
||||||
foreach(var mod in mulMods) {
|
|
||||||
result *= mod.Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(m.Operation) {
|
||||||
|
case ModifierOperation.Flat:
|
||||||
|
flatSum += m.Value;
|
||||||
|
hasFlat = true;
|
||||||
|
break;
|
||||||
|
case ModifierOperation.Addition:
|
||||||
|
addSum += m.Value;
|
||||||
|
break;
|
||||||
|
case ModifierOperation.Percentage:
|
||||||
|
pctSum += m.Value;
|
||||||
|
break;
|
||||||
|
case ModifierOperation.Multiplication:
|
||||||
|
mulValues.Add(m.Value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float result = hasFlat ? flatSum : baseValue;
|
||||||
|
result += addSum;
|
||||||
|
result *= 1f + (pctSum / 100f);
|
||||||
|
|
||||||
|
foreach(var mul in mulValues) {
|
||||||
|
result *= mul;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)Math.Round(result);
|
return (int)Math.Round(result);
|
||||||
@@ -61,38 +67,64 @@ namespace Nox.Game {
|
|||||||
|
|
||||||
public IEnumerable<IModifier> CollectModifiers(IEntityDefinition entity, StatType statType) {
|
public IEnumerable<IModifier> CollectModifiers(IEntityDefinition entity, StatType statType) {
|
||||||
if(entity == null) {
|
if(entity == null) {
|
||||||
return Enumerable.Empty<IModifier>();
|
return Array.Empty<IModifier>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var direct = entity.Modifiers?.modifiers?
|
var result = new List<IModifier>();
|
||||||
.Where(m => m != null && m.StatType == statType)
|
|
||||||
?? Enumerable.Empty<IModifier>();
|
|
||||||
|
|
||||||
var fromPerks = entity.Perks?.perks?
|
if(entity.Modifiers?.modifiers != null) {
|
||||||
.Where(p => p?.Modifiers?.modifiers != null)
|
foreach(var m in entity.Modifiers.modifiers) {
|
||||||
.SelectMany(p => p.Modifiers.modifiers)
|
if(m != null && m.StatType == statType) {
|
||||||
.Where(m => m != null && m.StatType == statType)
|
result.Add(m);
|
||||||
?? Enumerable.Empty<IModifier>();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return direct.Concat(fromPerks);
|
if(entity.Perks?.perks != null) {
|
||||||
|
foreach(var p in entity.Perks.perks) {
|
||||||
|
if(p?.Modifiers?.modifiers == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach(var m in p.Modifiers.modifiers) {
|
||||||
|
if(m != null && m.StatType == statType) {
|
||||||
|
result.Add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IModifier> CollectModifiers(IEntityDefinition entity, AttributeType attributeType) {
|
public IEnumerable<IModifier> CollectModifiers(IEntityDefinition entity, AttributeType attributeType) {
|
||||||
if(entity == null) {
|
if(entity == null) {
|
||||||
return Enumerable.Empty<IModifier>();
|
return Array.Empty<IModifier>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var direct = entity.Modifiers?.modifiers?
|
var result = new List<IModifier>();
|
||||||
.Where(m => m != null && m.AttributeType == attributeType)
|
|
||||||
?? Enumerable.Empty<IModifier>();
|
|
||||||
|
|
||||||
var fromPerks = entity.Perks?.perks?
|
if(entity.Modifiers?.modifiers != null) {
|
||||||
.Where(p => p?.Modifiers?.modifiers != null)
|
foreach(var m in entity.Modifiers.modifiers) {
|
||||||
.SelectMany(p => p.Modifiers.modifiers)
|
if(m != null && m.AttributeType == attributeType) {
|
||||||
.Where(m => m != null && m.AttributeType == attributeType)
|
result.Add(m);
|
||||||
?? Enumerable.Empty<IModifier>();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return direct.Concat(fromPerks);
|
if(entity.Perks?.perks != null) {
|
||||||
|
foreach(var p in entity.Perks.perks) {
|
||||||
|
if(p?.Modifiers?.modifiers == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach(var m in p.Modifiers.modifiers) {
|
||||||
|
if(m != null && m.AttributeType == attributeType) {
|
||||||
|
result.Add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
public interface IPartyFactory {
|
public interface IPartyFactory {
|
||||||
@@ -28,7 +28,7 @@ namespace Nox.Game {
|
|||||||
party.members.Add(protagonistClone);
|
party.members.Add(protagonistClone);
|
||||||
|
|
||||||
if(companions != null) {
|
if(companions != null) {
|
||||||
foreach(var companion in companions.Where(c => c != null)) {
|
foreach(var companion in companions.AsValueEnumerable().Where(c => c != null)) {
|
||||||
var companionClone = companion.Clone();
|
var companionClone = companion.Clone();
|
||||||
companionClone.Role = CharacterRole.Companion;
|
companionClone.Role = CharacterRole.Companion;
|
||||||
party.members.Add(companionClone);
|
party.members.Add(companionClone);
|
||||||
@@ -44,12 +44,12 @@ namespace Nox.Game {
|
|||||||
throw new ArgumentException($"Party size {party.members.Count} exceeds max {party.maxPartySize}.");
|
throw new ArgumentException($"Party size {party.members.Count} exceeds max {party.maxPartySize}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var protagonistCount = party.members.Count(m => m.Role == CharacterRole.Protagonist);
|
var protagonistCount = party.members.AsValueEnumerable().Count(m => m.Role == CharacterRole.Protagonist);
|
||||||
if(protagonistCount != 1) {
|
if(protagonistCount != 1) {
|
||||||
throw new ArgumentException($"Party must contain exactly one protagonist, found {protagonistCount}.");
|
throw new ArgumentException($"Party must contain exactly one protagonist, found {protagonistCount}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var uniqueIds = party.members
|
var uniqueIds = party.members.AsValueEnumerable()
|
||||||
.Where(m => m.Id != Guid.Empty)
|
.Where(m => m.Id != Guid.Empty)
|
||||||
.Select(m => m.Id)
|
.Select(m => m.Id)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Jovian.Logger;
|
using Jovian.Logger;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Nox.Game {
|
namespace Nox.Game {
|
||||||
@@ -45,7 +45,7 @@ namespace Nox.Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyCollection<IPerk> GetAll() {
|
public IReadOnlyCollection<IPerk> GetAll() {
|
||||||
return perkPool.Values.ToList();
|
return perkPool.Values.AsValueEnumerable().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPerk GetById(Guid perkId) {
|
public IPerk GetById(Guid perkId) {
|
||||||
@@ -55,14 +55,14 @@ namespace Nox.Game {
|
|||||||
|
|
||||||
public IReadOnlyCollection<IPerk> GetPerksFor(IEntityDefinition character) {
|
public IReadOnlyCollection<IPerk> GetPerksFor(IEntityDefinition character) {
|
||||||
if(character == null) {
|
if(character == null) {
|
||||||
return perkPool.Values.ToList();
|
return perkPool.Values.AsValueEnumerable().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var ownedPerkIds = character.Perks.perks
|
var ownedPerkIds = character.Perks.perks.AsValueEnumerable()
|
||||||
.Select(p => p.Id)
|
.Select(p => p.Id)
|
||||||
.ToHashSet();
|
.ToHashSet();
|
||||||
|
|
||||||
return perkPool.Values.Where(p => !ownedPerkIds.Contains(p.Id)).ToList();
|
return perkPool.Values.AsValueEnumerable().Where(p => !ownedPerkIds.Contains(p.Id)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryAddPerk(IEntityDefinition character, Guid perkId) {
|
public bool TryAddPerk(IEntityDefinition character, Guid perkId) {
|
||||||
@@ -74,7 +74,7 @@ namespace Nox.Game {
|
|||||||
GlobalLogger.LogException("Cannot add a perk with an empty Id!", LogCategory.GameLogic);
|
GlobalLogger.LogException("Cannot add a perk with an empty Id!", LogCategory.GameLogic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(character.Perks.perks.Any(p => p != null && p.Id == perkId)) {
|
if(character.Perks.perks.AsValueEnumerable().Any(p => p != null && p.Id == perkId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Jovian.SaveSystem;
|
using Jovian.SaveSystem;
|
||||||
using Nox.Core;
|
using Nox.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using PlayMode = Nox.Core.PlayMode;
|
using PlayMode = Nox.Core.PlayMode;
|
||||||
|
|
||||||
@@ -12,13 +12,13 @@ namespace Nox.Game {
|
|||||||
ISaveSystem saveSystem,
|
ISaveSystem saveSystem,
|
||||||
GameDataState gameDataState,
|
GameDataState gameDataState,
|
||||||
ref AdventureData adventureData) {
|
ref AdventureData adventureData) {
|
||||||
var sessions = saveSystem.GetAllSessions().OrderByDescending(s => s.lastSaveDateUtc).ToList();
|
var sessions = saveSystem.GetAllSessions().AsValueEnumerable().OrderByDescending(s => s.lastSaveDateUtc).ToList();
|
||||||
if(sessions.Count == 0) {
|
if(sessions.Count == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestSession = sessions[0];
|
var latestSession = sessions[0];
|
||||||
var slots = saveSystem.GetSlots(latestSession.sessionId).OrderByDescending(s => s.timestampUtc).ToList();
|
var slots = saveSystem.GetSlots(latestSession.sessionId).AsValueEnumerable().OrderByDescending(s => s.timestampUtc).ToList();
|
||||||
if(slots.Count == 0) {
|
if(slots.Count == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Jovian.ZoneSystem;
|
|||||||
using Nox.Core;
|
using Nox.Core;
|
||||||
using Nox.Platform;
|
using Nox.Platform;
|
||||||
using Nox.Game.UI;
|
using Nox.Game.UI;
|
||||||
using System.Linq;
|
using ZLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AddressableAssets;
|
using UnityEngine.AddressableAssets;
|
||||||
using PlayMode = Nox.Core.PlayMode;
|
using PlayMode = Nox.Core.PlayMode;
|
||||||
@@ -65,7 +65,7 @@ namespace Nox.Game {
|
|||||||
partyMovementHandler.ConsumeNextClick();
|
partyMovementHandler.ConsumeNextClick();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Addressables.LoadSceneAsync(bootstrapSettings.gameModeData.FirstOrDefault(g => g.playMode == PlayMode.Adventure)?.scene)
|
Addressables.LoadSceneAsync(bootstrapSettings.gameModeData.AsValueEnumerable().FirstOrDefault(g => g.playMode == PlayMode.Adventure)?.scene)
|
||||||
.WaitForCompletion().ActivateAsync().completed += InitializeGameMode;
|
.WaitForCompletion().ActivateAsync().completed += InitializeGameMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,13 +74,13 @@ namespace Nox.Game {
|
|||||||
inputActions.UI.PauseMenu.Enable();
|
inputActions.UI.PauseMenu.Enable();
|
||||||
Debug.Log("Entering Adventure Play Mode");
|
Debug.Log("Entering Adventure Play Mode");
|
||||||
if(partyDefinition == null) {
|
if(partyDefinition == null) {
|
||||||
var sessions = saveSystem.GetAllSessions().OrderByDescending(s => s.lastSaveDateUtc).ToList();
|
var sessions = saveSystem.GetAllSessions().AsValueEnumerable().OrderByDescending(s => s.lastSaveDateUtc).ToList();
|
||||||
if(sessions.Count == 0) {
|
if(sessions.Count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestSession = sessions[0];
|
var latestSession = sessions[0];
|
||||||
var slots = saveSystem.GetSlots(latestSession.sessionId).OrderByDescending(s => s.timestampUtc).ToList();
|
var slots = saveSystem.GetSlots(latestSession.sessionId).AsValueEnumerable().OrderByDescending(s => s.timestampUtc).ToList();
|
||||||
if(slots.Count == 0) {
|
if(slots.Count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8b9f7ed9a26cede488cbe67e3bed5938
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "Jovian.SaveSystem.RuntimeTests",
|
|
||||||
"rootNamespace": "Jovian.SaveSystem.Tests.Runtime",
|
|
||||||
"references": [
|
|
||||||
"Jovian.SaveSystem",
|
|
||||||
"UnityEngine.TestRunner",
|
|
||||||
"UnityEditor.TestRunner"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": true,
|
|
||||||
"precompiledReferences": [
|
|
||||||
"nunit.framework.dll"
|
|
||||||
],
|
|
||||||
"autoReferenced": false,
|
|
||||||
"defineConstraints": [
|
|
||||||
"UNITY_INCLUDE_TESTS"
|
|
||||||
],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": false
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 6c0ac5542b5d3b846a1ed415880d1411
|
|
||||||
AssemblyDefinitionImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user