Ejemplo n.º 1
0
        static public void OnHitAllEffects(GlobalEventManager globalEventManager, DamageInfo damageInfo, GameObject victim)
        {
            float           procCoefficient = damageInfo.procCoefficient;
            CharacterBody   body            = damageInfo.attacker.GetComponent <CharacterBody>();
            CharacterMaster master          = body.master;

            if (!(bool)body || procCoefficient <= 0.0 || !(bool)body || !(bool)master || !(bool)master.inventory)
            {
                return;
            }

            Inventory inventory = master.inventory;

            foreach (KeyValuePair <int, ModItem> Kv in ModItemDictionary)
            {
                int count = inventory.GetItemCount(Kv.Key);
                if (count > 0)
                {
                    foreach (ModHitEffect HitEffects in Kv.Value.GetHitEffectList)
                    {
                        if (HitEffects.EffectType == HitEffectType.OnHitAll && HitEffects.Condition(globalEventManager, damageInfo, victim, count))
                        {
                            HitEffects.Effect(globalEventManager, damageInfo, victim, count);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void OnMeleeDamage()
        {
            Collider[]          objectsInRange = Physics.OverlapSphere(transform.position, meleeRadius);
            List <Destructible> damagedObjects = new List <Destructible>(); // Keep track of what objects have been damaged so we don't do damage multiple times per collider.
            bool hasPlayedHitEffect            = false;

            foreach (Collider col in objectsInRange)
            {
                // Ignore terrain colliders
                if (col is TerrainCollider)
                {
                    continue;
                }

                // Ignore trigger colliders
                if (col.isTrigger)
                {
                    continue;
                }

                // Ignore the player's character controller (ie, don't allow hitting yourself)
                if (col is CharacterController && col.tag == "Player")
                {
                    continue;
                }

                if (!hasPlayedHitEffect) // Only play the hit effect once per melee attack.
                {
                    // Play hit effects
                    HitEffects hitEffects = col.gameObject.GetComponentInParent <HitEffects>();
                    if (hitEffects != null && hitEffects.effects.Count > 0)
                    {
                        hitEffects.PlayEffect(HitBy.Axe, transform.position, transform.forward * -1);
                    }

                    hasPlayedHitEffect = true;
                }

                // Apply impact force to rigidbody hit
                Rigidbody rbody = col.attachedRigidbody;
                if (rbody != null)
                {
                    rbody.AddForceAtPosition(transform.forward * 3f, transform.position, ForceMode.Impulse);
                }

                // Apply damage if object hit was Destructible
                Destructible destObj = col.gameObject.GetComponentInParent <Destructible>();
                if (destObj != null && !damagedObjects.Contains(destObj))
                {
                    damagedObjects.Add(destObj);
                    ImpactDamage meleeImpact = new ImpactDamage()
                    {
                        DamageAmount            = damageAmount, AdditionalForce = additionalForceAmount,
                        AdditionalForcePosition = transform.position, AdditionalForceRadius = additionalForceRadius
                    };
                    destObj.ApplyDamage(meleeImpact);
                }
            }
        }
Ejemplo n.º 3
0
        public void OnSoldierStartAttack(Soldier enemy, bool retaliate)
        {
            // Magic fighters can't retaliate D:
            if (Special_MagicFighter && retaliate)
            {
                return;
            }

            // Start of animation code
            attackTarget = enemy;

            Vector2 tPos = enemy.DrawPosition;
            Vector2 cPos = DrawPosition;

            Vector2 attackDirection = tPos - cPos;

            Vector2.Normalize(ref attackDirection, out normalizedAttackDirection);

            // TODO: Adding the walking animations to the attack directions and un-commenting this.
            if (normalizedAttackDirection == walkUpDirection)
            {
                DrawingTexture.SelectedSprite = new Point(0, ANIMATION_WALK_UP);
            }

            else if (normalizedAttackDirection == walkDownDirection)
            {
                DrawingTexture.SelectedSprite = new Point(0, ANIMATION_WALK_DOWN);
            }

            else if (normalizedAttackDirection == walkRightDirection || normalizedAttackDirection.X > walkDirectionZero.X)
            {
                DrawingTexture.SelectedSprite = new Point(0, ANIMATION_WALK_RIGHT);
            }

            else if (normalizedAttackDirection == walkLeftDirection || normalizedAttackDirection.X < walkDirectionZero.X)
            {
                DrawingTexture.SelectedSprite = new Point(0, ANIMATION_WALK_LEFT);
            }


            position = position + (normalizedAttackDirection * 10);

            h = new HitEffects(this.name);
            //(GameWorld as Grid).hitEffectList = new GameObjectList();
            h.DeterminePosition(enemy.PositionInGrid);
            (GameWorld as Grid).hitEffectList.Add(h);

            attackAnimationTimer = 0f;
            attacked             = true;
            duringAttack         = true;
            retaliating          = retaliate;
        }
Ejemplo n.º 4
0
        public void OnCollisionEnter(Collision collision)
        {
            // Check that the impact is forceful enough to cause damage
            if (collision.relativeVelocity.magnitude < minHitVelocity)
            {
                return;
            }

            if (collision.contacts.Length == 0)
            {
                return;
            }

            Collider other = collision.contacts[0].otherCollider;

            // Play hit effects
            HitEffects hitEffects = other.gameObject.GetComponentInParent <HitEffects>();

            if (hitEffects != null && hitEffects.effects.Count > 0)
            {
                hitEffects.PlayEffect(weaponType, collision.contacts[0].point, collision.contacts[0].normal);
            }

            // Apply impact damage to Destructible objects without rigidbodies
            Destructible destructibleObj = other.gameObject.GetComponentInParent <Destructible>();

            if (destructibleObj != null)
            {
                if (other.attachedRigidbody == null || other.attachedRigidbody.GetComponent <Destructible>() == null)
                {
                    if (collision.relativeVelocity.magnitude >= destructibleObj.ignoreCollisionsUnder)
                    {
                        destructibleObj.ProcessDestructibleCollision(collision, gameObject.GetComponent <Rigidbody>());
                        rbody.velocity = lastVelocity;
                    }
                }
            }

            // Check for Chip-Away Debris
            ChipAwayDebris chipAwayDebris = collision.contacts[0].otherCollider.gameObject.GetComponent <ChipAwayDebris>();

            if (chipAwayDebris != null)
            {
                chipAwayDebris.BreakOff(collision.relativeVelocity * -1, collision.contacts[0].point);
            }
        }
Ejemplo n.º 5
0
        public void ProcessBulletHit(RaycastHit hitInfo, Vector3 bulletDirection)
        {
            HitEffects hitEffects = hitInfo.collider.gameObject.GetComponentInParent <HitEffects>();

            if (hitEffects != null && hitEffects.effects.Count > 0)
            {
                hitEffects.PlayEffect(HitBy.Bullet, hitInfo.point, hitInfo.normal);
            }

            // Apply damage if object hit was Destructible
            Destructible destObj = hitInfo.collider.gameObject.GetComponentInParent <Destructible>();

            if (destObj != null)
            {
                ImpactDamage bulletImpact = new ImpactDamage()
                {
                    DamageAmount = Instance.bulletDamage, AdditionalForce = Instance.bulletForcePerSecond, AdditionalForcePosition = hitInfo.point, AdditionalForceRadius = .5f
                };
                destObj.ApplyDamage(bulletImpact);
            }

            Vector3 force = bulletDirection * (Instance.bulletForcePerSecond / Instance.bulletForceFrequency);

            // Apply impact force to rigidbody hit
            Rigidbody rbody = hitInfo.collider.attachedRigidbody;

            if (rbody != null)
            {
                rbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse);
            }

            // Check for Chip-Away Debris
            ChipAwayDebris chipAwayDebris = hitInfo.collider.gameObject.GetComponent <ChipAwayDebris>();

            if (chipAwayDebris != null)
            {
                chipAwayDebris.BreakOff(force, hitInfo.point);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 public virtual void OnHit(Targetable targetable)
 {
     Logger.Debug("Spell.OnHit");
     HitEffects.Run(targetable, Context);
 }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 public virtual void OnHit(Character character)
 {
     Logger.Debug("Spell.OnHit");
     HitEffects.Run(character, Context);
 }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 public virtual void OnHit(Vector3 position)
 {
     Logger.Debug("Spell.OnHit");
     HitEffects.Run(position, Context);
 }