public void IncreaseAgression(Character character, int amount)
 {
     if (_agressionLevels.ContainsKey(character.Id))
         _agressionLevels[character.Id] += amount;
     else
         _agressionLevels.Add(character.Id, amount);
 }
        /// <summary>
        /// Computes the damage of a skill given a user, victim and skill. This takes into account affinity
        /// resistance and all potential resistances.
        /// </summary>
        /// <param name="victim"></param>
        /// <param name="skill"></param>
        public static int ComputeDamage(Character user, Character victim, Skill skill)
        {
            var damageModifier = 1d;

            switch (skill.SkillTemplate.SkillType)
            {
                case SkillType.Elemental:
                    damageModifier += GetElementalModifier(user);
                    break;
                case SkillType.Healing:
                    damageModifier += GetHealingModifier(user);
                    damageModifier *= -1;
                    break;
                case SkillType.Physical:
                    damageModifier += GetPhysicalModifier(user);
                    break;
            }

            // Grab the damage modifier
            damageModifier = Math.Round(damageModifier, 3, MidpointRounding.AwayFromZero);

            var totalDamage = skill.SkillTemplate.Damage * damageModifier;

            return (int)totalDamage;
        }
Exemple #3
0
        protected AiBase(Character character)
        {
            if (character == null)
                throw new ArgumentNullException("A null character is not acceptable for an AI module");

            Character = character;

            AgressionTracker = new AgressionTracker();
        }
Exemple #4
0
        public void PayloadShouldCapAtZero()
        {
            var agressor = new Character("");
            var victim = new Character("");

            var payload = new DamagePayload(agressor);
            payload.Apply(victim);

            Assert.Equal(0, victim.CharacterStats[ (int) StatTypes.Hitpoints].CurrentValue);
        }
Exemple #5
0
        public override void UseItemOn(Character character, Character user)
        {
            var player = character as Player;

            if (player != null)
            {
                // Key items cannot be used; send a message notifying the user
                var packet = new ServerSendGameMessagePacket(GameMessage.ItemCannotBeUsed, new List<string>());
                player.Client.Send(packet);
            }
        }
Exemple #6
0
        public override void Apply(Character victim)
        {
            // Get the final stats from both our targets
            var aggressorFinalStats = GetCharacterStats(Aggressor);
            var victimFinalStats = GetCharacterStats(victim);

            // Compute the damage using a basic formula for now (STR * 2) - VIT
            var damageToDeal = (aggressorFinalStats[(int)StatTypes.Strength].CurrentValue * 2 - victimFinalStats[(int)StatTypes.Vitality].CurrentValue);

            victim.CharacterStats[(int)StatTypes.Hitpoints].CurrentValue -= damageToDeal;

            DamageInflicted = damageToDeal;
        }
        public static bool CanPerformSkill(Character user, Character target, Skill skill)
        {
            var container = new SkillValidationContainer(skill, user, target);
            var result = true;

            // Every skill needs to have these validators applied
            result &= EvaluateRequirementsForAllSkillTypes(container);

            // If your skill has a target, apply the below validators
            if (skill.SkillTemplate.SkillActivationType == SkillActivationType.Target)
                result &= EvaluateRequirementsForTargetSkillTypes(container);

            return result;
        }
Exemple #8
0
        private CharacterStatCollection GetCharacterStats(Character character)
        {
            var statsWithEquipmentMods = new CharacterStatCollection();

            // Include character stats
            statsWithEquipmentMods = CombineStats(statsWithEquipmentMods, character.CharacterStats);

            // Get inclusive equipment stats
            foreach (var equip in character.Equipment)
            {
                if (equip != null)
                    statsWithEquipmentMods = CombineStats(equip.GetEquipmentModifierStats(), statsWithEquipmentMods);
            }

            return statsWithEquipmentMods;
        }
        private void CharacterStatsOnCurrentValueChanged(long oldValue, long newValue, StatTypes statType, Character tracking)
        {
            var player = tracking as Player;
            Logger.Instance.Debug("{0} has {1} changed to {2}", player.Name, statType, newValue);

            //TODO: Revaluate this, right now we only broadcast hitpoint changes
            if (statType == StatTypes.Hitpoints)
            {
                var zone = player.Zone;
                var updatePacket = new ServerCharacterStatChange(statType, newValue,
                    player.CharacterStats[statType].MaximumValue,
                    (long)player.Id);

                // Broadcast to interested parties
                zone.SendToEveryone(updatePacket);
            }
        }
        public CombatAction GenerateActionFromSkill(Skill skill, long targetId, Character requestingHero)
        {
            CombatAction action = null;
            var skillTemplate = skill.SkillTemplate;

            switch (skillTemplate.SkillActivationType)
            {
                case SkillActivationType.Immediate:
                    return CreateImmediateSkillAction(skill, requestingHero);
                case SkillActivationType.Target:
                    return CreateTargetSkillAction(skill, requestingHero);
                default:
                    Logger.Instance.Warn("{0} is not a supported skill type, invoked on skill #{1}",
                        skillTemplate.SkillType.ToString(), skillTemplate.Id);
                    break;
            }

            return action;
        }
        public override void UseItemOn(Character character, Character user)
        {
            var player = character as Player;

            if (player != null)
            {

                using (var context = new GameDatabaseContext())
                {
                    var skillRepo = new SkillRepository(context);
                    var skillTemplate = skillRepo.Get(ItemTemplate.LearntSkillId);

                    player.AddSkill(new Skill(skillTemplate));
                }

            }

            else
            {
                Logger.Instance.Warn("You cannot use a skillbook on a non-player target.");
            }
        }
        /// <summary>
        /// Processes and consumes a request for a skill use on a specific hero.
        /// </summary>
        /// <param name="requestingHero"></param>
        /// <param name="skillRequest"></param>
        public void ProcessCombatRequest(Character requestingHero, long skillId, int targetId)
        {
            // You may only use a skill if you are idle
            if (requestingHero.CharacterState != CharacterState.Idle)
                return;

            // Fetch skill
            Skill skill = requestingHero.Skills.Find(x => x.SkillTemplate.Id == skillId);

            // Checks if the skill requested did not exist
            if (skill == null)
            {
                Logger.Instance.Info("{0} requested the use of the non-existent skill #{1}", requestingHero.Name, skillId);
                return;
            }

            var target = Zone.ZoneCharacters.FirstOrDefault(x => (int)x.Id == targetId);

            if (!SkillValidationUtility.CanPerformSkill(requestingHero, target, skill))
                return;

            // Skill is good, execute!
            var action = _actionGenerator.GenerateActionFromSkill(skill, targetId, requestingHero);

            if (action == null)
                return;

            // Set the execution time and add it in
            action.ExecutionTime = skill.SkillTemplate.CastTime;

            // Add the action to the queue to be executed
            _pendingActions.Add(action);

            Logger.Instance.Debug("Preparing for {0} to perform skill #{1}", requestingHero.Name, skillId);

            // Character is casting now
            requestingHero.CharacterState = CharacterState.UsingSkill;
        }
 public TargetSkillAction(Character executingCharacter, Skill skill, ulong targetId)
     : base(executingCharacter, skill)
 {
     TargetId = targetId;
 }
Exemple #14
0
 public override void UseItemOn(Character user, Character target)
 {
 }
 /// <summary>
 /// Generates an immediate skill action.
 /// </summary>
 private ImmediateSkillAction CreateImmediateSkillAction(Skill skill, Character user)
 {
     return new ImmediateSkillAction(user, skill);
 }
        /// <summary>
        /// Copies the template stats given to the <see cref="Character"/> being created from these.
        /// </summary>
        /// <param name="template">The template to copy from</param>
        /// <param name="character">The character being constructed</param>
        private static void CopyStatsFromTemplateToCharacter(IStatTemplate template, Character character)
        {
            character.CharacterStats[(int)StatTypes.Strength].CurrentValue = template.Strength;
            character.CharacterStats[(int)StatTypes.Vitality].CurrentValue = template.Vitality;
            character.CharacterStats[(int)StatTypes.Intelligence].CurrentValue = template.Intelligence;
            character.CharacterStats[(int)StatTypes.Dexterity].CurrentValue = template.Dexterity;
            character.CharacterStats[(int)StatTypes.Luck].CurrentValue = template.Luck;
            character.CharacterStats[StatTypes.Mind].CurrentValue = template.Mind;

            character.CharacterStats[(int)StatTypes.Hitpoints].CurrentValue = template.Hitpoints;
            character.CharacterStats[(int)StatTypes.Hitpoints].MaximumValue = template.MaximumHitpoints;

            character.CharacterStats[(int)StatTypes.SkillResource].CurrentValue = template.SkillResource;
            character.CharacterStats[(int)StatTypes.SkillResource].MaximumValue = template.MaximumSkillResource;
        }
Exemple #17
0
 public WanderAi(Character character)
     : base(character)
 {
 }
 public DamagePayload(Character aggressor, int damage)
     : base(aggressor)
 {
     DamageInflicted = damage;
 }
 public override void Apply(Character victim)
 {
     victim.CharacterStats[(int)StatTypes.Hitpoints].CurrentValue = victim.CharacterStats[StatTypes.Hitpoints].CurrentValue - DamageInflicted;
 }
Exemple #20
0
 public void SelectTarget(Character target)
 {
     TargetId = target.Id;
 }
 public override int OnComputeDamage(Character attacker, Character victim, int damage)
 {
     return damage * 50000;
 }
 private void OnCharacterAdded(Character character)
 {
 }
Exemple #23
0
        protected Point GetTileGridPoints(Character character)
        {
            var body = character.Body.GetBodyRectangle();
            var x = body.X;
            var y = body.Y;

            return new Point(MathHelper.ToLowMultiple(x, 32) / 32, MathHelper.ToLowMultiple(y, 32) / 32);
        }
 private CombatAction CreateTargetSkillAction(Skill skill, Character requestingHero)
 {
     // We have to pass the ID in to lock in the casting choice ahead of time or the user might change their choice later
     return new TargetSkillAction(requestingHero, skill, requestingHero.TargetId);
 }
 public int GetAgressionLevel(Character character)
 {
     if (_agressionLevels.ContainsKey(character.Id))
         return _agressionLevels[character.Id];
     return 0;
 }
 public void DecayAgression(Character character)
 {
 }
 private void OnCharacterRemoved(Character character)
 {
 }
Exemple #28
0
        public void ApplyDamage(DamagePayload damagePayload)
        {
            _lastCharacterToHitMe = damagePayload.Aggressor;

            // Applies the actual damage to this character
            damagePayload.Apply(this);

            // If this died, tell any interested parties
            if (CharacterStats[(int)StatTypes.Hitpoints].CurrentValue <= 0)
            {
                CharacterStats[(int)StatTypes.Hitpoints].CurrentValue = 0;
            }
        }
Exemple #29
0
 /// <summary>
 /// Performs an item action on a character, allowing something to be performed.
 /// </summary>
 /// <param name="user">A parameter representing the user of the item</param>
 /// <param name="target">A parameter representing the target of the item. For self use items, the target will be the user.</param>
 public abstract void UseItemOn(Character user, Character target);
Exemple #30
0
 protected virtual void OnKilled(Character aggressor, Character victim)
 {
     CharacterKilled handler = Killed;
     if (handler != null) handler(aggressor, victim);
 }