Esempio n. 1
0
        public void PrepareTargeting(TargetingEvent evt, WeaponNode weapon, [JoinByTank] TankNode tank)
        {
            TargetingData targetingData = evt.TargetingData;
            VerticalSectorsTargetingComponent verticalSectorsTargeting = weapon.verticalSectorsTargeting;
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);

            targetingData.Origin       = accessor.GetBarrelOriginWorld();
            targetingData.Dir          = accessor.GetFireDirectionWorld();
            targetingData.FullDistance = verticalSectorsTargeting.WorkDistance;
            targetingData.MaxAngle     = (verticalSectorsTargeting.VAngleUp <= verticalSectorsTargeting.VAngleDown) ? verticalSectorsTargeting.VAngleDown : verticalSectorsTargeting.VAngleUp;
            LinkedList <TargetSector> instance = BattleCache.targetSectors.GetInstance();

            instance.Clear();
            CollectTargetSectorsEvent eventInstance = BattleCache.collectTargetSectorsEvent.GetInstance().Init();

            eventInstance.TargetSectors = instance;
            TargetingCone cone = new TargetingCone {
                VAngleUp   = verticalSectorsTargeting.VAngleUp,
                VAngleDown = verticalSectorsTargeting.VAngleDown,
                HAngle     = verticalSectorsTargeting.HAngle,
                Distance   = verticalSectorsTargeting.WorkDistance
            };

            eventInstance.TargetingCone = cone;
            base.ScheduleEvent(eventInstance, weapon);
            CollectSectorDirectionsEvent event3 = BattleCache.collectSectorDirectionsEvent.GetInstance().Init();

            event3.TargetSectors = instance;
            event3.TargetingData = targetingData;
            base.ScheduleEvent(event3, weapon);
            base.ScheduleEvent(BattleCache.collectTargetsEvent.GetInstance().Init(targetingData), weapon);
            base.ScheduleEvent(BattleCache.targetEvaluateEvent.GetInstance().Init(targetingData), weapon);
        }
Esempio n. 2
0
        public void CollectTargetSectors(CollectTargetSectorsEvent e, WeaponNode weaponNode, [JoinByBattle] ICollection <TargetTankNode> targetTankNodes, WeaponNode weaponNode1, [JoinByTank] OwnerTankNode ownerTankNode, [JoinByTeam] Optional <TeamNode> team)
        {
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weaponNode.muzzlePoint, weaponNode.weaponInstance);
            bool   flag   = team.IsPresent();
            long   num    = !flag ? 0L : team.Get().teamGroup.Key;
            LookAt lookAt = new LookAt {
                Position = accessor.GetBarrelOriginWorld(),
                Forward  = accessor.GetFireDirectionWorld(),
                Left     = accessor.GetLeftDirectionWorld(),
                Up       = accessor.GetUpDirectionWorld()
            };
            IEnumerator <TargetTankNode> enumerator = targetTankNodes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                TargetTankNode current = enumerator.Current;
                if (!ownerTankNode.Entity.Equals(current.Entity) && (!flag || (num != current.Entity.GetComponent <TeamGroupComponent>().Key)))
                {
                    BoxCollider tankToTankCollider = (BoxCollider)current.tankColliders.TankToTankCollider;
                    LookTo      lookTo             = new LookTo {
                        Position = tankToTankCollider.bounds.center,
                        Radius   = this.CalculateTankMinimalRadius(lookAt.Forward, tankToTankCollider)
                    };
                    this.AddTargetSector(lookAt, lookTo, e.TargetingCone, e.TargetSectors, e.VAllowableAngleAcatter, e.HAllowableAngleAcatter);
                }
            }
        }
Esempio n. 3
0
        private bool IsWeaponBlocked(MuzzleLogicAccessor muzzlePoint, int mask, out RaycastHit hitInfo, GameObject[] raycastExclusionGameObjects)
        {
            Vector3 worldPosition     = muzzlePoint.GetWorldPosition();
            Vector3 barrelOriginWorld = muzzlePoint.GetBarrelOriginWorld();
            float   distance          = (worldPosition - barrelOriginWorld).magnitude + 0.1f;

            return(PhysicsUtil.RaycastWithExclusion(barrelOriginWorld, worldPosition - barrelOriginWorld, out hitInfo, distance, mask, raycastExclusionGameObjects));
        }
Esempio n. 4
0
        private bool IsWeaponUnderground(MuzzleLogicAccessor muzzlePoint, int mask, TankNode tank, GameObject[] raycastExclusionGameObjects)
        {
            RaycastHit hit;
            Vector3    center = tank.tankColliders.BoundsCollider.bounds.center;
            Vector3    dir    = muzzlePoint.GetBarrelOriginWorld() - center;

            return(PhysicsUtil.RaycastWithExclusion(center, dir, out hit, dir.magnitude, mask, raycastExclusionGameObjects));
        }
        public void ApplyKickback(FixedUpdateEvent evt, KickbackNode weapon, [JoinByTank] TankNode tank)
        {
            KickbackComponent   kickback = weapon.kickback;
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);
            float deltaTime = evt.DeltaTime;

            VulcanPhysicsUtils.ApplyVulcanForce(((-accessor.GetFireDirectionWorld() * kickback.KickbackForce) * WeaponConstants.WEAPON_FORCE_MULTIPLIER) * deltaTime, tank.rigidbody.Rigidbody, accessor.GetWorldMiddlePosition(), tank.tankFalling, tank.track);
        }
Esempio n. 6
0
        public void StartKickback(BaseShotEvent evt, KickbackNode weapon, [JoinByTank] TankNode tank)
        {
            KickbackComponent   kickback      = weapon.kickback;
            MuzzleLogicAccessor accessor      = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);
            Vector3             vector        = -accessor.GetFireDirectionWorld() * kickback.KickbackForce;
            Vector3             worldPosition = accessor.GetWorldPosition();

            tank.rigidbody.Rigidbody.AddForceAtPositionSafe(vector * WeaponConstants.WEAPON_FORCE_MULTIPLIER, worldPosition);
        }
Esempio n. 7
0
        public void PrepareTargetsAtFirstFrame(NodeAddedEvent e, BulletNode bulletNode, [JoinByTank] WeaponNode weaponNode)
        {
            MuzzleLogicAccessor accessor          = new MuzzleLogicAccessor(weaponNode.muzzlePoint, weaponNode.weaponInstance);
            Vector3             barrelOriginWorld = accessor.GetBarrelOriginWorld();
            TargetingData       targetingData     = BattleCache.targetingData.GetInstance().Init();

            targetingData.Origin       = barrelOriginWorld;
            targetingData.Dir          = bulletNode.bullet.Direction;
            targetingData.FullDistance = (accessor.GetWorldPosition() - barrelOriginWorld).magnitude * 1.2f;
            base.ScheduleEvent(BattleCache.targetingEvent.GetInstance().Init(targetingData), bulletNode);
            base.ScheduleEvent(BattleCache.updateBulletEvent.GetInstance().Init(targetingData), bulletNode);
        }
Esempio n. 8
0
        public void UpdateVerticalTargetingAngle(WeaponRotationUpdateVerticalEvent e, AimingVerticalTargetingControllerNode weapon, [JoinByUser] SingleNode <MouseControlStateHolderComponent> mouseControlStateHolder)
        {
            float min                  = -weapon.verticalSectorsTargeting.VAngleDown;
            float vAngleUp             = weapon.verticalSectorsTargeting.VAngleUp;
            float maxVerticalSpeed     = weapon.shaftAimingSpeed.MaxVerticalSpeed;
            float verticalAcceleration = weapon.shaftAimingSpeed.VerticalAcceleration;
            int   shaftElevationDirectionByKeyboard = weapon.weaponRotationControl.ShaftElevationDirectionByKeyboard;
            bool  mouseControlEnable = mouseControlStateHolder.component.MouseControlEnable;

            if (!mouseControlEnable)
            {
                weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle = 0f;
            }
            else
            {
                shaftElevationDirectionByKeyboard = (int)Mathf.Sign(weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle);
                weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle = Mathf.Clamp(weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle, min - weapon.shaftAimingWorkingState.VerticalAngle, vAngleUp - weapon.shaftAimingWorkingState.VerticalAngle);
            }
            bool isInputActive = false;

            if (weapon.shaftAimingWorkingState.VerticalElevationDir != shaftElevationDirectionByKeyboard)
            {
                weapon.shaftAimingWorkingState.VerticalSpeed        = 0f;
                weapon.shaftAimingWorkingState.VerticalElevationDir = shaftElevationDirectionByKeyboard;
                isInputActive = shaftElevationDirectionByKeyboard != 0;
            }
            else
            {
                weapon.shaftAimingWorkingState.VerticalElevationDir = shaftElevationDirectionByKeyboard;
                weapon.shaftAimingWorkingState.VerticalSpeed       += verticalAcceleration * e.DeltaTime;
                weapon.shaftAimingWorkingState.VerticalSpeed        = Mathf.Clamp(weapon.shaftAimingWorkingState.VerticalSpeed, 0f, maxVerticalSpeed);
                float num6 = (shaftElevationDirectionByKeyboard * weapon.shaftAimingWorkingState.VerticalSpeed) * e.DeltaTime;
                if (!mouseControlEnable)
                {
                    isInputActive = num6 != 0f;
                    weapon.shaftAimingWorkingState.VerticalAngle += num6;
                    weapon.shaftAimingWorkingState.VerticalAngle  = Mathf.Clamp(weapon.shaftAimingWorkingState.VerticalAngle, min, vAngleUp);
                }
                else if (!weapon.weaponRotationControl.BlockRotate)
                {
                    num6          = (shaftElevationDirectionByKeyboard <= 0) ? Mathf.Clamp(num6, weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle, 0f) : Mathf.Clamp(num6, 0f, weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle);
                    isInputActive = num6 != 0f;
                    weapon.weaponRotationControl.MouseShaftAimCumulativeVerticalAngle -= num6;
                    weapon.shaftAimingWorkingState.VerticalAngle += num6;
                    weapon.shaftAimingWorkingState.VerticalAngle  = Mathf.Clamp(weapon.shaftAimingWorkingState.VerticalAngle, min, vAngleUp);
                }
            }
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);

            weapon.shaftAimingWorkingState.WorkingDirection = (Vector3)(Quaternion.AngleAxis(weapon.shaftAimingWorkingState.VerticalAngle, accessor.GetLeftDirectionWorld()) * accessor.GetFireDirectionWorld());
            weapon.shaftAimingWorkingState.IsActive         = this.CheckManualTargetingActivity(weapon.weaponRotationControl, weapon.verticalSectorsTargeting, weapon.shaftAimingWorkingState, isInputActive);
        }
Esempio n. 9
0
        public void CheckTargetPoint(FixedUpdateEvent evt, ShaftAimingTargetPointWorkingStateNode weapon, [JoinByTank] SelfTankNode selfTank, [JoinAll] ICollection <SingleNode <TankPartIntersectedWithCameraStateComponent> > intersectedTankParts)
        {
            ShaftAimingTargetPointComponent          shaftAimingTargetPoint          = weapon.shaftAimingTargetPoint;
            ShaftAimingTargetPointContainerComponent shaftAimingTargetPointContainer = weapon.shaftAimingTargetPointContainer;
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);
            bool    isInsideTankPart     = weapon.shaftAimingTargetPoint.IsInsideTankPart;
            Vector3 barrelOriginWorld    = accessor.GetBarrelOriginWorld();
            float   verticalAngle        = weapon.shaftAimingWorkingState.VerticalAngle;
            Vector3 point = weapon.shaftAimingTargetPoint.Point;

            shaftAimingTargetPointContainer.Point            = this.GetTargetPoint(barrelOriginWorld, weapon.shaftAimingWorkingState.WorkingDirection, weapon.verticalSectorsTargeting.WorkDistance, weapon.targetCollector);
            shaftAimingTargetPointContainer.IsInsideTankPart = intersectedTankParts.Count > 1;
            this.CheckTargetPointDiff(point, verticalAngle, shaftAimingTargetPoint, shaftAimingTargetPointContainer, isInsideTankPart, !weapon.shaftAimingWorkingState.IsActive ? this.EPS_INACTIVE : this.EPS_ACTIVE);
        }
        public void PrepareTargeting(TargetingEvent evt, TargetingNode verticalTargeting)
        {
            TargetingData targetingData          = evt.TargetingData;
            VerticalTargetingComponent component = verticalTargeting.verticalTargeting;
            MuzzleLogicAccessor        accessor  = new MuzzleLogicAccessor(verticalTargeting.muzzlePoint, verticalTargeting.weaponInstance);

            targetingData.Origin       = accessor.GetWorldPosition();
            targetingData.Dir          = accessor.GetFireDirectionWorld();
            targetingData.FullDistance = component.WorkDistance;
            targetingData.MaxAngle     = (component.AngleUp <= component.AngleDown) ? component.AngleDown : component.AngleUp;
            base.ScheduleEvent(BattleCache.collectDirectionsEvent.GetInstance().Init(targetingData), verticalTargeting);
            base.ScheduleEvent(BattleCache.collectTargetsEvent.GetInstance().Init(targetingData), verticalTargeting);
            base.ScheduleEvent(BattleCache.targetEvaluateEvent.GetInstance().Init(targetingData), verticalTargeting);
        }
Esempio n. 11
0
        public void PrepareTargeting(TargetingEvent evt, TargetingNode conicTargeting)
        {
            TargetingData           targetingData = evt.TargetingData;
            ConicTargetingComponent component     = conicTargeting.conicTargeting;
            MuzzleLogicAccessor     accessor      = new MuzzleLogicAccessor(conicTargeting.muzzlePoint, conicTargeting.weaponInstance);

            targetingData.Origin       = accessor.GetWorldPositionShiftDirectionBarrel(component.FireOriginOffsetCoeff);
            targetingData.Dir          = accessor.GetFireDirectionWorld();
            targetingData.FullDistance = component.WorkDistance;
            targetingData.MaxAngle     = component.HalfConeAngle;
            base.ScheduleEvent(BattleCache.collectDirectionsEvent.GetInstance().Init(targetingData), conicTargeting);
            base.ScheduleEvent(BattleCache.collectTargetsEvent.GetInstance().Init(targetingData), conicTargeting);
            base.ScheduleEvent(BattleCache.targetEvaluateEvent.GetInstance().Init(targetingData), conicTargeting);
        }
        public void CollectDirections(CollectDirectionsEvent evt, TargetingNode conicTargeting)
        {
            TargetingData           targetingData = evt.TargetingData;
            ConicTargetingComponent component     = conicTargeting.conicTargeting;

            CollectDirection(targetingData.Origin, targetingData.Dir, 0f, targetingData);
            float   angleStep          = component.HalfConeAngle / ((float)component.HalfConeNumRays);
            Vector3 leftDirectionWorld = new MuzzleLogicAccessor(conicTargeting.muzzlePoint, conicTargeting.weaponInstance).GetLeftDirectionWorld();

            for (int i = 0; i < component.NumSteps; i++)
            {
                base.CollectSectorDirections(targetingData.Origin, targetingData.Dir, leftDirectionWorld, angleStep, component.HalfConeNumRays, targetingData);
                base.CollectSectorDirections(targetingData.Origin, targetingData.Dir, leftDirectionWorld, -angleStep, component.HalfConeNumRays, targetingData);
                leftDirectionWorld = (Vector3)(Quaternion.AngleAxis(180f / ((float)component.NumSteps), targetingData.Dir) * leftDirectionWorld);
            }
        }
Esempio n. 13
0
        public void CollectDirections(CollectDirectionsEvent evt, VerticalTargetingNode verticalTargeting)
        {
            TargetingData targetingData          = evt.TargetingData;
            VerticalTargetingComponent component = verticalTargeting.verticalTargeting;

            CollectDirection(targetingData.Origin, targetingData.Dir, 0f, targetingData);
            Vector3 leftDirectionWorld = new MuzzleLogicAccessor(verticalTargeting.muzzlePoint, verticalTargeting.weaponInstance).GetLeftDirectionWorld();

            if (component.NumRaysUp > 0)
            {
                base.CollectSectorDirections(targetingData.Origin, targetingData.Dir, leftDirectionWorld, component.AngleUp / ((float)component.NumRaysUp), component.NumRaysUp, targetingData);
            }
            if (component.NumRaysDown > 0)
            {
                base.CollectSectorDirections(targetingData.Origin, targetingData.Dir, leftDirectionWorld, -component.AngleDown / ((float)component.NumRaysDown), component.NumRaysDown, targetingData);
            }
        }
Esempio n. 14
0
 private void ValidateShot(Entity weapon, MuzzleLogicAccessor muzzlePoint, TankNode tank, ShotValidateComponent shotValidate)
 {
     if (this.IsWeaponUnderground(muzzlePoint, shotValidate.UnderGroundValidateMask, tank, shotValidate.RaycastExclusionGameObjects))
     {
         StateUtils.SwitchEntityState <WeaponUndergroundComponent>(weapon, this.weaponStates);
     }
     else
     {
         RaycastHit hit;
         if (this.IsWeaponBlocked(muzzlePoint, shotValidate.BlockValidateMask, out hit, shotValidate.RaycastExclusionGameObjects))
         {
             this.AddOrChangeWeaponBlockedComponent(weapon, hit);
         }
         else
         {
             StateUtils.SwitchEntityState <WeaponUnblockedComponent>(weapon, this.weaponStates);
         }
     }
 }
Esempio n. 15
0
        public void CreateTargetPoint(NodeAddedEvent evt, ShaftAimingWorkingStateNode weapon, [JoinByTank] SelfTankNode selfTank, [JoinAll] ICollection <SingleNode <TankPartIntersectedWithCameraStateComponent> > intersectedTankParts)
        {
            bool    flag = intersectedTankParts.Count > 1;
            Vector3 barrelOriginWorld = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance).GetBarrelOriginWorld();
            Vector3 vector3           = this.GetTargetPoint(barrelOriginWorld, weapon.shaftAimingWorkingState.WorkingDirection, weapon.verticalSectorsTargeting.WorkDistance, weapon.targetCollector);
            ShaftAimingTargetPointContainerComponent component = new ShaftAimingTargetPointContainerComponent {
                Point             = vector3,
                IsInsideTankPart  = flag,
                PrevVerticalAngle = weapon.shaftAimingWorkingState.VerticalAngle
            };

            weapon.Entity.AddComponent(component);
            ShaftAimingTargetPointComponent component3 = new ShaftAimingTargetPointComponent {
                Point            = vector3,
                IsInsideTankPart = flag
            };

            weapon.Entity.AddComponent(component3);
        }
Esempio n. 16
0
        public void CollectSectorDirectionsEvent(Tanks.Battle.ClientCore.API.CollectSectorDirectionsEvent evt, VerticalSectorTargetingNode verticalSectorTargeting, [JoinByTank] WeaponNode weapon)
        {
            TargetingData targetingData = evt.TargetingData;
            VerticalSectorsTargetingComponent verticalSectorsTargeting = verticalSectorTargeting.verticalSectorsTargeting;

            CollectDirection(evt.TargetingData.Origin, evt.TargetingData.Dir, 0f, targetingData);
            if (evt.TargetSectors.Count != 0)
            {
                Vector3 leftDirectionWorld = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance).GetLeftDirectionWorld();
                TargetSectorUtils.CutSectorsByOverlap((LinkedList <TargetSector>)evt.TargetSectors, 1f / verticalSectorsTargeting.RaysPerDegree);
                IEnumerator <TargetSector> enumerator = evt.TargetSectors.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    TargetSector current = enumerator.Current;
                    float        num     = current.Length();
                    int          numRays = (int)Math.Floor((double)(verticalSectorsTargeting.RaysPerDegree * num));
                    this.CollectSectorDirections(targetingData, leftDirectionWorld, current, numRays);
                }
            }
        }
 public void CheckWorkActivationState(TimeUpdateEvent evt, ShaftAimingWorkActivationWeaponControllerNode weapon)
 {
     if (!this.CheckHandleWeaponIntersectionStatus(weapon.Entity))
     {
         if (!InputManager.CheckAction(ShotActions.SHOT))
         {
             this.MakeQuickShot(weapon.Entity);
         }
         else if (weapon.shaftAimingWorkActivationState.ActivationTimer < weapon.shaftStateConfig.ActivationToWorkingTransitionTimeSec)
         {
             weapon.shaftAimingWorkActivationState.ActivationTimer += evt.DeltaTime;
         }
         else
         {
             MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);
             ShaftAimingWorkingStateComponent component = new ShaftAimingWorkingStateComponent {
                 InitialEnergy    = weapon.weaponEnergy.Energy,
                 WorkingDirection = accessor.GetFireDirectionWorld()
             };
             StateUtils.SwitchEntityState(weapon.Entity, component, this.weaponStates);
         }
     }
 }
Esempio n. 18
0
        public void SendShot(ShotPrepareEvent evt, BlockedWeaponNode weaponNode)
        {
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weaponNode.muzzlePoint, weaponNode.weaponInstance);

            base.ScheduleEvent(new SelfShotEvent(accessor.GetFireDirectionWorld()), weaponNode);
        }
Esempio n. 19
0
        public void SendShot(ShaftAimingShotPrepareEvent evt, UndergroundShaftNode weapon)
        {
            MuzzleLogicAccessor accessor = new MuzzleLogicAccessor(weapon.muzzlePoint, weapon.weaponInstance);

            base.ScheduleEvent(new SelfShotEvent(accessor.GetFireDirectionWorld()), weapon);
        }