public Character loadData(string textFile2, Unit u) { Character ch = new Character(); // ch.characterLoadout = characterLoadout; ch.setCharacterLoadout(characterLoadout); ch.unit = u; if (textFile2 != null && textFile2 != "") { textFile = textFile2; } if (textFile != null && textFile != "") { ch.loadCharacterFromTextFile(textFile); } else { CharacterRace mCRace = CharacterRace.getRace(mCRaceName); CharacterClass mCClass = CharacterClass.getClass(mCClassName); CharacterHairStyle hairSt; if (hairPrefab != null) { hairSt = new CharacterHairStyle(hairPrefab); } else { hairSt = new CharacterHairStyle((hairStyle >= 0 && hairStyle < PersonalInformation.hairTypes.Length ? hairStyle : 0)); } ch.loadCharacter(firstName, lastName, mCSex, mCRace, age, mCBackground, height, weight, mCClass, mCSturdy, mCPerception, mCTechnique, mCWellVersed, characterColor, headColor, primaryColor, secondaryColor, hairSt); int level = ch.characterSheet.characterProgress.setLevel(mClevel); int experience = ch.characterSheet.characterProgress.setExperience(mCexperience); } return(ch); }
public void loadCharacterFromTextFile(string fileName) { // TextAsset text = Resources.Load<TextAsset>("Saves/" + fileName); // string data = text.text; string data = Saves.getCharactersString(fileName); string[] components = data.Split(new char[] { ';' }); int curr = 0; string firstName = components[curr++]; string lastName = components[curr++]; int sex = int.Parse(components[curr++]); CharacterSex sexC = (sex == 0 ? CharacterSex.Male : (sex == 1 ? CharacterSex.Female : CharacterSex.Other)); int race = int.Parse(components[curr++]); CharacterRace raceC = CharacterRace.getRace(race == 0 ? RaceName.Berrind : (race == 1 ? RaceName.Ashpian : RaceName.Rorrul)); int background = int.Parse(components[curr++]); CharacterBackground backgroundC = (background == 0 ? (race == 0 ? CharacterBackground.FallenNoble : (race == 1 ? CharacterBackground.Commoner : CharacterBackground.Servant)) : (race == 0 ? CharacterBackground.WhiteGem : (race == 1 ? CharacterBackground.Immigrant : CharacterBackground.Unknown))); int age = int.Parse(components[curr++]); int height = int.Parse(components[curr++]); int weight = int.Parse(components[curr++]); int class1 = int.Parse(components[curr++]); ClassName className = (class1 == 0 ? ClassName.ExSoldier : (class1 == 1 ? ClassName.Engineer : (class1 == 2 ? ClassName.Investigator : (class1 == 3 ? ClassName.Researcher : ClassName.Orator)))); int sturdy = int.Parse(components[curr++]); int perception = int.Parse(components[curr++]); int technique = int.Parse(components[curr++]); int wellVersed = int.Parse(components[curr++]); int athletics = int.Parse(components[curr++]); int melee = int.Parse(components[curr++]); int ranged = int.Parse(components[curr++]); int stealth = int.Parse(components[curr++]); int mechanical = int.Parse(components[curr++]); int medicinal = int.Parse(components[curr++]); int historical = int.Parse(components[curr++]); int political = int.Parse(components[curr++]); Color characterColor = new Color(int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f); Debug.Log(characterColor.r + " " + characterColor.g + " " + characterColor.b); Color headColor = new Color(int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f); Color primaryColor = new Color(int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f); Color secondaryColor = new Color(int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f, int.Parse(components[curr++]) / 255.0f); int hairStyle = 0; int level = 1; int experience = 0; if (curr < components.Length - 1) { hairStyle = int.Parse(components[curr++]); } if (curr < components.Length - 1) { level = int.Parse(components[curr++]); } if (curr < components.Length - 1) { experience = int.Parse(components[curr++]); } int money = 0; int health = 100000; int composure = 100000; int numFeatures = 0; int numItems = 0; int focus = 0; if (curr < components.Length - 1) { money = int.Parse(components[curr++]); } if (curr < components.Length - 1) { health = int.Parse(components[curr++]); } if (curr < components.Length - 1) { composure = int.Parse(components[curr++]); } if (curr < components.Length - 1) { numFeatures = int.Parse(components[curr++]); } int[] features = new int[numFeatures]; for (int n = 0; n < numFeatures; n++) { if (curr < components.Length - 1) { features[n] = int.Parse(components[curr++]); } } if (curr < components.Length - 1) { focus = int.Parse(components[curr++]); } if (curr < components.Length - 1) { numItems = int.Parse(components[curr++]); } personalInfo = new PersonalInformation(new CharacterName(firstName, lastName), sexC, raceC, backgroundC, new CharacterAge(age), new CharacterHeight(height), new CharacterWeight(weight), new CharacterHairStyle(hairStyle)); characterProgress = new CharacterProgress(CharacterClass.getClass(className)); abilityScores = new AbilityScores(sturdy, perception, technique, wellVersed); combatScores = new CombatScores(abilityScores, personalInfo, characterProgress); skillScores = new SkillScores(combatScores, characterProgress); CharacterColors characterColors = new CharacterColors(characterColor, headColor, primaryColor, secondaryColor); characterSheet = new CharacterSheet(abilityScores, personalInfo, characterProgress, combatScores, skillScores, characterColors, this, characterLoadout); skillScores.incrementScore(Skill.Athletics, athletics); skillScores.incrementScore(Skill.Melee, melee); skillScores.incrementScore(Skill.Ranged, ranged); skillScores.incrementScore(Skill.Stealth, stealth); skillScores.incrementScore(Skill.Mechanical, mechanical); skillScores.incrementScore(Skill.Medicinal, medicinal); skillScores.incrementScore(Skill.Historical, historical); skillScores.incrementScore(Skill.Political, political); characterProgress.setLevel(level); characterProgress.setExperience(experience); characterSheet.inventory.purse.receiveMoney(money); combatScores.setHealth(health); combatScores.setComposure(composure); characterProgress.getCharacterClass().chosenFeatures = features; characterProgress.setWeaponFocus(focus); Inventory inv = characterSheet.inventory; for (int n = 0; n < numItems; n++) { int slot = int.Parse(components[curr++]); ItemCode code = (ItemCode)int.Parse(components[curr++]); string itemData = components[curr++]; Item i = Item.deserializeItem(code, itemData); if (slot < 100) { if (inv.inventory[slot].item != null) { if (inv.itemCanStackWith(inv.inventory[slot].item, i)) { inv.inventory[slot].item.addToStack(i); } } else if (inv.canInsertItemInSlot(i, Inventory.getSlotForIndex(slot))) { inv.insertItemInSlot(i, Inventory.getSlotForIndex(slot)); } } else { characterSheet.characterLoadout.setItemInSlot(getArmorSlot(slot), i); } //Inventory stuff } //Right Weapon = 100; //Left Weapon = 110; //Head = 120; //Shoulder = 130; //Chest = 140; //Legs = 150; //Boots = 160; //Gloves = 170; if (curr < components.Length - 1) { characterProgress.setFavoredRace(int.Parse(components[curr++])); } }