コード例 #1
0
        /// <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);
        }
コード例 #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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        private Vector2 GetNewDirection(MatrixManager.CustomPhysicsHit hit)
        {
            var normal       = hit.Normal;
            var newDirection = direction - 2 * (direction * normal) * normal;

            return(newDirection);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #10
0
        public override bool Interact(MatrixManager.CustomPhysicsHit hit, InteractableTiles interactableTiles, Vector3 worldPosition)
        {
            if (base.Interact(hit, interactableTiles, worldPosition) == false)
            {
                return(true);
            }

            return(ProcessCount());
        }
コード例 #11
0
        public override bool ProcessHit(MatrixManager.CustomPhysicsHit hit, IOnHit[] behavioursOnBulletHit)
        {
            foreach (var behaviour in behavioursOnBulletHit)
            {
                behaviour.OnHit(hit);
            }

            return(true);
        }
コード例 #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);
        }
コード例 #13
0
 public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
 {
     if (hit.CollisionHit.GameObject == null)
     {
         OnBeamEnd(point);
     }
     else
     {
         OnCollision(hit);
     }
 }
コード例 #14
0
 public void OnDespawn(MatrixManager.CustomPhysicsHit hit, Vector2 point)
 {
     if (isTriggeredOnHit && hit.ItHit)
     {
         OnBeamEnd(hit.HitWorld);
     }
     else
     {
         OnBeamEnd(point);
     }
 }
コード例 #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());
        }
コード例 #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));
        }
コード例 #17
0
        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);
        }
コード例 #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);
        }
コード例 #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);
     }
 }
コード例 #20
0
        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);
        }
コード例 #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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
ファイル: Bullet.cs プロジェクト: Unity-Marines/Unity-Marines
        /// <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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #26
0
ファイル: Bullet.cs プロジェクト: Unity-Marines/Unity-Marines
 /// <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);
 }
コード例 #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);
        }
コード例 #28
0
        /// <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);
        }
コード例 #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);
        }
コード例 #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);
                }
            }
        }