123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using UnityEngine;
- public class RandomPresetContent
- {
- public static Dictionary<string, RandomPresetContent.CSVData> dicCsvData { get; set; }
- public static Dictionary<MPN, RandomPresetContent.MPNMapping> m_dicMPNMapping
- {
- get
- {
- if (RandomPresetContent.m_dicMPNMapping_ == null)
- {
- Dictionary<MPN, SceneEditInfo.CCateNameType> dicPartsTypePair = SceneEditInfo.m_dicPartsTypePair;
- string text = "random_preset_mpn_map.nei";
- RandomPresetContent.m_dicMPNMapping_ = new Dictionary<MPN, RandomPresetContent.MPNMapping>();
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- for (int i = 1; i < csvParser.max_cell_y; i++)
- {
- if (csvParser.IsCellToExistData(0, i))
- {
- RandomPresetContent.MPNMapping mpnmapping = new RandomPresetContent.MPNMapping();
- int num = 0;
- MPN key = MPN.null_mpn;
- try
- {
- key = (MPN)Enum.Parse(typeof(MPN), csvParser.GetCellAsString(num++, i));
- }
- catch (Exception e)
- {
- NDebug.AssertParseError("MPN", e);
- }
- mpnmapping.m_buttonName = csvParser.GetCellAsString(num++, i);
- SceneEditInfo.CCateNameType ccateNameType;
- if (dicPartsTypePair.TryGetValue(key, out ccateNameType))
- {
- mpnmapping.m_buttonTitle = ccateNameType.m_strBtnPartsTypeName;
- if (RandomPresetContent.m_dicMPNMapping_.ContainsKey(key))
- {
- NDebug.Assert(text + "\n" + key.ToString() + "が重複しています", false);
- }
- RandomPresetContent.m_dicMPNMapping_.Add(key, mpnmapping);
- }
- }
- }
- }
- }
- }
- return RandomPresetContent.m_dicMPNMapping_;
- }
- }
- public void InitRandomPresetParamter()
- {
- if (!this.LoadParameterSheet())
- {
- return;
- }
- this.InitExecutionOrder();
- this.InitRandomBaseGroup();
- this.InitBodyBase();
- this.InitRandomMapping();
- this.InitExceptionPartMapping();
- this.InitPriorityPartMapping();
- this.InitRatioToPutOnItem();
- }
- private bool LoadParameterSheet()
- {
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen("random_preset_parameter_define.nei"))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- if (!csvParser.Open(afileBase))
- {
- Debug.LogWarning("csv open failed.\nrandom_preset_parameter_define.nei");
- return false;
- }
- RandomPresetContent.dicCsvData = new Dictionary<string, RandomPresetContent.CSVData>();
- this.CreateObjectFromCsv(csvParser);
- }
- }
- return true;
- }
- private void CreateObjectFromCsv(CsvParser csv)
- {
- int max_cell_y = csv.max_cell_y;
- for (int i = 0; i < max_cell_y; i++)
- {
- string cellAsString = csv.GetCellAsString(0, i);
- if (cellAsString == "*")
- {
- this.csvData = new RandomPresetContent.CSVData();
- string cellAsString2 = csv.GetCellAsString(1, i);
- this.csvData.ClassName = cellAsString2;
- List<string> list = new List<string>();
- List<int> list2 = new List<int>();
- int j;
- for (j = 0; j < csv.max_cell_x; j++)
- {
- string cellAsString3 = csv.GetCellAsString(1 + j, i + 2);
- if (cellAsString3 == "-")
- {
- list2.Add(j);
- }
- else
- {
- if (string.IsNullOrEmpty(cellAsString3))
- {
- break;
- }
- list.Add(cellAsString3);
- }
- }
- this.csvData.Header = list;
- Dictionary<int, List<string>> dictionary = new Dictionary<int, List<string>>();
- bool flag = false;
- for (int k = 1; k < csv.max_cell_y; k++)
- {
- List<string> list3 = new List<string>();
- for (int l = 0; l < j; l++)
- {
- if (!list2.Contains(l))
- {
- string cellAsString4 = csv.GetCellAsString(1 + l, i + 2 + k);
- if (l == 0 && string.IsNullOrEmpty(cellAsString4))
- {
- flag = true;
- l = list.Count;
- break;
- }
- list3.Add(cellAsString4);
- }
- }
- if (flag)
- {
- break;
- }
- dictionary.Add(k, list3);
- }
- this.csvData.Rows = dictionary;
- RandomPresetContent.dicCsvData.Add(this.csvData.ClassName, this.csvData);
- }
- }
- }
- private void InitExecutionOrder()
- {
- RandomPresetContent.ExecutionOrderMasterTable executionOrderMasterTable = new RandomPresetContent.ExecutionOrderMasterTable();
- executionOrderMasterTable.Load();
- foreach (RandomPresetContent.ExecutionOrder executionOrder in executionOrderMasterTable.All)
- {
- if (RandomPresetContent.m_dicMPNMapping.ContainsKey(executionOrder.category))
- {
- RandomPresetContent.m_dicMPNMapping[executionOrder.category].m_executionOrder = executionOrder.order;
- }
- }
- }
- private void InitRandomBaseGroup()
- {
- RandomPresetContent.RandomBaseGroupMasterTable randomBaseGroupMasterTable = new RandomPresetContent.RandomBaseGroupMasterTable();
- randomBaseGroupMasterTable.Load();
- RandomPresetContent.m_dicRandomBaseGroup = new Dictionary<int, RandomPresetContent.RandomBaseGroup>();
- foreach (RandomPresetContent.RandomBaseGroup randomBaseGroup in randomBaseGroupMasterTable.All)
- {
- RandomPresetContent.m_dicRandomBaseGroup.Add(randomBaseGroup.randomBaseGroupId, randomBaseGroup);
- }
- }
- private void InitBodyBase()
- {
- RandomPresetContent.BodyBaseMasterTable bodyBaseMasterTable = new RandomPresetContent.BodyBaseMasterTable();
- bodyBaseMasterTable.Load();
- RandomPresetContent.m_dicBodyBase = new Dictionary<int, RandomPresetContent.BodyBase>();
- foreach (RandomPresetContent.BodyBase bodyBase in bodyBaseMasterTable.All)
- {
- RandomPresetContent.m_dicBodyBase.Add(bodyBase.bodyBaseId, bodyBase);
- }
- }
- private void InitRandomMapping()
- {
- RandomPresetContent.RandomMappingMasterTable randomMappingMasterTable = new RandomPresetContent.RandomMappingMasterTable();
- randomMappingMasterTable.Load();
- RandomPresetContent.m_dicRandomMapping = new Dictionary<int, RandomPresetContent.RandomMapping>();
- foreach (RandomPresetContent.RandomMapping randomMapping in randomMappingMasterTable.All)
- {
- RandomPresetContent.m_dicRandomMapping.Add(randomMapping.randomMappingId, randomMapping);
- }
- foreach (KeyValuePair<int, RandomPresetContent.RandomMapping> keyValuePair in RandomPresetContent.m_dicRandomMapping)
- {
- RandomPresetContent.RandomBaseGroup randomBaseGroup;
- if (RandomPresetContent.m_dicRandomBaseGroup.TryGetValue(keyValuePair.Value.randomBaseGroupId, out randomBaseGroup))
- {
- RandomPresetContent.BodyBase bodyBase;
- if (RandomPresetContent.m_dicBodyBase.TryGetValue(keyValuePair.Value.bodyBaseId, out bodyBase))
- {
- keyValuePair.Value.randomBaseGroup = randomBaseGroup;
- keyValuePair.Value.bodyBase = bodyBase;
- }
- }
- }
- }
- private void InitExceptionPartMapping()
- {
- RandomPresetContent.ExceptionPartMappingMasterTable exceptionPartMappingMasterTable = new RandomPresetContent.ExceptionPartMappingMasterTable();
- exceptionPartMappingMasterTable.Load();
- RandomPresetContent.m_dicExceptionPartMapping = new Dictionary<int, RandomPresetContent.PartMapping>();
- foreach (RandomPresetContent.PartMapping partMapping in exceptionPartMappingMasterTable.All)
- {
- RandomPresetContent.m_dicExceptionPartMapping.Add(partMapping.partMappingId, partMapping);
- }
- }
- private void InitPriorityPartMapping()
- {
- RandomPresetContent.PriorityPartMappingMasterTable priorityPartMappingMasterTable = new RandomPresetContent.PriorityPartMappingMasterTable();
- priorityPartMappingMasterTable.Load();
- RandomPresetContent.m_dicPriorityPartMapping = new Dictionary<int, RandomPresetContent.PartMapping>();
- foreach (RandomPresetContent.PartMapping partMapping in priorityPartMappingMasterTable.All)
- {
- RandomPresetContent.m_dicPriorityPartMapping.Add(partMapping.partMappingId, partMapping);
- }
- }
- private void InitRatioToPutOnItem()
- {
- RandomPresetContent.RatioToPutOnItemMasterTable ratioToPutOnItemMasterTable = new RandomPresetContent.RatioToPutOnItemMasterTable();
- ratioToPutOnItemMasterTable.Load();
- foreach (RandomPresetContent.RatioToPutOnItem ratioToPutOnItem in ratioToPutOnItemMasterTable.All)
- {
- if (RandomPresetContent.m_dicMPNMapping.ContainsKey(ratioToPutOnItem.category))
- {
- RandomPresetContent.m_dicMPNMapping[ratioToPutOnItem.category].m_ratioToPutOn = ratioToPutOnItem.ratioToPutOn;
- }
- }
- }
- public static int GetRandomBaseGrpId(int maidPropValue)
- {
- bool flag = false;
- bool flag2 = false;
- int num = 0;
- if (maidPropValue < RandomPresetContent.m_dicRandomBaseGroup[1].lowerLimit)
- {
- return RandomPresetContent.m_dicRandomBaseGroup[1].randomBaseGroupId;
- }
- int count = RandomPresetContent.m_dicRandomBaseGroup.Count;
- if (maidPropValue > RandomPresetContent.m_dicRandomBaseGroup[count].upperLimit)
- {
- return RandomPresetContent.m_dicRandomBaseGroup[count].randomBaseGroupId;
- }
- foreach (KeyValuePair<int, RandomPresetContent.RandomBaseGroup> keyValuePair in RandomPresetContent.m_dicRandomBaseGroup)
- {
- if (maidPropValue >= keyValuePair.Value.lowerLimit)
- {
- flag = true;
- }
- if (maidPropValue <= keyValuePair.Value.upperLimit)
- {
- flag2 = true;
- }
- if (flag && flag2)
- {
- return keyValuePair.Value.randomBaseGroupId;
- }
- if (flag2)
- {
- int num2 = Math.Abs(num - maidPropValue);
- int num3 = Math.Abs(keyValuePair.Value.lowerLimit - maidPropValue);
- return (num2 <= num3) ? (keyValuePair.Value.randomBaseGroupId - 1) : keyValuePair.Value.randomBaseGroupId;
- }
- flag = false;
- flag2 = false;
- num = keyValuePair.Value.upperLimit;
- }
- return 1;
- }
- public static string GetButtonNameByMPN(MPN mpn)
- {
- RandomPresetContent.MPNMapping mpnmapping;
- return (!RandomPresetContent.m_dicMPNMapping.TryGetValue(mpn, out mpnmapping)) ? null : mpnmapping.m_buttonName;
- }
- private void MakeDummyData()
- {
- SceneEdit component = GameObject.Find("__SceneEdit__").GetComponent<SceneEdit>();
- List<SceneEdit.SCategory> categoryList = component.CategoryList;
- Texture2D texIcon = categoryList[1].m_listPartsType[0].m_listMenu[0].m_texIcon;
- }
- public static Dictionary<int, RandomPresetContent.RandomBaseGroup> m_dicRandomBaseGroup;
- public static Dictionary<int, RandomPresetContent.BodyBase> m_dicBodyBase;
- public static Dictionary<int, RandomPresetContent.RandomMapping> m_dicRandomMapping;
- public static Dictionary<int, RandomPresetContent.PartMapping> m_dicExceptionPartMapping;
- public static Dictionary<int, RandomPresetContent.PartMapping> m_dicPriorityPartMapping;
- private const string RANDOMPRESET_PARAMETE_CSV_NAME = "random_preset_parameter_define.nei";
- private const string RANDOMPRESET_MPNMAP_CSV_NAME = "random_preset_mpn_map.nei";
- private const string CLASS_MARKER = "*";
- private const string SKIP_COLUMN_MARKER = "-";
- private const int OFFSET_COLUMN = 1;
- private const int OFFSET_ROW = 2;
- private const int LOWEST_NUM = 1;
- private RandomPresetContent.CSVData csvData;
- public static List<MPN> m_listUnderwearsItemGroup = new List<MPN>
- {
- MPN.panz,
- MPN.bra
- };
- public static List<MPN> m_listClothesItemGroupn = new List<MPN>
- {
- MPN.wear,
- MPN.skirt,
- MPN.mizugi,
- MPN.stkg,
- MPN.shoes,
- MPN.headset,
- MPN.acchat,
- MPN.onepiece
- };
- public static Dictionary<SceneEditInfo.EMenuCategory, string> m_dicCategoryMapping = new Dictionary<SceneEditInfo.EMenuCategory, string>
- {
- {
- SceneEditInfo.EMenuCategory.頭,
- "Head"
- },
- {
- SceneEditInfo.EMenuCategory.髪,
- "Hair"
- },
- {
- SceneEditInfo.EMenuCategory.服装,
- "Cloth"
- },
- {
- SceneEditInfo.EMenuCategory.身体,
- "Body"
- },
- {
- SceneEditInfo.EMenuCategory.セット,
- "Package"
- },
- {
- SceneEditInfo.EMenuCategory.アクセサリ,
- "Accessory"
- }
- };
- public static Dictionary<MPN, MPN> m_dicColorFolderMapping = new Dictionary<MPN, MPN>
- {
- {
- MPN.mayu,
- MPN.folder_mayu
- },
- {
- MPN.eye,
- MPN.folder_eye
- },
- {
- MPN.haircolor,
- MPN.hairf
- },
- {
- MPN.skin,
- MPN.folder_skin
- },
- {
- MPN.underhair,
- MPN.folder_underhair
- },
- {
- MPN.chikubicolor,
- MPN.chikubi
- }
- };
- private static Dictionary<MPN, RandomPresetContent.MPNMapping> m_dicMPNMapping_;
- public class CSVData
- {
- public string ClassName { get; set; }
- public List<string> Header { get; set; }
- public Dictionary<int, List<string>> Rows { get; set; }
- }
- public class RandomBaseGroupMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.RandomBaseGroup>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["RandomBaseGroup"]);
- }
- }
- public class BodyBaseMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.BodyBase>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["BodyBase"]);
- }
- }
- public class RandomMappingMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.RandomMapping>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["RandomMapping"]);
- }
- }
- public class ExceptionPartMappingMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.PartMapping>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["ExceptionPartMapping"]);
- }
- }
- public class PriorityPartMappingMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.PartMapping>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["PriorityPartMapping"]);
- }
- }
- public class ExecutionOrderMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.ExecutionOrder>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["ExecutionOrder"]);
- }
- }
- public class RatioToPutOnItemMasterTable : RandomPresetContent.MasterTableBase<RandomPresetContent.RatioToPutOnItem>
- {
- public void Load()
- {
- base.Load(RandomPresetContent.dicCsvData["RatioToPutOnItem"]);
- }
- }
- public class MasterTableBase<T> where T : RandomPresetContent.MasterBase, new()
- {
- public List<T> All
- {
- get
- {
- return this.masters;
- }
- }
- public void Load(RandomPresetContent.CSVData csvData)
- {
- List<string> header = csvData.Header;
- this.masters = new List<T>();
- foreach (int key in csvData.Rows.Keys)
- {
- this.ParseLine(csvData.Rows[key], header);
- }
- }
- private void ParseLine(List<string> row, List<string> headerElements)
- {
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- for (int i = 0; i < headerElements.Count; i++)
- {
- dictionary.Add(headerElements[i], row[i]);
- }
- T item = Activator.CreateInstance<T>();
- item.Load(dictionary);
- this.masters.Add(item);
- }
- protected List<T> masters;
- }
- public class MasterBase
- {
- public void Load(Dictionary<string, string> param)
- {
- foreach (string key in param.Keys)
- {
- this.SetField(key, param[key]);
- }
- }
- private void SetField(string key, string value)
- {
- PropertyInfo property = base.GetType().GetProperty(key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- if (property.PropertyType == typeof(int))
- {
- property.SetValue(this, int.Parse(value), null);
- }
- else if (property.PropertyType == typeof(string))
- {
- property.SetValue(this, value, null);
- }
- else if (property.PropertyType == typeof(float))
- {
- property.SetValue(this, float.Parse(value), null);
- }
- else if (property.PropertyType == typeof(MPN))
- {
- property.SetValue(this, (MPN)Enum.Parse(typeof(MPN), value), null);
- }
- }
- }
- public class SliderCommon : RandomPresetContent.MasterBase
- {
- public int lowerLimit { get; set; }
- public int upperLimit { get; set; }
- }
- public class RandomBaseGroup : RandomPresetContent.SliderCommon
- {
- public int randomBaseGroupId { get; set; }
- public override string ToString()
- {
- return string.Format("RandomBaseGroup [randomBaseGrpId={0}, lowerLimit={1}, upperLimit={2}]", this.randomBaseGroupId, base.lowerLimit, base.upperLimit);
- }
- }
- public class BodyBase : RandomPresetContent.SliderCommon
- {
- public int bodyBaseId { get; set; }
- public MPN bodyBaseCategory { get; set; }
- public override string ToString()
- {
- return string.Format("BodyBase [bodyBaseId={0}, bodyBaseCategory={1}, lowerLimit={2}, upperLimit={3}]", new object[]
- {
- this.bodyBaseId,
- this.bodyBaseCategory,
- base.lowerLimit,
- base.upperLimit
- });
- }
- }
- public class RandomMapping : RandomPresetContent.MasterBase
- {
- public int randomMappingId { get; set; }
- public int randomBaseGroupId { get; set; }
- public RandomPresetContent.RandomBaseGroup randomBaseGroup { get; set; }
- public int bodyBaseId { get; set; }
- public RandomPresetContent.BodyBase bodyBase { get; set; }
- public override string ToString()
- {
- return string.Format("RandomMapping [randomMappingId={0}, randomBaseGroupId={1}, randomBaseGroup={2}, bodyBaseId={3}, bodyBase={4}]", new object[]
- {
- this.randomMappingId,
- this.randomBaseGroupId,
- this.randomBaseGroup,
- this.bodyBaseId,
- this.bodyBase
- });
- }
- }
- public class PartMapping : RandomPresetContent.MasterBase
- {
- public int partMappingId { get; set; }
- public MPN category { get; set; }
- public string partId { get; set; }
- public MPN targetCategory { get; set; }
- public string targetPartId { get; set; }
- }
- public class ExecutionOrder : RandomPresetContent.MasterBase
- {
- public int executionOrderId { get; set; }
- public MPN category { get; set; }
- public int order { get; set; }
- }
- public class RatioToPutOnItem : RandomPresetContent.MasterBase
- {
- public int ratioToPutOnItemId { get; set; }
- public MPN category { get; set; }
- public int ratioToPutOn { get; set; }
- }
- public class MPNMapping
- {
- public string m_buttonName;
- public string m_buttonTitle;
- public int m_executionOrder;
- public int m_ratioToPutOn;
- }
- }
|