Example #1
0
        public void BinarySerializationShouldWork()
        {
            var assembly = this.GetType().Assembly;

            var sut = new HitContext(assembly.FullName, this.GetType().FullName, nameof(BinarySerializationShouldWork), new Dictionary <int, int> {
                { 1, 15 }
            });

            byte[] data;
            using (var stream = new MemoryStream())
            {
                sut.Serialize(stream);
                data = stream.ToArray();
            }

            using (var stream = new MemoryStream(data))
            {
                var results = HitContext.Deserialize(stream).ToArray();
                results.Length.Should().Be(1);

                var result = results.First();
                result.ClassName.Should().Be(sut.ClassName);
                result.MethodName.Should().Be(sut.MethodName);
                result.AssemblyName.Should().Be(sut.AssemblyName);
                result.Hits.Should().BeEquivalentTo(sut.Hits);
            }
        }
Example #2
0
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            if (hitContext.IsProtected)
            {
                return;
            }
            float sourceCalculated = activeStats.GetStat(ModType.Identifier).Calculated; //0,8
            Stat  targetStat       = activeStats.GetStat(m_Target.Identifier);           // 0,75

            switch (m_Type)
            {
            case MathType.Min:
                if (sourceCalculated >= targetStat.Calculated)
                {
                    return;
                }
                break;

            case MathType.Max:
                if (sourceCalculated <= targetStat.Calculated)
                {
                    return;
                }
                break;
            }
            sourceCalculated = sourceCalculated / targetStat.Calculated;
            targetStat.AddStatModifier(
                new StatModifier(sourceCalculated - 1.0f, CalculationType.More, this));
        }
Example #3
0
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            if (hitContext.IsProtected)
            {
                return;
            }
            float stat = activeStats.GetStat(ModType.Identifier).GetValue(m_SourceCalculationType);

            switch (m_OpType)
            {
            case OpType.MinusValue:
                stat = stat - m_Value;
                break;

            case OpType.ValueMinus:
                stat = m_Value - stat;
                break;

            case OpType.PlusValue:
                stat = stat + m_Value;
                break;

            case OpType.TimesValue:
                stat = stat * m_Value;
                break;
            }
            hitContext.OffensiveEntity.GetStat(m_Target.Identifier).AddStatModifier(
                new StatModifier(stat, m_TargetCalculationType, this));
        }
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            if (hitContext.IsProtected)
            {
                return;
            }
            if (m_ProtectionCause != null)
            {
                hitContext.IsProtected     = true;
                hitContext.ProtectionCause = m_ProtectionCause;
            }
            if (m_NotifyTypeAttacker)
            {
                hitContext.Source.Entity.Notify(m_NotifyTypeAttacker, actionContext);
            }
            if (m_NotifyTypeDefender)
            {
                hitContext.Target.Entity.Notify(m_NotifyTypeDefender, actionContext);
            }
        }
        public void OnDeath(HitContext hitContext)
        {
            if (_isDead)
            {
                return;
            }

            if (!hitContext.IsMelee)
            {
                var ejector = gameObject.GetComponent <BloodEjector>();
                if (ejector != null)
                {
                    ejector.Eject(hitContext);
                    ejector.Eject(hitContext);
                    ejector.Eject(hitContext);
                }
            }

            Destroy(GetComponent <EnemyMovement>());
            Destroy(GetComponent <NavMeshAgent>());

            _isDead = true;
            GetComponent <Animator>().SetTrigger("Die");
            gameObject.layer = LayerMask.NameToLayer("TurnStaticSoon");
            GetComponent <EnemySounds>().PlayDeathSound();

            GetComponent <Rigidbody>().isKinematic = false;
            GetComponent <Rigidbody>().AddExplosionForce(hitContext.Force, transform.position - hitContext.Direction, 1f, 1f, ForceMode.Impulse);

            EventAggregator.SendMessage(new EnemyKilledMessage());
        }
    public void OnBodyEntered(Node2D node)
    {
        GD.Print($"Node in contact with {node.Name}!");
        HitContext hitContext = new HitContext(node, direction);

        physics.Physicist.HitActions.ForEach(action => action(hitContext));
        hitContext.ApplyHitActions();
        QueueFree();
    }
        protected override void OnAttackHit(HitContext hitContext)
        {
            base.OnAttackHit(hitContext);
            Stat pierce = Entity.GetStat("core.modtypes.skills.pierce");

            pierce.Current--;
            if (pierce.Current < 0.0f)
            {
                DestroyAttack();
            }
        }
Example #8
0
        private static StateTest AddOrUpdateTestCoverage(HitContext context, State state)
        {
            var contextName = $"{context.ClassName}.{context.MethodName}";

            var testState =
                state.Tests.SingleOrDefault(x => x.Name == contextName) ??
                new StateTest();

            testState.Name = contextName;

            state.Tests.Add(testState);
            return(testState);
        }
Example #9
0
        public static HitsInfo TryReadFromDirectory(string path)
        {
            var contexts = new List <HitContext>();

            foreach (var hitFile in Directory.GetFiles(path, "*.hits"))
            {
                using (var fileStream = File.Open(hitFile, FileMode.Open, FileAccess.Read))
                {
                    contexts.AddRange(HitContext.Deserialize(fileStream));
                }
            }

            return(new HitsInfo(contexts));
        }
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            if (hitContext.IsProtected)
            {
                return;
            }
            hitContext.Target.Entity.GetStat(m_Life.Identifier).Current -= activeStats.GetStat(m_Source.Identifier).Calculated;
        }
Example #11
0
 public HitsInfo(IEnumerable <HitContext> contexts)
 {
     _valuesById = HitContext.MergeDuplicates(contexts)
                   .SelectMany(c => c.Hits.Keys, (context, id) => new {
         context,
         id,
         hitCount = context.GetHitCount(id)
     })
                   .GroupBy(g => g.id)
                   .ToDictionary(g => g.Key, g => new HitValues
     {
         HitCount = g.Sum(d => d.hitCount),
         Contexts = g.Select(d => d.context).ToArray()
     });
 }
Example #12
0
 public void Attack()
 {
     if (Vector3.Distance(transform.position, _player.transform.position) < MinDistance)
     {
         GetComponent <EnemySounds>().PlayAttackSound();
         var hitContext = new HitContext
         {
             Force     = 3,
             Damage    = Damage,
             Direction = transform.forward,
             IsMelee   = true
         };
         _player.GetComponent <HealthBehavior>().TakeDamage(hitContext);
     }
 }
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            if (hitContext.IsProtected)
            {
                return;
            }
            Entity entity = hitContext.OffensiveEntity;
            Stat   stat   = entity.GetStat(m_Target.Identifier);

            stat.AddStatModifier(new StatModifier(entity.GetStat(m_Source.Identifier).Calculated, CalculationType.More, this));
        }
        public override void Notify(Entity activeStats, ActionContext actionContext)
        {
            HitContext hitContext = actionContext as HitContext;

            if (hitContext == null)
            {
                return;
            }
            Entity entity = GetTypeEntity(hitContext);
            Stat   target = entity.GetStat(m_Target.Identifier);
            Stat   source = activeStats.GetStat(m_Source.Identifier);

            target.AddStatModifier(new StatModifier(source.Flat, CalculationType.Flat, this));
            target.AddStatModifier(new StatModifier(source.Increased - 1.0f, CalculationType.Increased, this));
            target.AddStatModifier(new StatModifier(source.More - 1.0f, CalculationType.More, this));
            target.AddStatModifier(new StatModifier(source.FlatExtra, CalculationType.FlatExtra, this));
        }
Example #15
0
        public void Eject(HitContext hitContext)
        {
            // initial burst
            for (var i = 0; i < 5; i++)
            {
                var blood = Instantiate(BloodDroplet);
                blood.transform.position = transform.position + new Vector3(0, .2f, 0);
                blood.GetComponent <Rigidbody>().AddForce(Random.onUnitSphere.PositiveY() * Random.Range(MinForce, MaxForce));
            }

            // follow bullet path
            for (var i = 0; i < 5; i++)
            {
                var blood = Instantiate(BloodDroplet);
                blood.transform.position = transform.position + new Vector3(0, .2f, 0);
                blood.GetComponent <Rigidbody>().AddForce(hitContext.Direction * Random.Range(MinForce, MaxForce) * hitContext.Force);
            }
        }
        public void OnHit(HitContext hitContext)
        {
            if (_isDead)
            {
                return;
            }

            GetComponent <EnemySounds>().PlayHitSound();

            if (!hitContext.IsMelee)
            {
                var ejector = gameObject.GetComponent <BloodEjector>();
                if (ejector != null)
                {
                    ejector.Eject(hitContext);
                }
            }
        }
Example #17
0
        public void OnDeath(HitContext hitContext)
        {
            var rigidBody = GetComponent <Rigidbody>();

            rigidBody.constraints = RigidbodyConstraints.None;
            rigidBody.AddExplosionForce(hitContext.Force * 2, transform.position - hitContext.Direction, 1f, 3f, ForceMode.Impulse);

            gameObject.GetComponent <BoxCollider>().center = Vector3.zero;
            gameObject.GetComponent <BoxCollider>().size   = new Vector3(.4f, .3f, .27f);

            Destroy(GetComponent <CapsuleCollider>());
            Destroy(GetComponentInChildren <MouseRotationX>());
            Destroy(GetComponentInChildren <MouseRotationY>());
            Destroy(GetComponentInChildren <KeyboardMovement>());
            Destroy(GetComponentInChildren <Bobber>());
            Destroy(GetComponentInChildren <Tilter>());
            Destroy(GetComponentInChildren <PlayerInteractions>());
            Destroy(gameObject.GetComponent <PlayerGun>());
            Destroy(Hand);
        }
Example #18
0
        public void OnHit(HitContext hitContext)
        {
            if (_isDead)
            {
                return;
            }

            _pushback = hitContext.Direction / 20.0f;

            GetComponent <Animator>().SetTrigger("IsHit");
            GetComponent <EnemySounds>().PlayHitSound();

            if (!hitContext.IsMelee)
            {
                var ejector = gameObject.GetComponent <BloodEjector>();
                if (ejector != null)
                {
                    ejector.Eject(hitContext);
                }
            }
        }
Example #19
0
        public void MeleeAttack()
        {
            _lastShot = Time.fixedTime;

            var        ray = _viewCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit) && Vector3.Distance(transform.position, hit.point) < .5f)
            {
                if (hit.collider.tag == "Enemy")
                {
                    var hitContext = new HitContext
                    {
                        Damage    = Random.Range(0, 2),
                        Direction = transform.forward,
                        Force     = 1,
                        IsMelee   = true
                    };
                    hit.collider.GetComponent <HealthBehavior>().TakeDamage(hitContext);
                }
            }
        }
Example #20
0
 public void OnHit(HitContext hitContext)
 {
     // TODO: Flash screen red or some shit here
 }