コード例 #1
0
 protected virtual void OnTakesDamage(DamageEventArgs e)
 {
     if (TakesDamage != null)
     {
         TakesDamage(this, e);
     }
 }
コード例 #2
0
 protected override void OnTakesDamage(DamageEventArgs e)
 {
     base.OnTakesDamage(e);
     Program.Instance.SignalEvent(new ProgramEvents.UnitHit {
         DamageEventArgs = e
     });
     if (e.Performer == Game.Instance.Map.MainCharacter)
     {
         Game.Instance.Statistics.Actions.DamageDealt += e.ActualDamage;
     }
 }
コード例 #3
0
        //public override int CalculateHitDamage(Unit striker, int damage, AttackType attackType)
        //{
        //    if (Game.Instance.DifficultyLevel == DifficultyLevel.Easy)
        //        return (int)(base.CalculateHitDamage(striker, damage, attackType) * 1.5f);
        //    else if (Game.Instance.DifficultyLevel == DifficultyLevel.Insane)
        //        return base.CalculateHitDamage(striker, damage, attackType) / 2;
        //    else
        //        return base.CalculateHitDamage(striker, damage, attackType);
        //}

        protected override void OnTakesDamage(DamageEventArgs e)
        {
            base.OnTakesDamage(e);

            if (State == UnitState.Alive)
            {
                MakeAwareOfUnit(e.Performer);
            }
            else if (State != UnitState.RaisingCorpse)
            {
                return;
            }
            if (onHitSoundCooldown == 0 && onHitSoundPlaybackCount < onHitSoundLimit)
            {
                var sm = Program.Instance.SoundManager;

                if (e.AttackType == AttackType.Bullet)
                {
                    onHitSoundCooldown = onHitSoundCooldownLength;
                    onHitSoundPlaybackCount++;
                    sm.GetSoundResourceGroup(sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh1),
                                             sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh2),
                                             sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh5)).Play(new Sound.PlayArgs
                    {
                        Position = Position,
                        Velocity = Vector3.Zero
                    });
                }
                else if (e.AttackType == AttackType.Melee)
                {
                    onHitSoundCooldown = onHitSoundCooldownLength;
                    onHitSoundPlaybackCount++;
                    sm.GetSoundResourceGroup(sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh1),
                                             sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh2),
                                             sm.GetSFX(global::Client.Sound.SFX.SwordHitFlesh5)).Play(new Sound.PlayArgs
                    {
                        Position = Position,
                        Velocity = Vector3.Zero
                    });
                }
            }
            //else
            //{
            //    int i = 0;
            //    i = 2;
            //    i++;
            //    Console.Write(i);
            //    //System.Diagnostics.Debugger.Break();
            //}
        }
コード例 #4
0
        /// <returns>Actual damage amount</returns>
        public int Hit(Unit striker, int damage, AttackType attackType, Script script)
        {
            if (!CanBeDestroyed)
            {
                return(0);
            }
            //Console.WriteLine(striker + " strikes " + this.GetType().Name + " for " + damage + " damage");

            PlayHitEffect();
            int adjustedDamage = CalculateHitDamage(striker, damage, attackType);
            int actualDamage   = Math.Min(HitPoints, adjustedDamage);

            DamageLastFrame += adjustedDamage;

#if DEBUG
            if (this is Units.MainCharacter && Program.Settings.GodMode)
            {
                actualDamage = 0;
            }
#endif
            HitPoints -= actualDamage;
            if (Program.Settings.DisplayScrollingCombatText &&
                (striker is Units.MainCharacter || this is Units.MainCharacter))
            {
                if (currentScrollingCombatText == null)
                {
                    currentScrollingCombatText = new Interface.ScrollingCombatText
                    {
                        WorldPosition = Translation + Vector3.UnitZ * 1
                    };
                    Game.Instance.Interface.AddChild(currentScrollingCombatText);
                }
                currentScrollingCombatText.Text = DamageLastFrame.ToString();
                var font           = new Graphics.Content.Font();
                int damageCategory = Common.Math.Clamp(DamageLastFrame / 70, 0, 4);
                //var fontSize = 8 + 6 * damageCategory;
                //currentScrollingCombatText.Font.SystemFont = new System.Drawing.Font(Fonts.DefaultFontFamily, fontSize);
                // 8, 14, 20, 26, 32
                if (damageCategory == 0)
                {
                    font.SystemFont = Fonts.DefaultSystemFont;
                }
                else if (damageCategory == 1)
                {
                    font.SystemFont = Fonts.DefaultSystemFont;
                }
                else if (damageCategory == 2)
                {
                    font.SystemFont = Fonts.MediumSystemFont;
                }
                else if (damageCategory == 3)
                {
                    font.SystemFont = Fonts.LargeSystemFont;
                }
                else if (damageCategory == 4)
                {
                    font.SystemFont = Fonts.HugeSystemFont;
                }


                var alpha = Common.Math.Clamp(50 + damageCategory * 70, 50, 255);
                if (striker is Units.MainCharacter)
                {
                    font.Color = System.Drawing.Color.White;
                }
                else
                {
                    font.Color = System.Drawing.Color.Red;
                }
                currentScrollingCombatText.TextGraphic.Alpha = alpha / 255f;
                font.Backdrop = System.Drawing.Color.Transparent;
                currentScrollingCombatText.Font = font;
            }
            var de = new DamageEventArgs
            {
                Performer      = striker,
                Target         = this,
                Damage         = damage,
                AdjustedDamage = adjustedDamage,
                ActualDamage   = actualDamage,
                AttackType     = attackType
            };
            OnTakesDamage(de);
            if (HitPoints <= 0)
            {
                HitPoints = 0;
                Kill(striker, script);
            }
            if (striker != null)
            {
                striker.OnGivesDamage(de);
            }
            return(actualDamage);
        }
コード例 #5
0
 protected virtual void OnGivesDamage(DamageEventArgs e)
 {
 }