Exemple #1
0
        /// <summary>
        /// Distributes the given amount of XP over the group of the given Character (or adds it only to the Char, if not in Group).
        /// </summary>
        /// <remarks>Requires Map-Context.</remarks>
        /// <param name="chr"></param>
        public static void DistributeCombatXp(Character chr, INamed killed, int xp)
        {
            if (chr.SoulmateRecord != null)
            {
                chr.SoulmateRecord.OnExpGained(true);
            }
            GroupMember groupMember = chr.GroupMember;

            if (groupMember != null)
            {
                List <Character> members = new List <Character>();
                int highestLevel         = 0;
                int totalLevels          = 0;
                groupMember.IterateMembersInRange(WorldObject.BroadcastRange, member =>
                {
                    Character character = member.Character;
                    if (character == null)
                    {
                        return;
                    }
                    totalLevels += character.Level;
                    if (character.Level > highestLevel)
                    {
                        highestLevel = character.Level;
                    }
                    members.Add(character);
                });
                foreach (Character character in members)
                {
                    int experience = MathUtil.Divide(xp * character.Level, totalLevels);
                    character.GainCombatXp(experience, killed, true);
                }
            }
            else
            {
                chr.GainCombatXp(xp, killed, true);
            }
        }