Esempio n. 1
0
        public void CalculateSplashCenterByStatic(CalculateSplashCenterByStaticHitEvent evt, SplashWeaponNode weapon)
        {
            SplashHitData splashHit = evt.SplashHit;
            StaticHit     staticHit = splashHit.StaticHit;

            splashHit.SplashCenter = staticHit.Position + (staticHit.Normal * 0.01f);
        }
Esempio n. 2
0
        public void PrepareSplashTargetsWhenBlockedWeapon(ShotPrepareEvent evt, BlockedWeaponNode weapon)
        {
            WeaponBlockedComponent weaponBlocked = weapon.weaponBlocked;
            StaticHit staticHit = new StaticHit {
                Position = weaponBlocked.BlockPoint,
                Normal   = weaponBlocked.BlockNormal
            };
            SplashHitData splashHit = SplashHitData.CreateSplashHitData(new List <HitTarget>(), staticHit, weapon.Entity);

            base.ScheduleEvent(new CollectSplashTargetsEvent(splashHit), weapon);
        }
Esempio n. 3
0
        public void SendHit(SendHitToServerIfNeedEvent evt, UnblockedWeaponNode weapon)
        {
            WeaponHitComponent weaponHit = weapon.weaponHit;
            StaticHit          staticHit = null;
            List <HitTarget>   targets   = new List <HitTarget>(4);

            if (evt.TargetingData.HasTargetHit())
            {
                if (!weaponHit.RemoveDuplicateTargets)
                {
                    targets = HitTargetAdapter.Adapt(evt.TargetingData.BestDirection.Targets);
                }
                else
                {
                    HashSet <Entity> set = new HashSet <Entity>();
                    int num = 0;
                    while (num < evt.TargetingData.Directions.Count)
                    {
                        DirectionData data = evt.TargetingData.Directions[num];
                        int           num2 = 0;
                        while (true)
                        {
                            if (num2 >= data.Targets.Count)
                            {
                                num++;
                                break;
                            }
                            TargetData targetData = data.Targets[num2];
                            if (set.Add(targetData.TargetEntity))
                            {
                                targets.Add(HitTargetAdapter.Adapt(targetData));
                            }
                            num2++;
                        }
                    }
                }
            }
            if (weaponHit.SendStaticHit && evt.TargetingData.HasStaticHit())
            {
                staticHit = evt.TargetingData.BestDirection.StaticHit;
            }
            if ((staticHit == null) && (targets.Count == 0))
            {
                base.ScheduleEvent <SelfHitSkipEvent>(weapon);
            }
            else
            {
                base.ScheduleEvent(new SendHitToServerEvent(evt.TargetingData, targets, staticHit), weapon);
            }
        }
Esempio n. 4
0
        public static void ExecuteSplashExplosion(Entity mine, Entity tank, Vector3 splashCenter)
        {
            StaticHit staticHit = new StaticHit {
                Normal   = Vector3.up,
                Position = splashCenter
            };
            SplashHitData    splashHit = SplashHitData.CreateSplashHitData(new List <HitTarget>(), staticHit, mine);
            HashSet <Entity> set       = new HashSet <Entity> {
                tank
            };

            splashHit.ExcludedEntityForSplashHit = set;
            EngineService.Engine.ScheduleEvent <SendTankMovementEvent>(tank);
            EngineService.Engine.ScheduleEvent(new CollectSplashTargetsEvent(splashHit), mine);
        }
Esempio n. 5
0
        private void UpdateHitData(HitNode weapon, TargetingData targetingData, bool skipTimeoutCheck)
        {
            StreamHitConfigComponent   streamHitConfig   = weapon.streamHitConfig;
            StreamHitCheckingComponent streamHitChecking = weapon.streamHitChecking;
            StreamHitComponent         streamHit         = weapon.streamHit;
            HitTarget     tankHit       = GetTankHit(targetingData);
            DirectionData bestDirection = targetingData.BestDirection;

            weapon.streamHitChecking.LastCheckTime = UnityTime.time;
            streamHit.TankHit   = tankHit;
            streamHit.StaticHit = bestDirection.StaticHit;
            StaticHit staticHit = !streamHitConfig.DetectStaticHit ? null : bestDirection.StaticHit;
            bool      flag      = false;
            bool      flag2     = false;

            if (!this.IsSameTank(tankHit, streamHitChecking.LastSentTankHit))
            {
                flag = true;
            }
            else if (skipTimeoutCheck || ((streamHitChecking.LastSendToServerTime + streamHitConfig.SendToServerPeriod) < UnityTime.time))
            {
                if (!IsAlmostEqual(staticHit, streamHitChecking.LastSentStaticHit))
                {
                    flag2 = true;
                }
                else if (!this.IsAlmostEqual(tankHit, streamHitChecking.LastSentTankHit))
                {
                    flag2 = true;
                }
            }
            if (flag)
            {
                weapon.Entity.RemoveComponent <StreamHitComponent>();
                this.AddStreamHit(weapon.Entity, targetingData, streamHitConfig, streamHitChecking);
            }
            else if (flag2)
            {
                base.ScheduleEvent(new SelfUpdateStreamHitEvent(tankHit, staticHit), weapon);
                this.SaveHitSentToServer(streamHitChecking, streamHit);
            }
        }
        public void CollectSplashTarget(StartSplashEffectEvent e, SplashEffectNode effect, [JoinByTank] SelfTankNode selfTank, [JoinByTeam] ICollection <RemoteTankNode> remoteTanks)
        {
            StaticHit staticHit = new StaticHit {
                Normal   = Vector3.up,
                Position = selfTank.rigidbody.Rigidbody.position + (this.SPLASH_CENTER_HEIGHT * (selfTank.rigidbody.Rigidbody.rotation * Vector3.up))
            };
            SplashHitData    splashHit = SplashHitData.CreateSplashHitData(new List <HitTarget>(), staticHit, effect.Entity);
            HashSet <Entity> set       = new HashSet <Entity> {
                selfTank.Entity
            };

            splashHit.ExcludedEntityForSplashHit = set;
            if (!effect.splashEffect.CanTargetTeammates)
            {
                foreach (RemoteTankNode node in remoteTanks)
                {
                    splashHit.ExcludedEntityForSplashHit.Add(node.Entity);
                }
            }
            base.ScheduleEvent <SendTankMovementEvent>(selfTank);
            base.ScheduleEvent(new CollectSplashTargetsEvent(splashHit), effect);
        }
Esempio n. 7
0
        public void Collect(TargetValidator validator, float fullDistance, DirectionData direction, int layerMask = 0)
        {
            Ray ray = new Ray {
                origin    = direction.Origin,
                direction = direction.Dir
            };
            float num = 0f;

            validator.Begin();
            Entity           entity = null;
            HashSet <Entity> set    = new HashSet <Entity>();
            int num2 = SAFE_ITERATION_LIMIT;
            int num3 = (layerMask == 0) ? validator.LayerMask : layerMask;

            while (true)
            {
                RaycastHit hit;
                if ((num2 > 0) && Physics.Raycast(ray, out hit, fullDistance - num, num3))
                {
                    StaticHit hit2;
                    num2--;
                    float distance = hit.distance;
                    num += distance;
                    Rigidbody       rigidbody = hit.rigidbody;
                    TargetBehaviour behaviour = !rigidbody ? null : rigidbody.GetComponentInParent <TargetBehaviour>();
                    Vector3         normal    = hit.normal;
                    if (!rigidbody || ((behaviour == null) || (behaviour.TargetEntity == null)))
                    {
                        hit2 = new StaticHit {
                            Position = PhysicsUtil.GetPulledHitPoint(hit),
                            Normal   = hit.normal
                        };
                        direction.StaticHit = hit2;
                        if (!validator.BreakOnStaticHit())
                        {
                            ray = validator.ContinueOnStaticHit(ray, normal, distance);
                            continue;
                        }
                    }
                    else
                    {
                        Entity targetEntity = behaviour.TargetEntity;
                        if (set.Contains(targetEntity) || targetEntity.Equals(entity))
                        {
                            ray = validator.Continue(ray, hit.distance);
                            continue;
                        }
                        entity = targetEntity;
                        if (validator.CanSkip(targetEntity) || behaviour.CanSkip(this.ownerEntity))
                        {
                            ray = validator.Continue(ray, hit.distance);
                            continue;
                        }
                        if (validator.AcceptAsTarget(targetEntity) && behaviour.AcceptAsTarget(this.ownerEntity))
                        {
                            TargetData targetData = BattleCache.targetData.GetInstance().Init(behaviour.TargetEntity, behaviour.TargetIcarnationEntity);
                            validator.FillTargetData(targetData, hit, behaviour.gameObject, ray, num);
                            direction.Targets.Add(targetData);
                            set.Add(targetEntity);
                            if (!validator.BreakOnTargetHit(targetEntity))
                            {
                                ray = validator.ContinueOnTargetHit(ray, normal, distance);
                                continue;
                            }
                        }
                        else
                        {
                            hit2 = new StaticHit {
                                Position = PhysicsUtil.GetPulledHitPoint(hit),
                                Normal   = hit.normal
                            };
                            direction.StaticHit = hit2;
                            if (!validator.BreakOnStaticHit())
                            {
                                ray = validator.ContinueOnStaticHit(ray, normal, distance);
                                continue;
                            }
                        }
                    }
                }
                return;
            }
        }
 private void ProcessRicochet(BulletComponent bullet, StaticHit staticHit)
 {
     bullet.Position = staticHit.Position - (bullet.Direction * bullet.Radius);
     Vector3 direction = bullet.Direction;
     bullet.Direction = (direction - ((2f * Vector3.Dot(direction, staticHit.Normal)) * staticHit.Normal)).normalized;
 }
Esempio n. 9
0
 private static bool IsAlmostEqual(StaticHit staticHit, StaticHit lastSentStaticHit) =>
 ((staticHit != null) || (lastSentStaticHit != null)) ? ((staticHit != null) && ((lastSentStaticHit != null) && MathUtil.NearlyEqual(staticHit.Position, lastSentStaticHit.Position, NEAR_HIT_POSITION_EPSILON))) : true;
Esempio n. 10
0
        private void CalculateAndSendSplashImpactEffectByBaseEvent(List <HitTarget> splashTargets, StaticHit staticHit, List <HitTarget> targets, SplashImpactNode weapon, TankPhysicsNode tank)
        {
            SplashImpactComponent splashImpact = weapon.splashImpact;
            SplashWeaponComponent splashWeapon = weapon.splashWeapon;
            Vector3 vector = (staticHit == null) ? targets[0].TargetPosition : staticHit.Position;
            float   impactWeakeningByRange = 1f;

            if (weapon.Entity.HasComponent <DamageWeakeningByDistanceComponent>())
            {
                float magnitude = (tank.rigidBody.Rigidbody.position - vector).magnitude;
                impactWeakeningByRange = base.GetImpactWeakeningByRange(magnitude, weapon.Entity.GetComponent <DamageWeakeningByDistanceComponent>());
            }
            foreach (HitTarget target in splashTargets)
            {
                float       hitDistance = target.HitDistance;
                float       splashImpactWeakeningByRange = this.GetSplashImpactWeakeningByRange(hitDistance, splashWeapon);
                ImpactEvent eventInstance = new ImpactEvent();
                Vector3     vector4       = (Vector3.Normalize(target.HitDirection) * splashImpact.ImpactForce) * WeaponConstants.WEAPON_FORCE_MULTIPLIER;
                eventInstance.Force          = (vector4 * impactWeakeningByRange) * splashImpactWeakeningByRange;
                eventInstance.LocalHitPoint  = target.LocalHitPoint;
                eventInstance.WeakeningCoeff = splashImpactWeakeningByRange;
                Entity[] entities = new Entity[] { weapon.Entity, target.Entity };
                base.NewEvent(eventInstance).AttachAll(entities).Schedule();
            }
        }
 public SelfUpdateStreamHitEvent(HitTarget tankHit, StaticHit staticHit) : base(tankHit, staticHit)
 {
 }