private async void SaveTrait(IRpcEvent e, Guid characterId, CharacterTrait trait)
        {
            using (var context = new StorageContext())
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var save = context.Characters.Include(c => c.Trait).Single(c => c.Id == characterId);

                        trait.Id = save.TraitId;

                        context.Entry(save.Trait).CurrentValues.SetValues(trait);

                        await context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        this.Logger.Error(ex, "Character Trait Save");

                        transaction.Rollback();
                    }
                }
        }
示例#2
0
        public CharacterTrait FindByNameAndModset(string name, string modset)
        {
            CharacterTrait characterTrait = (from traits in db.CharacterTraits where traits.Name == name && traits.ModSet == modset select traits).FirstOrDefault();

            characterTrait.Description = HttpUtility.HtmlDecode(characterTrait.Description);
            return(characterTrait);
        }
        public async Task Education(string traitName)
        {
            var trait = _stewardContext.Traits.FirstOrDefault(t => t.Description.StartsWith(traitName.ToLowerInvariant()));

            if (trait == null)
            {
                await ReplyAsync($"Could not find a trait with the name {traitName}.");

                return;
            }

            if (!trait.IsEducation)
            {
                await ReplyAsync($"{traitName} is not a valid Education");

                return;
            }
            DiscordUser discordUser = null;

            PlayerCharacter activeCharacter = null;


            discordUser = _stewardContext.DiscordUsers
                          .Include(du => du.Characters)
                          .ThenInclude(c => c.CharacterTraits)
                          .ThenInclude(ct => ct.Trait)
                          .SingleOrDefault(u => u.DiscordId == Context.User.Id.ToString());

            activeCharacter = discordUser.Characters.Find(c => c.IsAlive());

            if (activeCharacter == null)
            {
                await ReplyAsync("Could not find a living character.");

                return;
            }

            var traitAlreadyExistsList = activeCharacter.CharacterTraits.Where(ct => ct.Trait.IsEducation);

            if (traitAlreadyExistsList.Count() > 0)
            {
                await ReplyAsync("You already have an education trait!");

                return;
            }

            var newCharacterTrait = new CharacterTrait()
            {
                Trait           = trait,
                PlayerCharacter = activeCharacter
            };

            await _stewardContext.CharacterTraits.AddAsync(newCharacterTrait);

            await _stewardContext.SaveChangesAsync();

            await ReplyAsync("Trait has been added.");
        }
        public void ShouldNotValidateWhenPointsIsNotWithinRange(TypeOfTrait typeOfTrait, int points)
        {
            var trait = new CharacterTrait(typeOfTrait, points);

            unitToTest.ShouldHaveValidationErrorFor(x => x.Points, trait);
        }
        public async Task AddTraitToCharacter(string traitName, [Remainder] SocketGuildUser mention = null)
        {
            var trait = _stewardContext.Traits.FirstOrDefault(t => t.Description.StartsWith(traitName.ToLowerInvariant()));

            if (trait == null)
            {
                await ReplyAsync($"Could not find a trait with the name {traitName}.");

                return;
            }

            DiscordUser discordUser = null;

            PlayerCharacter activeCharacter = null;

            if (mention == null)
            {
                discordUser = _stewardContext.DiscordUsers
                              .Include(du => du.Characters)
                              .ThenInclude(c => c.CharacterTraits)
                              .ThenInclude(ct => ct.Trait)
                              .SingleOrDefault(u => u.DiscordId == Context.User.Id.ToString());

                activeCharacter = discordUser.Characters.Find(c => c.IsAlive());

                if (activeCharacter == null)
                {
                    await ReplyAsync("Could not find a living character.");

                    return;
                }
            }
            else
            {
                discordUser = _stewardContext.DiscordUsers
                              .Include(du => du.Characters)
                              .ThenInclude(c => c.CharacterTraits)
                              .ThenInclude(ct => ct.Trait)
                              .SingleOrDefault(u => u.DiscordId == mention.Id.ToString());

                activeCharacter = discordUser.Characters.Find(c => c.IsAlive());

                if (activeCharacter == null)
                {
                    await ReplyAsync("Could not find a living character.");

                    return;
                }

                var commandUser =
                    _stewardContext.DiscordUsers.SingleOrDefault(du => du.DiscordId == Context.User.Id.ToString());

                if (!commandUser.CanUseAdminCommands)
                {
                    await ReplyAsync("You don't have the required permissions to use this command.");

                    return;
                }
            }

            var traitAlreadyExistsList = activeCharacter.CharacterTraits.Where(ct => ct.Trait == trait);

            if (traitAlreadyExistsList.Count() != 0)
            {
                activeCharacter.CharacterTraits.Remove(traitAlreadyExistsList.First());
                _stewardContext.PlayerCharacters.Update(activeCharacter);
                await _stewardContext.SaveChangesAsync();
                await ReplyAsync("Trait has been removed.");

                return;
            }

            var newCharacterTrait = new CharacterTrait()
            {
                Trait           = trait,
                PlayerCharacter = activeCharacter
            };

            await _stewardContext.CharacterTraits.AddAsync(newCharacterTrait);

            await _stewardContext.SaveChangesAsync();

            await ReplyAsync("Trait has been added.");
        }
    public static void ReadCharacterTraitXMLFiles()
    {
        string path = Application.dataPath;
            GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent<GlobalGameData>();

            XmlDocument xmlDoc = new XmlDocument(); // creates the new document
            TextAsset traitData = null;
            traitData = Resources.Load("Character Trait XML Data") as TextAsset;  // load the XML file from the Resources folder
            xmlDoc.LoadXml(traitData.text); // and add it to the xmldoc object
            XmlNodeList traitList = xmlDoc.GetElementsByTagName("Row"); // separate elements by type (trait, in this case)

            foreach (XmlNode Trait in traitList)
            {
                XmlNodeList traitContent = Trait.ChildNodes;
                CharacterTrait currentTrait = new CharacterTrait();

                foreach (XmlNode trait in traitContent)
                {
                    if (trait.Name == "ID")
                    {
                        currentTrait.ID = trait.InnerText;
                    }
                    if (trait.Name == "Name")
                    {
                        currentTrait.Name = trait.InnerText;
                    }
                    if (trait.Name == "Description")
                    {
                        currentTrait.Description = trait.InnerText;
                    }
                    if (trait.Name == "Opposite_Trait_ID")
                    {
                        currentTrait.OppositeTraitID = trait.InnerText;
                    }
                    if (trait.Name == "Change")
                    {
                        currentTrait.ChangeTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Goal_Focus")
                    {
                        currentTrait.GoalFocusTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Wealth")
                    {
                        currentTrait.WealthTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Pops")
                    {
                        currentTrait.PopsTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Budget")
                    {
                        currentTrait.BudgetTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Courage")
                    {
                        currentTrait.CourageTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Goal_Stability")
                    {
                        currentTrait.GoalStabilityTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Tax")
                    {
                        currentTrait.TaxTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Science")
                    {
                        currentTrait.ScienceTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Gluttony")
                    {
                        currentTrait.GluttonyTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Learning")
                    {
                        currentTrait.LearningTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Reserve")
                    {
                        currentTrait.ReserveTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Trader")
                    {
                        currentTrait.TraderTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Diplomacy")
                    {
                        currentTrait.DiplomacyTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Traveler")
                    {
                        currentTrait.TravelerTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Trust")
                    {
                        currentTrait.TrustTendency = int.Parse(trait.InnerText);
                    }
                    if (trait.Name == "Admin")
                    {
                        currentTrait.AdminTendency = int.Parse(trait.InnerText);
                    }
                }

                // add the trait once done
                CharacterTraitList.Add(currentTrait);
            }
            gameDataRef.CharacterTraitList = CharacterTraitList;
    }
    public static Character GenerateNewCharacter(Character.eRole cRole, string empireID)
    {
        Character newChar = new Character();

        // Step 0: Initialize the character
        newChar.CivID = empireID;
        newChar.Role = cRole;

        // Step 1: Generate basic type (sex, age, health, ID)
        int sex = UnityEngine.Random.Range(0, 2);
        if (sex == 0)
        {
            newChar.Gender = Character.eSex.Female;
        }
        else
        {
            newChar.Gender = Character.eSex.Male;
        }

        int lifeForm = UnityEngine.Random.Range(0, 20);
        if (lifeForm < 12)
        {
            newChar.Lifeform = Character.eLifeformType.Human;
        }
        else if (lifeForm < 14)
        {
            newChar.Lifeform = Character.eLifeformType.Human_Immobile;
        }
        else if (lifeForm < 16)
        {
            newChar.Lifeform = Character.eLifeformType.Hybrid;
        }
        else if (lifeForm < 18)
        {
            newChar.Lifeform = Character.eLifeformType.Machine;
        }
        else if (lifeForm < 20)
        {
            newChar.Lifeform = Character.eLifeformType.AI;
        }
        else
            newChar.Lifeform = Character.eLifeformType.Resuscitated;

        // 1A: determine age based on lifeform type
        int charTypeMax = 0;
        if (newChar.Lifeform == Character.eLifeformType.Human || newChar.Lifeform == Character.eLifeformType.Human_Immobile)
            charTypeMax = 90;
        else if (newChar.Lifeform == Character.eLifeformType.Resuscitated)
            charTypeMax = 200;
        else if (newChar.Lifeform == Character.eLifeformType.Hybrid)
            charTypeMax = 140;
        else if (newChar.Lifeform == Character.eLifeformType.Machine || newChar.Lifeform == Character.eLifeformType.AI)
            charTypeMax = 500;
        newChar.Age = UnityEngine.Random.Range(18, charTypeMax); // generate ages between 18 and 80

        // 1B: set health type depending on type of lifeform
        if (newChar.Lifeform == Character.eLifeformType.Human || newChar.Lifeform == Character.eLifeformType.Human_Immobile || newChar.Lifeform == Character.eLifeformType.Resuscitated)
        {
            int healthRating = newChar.Age + UnityEngine.Random.Range(-50, 50);

            if (healthRating <= 30)
                newChar.Health = Character.eHealth.Perfect;
            else if (healthRating <= 50)
                newChar.Health = Character.eHealth.Fine;
            else if (healthRating <= 70)
                newChar.Health = Character.eHealth.Healthy;
            else if (healthRating <= 90)
                newChar.Health = Character.eHealth.Impaired;
            else if (healthRating <= 120)
                newChar.Health = Character.eHealth.Unhealthy;
            else
                newChar.Health = Character.eHealth.Bedridden;
        }
        else
        {
            int healthRating = UnityEngine.Random.Range(0, 100);
            if (healthRating <= 60)
                newChar.Health = Character.eHealth.Perfect;
            else if (healthRating <= 70)
                newChar.Health = Character.eHealth.Functional;
            else if (healthRating <= 80)
                newChar.Health = Character.eHealth.Malfunctioning;
            else if (healthRating <= 95)
                newChar.Health = Character.eHealth.Seriously_Damaged;
            else
                newChar.Health = Character.eHealth.Critically_Damaged;
        }

        newChar.ID = "CHA" + UnityEngine.Random.Range(0, 1000000);

        // Step 2: Create name
        if (newChar.Gender == Character.eSex.Female)
        {
            var nameIndex = UnityEngine.Random.Range(0, DataManager.characterFemaleFirstNameList.Count);
            newChar.Name = DataManager.characterFemaleFirstNameList[nameIndex];
        }
        else if (newChar.Gender == Character.eSex.Male)
        {
            var nameIndex = UnityEngine.Random.Range(0, DataManager.characterMaleFirstNameList.Count);
            newChar.Name = DataManager.characterMaleFirstNameList[nameIndex];
        }
        else
        {
            newChar.Name = "GenericName";
        }

        if (newChar.Lifeform == Character.eLifeformType.Machine) // add 'r' to the beginning for robot
        {
            newChar.Name = "R. " + newChar.Name;
        }

        // Step 3: Generate base stats
        newChar.Intelligence = UnityEngine.Random.Range(20, 90); // min and max intelligence, add bonus for AIs
        if (newChar.Lifeform == Character.eLifeformType.AI || newChar.Lifeform == Character.eLifeformType.Machine)
            newChar.Intelligence += UnityEngine.Random.Range(15, 60);
        newChar.Honor = UnityEngine.Random.Range(5, 95); // younger characters tend to be more loyal base
        newChar.Passion = UnityEngine.Random.Range(5, 95);
        if (newChar.Lifeform == Character.eLifeformType.AI || newChar.Lifeform == Character.eLifeformType.Machine)
            newChar.Passion = 0; // machines are emotionless
        newChar.Drive = UnityEngine.Random.Range(5, 95);
        if (newChar.Lifeform == Character.eLifeformType.AI || newChar.Lifeform == Character.eLifeformType.Machine)
            newChar.Drive = 95; // machines never stop
        newChar.Charm = UnityEngine.Random.Range(-95, 95);
        newChar.Empathy = UnityEngine.Random.Range(-95, 95);
        newChar.Caution = UnityEngine.Random.Range(-95, 95); // low end - risk taker, high end - security
        newChar.Piety = UnityEngine.Random.Range(5, 95);
        newChar.Morality = UnityEngine.Random.Range(-95, 95);
        newChar.BaseInfluence = UnityEngine.Random.Range(0, 15); // base influence before calculation
        newChar.Admin = UnityEngine.Random.Range(1,5); // AP points
        if (newChar.CivID == "CIV0")
            newChar.IntelLevel = UnityEngine.Random.Range(0, 5) + (newChar.Age / 25); // older characters are more well-known
        else
            newChar.IntelLevel = 0; // base no knowledge of other civ's characters

        // Step 3a: Generate AI tendencies
        newChar.AdminTendency = UnityEngine.Random.Range(-90, 90);
        newChar.BudgetTendency = UnityEngine.Random.Range(-90, 90);
        newChar.ChangeTendency = UnityEngine.Random.Range(-90, 90);
        newChar.CourageTendency = UnityEngine.Random.Range(-90, 90);
        newChar.DiplomacyTendency = UnityEngine.Random.Range(-90, 90);
        newChar.GluttonyTendency = UnityEngine.Random.Range(-90, 90);
        newChar.GoalFocusTendency = UnityEngine.Random.Range(-90, 90);
        newChar.GoalStabilityTendency = UnityEngine.Random.Range(-90, 90);
        newChar.LearningTendency = UnityEngine.Random.Range(-90, 90);
        newChar.PopsTendency = UnityEngine.Random.Range(-90, 90);
        newChar.ReserveTendency = UnityEngine.Random.Range(-90, 90);
        newChar.ScienceTendency = UnityEngine.Random.Range(-90, 90);
        newChar.TaxTendency = UnityEngine.Random.Range(-90, 90);
        newChar.TraderTendency = UnityEngine.Random.Range(-90, 90);
        newChar.TravelTendency = UnityEngine.Random.Range(-90, 90);

        // Step 3b: Generate traits
        int traitMax = gameDataRef.CharacterTraitList.Count - 1;
        int traitMin = 0;
        int totalTraits = UnityEngine.Random.Range(1, Constants.Constants.MaxCharTraits);
        int traitCount = 0;
        while (traitCount < totalTraits)
        {
            CharacterTrait tempTrait = new CharacterTrait();
            int traitChoice = UnityEngine.Random.Range(traitMin,traitMax); // choose a trait from the data list
            tempTrait = gameDataRef.CharacterTraitList[traitChoice];

            if (!newChar.Traits.Exists(p=> p.ID == tempTrait.ID)) // check trait against being already present and that it does not have an opposite trait ID already present
            {
                if (!newChar.Traits.Exists(p=> p.OppositeTraitID == tempTrait.ID))
                {
                    newChar.Traits.Add(tempTrait);
                    traitCount += 1; // only add to count if a valid trait is picked
                }
            }
        }

        // Step 3a: Adjust tendencies based on traits
        foreach (CharacterTrait trait in newChar.Traits)
        {
            if (trait.AdminTendency != 0)
            {
                newChar.AdminTendency = trait.AdminTendency;
            }

            if (trait.BudgetTendency != 0)
            {
                newChar.BudgetTendency = trait.BudgetTendency;
            }

            if (trait.ChangeTendency != 0)
            {
                newChar.ChangeTendency = trait.BudgetTendency;
            }

            if (trait.CourageTendency != 0)
            {
                newChar.CourageTendency = trait.CourageTendency;
            }

            if (trait.DiplomacyTendency != 0)
            {
                newChar.DiplomacyTendency = trait.DiplomacyTendency;
            }

            if (trait.GluttonyTendency != 0)
            {
                newChar.GluttonyTendency = trait.GluttonyTendency;
            }

            if (trait.GoalFocusTendency != 0)
            {
                newChar.GoalFocusTendency = trait.GoalFocusTendency;
            }

            if (trait.GoalStabilityTendency != 0)
            {
                newChar.GoalStabilityTendency = trait.GoalStabilityTendency;
            }

            if (trait.LearningTendency != 0)
            {
                newChar.LearningTendency = trait.LearningTendency;
            }

            if (trait.PopsTendency != 0)
            {
                newChar.PopsTendency = trait.PopsTendency;
            }

            if (trait.ReserveTendency != 0)
            {
                newChar.ReserveTendency = trait.ReserveTendency;
            }

            if (trait.ScienceTendency != 0)
            {
                newChar.ScienceTendency = trait.ScienceTendency;
            }

            if (trait.TaxTendency != 0)
            {
                newChar.TaxTendency = trait.TaxTendency;
            }

            if (trait.TraderTendency != 0)
            {
                newChar.TraderTendency = trait.TraderTendency;
            }

            if (trait.TravelerTendency != 0)
            {
                newChar.TravelTendency = trait.TravelerTendency;
            }

            if (trait.AdminTendency != 0)
            {
                newChar.AdminTendency = trait.AdminTendency;
            }

            if (trait.TrustTendency != 0)
            {
                newChar.TrustTendency = trait.TrustTendency;
            }

            if (trait.WealthTendency != 0)
            {
                newChar.WealthTendency = trait.WealthTendency;
            }

        }

        // Step 4: Generate picture ID
        AssignCharacterPictureID(newChar);

        // Step 5: Generate base history
        string creationVerb = "";
        if (newChar.Lifeform == Character.eLifeformType.Human || newChar.Lifeform == Character.eLifeformType.Human_Immobile || newChar.Lifeform == Character.eLifeformType.Hybrid)
            creationVerb = "born";
        else if (newChar.Lifeform == Character.eLifeformType.Resuscitated)
            creationVerb = "reborn";
        else
            creationVerb = "built and programmed";
        newChar.History += "In " + (gameDataRef.GameDate - newChar.Age).ToString("G0") + ", the esteemed " + newChar.Name + " was " + creationVerb + ". ";

        return newChar;
    }
示例#8
0
 public GameEffectTrait(GameCharacter inputCharacter, CharacterTrait inputTrait)
 {
     inputCharacter.TraitList.Add(inputTrait);
 }
示例#9
0
        private void OnClientTriggerEvent(Client sender, string eventName, object[] arguments)
        {
            if (eventName == "FinishCharacterCreation")
            {
                if (!API.hasEntityData(sender, "User"))
                {
                    return;
                }

                User user          = API.getEntityData(sender, "User");
                var  characterData = API.fromJson((string)arguments[0]);

                using (var ctx = new ContextFactory().Create())
                {
                    // Checking if name is available
                    string characterName = null;
                    characterName = characterData.name;
                    var isNameTaken = ctx.Characters.FirstOrDefault(up => up.Name == characterName);
                    if (isNameTaken != null)
                    {
                        API.triggerClientEvent(sender, "CharacterNameAlreadyTaken");
                        return;
                    }

                    // Character
                    Character character = new Character
                    {
                        UserId     = user.Id,
                        Name       = characterData.name,
                        Gender     = characterData.gender,
                        Money      = 0,
                        Bank       = 8500,
                        Level      = 1,
                        Experience = 0,
                        PlayedTime = 0,
                        PositionX  = 169.3792f,
                        PositionY  = -967.8402f,
                        PositionZ  = 29.98808f,
                        RotationZ  = 138.6666f,
                        LastLogin  = DateTime.Now,
                        CreatedAt  = DateTime.Now
                    };

                    ctx.Characters.Add(character);
                    Data.Character.Add(sender, character);

                    // Traits
                    CharacterTrait traits = new CharacterTrait
                    {
                        Character      = character,
                        FaceFirst      = characterData.faceFirst,
                        FaceSecond     = characterData.faceSecond,
                        FaceMix        = characterData.faceMix,
                        SkinFirst      = characterData.skinFirst,
                        SkinSecond     = characterData.skinSecond,
                        SkinMix        = characterData.skinMix,
                        HairType       = characterData.hairType,
                        HairColor      = characterData.hairColor,
                        HairHighlight  = characterData.hairHighlight,
                        EyeColor       = characterData.eyeColor,
                        Eyebrows       = characterData.eyebrows,
                        EyebrowsColor1 = characterData.eyebrowsColor1,
                        EyebrowsColor2 = characterData.eyebrowsColor2,
                        Beard          = characterData.beard,
                        BeardColor     = characterData.beardColor,
                        Makeup         = characterData.makeup,
                        MakeupColor    = characterData.makeupColor,
                        Lipstick       = characterData.lipstick,
                        LipstickColor  = characterData.lipstickColor
                    };

                    ctx.Traits.Add(traits);

                    // Clothes
                    CharacterClothes torso = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 3,
                        Variation   = characterData.torso,
                        Texture     = 0,
                        IsAccessory = false
                    };

                    CharacterClothes top = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 11,
                        Variation   = characterData.topshirt,
                        Texture     = characterData.topshirtTexture,
                        IsAccessory = false
                    };

                    CharacterClothes undershirt = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 8,
                        Variation   = characterData.undershirt,
                        Texture     = 0,
                        IsAccessory = false
                    };

                    CharacterClothes pants = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 4,
                        Variation   = characterData.legs,
                        Texture     = 0,
                        IsAccessory = false
                    };

                    CharacterClothes shoes = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 6,
                        Variation   = characterData.feet,
                        Texture     = 0,
                        IsAccessory = false
                    };

                    CharacterClothes accessory = new CharacterClothes
                    {
                        CharacterId = character.Id,
                        BodyPart    = 7,
                        Variation   = characterData.accessory,
                        Texture     = 0,
                        IsAccessory = false
                    };

                    ctx.Clothes.Add(torso);
                    ctx.Clothes.Add(top);
                    ctx.Clothes.Add(undershirt);
                    ctx.Clothes.Add(pants);
                    ctx.Clothes.Add(shoes);
                    ctx.Clothes.Add(accessory);

                    sender.name = characterData.name;

                    // Send to spawn
                    API.triggerClientEvent(sender, "closeCharacterCreationBrowser");

                    Managers.DimensionManager.DismissPrivateDimension(sender);
                    API.setEntityDimension(sender, 0);

                    ctx.SaveChanges();

                    // Sync player face with other players
                    Customization.CustomizationModel gtao = new Customization.CustomizationModel();
                    gtao.InitializePedFace(sender);
                    gtao.UpdatePlayerFace(sender);
                }
            }
        }
 public int this[CharacterClass characterClass, CharacterTrait characterTrait, int level]
 {
     get => Check(characterClass, characterTrait, level);
示例#11
0
 public static int GetCharacterTraitLevel(this Hero hero, CharacterTrait characterTrait)
 {
     return(hero.GetTraitLevel(TraitObject.Find(characterTrait.ToString())));
 }
示例#12
0
        private void SaveCharacter()
        {
            if (!this.isPlaying)
            {
                return;
            }

            var player = Game.PlayerPed;

            this.activeCharacter.Position = player.Position.ToVector3().ToPosition();
            this.activeCharacter.Model    = ((uint)player.Model.Hash).ToString();

            this.Rpc.Event(CharacterEvents.SaveCharacter).Trigger(this.activeCharacter);

            this.Rpc.Event(CharacterEvents.SaveStyle).Trigger(this.activeCharacter.Id, CharacterStyle.ConvertStyle(player.Style, this.activeCharacter.Id));

            // FreeMode Models only
            if (!(this.activeCharacter.ModelHash == PedHash.FreemodeMale01 ||
                  this.activeCharacter.ModelHash == PedHash.FreemodeFemale01))
            {
                return;
            }

            this.Rpc.Event(CharacterEvents.SaveFacialTrait).Trigger(this.activeCharacter.Id, CharacterFacialTrait.ConvertFacialTrait(player.Handle));
            this.Rpc.Event(CharacterEvents.SaveHeritage).Trigger(this.activeCharacter.Id, CharacterHeritage.ConvertHeritage(player.GetHeadBlendData(), this.activeCharacter.Created));
            this.Rpc.Event(CharacterEvents.SaveTrait).Trigger(this.activeCharacter.Id, CharacterTrait.ConvertTrait(player));
        }
示例#13
0
    public static void ReadCharacterTraitXMLFiles()
    {
        string         path        = Application.dataPath;
        GlobalGameData gameDataRef = GameObject.Find("GameManager").GetComponent <GlobalGameData>();

        XmlDocument xmlDoc    = new XmlDocument();  // creates the new document
        TextAsset   traitData = null;

        traitData = Resources.Load("Character Trait XML Data") as TextAsset; // load the XML file from the Resources folder
        xmlDoc.LoadXml(traitData.text);                                      // and add it to the xmldoc object
        XmlNodeList traitList = xmlDoc.GetElementsByTagName("Row");          // separate elements by type (trait, in this case)

        foreach (XmlNode Trait in traitList)
        {
            XmlNodeList    traitContent = Trait.ChildNodes;
            CharacterTrait currentTrait = new CharacterTrait();

            foreach (XmlNode trait in traitContent)
            {
                if (trait.Name == "ID")
                {
                    currentTrait.ID = trait.InnerText;
                }
                if (trait.Name == "Name")
                {
                    currentTrait.Name = trait.InnerText;
                }
                if (trait.Name == "Description")
                {
                    currentTrait.Description = trait.InnerText;
                }
                if (trait.Name == "Opposite_Trait_ID")
                {
                    currentTrait.OppositeTraitID = trait.InnerText;
                }
                if (trait.Name == "Change")
                {
                    currentTrait.ChangeTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Goal_Focus")
                {
                    currentTrait.GoalFocusTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Wealth")
                {
                    currentTrait.WealthTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Pops")
                {
                    currentTrait.PopsTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Budget")
                {
                    currentTrait.BudgetTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Courage")
                {
                    currentTrait.CourageTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Goal_Stability")
                {
                    currentTrait.GoalStabilityTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Tax")
                {
                    currentTrait.TaxTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Science")
                {
                    currentTrait.ScienceTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Gluttony")
                {
                    currentTrait.GluttonyTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Learning")
                {
                    currentTrait.LearningTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Reserve")
                {
                    currentTrait.ReserveTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Trader")
                {
                    currentTrait.TraderTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Diplomacy")
                {
                    currentTrait.DiplomacyTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Traveler")
                {
                    currentTrait.TravelerTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Trust")
                {
                    currentTrait.TrustTendency = int.Parse(trait.InnerText);
                }
                if (trait.Name == "Admin")
                {
                    currentTrait.AdminTendency = int.Parse(trait.InnerText);
                }
            }

            // add the trait once done
            CharacterTraitList.Add(currentTrait);
        }
        gameDataRef.CharacterTraitList = CharacterTraitList;
    }