Skip to content

Commit

Permalink
adds preferences to npc and configuration for those in generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-dupdyke committed Mar 9, 2024
1 parent 0636c67 commit 43549d8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/Ghosts.Animator/Models/NpcGenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Collections.Generic;
using Ghosts.Animator.Enums;
using Newtonsoft.Json;

namespace Ghosts.Animator.Models
{
Expand All @@ -23,6 +24,19 @@ public class NpcGenerationConfiguration
/// Set this to generate NPCs that are all part of the same service branch unit
/// </summary>
public string Unit { get; set; }

public string Username { get; set; }

public IEnumerable<PreferenceOption> PreferenceSettings { get; set; }
}

public class PreferenceOption
{
public int Score { get; set; }
public int ScoreHigh { get; set; }
public int ScoreLow { get; set; }
public string Name { get; set; }
public string Meta { get; set; }
}

public class RankDistribution
Expand Down
2 changes: 2 additions & 0 deletions src/Ghosts.Animator/Models/NpcProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class NpcProfile
public string Password { get; set; }
public string HomePhone { get; set; }
public string CellPhone { get; set; }

public IEnumerable<Preference> Preferences { get; set; }
public MilitaryUnit Unit { get; set; }
public MilitaryRank.Branch.Rank Rank { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/Ghosts.Animator/Models/NpcProfileSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public class NpcProfileSummary
public IEnumerable<AccountsProfile.Account> Accounts { get; set; }
public MotivationalProfile MotivationalProfile { get; set; } = new();
public DateTime Created { get; set; } = DateTime.UtcNow;
public IEnumerable<Preference> Preferences { get; set; } = new List<Preference>();
}
}
23 changes: 18 additions & 5 deletions src/Ghosts.Animator/Npc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Collections.Generic;
using Ghosts.Animator.Models;
using Ghosts.Animator.Services;
using Newtonsoft.Json;
Expand All @@ -23,10 +24,10 @@ public static NpcProfile Generate(Enums.MilitaryBranch branch)

public static NpcProfile Generate(Enums.MilitaryBranch branch, string username)
{
return Generate(new NpcGenerationConfiguration { Branch = branch}, username);
return Generate(new NpcGenerationConfiguration { Branch = branch, Username = username });
}

public static NpcProfile Generate(NpcGenerationConfiguration config, string username = null)
public static NpcProfile Generate(NpcGenerationConfiguration config)
{
if(!config.Branch.HasValue)
config.Branch = MilitaryUnits.GetServiceBranch();
Expand All @@ -46,10 +47,10 @@ public static NpcProfile Generate(NpcGenerationConfiguration config, string user

NpcProfile.Address.Add(Address.GetHomeAddress());

if(string.IsNullOrEmpty(username))
if(string.IsNullOrEmpty(config.Username))
NpcProfile.Name = Name.GetName();
else
NpcProfile.SetName(username);
NpcProfile.SetName(config.Username);

NpcProfile.Email = Internet.GetMilEmail(NpcProfile.Name.ToString());
NpcProfile.Password = Internet.GetPassword();
Expand Down Expand Up @@ -87,7 +88,19 @@ public static NpcProfile Generate(NpcGenerationConfiguration config, string user
NpcProfile.Attributes = AttributesService.GetAttributes();

NpcProfile.MotivationalProfile = MotivationalProfile.GetNew();


var preferences = new List<Preference>();
var i = 0;
foreach (var p in config.PreferenceSettings)
{
var score = p.Score;
if (p.ScoreLow > -1 && p.ScoreHigh > p.ScoreLow)
score = AnimatorRandom.Rand.Next(p.ScoreLow, p.ScoreHigh);
preferences.Add(new Preference { Id = i, Name = p.Name, Meta = p.Meta, Score = score});
i++;
}
NpcProfile.Preferences = preferences;

return NpcProfile;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ghosts.api.Areas.Animator.Infrastructure.Models;
namespace Ghosts.Animator;

public class Preference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ public IEnumerable<NpcRecord> Create(GenerationConfiguration config, Cancellatio
{
var last = t.ElapsedMilliseconds;
var branch = team.Npcs.Configuration?.Branch ?? MilitaryUnits.GetServiceBranch();
var npc = NpcRecord.TransformToNpc(Npc.Generate(branch));
var npc = NpcRecord.TransformToNpc(Npc.Generate(new NpcGenerationConfiguration { Branch = branch, PreferenceSettings = team.PreferenceSettings }));
npc.Id = npc.NpcProfile.Id;
npc.Team = team.Name;
npc.Campaign = config.Campaign;
npc.Enclave = enclave.Name;

this._context.Npcs.Add(npc);
createdNpcs.Add(npc);
_log.Trace($"{i} generated in {t.ElapsedMilliseconds - last} ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class TeamConfiguration
public string Name { get; set; }
public string MachineNameTemplate { get; set; }
public string DomainTemplate { get; set; }

public IEnumerable<PreferenceOption> PreferenceSettings { get; set; }
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Ghosts.Api/Areas/Animator/Infrastructure/Models/NPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class NpcRecord
// this is also currently jsonb
public NpcProfile NpcProfile { get; set; }

public IEnumerable<Preference> Preferences { get; set; }

public static NpcRecord TransformToNpc(NpcProfile o)
{
var n = new NpcRecord
Expand Down
1 change: 0 additions & 1 deletion src/Ghosts.Api/Infrastructure/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
// Add your customizations after calling base.OnModelCreating(modelBuilder);

modelBuilder.Entity<NpcRecord>().Property(o => o.NpcProfile).HasColumnType("jsonb");
modelBuilder.Entity<NpcRecord>().Property(o => o.Preferences).HasColumnType("jsonb");

modelBuilder.Entity<Machine>().HasIndex(o => new {o.CreatedUtc});
modelBuilder.Entity<Machine>().HasIndex(o => new {o.Status});
Expand Down

0 comments on commit 43549d8

Please sign in to comment.