private ShaftAimingLaserBehaviour InterpolateLaser(AimingLaserTargetPointNode weapon, Vector3 startPosition, Vector3 laserDir)
        {
            bool    flag;
            bool    flag2;
            Vector3 vector3;
            Vector3 leftDirectionWorld = new MuzzleVisualAccessor(weapon.muzzlePoint).GetLeftDirectionWorld();

            laserDir = Vector3.ProjectOnPlane(laserDir, leftDirectionWorld).normalized;
            ShaftAimingLaserBehaviour effectInstance = weapon.shaftAimingLaser.EffectInstance;
            float         maxLength = weapon.shaftAimingLaser.MaxLength;
            float         minLength = weapon.shaftAimingLaser.MinLength;
            DirectionData data      = weapon.targetCollector.Collect(startPosition, laserDir, maxLength, LayerMasks.VISUAL_TARGETING);

            if (data.HasAnyHit())
            {
                flag    = true;
                flag2   = data.FirstAnyHitDistance() >= minLength;
                vector3 = data.FirstAnyHitPosition();
            }
            else
            {
                flag    = false;
                flag2   = true;
                vector3 = startPosition + (laserDir * maxLength);
            }
            bool flag3 = !weapon.shaftAimingTargetPoint.IsInsideTankPart;

            effectInstance.UpdateTargetPosition(weapon.shaftAimingLaserSource.transform.position, vector3, flag2 & flag3, flag & flag3);
            weapon.shaftAimingLaser.CurrentLaserDirection = laserDir;
            return(effectInstance);
        }
 public void DrawDecals(UpdateEvent evt, StreaminWeaponNode weaponNode, [JoinAll] SingleNode <DecalManagerComponent> decalManagerNode)
 {
     if (decalManagerNode.component.EnableDecals)
     {
         StreamingDecalProjectorComponent streamingDecalProjector = weaponNode.streamingDecalProjector;
         DecalManagerComponent            component = decalManagerNode.component;
         if ((weaponNode.streamHit.StaticHit != null) && ((streamingDecalProjector.LastDecalCreationTime + streamingDecalProjector.DecalCreationPeriod) <= Time.time))
         {
             streamingDecalProjector.LastDecalCreationTime = Time.time;
             Vector3         barrelOriginWorld = new MuzzleVisualAccessor(weaponNode.muzzlePoint).GetBarrelOriginWorld();
             Vector3         normalized        = (weaponNode.streamHit.StaticHit.Position - barrelOriginWorld).normalized;
             DecalProjection decalProjection   = new DecalProjection {
                 AtlasHTilesCount      = streamingDecalProjector.AtlasHTilesCount,
                 AtlasVTilesCount      = streamingDecalProjector.AtlasVTilesCount,
                 SurfaceAtlasPositions = streamingDecalProjector.SurfaceAtlasPositions,
                 HalfSize   = streamingDecalProjector.HalfSize,
                 Up         = streamingDecalProjector.Up,
                 Distantion = streamingDecalProjector.Distance,
                 Ray        = new Ray(barrelOriginWorld - normalized, normalized)
             };
             Mesh mesh = null;
             if (component.DecalMeshBuilder.Build(decalProjection, ref mesh))
             {
                 component.BulletHoleDecalManager.AddDecal(mesh, streamingDecalProjector.Material, streamingDecalProjector.Color, streamingDecalProjector.LifeTime);
             }
         }
     }
 }
 private void DrawHammerHitDecals(Vector3 shotDirection, PelletThrowingGraphicsNode weapon, SingleNode <DecalManagerComponent> decalManagerNode, DecalSettingsComponent settings)
 {
     if (settings.EnableDecals && (settings.MaxDecalsForHammer > 0))
     {
         DecalMeshBuilder              decalMeshBuilder       = decalManagerNode.component.DecalMeshBuilder;
         BulletHoleDecalManager        bulletHoleDecalManager = decalManagerNode.component.BulletHoleDecalManager;
         MuzzlePointComponent          muzzlePoint            = weapon.muzzlePoint;
         HammerDecalProjectorComponent hammerDecalProjector   = weapon.hammerDecalProjector;
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePoint).GetBarrelOriginWorld();
         decalMeshBuilder.Clean();
         DecalProjection projection2 = new DecalProjection {
             HalfSize   = hammerDecalProjector.CombineHalfSize,
             Distantion = hammerDecalProjector.Distance,
             Ray        = new Ray(barrelOriginWorld - shotDirection, shotDirection)
         };
         DecalProjection decalProjection = projection2;
         if (decalMeshBuilder.CompleteProjectionByRaycast(decalProjection) && decalMeshBuilder.CollectPolygons(decalProjection))
         {
             Vector3     localDirection = muzzlePoint.Current.InverseTransformVector(shotDirection);
             Vector3[]   vectorArray    = PelletDirectionsCalculator.GetRandomDirections(weapon.hammerPelletCone, muzzlePoint.Current.rotation, localDirection);
             List <Mesh> list           = new List <Mesh>(vectorArray.Length);
             for (int i = 0; i < Math.Min(vectorArray.Length, settings.MaxDecalsForHammer); i++)
             {
                 Vector3 direction = vectorArray[i];
                 projection2 = new DecalProjection {
                     AtlasHTilesCount      = hammerDecalProjector.AtlasHTilesCount,
                     AtlasVTilesCount      = hammerDecalProjector.AtlasVTilesCount,
                     SurfaceAtlasPositions = hammerDecalProjector.SurfaceAtlasPositions,
                     HalfSize   = hammerDecalProjector.HalfSize,
                     Up         = hammerDecalProjector.Up,
                     Distantion = hammerDecalProjector.Distance,
                     Ray        = new Ray(barrelOriginWorld - shotDirection, direction)
                 };
                 DecalProjection projection3 = projection2;
                 if (decalMeshBuilder.CompleteProjectionByRaycast(projection3))
                 {
                     decalMeshBuilder.BuilldDecalFromCollectedPolygons(projection3);
                     Mesh mesh = null;
                     if (decalMeshBuilder.GetResultToMesh(ref mesh))
                     {
                         list.Add(mesh);
                     }
                 }
             }
             if (list.Count != 0)
             {
                 CombineInstance[] combine = new CombineInstance[list.Count];
                 for (int j = 0; j < list.Count; j++)
                 {
                     combine[j].mesh = list[j];
                 }
                 Mesh decalMesh = new Mesh();
                 decalMesh.CombineMeshes(combine, true, false);
                 decalMesh.RecalculateBounds();
                 bulletHoleDecalManager.AddDecal(decalMesh, hammerDecalProjector.Material, hammerDecalProjector.Color, hammerDecalProjector.LifeTime);
             }
         }
     }
 }
Exemple #4
0
 protected void DrawHitDecal(HitEvent evt, DecalManagerComponent decalManager, DynamicDecalProjectorComponent decalProjector, MuzzlePointComponent muzzlePoint)
 {
     if (evt.StaticHit != null)
     {
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePoint).GetBarrelOriginWorld();
         this.DrawHitDecal(decalManager, decalProjector, barrelOriginWorld, (evt.StaticHit.Position - barrelOriginWorld).normalized);
     }
 }
Exemple #5
0
 public void DrawBulletHitDecal(BulletHitEvent evt, Node node, [JoinByTank] SingleNode <DynamicDecalProjectorComponent> decalHitNode, [JoinByTank] SingleNode <MuzzlePointComponent> muzzlePointNode, [JoinAll] SingleNode <DecalManagerComponent> decalManagerNode)
 {
     if (decalManagerNode.component.EnableDecals && (evt is BulletStaticHitEvent))
     {
         DynamicDecalProjectorComponent decalProjector = decalHitNode.component;
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePointNode.component).GetBarrelOriginWorld();
         base.DrawHitDecal(decalManagerNode.component, decalProjector, barrelOriginWorld, (evt.Position - barrelOriginWorld).normalized);
     }
 }
        public void ShotTrail(BaseShotEvent evt, WeaponNode weapon)
        {
            RailgunTrailComponent railgunTrail = weapon.railgunTrail;
            Vector3       worldPosition        = new MuzzleVisualAccessor(weapon.muzzlePoint).GetWorldPosition();
            Vector3       shotDirection        = evt.ShotDirection;
            DirectionData data        = weapon.targetCollector.Collect(worldPosition, shotDirection, 1000f, LayerMasks.VISUAL_STATIC);
            Vector3       hitPosition = !data.HasAnyHit() ? (worldPosition + (shotDirection * 1000f)) : data.FirstAnyHitPosition();

            this.DrawShotTrailEffect(worldPosition, hitPosition, railgunTrail.Prefab, railgunTrail.TipPrefab);
        }
        private void EnableHidingItem(Material item, float startTime, ShaftAimingMapWorkingNode weapon)
        {
            Vector3 barrelOriginWorld = new MuzzleVisualAccessor(weapon.muzzlePoint).GetBarrelOriginWorld();
            ShaftAimingMapEffectComponent shaftAimingMapEffect = weapon.shaftAimingMapEffect;
            float   initialEnergy = weapon.shaftAimingWorkingState.InitialEnergy;
            float   maxRadius     = shaftAimingMapEffect.ShrubsHidingRadiusMax * initialEnergy;
            Vector4 hidingCenter  = new Vector4(barrelOriginWorld.x, barrelOriginWorld.y, barrelOriginWorld.z, 0f);

            this.EnableMaterialHiding(item, hidingCenter, weapon.shaftEnergy.UnloadAimingEnergyPerSec, maxRadius, Mathf.Lerp(shaftAimingMapEffect.ShrubsHidingRadiusMin, maxRadius, weapon.shaftAimingWorkingState.ExhaustedEnergy / initialEnergy), startTime);
        }
Exemple #8
0
        public void InterpolateManualTargetingCamera(UpdateEvent evt, AimingWorkActivationStateNode weapon, [JoinAll] AimingCameraNode cameraNode)
        {
            MuzzleVisualAccessor       accessor          = new MuzzleVisualAccessor(weapon.muzzlePoint);
            CameraComponent            camera            = cameraNode.camera;
            Transform                  root              = cameraNode.cameraRootTransform.Root;
            ShaftAimingCameraComponent shaftAimingCamera = cameraNode.shaftAimingCamera;
            float t = Mathf.Clamp01(weapon.shaftAimingWorkActivationState.ActivationTimer / weapon.shaftStateConfig.ActivationToWorkingTransitionTimeSec);
            MuzzleLogicAccessor accessor2 = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);

            root.SetPositionSafe(Vector3.Lerp(shaftAimingCamera.WorldInitialCameraPosition, accessor2.GetBarrelOriginWorld(), t));
            Quaternion quaternion2 = Quaternion.LookRotation(accessor.GetFireDirectionWorld(), accessor.GetUpDirectionWorld());

            weapon.weaponRotationControl.MouseRotationCumulativeHorizontalAngle = Mathf.Clamp(weapon.weaponRotationControl.MouseRotationCumulativeHorizontalAngle, -weapon.shaftAimingRotationConfig.AimingOffsetClipping, weapon.shaftAimingRotationConfig.AimingOffsetClipping);
            Vector3 eulerAngles = quaternion2.eulerAngles;

            root.SetRotationSafe(Quaternion.Slerp(shaftAimingCamera.WorldInitialCameraRotation, Quaternion.Euler(eulerAngles.x, eulerAngles.y + weapon.weaponRotationControl.MouseRotationCumulativeHorizontalAngle, eulerAngles.z), t));
            camera.FOV = Mathf.Lerp(shaftAimingCamera.InitialFOV, weapon.shaftAimingCameraConfigEffect.ActivationStateTargetFov, t);
        }
 public void Build(BulletBuildEvent e, WeaponNode weaponNode, [JoinByTank] TankNode tankNode)
 {
     Entity entity = base.CreateEntity<RicochetBulletTemplate>("battle/weapon/ricochet/bullet");
     BulletComponent bullet = new BulletComponent();
     WeaponBulletShotComponent weaponBulletShot = weaponNode.weaponBulletShot;
     float bulletRadius = weaponBulletShot.BulletRadius;
     bullet.Radius = bulletRadius;
     bullet.Speed = weaponBulletShot.BulletSpeed;
     MuzzleVisualAccessor accessor = new MuzzleVisualAccessor(weaponNode.muzzlePoint);
     BulletTargetingComponent component4 = entity.AddComponentAndGetInstance<BulletTargetingComponent>();
     component4.RadialRaysCount = entity.AddComponentAndGetInstance<BulletConfigComponent>().RadialRaysCount;
     component4.Radius = bulletRadius;
     Rigidbody tankRigidbody = tankNode.rigidbody.Rigidbody;
     bullet.ShotId = weaponNode.shotId.ShotId;
     base.InitBullet(bullet, accessor.GetWorldPosition(), e.Direction, bullet.Radius, tankRigidbody);
     entity.AddComponent(bullet);
     entity.AddComponent(new TankGroupComponent(weaponNode.tankGroup.Key));
     entity.AddComponent<RicochetBulletComponent>();
     entity.AddComponent(new TargetCollectorComponent(new TargetCollector(tankNode.Entity), new TargetValidator(tankNode.Entity)));
     entity.AddComponent<ReadyBulletComponent>();
 }
        public void CreateExplosionOnEachTarget(HitEvent evt, WeaponNode weapon)
        {
            HitExplosionGraphicsComponent hitExplosionGraphics = weapon.hitExplosionGraphics;
            Vector3 fireDirectionWorld = new MuzzleVisualAccessor(weapon.muzzlePoint).GetFireDirectionWorld();

            foreach (HitTarget target in evt.Targets)
            {
                ExplosionEvent eventInstance = new ExplosionEvent {
                    ExplosionOffset = -fireDirectionWorld * hitExplosionGraphics.ExplosionOffset,
                    HitDirection    = target.HitDirection,
                    Asset           = hitExplosionGraphics.ExplosionAsset,
                    Duration        = hitExplosionGraphics.ExplosionDuration,
                    Target          = target
                };
                base.ScheduleEvent(eventInstance, target.Entity);
            }
            if (evt.StaticHit != null)
            {
                Vector3 position = evt.StaticHit.Position - (fireDirectionWorld * hitExplosionGraphics.ExplosionOffset);
                this.DrawExplosionEffect(position, evt.StaticHit.Normal, hitExplosionGraphics.ExplosionAsset, hitExplosionGraphics.ExplosionDuration, weapon);
            }
        }
        public void UpdateLaserTargetPosition(UpdateEvent evt, AimingLaserTargetPointNode weapon, [JoinByTank] RemoteTankNode tank, [JoinAll] CameraNode camera)
        {
            Vector3 barrelOriginWorld = new MuzzleVisualAccessor(weapon.muzzlePoint).GetBarrelOriginWorld();

            this.InterpolateLaser(weapon, barrelOriginWorld, Vector3.Lerp(weapon.shaftAimingLaser.CurrentLaserDirection, Vector3.Normalize(weapon.shaftAimingTargetPoint.Point - barrelOriginWorld), weapon.shaftAimingLaser.InterpolationCoeff).normalized);
        }
        public void ShowAndInitLaser(NodeAddedEvent evt, AimingLaserTargetPointNode weapon, [Context, JoinByTank] ActiveTankNode tank, [JoinAll, Context] CameraNode camera)
        {
            Vector3 barrelOriginWorld = new MuzzleVisualAccessor(weapon.muzzlePoint).GetBarrelOriginWorld();

            this.InterpolateLaser(weapon, barrelOriginWorld, Vector3.Normalize(weapon.shaftAimingTargetPoint.Point - barrelOriginWorld)).Show();
        }
        public void PlayTwinsShotAnimation(BaseShotEvent evt, ReadyTwinsAnimationNode weapon)
        {
            int currentIndex = new MuzzleVisualAccessor(weapon.muzzlePoint).GetCurrentIndex();

            weapon.twinsAnimation.Play(currentIndex);
        }
        public void RequestBulletBuild(BaseShotEvent evt, BlockedWeaponNode weaponNode)
        {
            MuzzleVisualAccessor accessor = new MuzzleVisualAccessor(weaponNode.muzzlePoint);

            base.ScheduleEvent(new BulletBuildEvent(accessor.GetFireDirectionWorld()), weaponNode);
        }