/// <summary>
        /// What to do if the Mob will only act on the target
        /// </summary>
        protected virtual bool PerformActionOnlyOnTarget(MatrixManager.CustomPhysicsHit hitInfo, Vector3 dir)
        {
            var healthBehaviourV2 = hitInfo.CollisionHit.GameObject.GetComponent <LivingHealthMasterBase>();

            if (healthBehaviourV2 != null)
            {
                if (hitInfo.CollisionHit.GameObject == FollowTarget && healthBehaviourV2.IsDead == false)
                {
                    ActOnLivingV2(dir, healthBehaviourV2);
                    return(true);
                }
            }
            else
            {
                var healthBehaviour = hitInfo.CollisionHit.GameObject.GetComponent <LivingHealthBehaviour>();
                if (healthBehaviour != null)
                {
                    if (hitInfo.CollisionHit.GameObject == FollowTarget && healthBehaviour.IsDead == false)
                    {
                        ActOnLiving(dir, healthBehaviour);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (setsMobsOnFire == false)
            {
                return(false);
            }

            if (hit.CollisionHit.GameObject == null)
            {
                return(true);
            }

            //TODO REMOVE AFTER MOBS ARE MOVED TO NEW HEALTH
            if (hit.CollisionHit.GameObject.TryGetComponent(out LivingHealthMasterBase health))
            {
                health.ChangeFireStacks(fireStacksToGive);
            }

            if (hit.CollisionHit.GameObject.TryGetComponent(out LivingHealthMasterBase healthMasterBase))
            {
                healthMasterBase.ChangeFireStacks(fireStacksToGive);
            }

            return(true);
        }
        /// <summary>
        /// What to do if the Mob is trying to act on a Player
        /// </summary>
        protected virtual bool PerformActionPlayer(MatrixManager.CustomPhysicsHit hitInfo, Vector3 dir)
        {
            var healthBehaviour = hitInfo.CollisionHit.GameObject.GetComponent <LivingHealthMasterBase>();

            if (healthBehaviour != null)
            {
                if (healthBehaviour.IsDead)
                {
                    return(false);
                }
                ActOnLivingV2(dir, healthBehaviour);

                if (FollowTarget != null && FollowTarget.gameObject.layer != playersLayer)
                {
                    return(true);
                }

                if (FollowTarget != null && FollowTarget == hitInfo.CollisionHit.GameObject)
                {
                    return(true);
                }

                if (targetOtherPlayersWhoGetInWay)
                {
                    FollowTarget = hitInfo.CollisionHit.GameObject;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        private Vector2 GetNewDirection(MatrixManager.CustomPhysicsHit hit)
        {
            var normal       = hit.Normal;
            var newDirection = direction - 2 * (direction * normal) * normal;

            return(newDirection);
        }
        private bool TryDamage(MatrixManager.CustomPhysicsHit hit)
        {
            if (hit.CollisionHit.GameObject == null)
            {
                return(false);
            }
            var coll      = hit.CollisionHit.GameObject;
            var integrity = coll.GetComponent <Integrity>();

            if (integrity == null)
            {
                return(false);
            }
            if (damageData == null)
            {
                return(true);
            }

            integrity.ApplyDamage(damageData.Damage, damageData.AttackType, damageData.DamageType);

            Chat.AddThrowHitMsgToChat(gameObject, coll.gameObject, targetZone);
            Logger.LogTraceFormat("Hit {0} for {1} with Integrity! bullet absorbed", Category.Firearms,
                                  integrity.gameObject.name, damageData.Damage);

            foreach (var hitDetect in coll.GetComponents <IOnHitDetect>())
            {
                hitDetect.OnHitDetect(damageData);
            }

            return(true);
        }
        private bool TryStun(MatrixManager.CustomPhysicsHit hit)
        {
            var coll = hit.CollisionHit.GameObject;

            if (coll == null)
            {
                return(false);
            }
            var player = coll.GetComponent <RegisterPlayer>();

            if (player == null)
            {
                return(false);
            }

            player.ServerStun(stunTime, willDisarm);

            if (doMsg)
            {
                Chat.AddThrowHitMsgToChat(gameObject, coll.gameObject, targetZone);
            }
            Logger.LogTraceFormat($"{shooter} stunned {player.gameObject.name} for {stunTime} seconds with {weapon.OrNull()?.name}", Category.Firearms);

            return(true);
        }
        private bool TryDamage(MatrixManager.CustomPhysicsHit hit)
        {
            var coll = hit.CollisionHit.GameObject;

            if (coll == null)
            {
                return(true);
            }
            var livingHealth = coll.GetComponent <LivingHealthBehaviour>();

            if (livingHealth == null)
            {
                return(false);
            }

            var newDamage = projectileKineticDamage.DamageByPressureModifier(damageData.Damage);

            livingHealth.ApplyDamageToBodypart(shooter, newDamage, damageData.AttackType, damageData.DamageType, targetZone);

            Chat.AddThrowHitMsgToChat(gameObject, coll.gameObject, targetZone);

            Logger.LogTraceFormat(
                "Hit {0} for {1} with HealthBehaviour! bullet absorbed",
                Category.Firearms,
                livingHealth.gameObject.name,
                newDamage);

            return(true);
        }
Esempio n. 8
0
        private bool TryDamage(MatrixManager.CustomPhysicsHit hit)
        {
            var coll = hit.CollisionHit.GameObject;

            if (coll == null)
            {
                return(false);
            }
            var integrity = coll.GetComponent <Integrity>();

            if (integrity == null)
            {
                return(false);
            }

            float newDamage = projectileKineticDamage.DamageByPressureModifier(damageData.Damage);

            integrity.ApplyDamage(newDamage, damageData.AttackType, damageData.DamageType);

            Chat.AddThrowHitMsgToChat(gameObject, coll.gameObject, targetZone);

            Logger.LogTraceFormat(
                "Hit {0} for {1} with Integrity! bullet absorbed",
                Category.Firearms,
                integrity.gameObject.name,
                newDamage);

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// It is necessary to off set hit position of a raycast
        /// If you won't do it, you will get wrong tile
        /// when shooting up or left side of the tile
        /// </summary>
        /// <param name="hit"></param>
        /// <returns></returns>
        private Vector3 GetHitTileWorldPosition(MatrixManager.CustomPhysicsHit hit)
        {
            var bulletHitTarget = Vector3.zero;

            bulletHitTarget.x = hit.TileHitWorld.x;
            bulletHitTarget.y = hit.TileHitWorld.y;
            return(bulletHitTarget);
        }
Esempio n. 10
0
        public override bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (base.Interact(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            return(ProcessCount());
        }
Esempio n. 11
0
        public override bool ProcessHit(MatrixManager.CustomPhysicsHit hit, IOnHit[] behavioursOnBulletHit)
        {
            foreach (var behaviour in behavioursOnBulletHit)
            {
                behaviour.OnHit(hit);
            }

            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// What to do if the Mob is trying to act on a Tile
        /// </summary>
        protected virtual void PerformActionTile(MatrixManager.CustomPhysicsHit hitInfo, Vector3 dir)
        {
            if (TargetDistance() > 4.5f)
            {
                //Don't bother, the target is too far away to warrant a decision to break a tile
                return;
            }

            ActOnTile(hitInfo.TileHitWorld.RoundToInt(), dir);
        }
 public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
 {
     if (hit.CollisionHit.GameObject == null)
     {
         OnBeamEnd(point);
     }
     else
     {
         OnCollision(hit);
     }
 }
 public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
 {
     if (isTriggeredOnHit && hit.ItHit)
     {
         OnBeamEnd(hit.HitWorld);
     }
     else
     {
         OnBeamEnd(point);
     }
 }
Esempio n. 15
0
        public bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (CheckConditions(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            movingProjectile.position = hit.HitWorld;
            RotateBullet(GetNewDirection(hit));

            return(IsCountReached());
        }
Esempio n. 16
0
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (hit.CollisionHit.TileLocation == null)
            {
                return(false);
            }
            var interactableTile = hit.CollisionHit.TileLocation.PresentMetaTileMap.GetComponentInParent <InteractableTiles>();

            var bulletHitTarget = GetHitTileWorldPosition(hit);

            return(TryProcessBehaviours(hit, interactableTile, bulletHitTarget));
        }
        private void OnCollision(MatrixManager.CustomPhysicsHit hit)
        {
            var coll = hit.CollisionHit.GameObject;
            var interactableTiles = coll.GetComponentInParent <InteractableTiles>();

            var bulletHitTarget = Vector3.zero;

            bulletHitTarget.x = hit.HitWorld.x - 0.01f * hit.Normal.x;
            bulletHitTarget.y = hit.HitWorld.y - 0.01f * hit.Normal.y;

            interactableTiles.CreateAnimatedTile(bulletHitTarget, animationTile.Tile, animationTile.Time);
        }
Esempio n. 18
0
        public bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layerToHit = GetLayerToHitOrGetNull(interactableTiles.MetaTileMap.DamageableLayers);

            if (layerToHit == null)
            {
                return(false);
            }

            layerToHit.TilemapDamage.ApplyDamage(damageData.Damage, damageData.AttackType, worldPosition);

            return(true);
        }
Esempio n. 19
0
 public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
 {
     if (hit.CollisionHit.GameObject == null)
     {
         RayCastAt(point);
     }
     else
     {
         var bulletHitTarget = Vector3.zero;
         bulletHitTarget.x = hit.HitWorld.x - 0.01f * hit.Normal.x;
         bulletHitTarget.y = hit.HitWorld.y - 0.01f * hit.Normal.y;
         RayCastAt(bulletHitTarget);
     }
 }
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (hit.CollisionHit.GameObject == null)
            {
                // Don't explode on top of the tile, but on the tile adjacent to it.
                Explode((Vector2)hit.HitWorld + (hit.Normal * 0.2f));
            }
            else
            {
                Explode(hit.HitWorld);
            }

            return(true);
        }
Esempio n. 21
0
        /// <summary>
        ///  Invokes cached behaviours
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="interactableTile"></param>
        /// <param name="bulletHitTarget"></param>
        /// <returns> True if at least one behaviour returned true </returns>
        private bool TryProcessBehaviours(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTile, Vector3 bulletHitTarget)
        {
            bool isAnyProcessed = false;

            foreach (var behaviour in behavioursInteractTile)
            {
                if (behaviour.Interact(hit, interactableTile, bulletHitTarget))
                {
                    isAnyProcessed = true;
                }
            }

            return(isAnyProcessed);
        }
        public override bool CheckCondition(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            var layers = interactableTiles.MetaTileMap.DamageableLayers;

            foreach (var layer in layers)
            {
                if (CheckType(layer.LayerType))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 23
0
        /// <summary>
        /// Main method for processing ray cast hit
        /// </summary>
        /// <param name="hit"></param>
        public void ProcessRaycastHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (IsHitValid(hit) == false)
            {
                return;
            }

            if (hitProcessor.ProcessHit(hit, behavioursOnBulletHit) == false)
            {
                return;
            }

            DespawnThis(hit, hit.HitWorld);
        }
Esempio n. 24
0
        public override bool ProcessHit(MatrixManager.CustomPhysicsHit hit, IOnHit[] behavioursOnBulletHit)
        {
            var isRequesting = false;

            foreach (var behaviour in behavioursOnBulletHit)
            {
                if (behaviour.OnHit(hit))
                {
                    isRequesting = true;
                }
            }

            return(isRequesting);
        }
Esempio n. 25
0
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (decal == null)
            {
                Logger.LogError($"{this} on {gameObject} decal field not set in inspector!");
                return(false);
            }

            var newDecal = Spawn.ClientPrefab(decal.name,
                                              hit.HitWorld).GameObject;
            var timeLimitedDecal = newDecal.GetComponent <TimeLimitedDecal>();

            timeLimitedDecal.SetUpDecal(animationTime);
            return(false);
        }
Esempio n. 26
0
 /// <summary>
 /// Check if we hit anything
 /// and that hit is not the shooter
 /// </summary>
 /// <param name="hit"></param>
 /// <returns></returns>
 private bool IsHitValid(MatrixManager.CustomPhysicsHit hit)
 {
     if (hit.ItHit == false)
     {
         return(false);
     }
     if (WillHurtShooter)
     {
         return(true);
     }
     if (hit.CollisionHit.GameObject == shooter)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 27
0
        public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
        {
            var     pos      = thisTransform.position;
            Vector3 startPos = new Vector3(direction.x, direction.y, pos.z) * 0.7f;

            if (hit.CollisionHit.GameObject == null)
            {
                lineRenderer.SetPosition(0, pos + startPos);
                lineRenderer.SetPosition(1, point);
                return;
            }

            var endPosition = hit.HitWorld;

            lineRenderer.SetPosition(0, pos + startPos);
            lineRenderer.SetPosition(1, endPosition);
        }
        /// <summary>
        /// What to do if the Mob is trying to act on an NPC
        /// </summary>
        protected virtual bool PerformActionNpc(MatrixManager.CustomPhysicsHit hitInfo, Vector3 dir)
        {
            var target = hitInfo.CollisionHit.GameObject.GetComponent <MobAI>();

            //Prevent the mob from acting on itself and those like it
            if (target != null && mobAI != null)
            {
                if (target.mobName.Equals(mobAI.mobName, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            var healthBehaviour = hitInfo.CollisionHit.GameObject.GetComponent <LivingHealthBehaviour>();


            if (healthBehaviour != null)
            {
                if (healthBehaviour.IsDead)
                {
                    return(false);
                }

                ActOnLiving(dir, healthBehaviour);
                return(true);
            }
            else
            {
                //Safety catch in case the NPC is using the new health system
                var healthBehaviourV2 = hitInfo.CollisionHit.GameObject.GetComponent <LivingHealthMasterBase>();
                if (healthBehaviourV2 != null)
                {
                    if (healthBehaviourV2.IsDead)
                    {
                        return(false);
                    }

                    ActOnLivingV2(dir, healthBehaviourV2);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 29
0
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (setsMobsOnFire == false)
            {
                return(false);
            }

            if (hit.CollisionHit.GameObject == null)
            {
                return(true);
            }

            if (hit.CollisionHit.GameObject.TryGetComponent(out LivingHealthBehaviour health))
            {
                health.ChangeFireStacks(fireStacksToGive);
            }

            return(true);
        }
Esempio n. 30
0
        /// <summary>
        /// Despawn bullet and call all
        /// on despawn behaviours
        /// </summary>
        private void DespawnThis(MatrixManager.CustomPhysicsHit hit, Vector2 point)
        {
            foreach (var behaviour in behavioursOnBulletDespawn)
            {
                behaviour.OnDespawn(hit, point);
            }

            if (CustomNetworkManager.IsServer)
            {
                _ = Despawn.ServerSingle(gameObject);
            }
            else
            {
                if (Despawn.ClientSingle(gameObject).Successful == false)
                {
                    Destroy(gameObject);
                }
            }
        }