示例#1
0
        private void SendCommand(TankNode tankNode, MoveCommand moveCommand)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;
            Movement?movement = moveCommand.Movement;

            if (movement != null)
            {
                if (!PhysicsUtil.ValidateMovement(movement.Value))
                {
                    return;
                }
                tankMovementSender.LastSentMovement     = movement;
                tankMovementSender.LastSentMovementTime = PreciseTime.Time;
                base.Log.Debug("SEND MOVEMENT");
            }
            if (moveCommand.WeaponRotation != null)
            {
                if (!PhysicsUtil.IsValidFloat(moveCommand.WeaponRotation.Value))
                {
                    LoggerProvider.GetLogger(typeof(PhysicsUtil)).ErrorFormat("Invalid WeaponRotation. StackTrace:[{0}]", Environment.StackTrace);
                    return;
                }
                tankMovementSender.LastSentWeaponRotationTime = PreciseTime.Time;
                base.Log.Debug("SEND WEAPON_ROTATION");
            }
            base.ScheduleEvent(new MoveCommandEvent(moveCommand), tankNode.Entity);
            base.Log.Debug("SEND DISCRETE");
        }
示例#2
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));
        }
示例#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));
        }
示例#4
0
        private void AddOrChangeWeaponBlockedComponent(Entity weapon, RaycastHit hitInfo)
        {
            WeaponBlockedComponent component = !weapon.HasComponent <WeaponBlockedComponent>() ? ((WeaponBlockedComponent)weapon.CreateNewComponentInstance(typeof(WeaponBlockedComponent))) : weapon.GetComponent <WeaponBlockedComponent>();

            component.BlockPoint      = PhysicsUtil.GetPulledHitPoint(hitInfo);
            component.BlockGameObject = hitInfo.collider.gameObject;
            component.BlockNormal     = hitInfo.normal;
            StateUtils.SwitchEntityState(weapon, component, this.weaponStates);
        }
示例#5
0
        protected static float ReadFloat(BitArray bits, ref int position, int size, float factor)
        {
            float val = (Read(bits, ref position, size) - (1 << ((size - 1) & 0x1f))) * factor;

            if (PhysicsUtil.IsValidFloat(val))
            {
                return(val);
            }
            Debug.LogError("AbstractMoveCodec.ReadFloat: invalid float: " + val);
            return(0f);
        }
示例#6
0
 private bool IsValidSplashPoint(ActiveTankNode activeTank, Vector3 splashPositionForValidation, Vector3 splashCenter, ValidateSplashHitPointsEvent e, float radius)
 {
     if (!PhysicsUtil.ValidateVector3(splashCenter))
     {
         return(false);
     }
     if (!PhysicsUtil.ValidateVector3(splashPositionForValidation))
     {
         return(false);
     }
     using (new RaycastExclude(e.excludeObjects))
     {
         return(((splashPositionForValidation - splashCenter).magnitude <= radius) ? !this.IsPointOccluded(activeTank, splashCenter, splashPositionForValidation) : false);
     }
 }
 private void ApplyMovement(TankNode tank, ref Movement?movement, bool init)
 {
     if (movement != 0)
     {
         Movement m = movement.Value;
         if (PhysicsUtil.ValidateMovement(m))
         {
             bool flag = this.HalveMoveCommandIfNeed(tank, init, ref m);
             base.Log.Debug(!flag ? "APPLY MOVEMENT" : "APPLY HALVED MOVEMENT");
             Transform rigidbodyTransform = tank.rigidbody.RigidbodyTransform;
             Rigidbody rigidbody          = tank.rigidbody.Rigidbody;
             rigidbodyTransform.SetRotationSafe(m.Orientation);
             rigidbodyTransform.SetPositionSafe(TankPositionConverter.ConvertedReceptionFromServer(m.Position, tank.tankCollidersUnity, rigidbodyTransform.position));
             rigidbody.SetVelocitySafe(m.Velocity);
             rigidbody.SetAngularVelocitySafe(m.AngularVelocity);
         }
     }
 }
示例#8
0
        public bool TryFix()
        {
            int num = 0;

            if (this.body != null)
            {
                if (!PhysicsUtil.ValidateVector3(this.body.position))
                {
                    this.body.position = this.prevBodyPosition;
                    num++;
                }
                if (!PhysicsUtil.ValidateQuaternion(this.body.rotation))
                {
                    this.body.rotation = this.prevBodyRotation;
                    num++;
                }
                if (!PhysicsUtil.ValidateVector3(this.body.velocity))
                {
                    this.body.velocity = this.prevBodyVelocity;
                    num++;
                }
                if (!PhysicsUtil.ValidateVector3(this.body.angularVelocity))
                {
                    this.body.angularVelocity = this.prevBodyAngularVelocity;
                    num++;
                }
            }
            if (this.tr != null)
            {
                if (!PhysicsUtil.ValidateVector3(this.tr.position))
                {
                    this.tr.position = this.prevPosition;
                    num++;
                }
                if (!PhysicsUtil.ValidateQuaternion(this.tr.rotation))
                {
                    this.tr.rotation = this.prevRotation;
                    num++;
                }
            }
            return(num > 0);
        }
示例#9
0
        public void InstantiateHull(InstantiateHullEvent e, HullSkin hullSkin, [JoinByTank] TankNode tank, PrefabLoadedNode node)
        {
            Entity     entity       = tank.Entity;
            GameObject hullInstance = Object.Instantiate <GameObject>((GameObject)hullSkin.resourceData.Data);

            hullInstance.SetActive(false);
            if (entity.HasComponent <HullInstanceComponent>())
            {
                entity.GetComponent <HullInstanceComponent>().HullInstance = hullInstance;
            }
            else
            {
                HullInstanceComponent component = new HullInstanceComponent {
                    HullInstance = hullInstance
                };
                entity.AddComponent(component);
            }
            Rigidbody rigidbody = this.BuildRigidBody(hullInstance);

            entity.AddComponent(new RigidbodyComponent(rigidbody));
            PhysicsUtil.SetGameObjectLayer(hullInstance, Layers.INVISIBLE_PHYSICS);
            hullInstance.AddComponent <NanFixer>().Init(rigidbody, hullInstance.transform, tank.Entity.GetComponent <UserGroupComponent>().Key);
            base.NewEvent <InstantiateTankCommonPartEvent>().Attach(node).ScheduleDelayed(0.3f);
        }
示例#10
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;
            }
        }
示例#11
0
 public virtual void FillTargetData(TargetData targetData, RaycastHit hitInfo, GameObject hitRootGo, Ray ray, float fullDistance)
 {
     targetData.HitPoint               = hitInfo.point;
     targetData.LocalHitPoint          = MathUtil.WorldPositionToLocalPosition(PhysicsUtil.GetPulledHitPoint(hitInfo), hitRootGo);
     targetData.TargetPosition         = hitRootGo.transform.position;
     targetData.HitDistance            = fullDistance;
     targetData.HitDirection           = ray.direction;
     targetData.PriorityWeakeningCount = this.hitCount - 1;
 }
 private void BuildWeaponEntity(GameObject weaponInstance, Entity weaponEntity)
 {
     weaponInstance.GetComponent <EntityBehaviour>().BuildEntity(weaponEntity);
     PhysicsUtil.SetGameObjectLayer(weaponInstance, Layers.INVISIBLE_PHYSICS);
 }
示例#13
0
 public static bool ValidateImpactData(Vector3 force) =>
 PhysicsUtil.IsValidVector3(force);