Example #1
0
        /// <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;
        }
Example #2
0
        public Player(string sprite, GameClient client, UserHero userHero)
            : base(sprite)
        {
            Client = client;
            Backpack = new ItemStorage();
            Bank = new ItemStorage();
            QuestInfo = new List<UserQuestInfo>();

            using (var context = new GameDatabaseContext())
            {
                // Add the skills this player knows
                foreach (var skillEntry in userHero.Skills)
                {
                    var skillTemplate = context.SkillTemplates.First(x => x.Id == skillEntry.SkillId);
                    var skill = new Skill(skillTemplate);
                    Skills.Add(skill);
                }

                // Add the inventory stuff...
                foreach (var inventoryItem in userHero.Inventory)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == inventoryItem.ItemId);
                    var item = ItemFactory.CreateItem(itemTemplate);
                    Backpack.TryAddItemAt(item, inventoryItem.ItemAmount, inventoryItem.SlotId);
                }

                // Add the state of the quest world to the user
                foreach (var questEntry in userHero.QuestInfo)
                {
                    QuestInfo.Add(questEntry);
                }

                foreach (var eq in userHero.Equipment)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == eq.ItemId);
                    var equipment = ItemFactory.CreateItem(itemTemplate) as Equipment;
                    Equipment[(int)equipment.Slot] = equipment;
                }

                UserId = userHero.UserHeroId;
                Experience = userHero.Experience;
                Level = userHero.Level;

            }

            // Store the user hero internally
            _hero = userHero;
        }
Example #3
0
        public Player(string sprite, GameClient client, UserHero userHero)
            : base(sprite)
        {
            Client = client;
            Backpack = new ItemStorage();
            Bank = new ItemStorage();

            // Allow extraction of the quest information
            QuestLog = new QuestLog(userHero.QuestInfo);

            using (var context = new GameDatabaseContext())
            {
                // Add the skills this player knows
                foreach (var skillEntry in userHero.Skills)
                {
                    var skillTemplate = context.SkillTemplates.First(x => x.Id == skillEntry.SkillId);
                    var skill = new Skill(skillTemplate);
                    Skills.Add(skill);
                }

                // Add the inventory stuff...
                foreach (var inventoryItem in userHero.Inventory)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == inventoryItem.ItemId);
                    var item = ItemFactory.CreateItem(itemTemplate);
                    Backpack.TryAddItemAt(item, inventoryItem.ItemAmount, inventoryItem.SlotId);
                }

                foreach (var eq in userHero.Equipment)
                {
                    var itemTemplate = context.ItemTemplates.First(x => x.Id == eq.ItemId);
                    var equipment = ItemFactory.CreateItem(itemTemplate) as Equipment;
                    Equipment[(int)equipment.Slot] = equipment;
                }

                UserId = userHero.UserHeroId;
                Experience = userHero.Experience;
                Level = userHero.Level;

                Backpack.StorageChanged += BackpackOnStorageChanged;
                QuestLog.QuestAccepted += QuestLogOnQuestAccepted;
            }

            // Store the user hero internally
            _hero = userHero;
        }
        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;
        }
        /// <summary>
        /// This is called to synchronize this new fact to the player
        /// </summary>
        /// <param name="skill">The skill that was learned and to be synced</param>
        /// <param name="player">The player that has learned this skill</param>
        private void PlayerOnLearnedSkill(Skill skill, Player player)
        {
            // Notify the player that they learned this skill, send it over
            var packet = new ServerSkillChangePacket(player.Skills);
            player.Client.Send(packet);

            Logger.Instance.Info("{0} has learned the skill {1}.", player.Name, skill.SkillTemplate.Name);
        }
Example #6
0
 protected virtual void OnLearnedSkill(Skill skill, Player player)
 {
     SkillEvent handler = LearnedSkill;
     if (handler != null) handler(skill, player);
 }
Example #7
0
 public void AddSkill(Skill skill)
 {
     Skills.Add(skill);
 }
 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);
 }
 /// <summary>
 /// Generates an immediate skill action.
 /// </summary>
 private ImmediateSkillAction CreateImmediateSkillAction(Skill skill, Character user)
 {
     return new ImmediateSkillAction(user, skill);
 }
 /// <summary>
 /// This is called when a character afflicted by a status effect is attempting to perform damage.
 /// </summary>
 /// <param name="afflictedCharacter"></param>
 /// <param name="?"></param>
 /// <param name="skill"></param>
 /// <returns></returns>
 public virtual int OnCalculateSkillDamage(Character afflictedCharacter, Character target, Skill skill, int damage)
 {
     return damage;
 }
 /// <summary>
 /// Provides a method that is called when a user with this status effect is harmed via combat.
 /// </summary>
 /// <param name="afflictedCharacter"></param>
 /// <param name="agressor"></param>
 /// <param name="skill"></param>
 /// <param name="damage"></param>
 /// <returns></returns>
 public virtual int OnCalculateDamageTaken(Character afflictedCharacter, Character aggressor, Skill skill,
     int damage)
 {
     return damage;
 }
Example #12
0
 public void Init(Skill skill)
 {
     _skill = skill;
 }