Ejemplo n.º 1
0
 public static Damage Mitigate(IDestructible defender, Damage payload)
 {
     payload.Target = defender;
     //payload.Effective = attacker.Damage;//TOdo: This is subject to change when armor and stuff
     defender.HitPoints.Current -= payload.Total;
     return(payload);
 }
Ejemplo n.º 2
0
    public IEnumerator AttackVFX(Transform _start, IDestructible _end, float _time, bool _miss = false)
    {
        var T = 0.0f;

        line.SetPosition(0, _start.position);
        line.SetPosition(1, _start.position);

        var endPos = _miss ? DamageUtility.GetMissPosition(_start, _end.GetTransform(), _end.SizeType) : _start.position;

        while (T < _time)
        {
            if (!_miss)
            {
                endPos = Vector3.MoveTowards(line.GetPosition(1), _end.GetPointToAttack(_start.position), speed * Time.deltaTime);
            }

            line.SetPosition(0, _start.position);
            line.SetPosition(1, endPos);

            yield return(null);

            T += Time.deltaTime;
        }

        HideLaser();
    }
Ejemplo n.º 3
0
    public async void Explode()
    {
        var explosion = Instantiate(_explosionEffectPrefab, _selfTransform.position, _selfTransform.rotation);

        Collider[] collidersToDestroy = Physics.OverlapSphere(_selfTransform.position, _radius);

        foreach (var nearbyObject in collidersToDestroy)
        {
            IDestructible nearDestructible = nearbyObject.GetComponent <IDestructible>();

            if (nearDestructible != null)
            {
                nearDestructible.DestroyObject();
            }
        }

        Collider[] collidersToMove = Physics.OverlapSphere(_selfTransform.position, _radius);

        foreach (var nearbyObject in collidersToMove)
        {
            Rigidbody nearRigidbody = nearbyObject.GetComponent <Rigidbody>();
            if (nearRigidbody)
            {
                nearRigidbody.AddExplosionForce(_force, _selfTransform.position, _radius);
            }
        }

        await Task.Delay(TimeSpan.FromSeconds(3)); // время работы частиц

        if (explosion)
        {
            Destroy(explosion.gameObject);
        }
    }
Ejemplo n.º 4
0
    protected override void OnTriggerAction(Collider other)
    {
        if (!enabled)
        {
            return;
        }
        if (!Math.LayerMaskContainsLayer(layersToDamage, other.gameObject.layer))
        {
            return;
        }

        IDestructible destructible = other.GetComponent <IDestructible>();

        if (debug)
        {
            Debug.Log(name + " dealing damage via OnTriggerAction to " + other.name);
        }


        if (destructible != null)
        {
            destructible.DoDamage(damage.Value, (transform.position + other.transform.position) / 2,
                                  (transform.position - other.transform.position).normalized);
            onDoDamage.Invoke();
        }
    }
Ejemplo n.º 5
0
        public void shoot()
        {
            if (shootsInMagazine >= 1)
            {
                shootsInMagazine--;

                Vector3 shootOrigin  = transform.TransformPoint(cannonRelativePosition);
                Vector3 shootEnd     = new Vector3();
                Vector3 rayDirection = getWorldDeviatedDirection();

                RaycastHit hit;
                if (Physics.Raycast(shootOrigin, rayDirection, out hit, rayDistance))
                {
                    shootEnd = hit.point;

                    IDestructible destructible = hit.transform.GetComponent <IDestructible>();

                    if (destructible != null)
                    {
                        destructible.damage(damage, user);
                    }
                }
                else
                {
                    shootEnd  = transform.TransformPoint(cannonRelativePosition);
                    shootEnd += rayDirection * rayDistance;
                }

                StartCoroutine(drawShoot(shootOrigin, shootEnd));
            }
        }
Ejemplo n.º 6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //接触后消除眼泪,不触发其他方法
        if (CommonUnit.TagCheck(collision.gameObject, player.TagThatDefaultByBullet) || CommonUnit.ComponentCheck(collision.gameObject, player.TypeThatDefaultByBullet))
        {
            Destroy();
        }

        if (CommonUnit.TagCheck(collision.gameObject, new string[] { }))
        {
        }
        //接触后消除眼泪并触发对象的受击方法
        else if (CommonUnit.ComponentCheck(collision.gameObject, player.TypeThatCanBeAttackedByBullet))
        {
            Vector3     force       = Vector3.Normalize(collision.transform.position - transform.position) * playerKnockback;
            IAttackable iAttackable = collision.GetComponent <IAttackable>();
            iAttackable.BeAttacked(damage, force);
            if (player.penetrating == false)
            {
                Destroy();
            }
        }
        //接触后消除眼泪并触发对象的销毁方法
        else if (CommonUnit.ComponentCheck(collision.gameObject, player.TypeThatCanBeDestroyedByBullet))
        {
            IDestructible destructible = collision.GetComponent <IDestructible>();
            destructible.DestorySelf();
            if (player.penetrating == false)
            {
                Destroy();
            }
        }
        //其他的接触后无反应
    }
Ejemplo n.º 7
0
    void GetMoveOrAttackTile()
    {
        Tile t = currentTile.GetDownNeighbour(jumpHeight, true);

        if (t != null)
        {
            MoveToTile(t);
        }
        else
        {
            var go = currentTile.GetGameObject(-Vector3.forward); //Get Gameobject in front

            if (go == null)                                       //Nothing in Front, reach end of map
            {
                return;
            }

            var isEnemy      = go.GetComponent <Enemy>() != null; //Avoid enemy attack enemy
            var destructible = go.GetComponent <IDestructible>();

            if (destructible != null && !isEnemy)
            {
                destructibleInFront = destructible;
            }
        }
    }
Ejemplo n.º 8
0
 public Shield(IDestructible destructible, Shield.Type type, Shield.Status status, int hitPoints)
 {
     this.type         = type;
     this.hitPoints    = hitPoints;
     this.status       = status;
     this.destructible = destructible;
 }
Ejemplo n.º 9
0
    /*private void OnMouseUpAsButton()
     * {
     *  //Debug.Log("OnMouseUpAsButton to Point");
     *
     *  //OnClick();
     * }*/
    #endregion

    #region Public methods
    public void Initialize(EnumPointType _type, IDestructible _destr = null)
    {
        type         = _type;
        destructible = _destr;

        EventManager.CallOnInitPointController(this);
    }
Ejemplo n.º 10
0
 private void UpdateProgression(IDestructible inTarget, Vector3 inPosition)
 {
     if (_destructible == null || inTarget != _destructible)
     {
         return;
     }
     fill.fillAmount = _destructible.Percentage;
 }
 private void DetachHealthBar(IDestructible inEnemy)
 {
     if (!_healthBars.ContainsKey(inEnemy))
     {
         return;
     }
     Destroy(_healthBars[inEnemy].gameObject);
     _healthBars.Remove(inEnemy);
 }
Ejemplo n.º 12
0
        protected override ReadonlyEvent GatherData()
        {
            Validate();

            _actor  = ResourceLocator.Get(_attackerId, serviceProvider) as IAttack;
            _target = ResourceLocator.Get(_targetId, serviceProvider) as IDestructible;

            return(this);
        }
Ejemplo n.º 13
0
        public virtual Damage Attack(IDestructible target, Damage payload)
        {
            //1. Calc damage
            //TODO: There should be a range of damage
            const int cDamage = 1;

            payload.Total = cDamage;
            return(payload);
        }
Ejemplo n.º 14
0
 internal void SetHp(int nextHp, GameObject source, IDestructible destructibleSource)
 {
     health = nextHp;
     if (health <= 0)
     {
         destructibleSource.OnObjDestroyed();
         GameObject.Destroy(source);
     }
 }
Ejemplo n.º 15
0
 protected override void ReleaseReferences()
 {
     if (_destructible != null)
     {
         _destructible.OnTakeDamage -= UpdateProgression;
     }
     _destructible = null;
     _c            = null;
     fill          = null;
 }
Ejemplo n.º 16
0
 protected override void ReleaseReferences()
 {
     _currentTarget   = null;
     settings         = null;
     camera           = null;
     touchAndRotation = null;
     animController   = null;
     laserBeam        = null;
     animator         = null;
 }
Ejemplo n.º 17
0
        public Character GetGameObjectCharacter(GameObject obj)
        {
            IDestructible destructible = obj.GetComponent <IDestructible>();

            if (destructible == null)
            {
                return(null);
            }
            return(destructible as Character);
        }
Ejemplo n.º 18
0
            override public void OnHit(GameObject gameObject)
            {
                IDestructible component = gameObject.GetComponent <IDestructible>();

                if (component != null && component is Character character)
                {
                    var     randAngle = UnityEngine.Random.Range(0, (float)(2 * Math.PI));
                    Vector3 randDir   = new Vector3((float)Math.Cos(randAngle), 0, (float)Math.Sin(randAngle));
                    typeof(Character).GetMethod("AddStaggerDamage", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(character, new object[] { staggerDamage, randDir });
                }
            }
Ejemplo n.º 19
0
    // Token: 0x06000E59 RID: 3673 RVA: 0x00066A80 File Offset: 0x00064C80
    private void Destroy()
    {
        IDestructible component = base.GetComponent <IDestructible>();

        if (component != null)
        {
            HitData hitData = new HitData();
            hitData.m_damage.m_damage = 9999f;
            component.Damage(hitData);
        }
    }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShotEventArgs"/> class.
        /// </summary>
        /// <param name="shooter"><inheritdoc cref="Shooter"/></param>
        /// <param name="destructible">The <see cref="IDestructible"/> hit.</param>
        /// <param name="hit"><inheritdoc cref="Distance"/></param>
        /// <param name="damage"><inheritdoc cref="Damage"/></param>
        public ShotEventArgs(Player shooter, RaycastHit hit, IDestructible destructible, float damage)
        {
            Shooter  = shooter;
            Damage   = damage;
            Distance = hit.distance;

            if (destructible is HitboxIdentity identity)
            {
                Hitbox = identity;
                Target = Player.Get(Hitbox.TargetHub);
            }
        }
        private void AttachHealthBar(IDestructible inEnemy)
        {
            if (_healthBars.ContainsKey(inEnemy))
            {
                return;
            }
            var healthBar = Instantiate(healthBarPrefab, transform);

            healthBar.Initialize();
            healthBar.BindData(inEnemy);
            inEnemy.AssignHealthBar(healthBar);
        }
Ejemplo n.º 22
0
    // Token: 0x0600030B RID: 779 RVA: 0x0001A1A4 File Offset: 0x000183A4
    public static GameObject FindHitObject(Collider collider)
    {
        IDestructible componentInParent = collider.gameObject.GetComponentInParent <IDestructible>();

        if (componentInParent != null)
        {
            return((componentInParent as MonoBehaviour).gameObject);
        }
        if (collider.attachedRigidbody)
        {
            return(collider.attachedRigidbody.gameObject);
        }
        return(collider.gameObject);
    }
Ejemplo n.º 23
0
    private void OnCollisionEnter(Collision collision)
    {
        IDestructible otherDestructibleBehaviour = collision.gameObject.GetComponent <IDestructible>();
        IDestructible thisDestructibleBehaviour  = GetComponent <IDestructible>();

        if (otherDestructibleBehaviour != null)
        {
            otherDestructibleBehaviour.DestroySelf();
        }
        if (thisDestructibleBehaviour != null)
        {
            thisDestructibleBehaviour.DestroySelf();
        }
    }
Ejemplo n.º 24
0
    private void OnTriggerEnter(Collider other)
    {
        if (dealtDamage)
        {
            return;
        }

        IDestructible destructible = other.GetComponent <IDestructible>();

        if (destructible != null)
        {
            DealDamage(destructible);
        }
    }
Ejemplo n.º 25
0
        public override void Initialize()
        {
            //- init
            _currentTarget = null;
            _isMouseDown   = false;
            animController = new PlayerAnimController(animator, camera, settings);
            touchAndRotation.Initialize(settings, camera.transform);
            laserBeam.Initialize();

            //- subscribe to events
            touchAndRotation.onFingerDown += FingerDown;
            touchAndRotation.onFingerUp   += FingerUp;
            touchAndRotation.onMove       += OnMove;
        }
    void ApplyDmg(int dmg, UnitStats stats, GameObject source, IDestructible destructibleSource)
    {
        if (dmg == 0 || stats == null)
        {
            return;
        }
        int nextShield = Mathf.Clamp(stats.shields - dmg, 0, stats.shields);
        int nextHp     = stats.health - Mathf.CeilToInt((Mathf.Clamp(dmg - stats.shields, 0, dmg)) * (1f - stats.armor));

        CombatMessageManager.AddMessage("DMG: " + dmg + " armor(hp):" + (100 - stats.armor * 100) +
                                        string.Format("Set shields on {0} {1} -> {2}", source.name, stats.shields, nextShield) +
                                        "Set hp on " + source.name + " " + stats.health + " -> " + nextHp, 10);
        stats.SetShields(nextShield, source);
        stats.SetHp(nextHp, source, destructibleSource);
    }
Ejemplo n.º 27
0
 public static void TakeDamage(this IDestructible destructible, float damage)
 {
     if (destructible.HealthPoints > 0)
     {
         destructible.HealthPoints -= damage;
         if (destructible.HealthPoints <= 0)
         {
             if (destructible is MainCharacter)
             {
                 MainCharacter.Current.EatenByZombie.Fire();
             }
             (destructible as Thing).Scene.Remove(destructible as Thing);
         }
     }
 }
Ejemplo n.º 28
0
        private static bool ExplodeDestructible(ExplosionGrenade __instance, IDestructible dest, Footprinting.Footprint attacker, Vector3 pos, ExplosionGrenade setts, out bool __result)
        {
            __result = false;
            try
            {
                if (Physics.Linecast(dest.CenterOfMass, pos, InventorySystem.Items.MicroHID.MicroHIDItem.WallMask))
                {
                    return(false);
                }
                Vector3      a         = dest.CenterOfMass - pos;
                float        magnitude = a.magnitude;
                float        num       = setts._playerDamageOverDistance.Evaluate(magnitude);
                ReferenceHub referenceHub;
                bool         flag = ReferenceHub.TryGetHubNetID(dest.NetworkId, out referenceHub);
                if (flag && referenceHub.characterClassManager.CurRole.team == Team.SCP)
                {
                    num *= setts._scpDamageMultiplier;
                }
                Vector3 force = (1f - magnitude / setts._maxRadius) * (a / magnitude) * setts._rigidbodyLiftForce + Vector3.up * setts._rigidbodyLiftForce;
                if (num > 0f && dest.Damage(num, new PlayerStatsSystem.ExplosionDamageHandler(attacker, force, num, 50), dest.CenterOfMass) && flag)
                {
                    float num2  = setts._effectDurationOverDistance.Evaluate(magnitude);
                    bool  flag2 = attacker.Hub == referenceHub;
                    if (num2 > 0f && (flag2 || HitboxIdentity.CheckFriendlyFire(attacker.Hub, referenceHub, false)))
                    {
                        float minimalDuration = setts._minimalDuration;
                        ExplosionGrenade.TriggerEffect <CustomPlayerEffects.Burned>(referenceHub, num2 * setts._burnedDuration, minimalDuration);
                        ExplosionGrenade.TriggerEffect <CustomPlayerEffects.Deafened>(referenceHub, num2 * setts._deafenedDuration, minimalDuration);
                        ExplosionGrenade.TriggerEffect <CustomPlayerEffects.Concussed>(referenceHub, num2 * setts._concussedDuration, minimalDuration);
                    }
                    if (!flag2 && attacker.Hub != null)
                    {
                        Hitmarker.SendHitmarker(attacker.Hub, 1f);
                    }
                    referenceHub.inventory.connectionToClient.Send(new GunHitMessage(false, num, pos), 0);
                }

                __result = true;
                return(false);
            }
            catch (Exception ex)
            {
                Logger.Get.Error($"Synapse-FF: ExplodeDestructible failed!!\n{ex}");
                return(true);
            }
        }
Ejemplo n.º 29
0
            public static bool Prefix(Projectile __instance, ref Collider collider, Vector3 hitPoint)
            {
                if (__instance.name.Contains(customProjectileName))
                {
                    GameObject    gameObject   = (collider ? Projectile.FindHitObject(collider) : null);
                    IDestructible destructible = (gameObject ? gameObject.GetComponent <IDestructible>() : null);
                    if (destructible != null)
                    {
                        bool hitCharacter = false;
                        bool hitValid     = (bool)typeof(Projectile).GetMethod("IsValidTarget", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { destructible, hitCharacter });
                        if (!hitValid)
                        {
                            return(true);
                        }
                        HitData hitData = new HitData();
                        hitData.m_hitCollider = collider;
                        hitData.m_damage      = __instance.m_damage.Clone();
                        hitData.m_toolTier    = __instance.m_damage.m_chop == darkChopDamage ? 2 : 0;
                        if ((destructible is Character character) && !treelikeCreatures.Contains(character.m_name))
                        {
                            hitData.m_damage.m_pierce = 0;
                        }
                        hitData.m_pushForce     = 20;
                        hitData.m_backstabBonus = 3;
                        hitData.m_point         = hitPoint;
                        hitData.m_dir           = __instance.transform.forward;
                        hitData.m_dodgeable     = true;
                        hitData.m_blockable     = true;
                        hitData.m_skill         = MagicSkill.MagicSkillDef.m_skill;
                        var owner = (Character)typeof(Projectile).GetField("m_owner", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(__instance);
                        hitData.SetAttacker(owner);
                        destructible.Damage(hitData);

                        __instance.m_hitEffects.Create(hitPoint, Quaternion.identity);
                        if (__instance.m_hitNoise > 0f)
                        {
                            BaseAI.DoProjectileHitNoise(__instance.transform.position, __instance.m_hitNoise, owner);
                        }
                        ((ZNetView)typeof(Projectile).GetField("m_nview", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(__instance)).InvokeRPC("OnHit");
                        ZNetScene.instance.Destroy(__instance.gameObject);
                        return(false);
                    }
                }
                return(true);
            }
Ejemplo n.º 30
0
    // Token: 0x06000CF2 RID: 3314 RVA: 0x0005CA74 File Offset: 0x0005AC74
    private void Awake()
    {
        IDestructible component    = base.GetComponent <IDestructible>();
        Destructible  destructible = component as Destructible;

        if (destructible)
        {
            Destructible destructible2 = destructible;
            destructible2.m_onDestroyed = (Action)Delegate.Combine(destructible2.m_onDestroyed, new Action(this.OnDestroyed));
        }
        WearNTear wearNTear = component as WearNTear;

        if (wearNTear)
        {
            WearNTear wearNTear2 = wearNTear;
            wearNTear2.m_onDestroyed = (Action)Delegate.Combine(wearNTear2.m_onDestroyed, new Action(this.OnDestroyed));
        }
    }
Ejemplo n.º 31
0
 public void SetDestructibleObject(IDestructible i)
 {
     DesctructibleObject = i;
 }