97 lines
2.8 KiB
C#
Executable File
97 lines
2.8 KiB
C#
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Dalamud.Logging;
|
|
using Lumina.Excel.GeneratedSheets;
|
|
|
|
namespace NominaOcculta;
|
|
|
|
internal class AppearanceRepository {
|
|
private Plugin Plugin { get; }
|
|
private List<ENpcBase> Npcs { get; }
|
|
private List<ENpcBase> PersonalNpcs { get; }
|
|
private int Salt { get; set; } = new Random().Next();
|
|
|
|
private static readonly string[] Exclude = {
|
|
"Thancred",
|
|
"Y'shtola",
|
|
"Alphinaud",
|
|
"Alisaie",
|
|
"Urianger",
|
|
"Tataru",
|
|
"Minfilia",
|
|
"Lyse",
|
|
"Yda",
|
|
"Papalymo",
|
|
"Krile",
|
|
"Ryne",
|
|
"Estinien",
|
|
"Nanamo Ul Namo",
|
|
"G'raha Tia",
|
|
"Raubahn",
|
|
"Cid",
|
|
"Biggs",
|
|
"Wedge",
|
|
"Haurchefant",
|
|
"Merlwyb",
|
|
"Kan-E-Senna",
|
|
"Yugiri",
|
|
"Aymeric",
|
|
"Lahabrea",
|
|
"Igeyorhm",
|
|
"Hildibrand",
|
|
"Godbert",
|
|
};
|
|
|
|
internal AppearanceRepository(Plugin plugin) {
|
|
this.Plugin = plugin;
|
|
|
|
var names = this.Plugin.DataManager.GetExcelSheet<ENpcResident>()!;
|
|
this.Npcs = this.Plugin.DataManager.GetExcelSheet<ENpcBase>()!
|
|
.Where(row => row.BodyType == 1)
|
|
.Where(row => row.ModelChara.Row == 0)
|
|
.Where(row => row.ModelBody != 0)
|
|
.Where(row => row.ModelLegs != 0)
|
|
.Where(row => !Exclude.Contains(names.GetRow(row.RowId)?.Singular.RawString))
|
|
.ToList();
|
|
PluginLog.Log($"npcs: {this.Npcs.Count}");
|
|
}
|
|
|
|
internal void Reset() {
|
|
this.Salt = new Random().Next();
|
|
}
|
|
|
|
internal void RefilterPersonal() {
|
|
this.PersonalNpcs.Clear();
|
|
this.PersonalNpcs.AddRange(this.Npcs
|
|
.Where(row => {
|
|
var sex = (Sex) (row.Gender + 1);
|
|
return this.Plugin.Config.PreferredSex.HasFlag(sex);
|
|
})
|
|
.Where(row => {
|
|
var race = 1 << (int) row.Race.Row;
|
|
return (this.Plugin.Config.PreferredRaces & race) > 0;
|
|
})
|
|
.Where(row => {
|
|
var tribe = 1 << (int) row.Tribe.Row;
|
|
return (this.Plugin.Config.PreferredTribes & tribe) > 0;
|
|
}));
|
|
}
|
|
|
|
private int GetNpcIndex(uint objectId) {
|
|
return new Random((int) (objectId + this.Salt)).Next(0, this.Npcs.Count);
|
|
}
|
|
|
|
private int GetNpcIndexPersonal(uint objectId) {
|
|
return new Random((int) (objectId + this.Salt)).Next(0, this.PersonalNpcs.Count);
|
|
}
|
|
|
|
internal ENpcBase GetNpc(uint objectId) {
|
|
if (objectId == this.Plugin.ClientState.LocalPlayer?.ObjectId) {
|
|
return this.PersonalNpcs[this.GetNpcIndexPersonal(objectId)];
|
|
}
|
|
|
|
return this.Npcs[this.GetNpcIndex(objectId)];
|
|
}
|
|
}
|