You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
25 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Gaia;
using SiegeSong;
namespace SiegeSong
{
public class ActorLoader : MonoBehaviour
{
public string Input;
public GameObject Species;
public GameObject Instance;
public InstanceManager InstanceManager;
public Transform StartLocation;
public GameObject PlayerTracker;
public bool IsPlayer;
public int ActorID;
void Start()
{
if (Input.Length > 0)
LoadActor();
}
void Update()
{
}
public void SaveActor()
{
var actorDataString = "A-";
var value = "";
if (Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories == null)
Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories = new Dictionary<int, Dictionary<int, int>>();
if (Instance.GetComponentInChildren<ActorStatistics>().RespectForActor == null)
Instance.GetComponentInChildren<ActorStatistics>().RespectForActor = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<ActorStatistics>().AdmirationForActor == null)
Instance.GetComponentInChildren<ActorStatistics>().AdmirationForActor = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor == null)
Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<ActorStatistics>().FactionRank == null)
Instance.GetComponentInChildren<ActorStatistics>().FactionRank = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty == null)
Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<ActorStatistics>().RegionalFame == null)
Instance.GetComponentInChildren<ActorStatistics>().RegionalFame = new Dictionary<int, int>();
if (Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes == null)
Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes = new Dictionary<string, float>();
if (Instance.GetComponentInChildren<InventoryManager>().Inventory.Contents == null)
Instance.GetComponentInChildren<InventoryManager>().Inventory.Contents = new Dictionary<int, int>();
foreach (var skillCategory in Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories.Keys)
{
if (Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories[skillCategory] == null)
Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories[skillCategory] = new Dictionary<int, int>();
foreach (var skill in Instance.GetComponentInChildren<ActorStatistics>().SkillValueCategories[skillCategory])
{
actorDataString += $"sc{skillCategory.ToString("00")}_{skill.Key.ToString("00")}_{skill.Value.ToString("00")}/";
}
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().RespectForActor.Keys)
{
actorDataString += $"ra{id}_{Instance.GetComponentInChildren<ActorStatistics>().RespectForActor[id]}/";
value = Instance.GetComponentInChildren<ActorStatistics>().RespectForActor[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().RespectForActor[id].ToString() : "0";
actorDataString += $"ra{id}_{value}/";
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().AdmirationForActor.Keys)
{
value = Instance.GetComponentInChildren<ActorStatistics>().AdmirationForActor[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().AdmirationForActor[id].ToString() : "0";
actorDataString += $"aa{id}_{value}/";
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor.Keys)
{
actorDataString += $"sa{id}_{Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor[id]}/";
value = Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().SuspicionOfActor[id].ToString() : "0";
actorDataString += $"sa{id}_{value}/";
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().FactionRank.Keys)
{
actorDataString += $"fr{id}_{Instance.GetComponentInChildren<ActorStatistics>().FactionRank[id]}/";
value = Instance.GetComponentInChildren<ActorStatistics>().FactionRank[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().FactionRank[id].ToString() : "0";
actorDataString += $"fr{id}_{value}/";
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty.Keys)
{
actorDataString += $"rb{id}_{Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty[id]}/";
value = Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().RegionalBounty[id].ToString() : "0";
actorDataString += $"rb{id}_{value}/";
}
foreach (var id in Instance.GetComponentInChildren<ActorStatistics>().RegionalFame.Keys)
{
actorDataString += $"rf{id}_{Instance.GetComponentInChildren<ActorStatistics>().RegionalFame[id]}/";
value = Instance.GetComponentInChildren<ActorStatistics>().RegionalFame[id] != null ? Instance.GetComponentInChildren<ActorStatistics>().RegionalFame[id].ToString() : "0";
actorDataString += $"rf{id}_{value}/";
}
foreach (var blendshape in Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes.Keys)
{
actorDataString += $"bs{blendshape}_{Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes[blendshape]}/";
value = Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes[blendshape] != null ? Instance.GetComponentInChildren<BlendshapeLoader>().Blendshapes[blendshape].ToString() : "0";
actorDataString += $"bs{blendshape}_{value}/";
}
actorDataString += $"pl{IsPlayer}/";
actorDataString += $"lx{Instance.transform.position.x.ToString("00000")}/";
actorDataString += $"ly{Instance.transform.position.y.ToString("00000")}/";
actorDataString += $"lz{Instance.transform.position.z.ToString("00000")}/";
actorDataString += $"hs{Instance.GetComponentInChildren<BlendshapeLoader>().HairstyleID.ToString("00")}/";
actorDataString += $"fh{Instance.GetComponentInChildren<BlendshapeLoader>().FacialHairID.ToString("00")}/";
actorDataString += $"fd{Instance.GetComponentInChildren<BlendshapeLoader>().FacialDetailID.ToString("00")}/";
actorDataString += $"hr{Instance.GetComponentInChildren<BlendshapeLoader>().HairColorR.ToString("000")}/";
actorDataString += $"hg{Instance.GetComponentInChildren<BlendshapeLoader>().HairColorG.ToString("000")}/";
actorDataString += $"hb{Instance.GetComponentInChildren<BlendshapeLoader>().HairColorB.ToString("000")}/";
actorDataString += $"ha{Instance.GetComponentInChildren<BlendshapeLoader>().HairColorA.ToString("000")}/";
actorDataString += $"mm{Instance.GetComponentInChildren<ActorStatistics>().MaxMagic}/";
actorDataString += $"ms{Instance.GetComponentInChildren<ActorStatistics>().MaxStamina}/";
actorDataString += $"mh{Instance.GetComponentInChildren<ActorStatistics>().MaxHealth}/";
foreach (var item in Instance.GetComponentInChildren<ActorStatistics>().Inventory.Inventory.Contents)
{
if (item.Key != 0)
{
actorDataString += $"iid{item.Key.ToString("00")}";
actorDataString += $"-ius{Instance.GetComponentInChildren<ActorStatistics>().Inventory.GetItemByID(item.Key).GetComponent<InventoryItem>().Using}";
actorDataString += $"-icn{Instance.GetComponentInChildren<ActorStatistics>().Inventory.GetItemByID(item.Key).GetComponent<InventoryItem>().PhysicalCondition.ToString("00")}";
actorDataString += $"-/";
}
}
Input = actorDataString;
}
public void LoadActor(bool despawnOldInstance = false)
{
if (IsPlayer)
{
PlayerTracker.transform.parent = null;
}
if (Instance != null && despawnOldInstance)
GameObject.Destroy(Instance);
Instance = GameObject.Instantiate(Species);
Instance.transform.position = StartLocation.position;
Instance.GetComponent<ActorStatistics>().ID = ActorID;
Instance.GetComponent<ActorStatistics>().ActorLoader = this;
if (!Instance.active)
Instance.active = true;
if (IsPlayer)
{
PlayerTracker.transform.parent = Instance.transform;
}
var parsedText = "";
var parseStartIndex = 2;
var id = -1;
var key = "";
var subId = 0;
var valueStartIndex = -1;
var integerValue = 0;
var floatValue = 0.0f;
var itemId = -1;
for (var i = parseStartIndex; i < Input.Length; i++)
{
if (Input[i] == '/')
{
parsedText = Input.Substring(parseStartIndex, i - parseStartIndex);
parseStartIndex = i + 1;
if (parsedText.Length > 2)
{
var parsedTextPrefix = parsedText.Substring(0, 2);
switch (parsedTextPrefix)
{
case "sc":
id = int.Parse(parsedText.Substring(2, 2));
subId = int.Parse(parsedText.Substring(5, 2));
integerValue = int.Parse(parsedText.Substring(8, 2));
if (Instance.GetComponent<ActorStatistics>().SkillValueCategories == null)
Instance.GetComponent<ActorStatistics>().SkillValueCategories = new Dictionary<int, Dictionary<int, int>>();
if (!Instance.GetComponent<ActorStatistics>().SkillValueCategories.ContainsKey(id))
Instance.GetComponent<ActorStatistics>().SkillValueCategories[id] = new Dictionary<int, int>();
if (!Instance.GetComponent<ActorStatistics>().SkillValueCategories[id].ContainsKey(subId))
Instance.GetComponent<ActorStatistics>().SkillValueCategories[id].Add(subId, integerValue);
else
Instance.GetComponent<ActorStatistics>().SkillValueCategories[id][subId] = integerValue;
break;
case "ra":
valueStartIndex = parsedText.Substring(3, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().RespectForActor[id] = integerValue;
break;
case "aa":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().AdmirationForActor[id] = integerValue;
break;
case "sa":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().SuspicionOfActor[id] = integerValue;
break;
case "fr":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().FactionRank[id] = integerValue;
break;
case "rb":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().RegionalBounty[id] = integerValue;
break;
case "rf":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
id = int.Parse(parsedText.Substring(2, valueStartIndex));
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<ActorStatistics>().RegionalFame[id] = integerValue;
break;
case "bs":
valueStartIndex = parsedText.Substring(2, 2).IndexOf('_');
key = parsedText.Substring(2, valueStartIndex);
integerValue = int.Parse(parsedText.Substring(valueStartIndex));
Instance.GetComponent<BlendshapeLoader>().Blendshapes[key] = floatValue;
break;
case "pl":
IsPlayer = parsedText.Substring(2, 4) == "True";
for (var j = 0; j < Instance.transform.childCount - 1; j++)
{
if (Instance.transform.GetChild(j).name == "PlayerAgent")
Instance.transform.GetChild(j).gameObject.active = IsPlayer;
}
break;
case "hs":
id = int.Parse(parsedText.Substring(2, 2));
Instance.GetComponent<BlendshapeLoader>().HairstyleID = id;
break;
case "fh":
id = int.Parse(parsedText.Substring(2, 2));
Instance.GetComponent<BlendshapeLoader>().FacialHairID = id;
break;
case "fd":
id = int.Parse(parsedText.Substring(2, 2));
Instance.GetComponent<BlendshapeLoader>().FacialDetailID = id;
break;
case "hr":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<BlendshapeLoader>().HairColorR = id;
break;
case "hg":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<BlendshapeLoader>().HairColorG = id;
break;
case "hb":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<BlendshapeLoader>().HairColorB = id;
break;
case "ha":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<BlendshapeLoader>().HairColorA = id;
break;
case "mm":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<ActorStatistics>().MaxMagic = id;
break;
case "nm":
Instance.GetComponent<ActorStatistics>().FirstName = parsedText.Substring(2).Contains("_") ? parsedText.Substring(2, parsedText.IndexOf("_") - 2) : parsedText.Substring(2);
if (parsedText.Substring(2).Contains("_"))
Instance.GetComponent<ActorStatistics>().LastName = parsedText.Substring(parsedText.IndexOf("_") + 1);
Instance.name = parsedText.Substring(2).Replace("_", " ");
break;
case "ms":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<ActorStatistics>().MaxStamina = id;
break;
case "mh":
id = int.Parse(parsedText.Substring(2, 3));
Instance.GetComponent<ActorStatistics>().MaxHealth = id;
break;
//case "lx":
// if (parsedText[2] == '-')
// integerValue = int.Parse(parsedText.Substring(2, 6));
// else
// integerValue = int.Parse(parsedText.Substring(2, 5));
// Instance.transform.position = new Vector3((float)integerValue, Instance.transform.position.y, Instance.transform.position.z);
// break;
//case "ly":
// if (parsedText[2] == '-')
// integerValue = int.Parse(parsedText.Substring(2, 6));
// else
// integerValue = int.Parse(parsedText.Substring(2, 5));
// Instance.transform.position = new Vector3(Instance.transform.position.x, (float)integerValue, Instance.transform.position.z);
// break;
//case "lz":
// if (parsedText[2] == '-')
// integerValue = int.Parse(parsedText.Substring(2, 6));
// else
// integerValue = int.Parse(parsedText.Substring(2, 5));
// Instance.transform.position = new Vector3(Instance.transform.position.x, Instance.transform.position.y, (float)integerValue);
break;
case "ii":
var parsedSubText = "";
var parseSubStartIndex = 0;
itemId = int.Parse(parsedText.Substring(3, 2));
for (var j = parseSubStartIndex; j < parsedText.Length - 2; j++)
{
if (parsedText[j] == '-')
{
parsedSubText = parsedText.Substring(parseSubStartIndex, j - parseSubStartIndex);
parseSubStartIndex = j + 1;
if (parsedSubText.Length > 2)
{
var parsedSubTextPrefix = parsedSubText.Substring(0, 3);
var subKey = "";
var subSubId = 0;
var subValueStartIndex = -1;
var subIntegerValue = 0;
var subFloatValue = 0.0f;
switch (parsedSubTextPrefix)
{
case "iid":
itemId = int.Parse(parsedText.Substring(3, 2));
Instance.GetComponent<ActorStatistics>().Inventory.SelectedItemID = itemId;
Instance.GetComponent<ActorStatistics>().Inventory.SelectedAmount = 1;
Instance.GetComponent<ActorStatistics>().Inventory.AddItem();
Instance.GetComponent<ActorStatistics>().Inventory.SelectedItemID = 0;
Instance.GetComponent<ActorStatistics>().Inventory.SelectedAmount = 0;
Instance.GetComponent<ActorStatistics>().Inventory.SelectedItemIndex = 0;
break;
case "icn":
Instance.GetComponent<ActorStatistics>().Inventory.GetItemByID(itemId).GetComponentInChildren<InventoryItem>().PhysicalCondition = integerValue;
integerValue = int.Parse(parsedSubText.Substring(3, 2));
break;
case "ius":
var boolValue = parsedSubText.Substring(3, 4) == "True";
Instance.GetComponent<ActorStatistics>().Inventory.GetItemByID(itemId).GetComponentInChildren<InventoryItem>().Using = boolValue;
if (boolValue)
{
var newArray = new int[Instance.GetComponent<ActorStatistics>().Inventory.ApparrelManager.CurrentlyActiveIDs.Length + 1];
Instance.GetComponent<ActorStatistics>().Inventory.ApparrelManager.CurrentlyActiveIDs.CopyTo(newArray, 1);
newArray[0] = itemId;
Instance.GetComponent<ActorStatistics>().Inventory.ApparrelManager.CurrentlyActiveIDs = newArray;
Instance.GetComponent<ActorStatistics>().Inventory.ApparrelManager.UpdateApparrel();
if (Instance.GetComponent<ActorStatistics>().Inventory.GetItemByID(itemId).GetComponent<Equipable>() != null)
Instance.GetComponent<ActorStatistics>().Inventory.EquipmentManager.AddEquipmentToSlots(Instance.GetComponent<ActorStatistics>().Inventory.GetItemByID(itemId));
}
break;
}
}
}
}
break;
}
}
}
}
Instance.GetComponent<ActorStatistics>().InstanceID = InstanceManager.GenerateInstanceID();
InstanceManager.AddInstance(Instance.GetComponent<ActorStatistics>().InstanceID, Instance);
if (IsPlayer)
{
InstanceManager.CurrentPlayerInstanceID = Instance.GetComponent<ActorStatistics>().InstanceID;
InstanceManager.RuntimeManager.PlayerInstance = Instance;
InstanceManager.RuntimeManager.PopulateReferences();
}
}
}
}