Exemple #1
0
 protected override void OnInitializeComplete()
 {
     base.OnInitializeComplete();
     propertyComponent   = entity.GetCComponent <CPropertyComponent>();
     relationComponent   = entity.GetCComponent <CTeamComponent>();
     m_AnimatorComponent = entity.GetCComponent <CAnimatorComponent>();
     damageResist        = new DamageResist();
     damageShield        = new DamageShield();
     damageGain          = new DamageGain();
     modifyDamageMark    = new ModifyDamageMark();
     dodgeDamage         = new DodgeDamage();
     damageBlock         = new DamageBlock();
 }
Exemple #2
0
        public static List <RawBmp> DealDamage(EntityDamageProfileDB damageProfile, DamageFragment damage)
        {
            RawBmp shipDamageProfile = damageProfile.DamageProfile;

            List <RawBmp> damageFrames = new List <RawBmp>();

            var    fragmentMass  = damage.Mass;
            var    dpos          = damage.Position;
            var    dvel          = damage.Velocity;
            var    dden          = damage.Density;
            var    dlen          = damage.Length;
            var    pos           = new Vector2(dpos.x, dpos.y);
            var    pixelscale    = 0.01;
            double startMomentum = dvel.Length() * fragmentMass;
            double momentum      = startMomentum;

            byte[] byteArray = new byte[shipDamageProfile.ByteArray.Length];
            Buffer.BlockCopy(shipDamageProfile.ByteArray, 0, byteArray, 0, shipDamageProfile.ByteArray.Length);
            RawBmp firstFrame = new RawBmp()
            {
                ByteArray = byteArray,
                Height    = shipDamageProfile.Height,
                Width     = shipDamageProfile.Width,
                Depth     = shipDamageProfile.Depth,
                Stride    = shipDamageProfile.Stride
            };

            damageFrames.Add(firstFrame);
            (byte r, byte g, byte b, byte a)savedpx = shipDamageProfile.GetPixel(dpos.x, dpos.y);
            (int x, int y)savedpxloc = dpos;

            while (momentum > 0 && dpos.x >= 0 && dpos.x <= shipDamageProfile.Width && dpos.y >= 0 && dpos.y <= shipDamageProfile.Height)
            {
                byteArray = new byte[shipDamageProfile.ByteArray.Length];
                RawBmp lastFrame = damageFrames.Last();
                Buffer.BlockCopy(lastFrame.ByteArray, 0, byteArray, 0, shipDamageProfile.ByteArray.Length);
                var thisFrame = new RawBmp()
                {
                    ByteArray = byteArray,
                    Height    = shipDamageProfile.Height,
                    Width     = shipDamageProfile.Width,
                    Depth     = shipDamageProfile.Depth,
                    Stride    = shipDamageProfile.Stride
                };

                (byte r, byte g, byte b, byte a)px = thisFrame.GetPixel(dpos.x, dpos.y);
                if (px.a > 0)
                {
                    DamageResist damageresist = DamageResistsLookupTable[px.r];

                    double density        = damageresist.Density / (px.a / 255f); //density / health
                    double maxImpactDepth = dlen * dden / density;
                    double depthPercent   = pixelscale / maxImpactDepth;
                    dlen -= (float)(damage.Length * depthPercent);
                    var momentumLoss = startMomentum * depthPercent;
                    momentum -= momentumLoss;
                    if (momentum > 0)
                    {
                        px = (px.r, px.g, px.b, 0);
                        damageProfile.ComponentLookupTable[px.g].HTKRemaining -= 1;
                    }
                }

                thisFrame.SetPixel(dpos.x, dpos.y, byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)fragmentMass);
                thisFrame.SetPixel(savedpxloc.x, savedpxloc.y, savedpx.r, savedpx.g, savedpx.b, savedpx.a);
                damageFrames.Add(thisFrame);
                savedpxloc = dpos;
                savedpx    = px;


                double dt = 1 / dvel.Length();
                pos.X += dvel.X * dt;
                pos.Y += dvel.Y * dt;
                dpos.x = Convert.ToInt32(pos.X);
                dpos.y = Convert.ToInt32(pos.Y);
            }


            Buffer.BlockCopy(damageFrames.Last().ByteArray, 0, byteArray, 0, shipDamageProfile.ByteArray.Length);
            var finalFrame = new RawBmp()
            {
                ByteArray = byteArray,
                Height    = shipDamageProfile.Height,
                Width     = shipDamageProfile.Width,
                Depth     = shipDamageProfile.Depth,
                Stride    = shipDamageProfile.Stride
            };

            finalFrame.SetPixel(savedpxloc.x, savedpxloc.y, savedpx.r, savedpx.g, savedpx.b, savedpx.a);
            return(damageFrames);
        }