示例#1
0
        public bool ShouldApplyNextHealthUpdate(LiveMixin reciever, GameObject dealer = null)
        {
            NitroxId id = NitroxEntity.GetId(reciever.gameObject);

            if (!simulationOwnership.HasAnyLockType(id) && !processingRemoteHealthChange)
            {
                return(false);
            }

            // Check to see if this health change is caused by docked vehicle collisions.  If so, we don't want to apply it.
            if (dealer)
            {
                Vehicle           dealerVehicle     = dealer.GetComponent <Vehicle>();
                VehicleDockingBay vehicleDockingBay = reciever.GetComponentInChildren <VehicleDockingBay>();

                if (vehicleDockingBay && dealerVehicle)
                {
                    if (vehicleDockingBay.GetDockedVehicle() == dealerVehicle || vehicleDockingBay.interpolatingVehicle == dealerVehicle ||
                        vehicleDockingBay.nearbyVehicle == dealerVehicle)
                    {
                        Log.Debug($"Dealer {dealer} is vehicle and currently docked or nearby {reciever}, do not harm it!");
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Indicates if a LiveMixin object should execute TakeDamage or HealthBack method
        /// </summary>
        /// <param name="reciever">The one who takes damage or gets health back</param>
        /// <param name="healthChange">The amount of health it gets back or damage dealt</param>
        /// <param name="dealer">Damage dealer</param>
        /// <returns>Tuple where the first item indicates execution and the second indicates if the player has the ownership of the reciever GameObject (if vehicle)</returns>
        public ExecutionAndOwnership ShouldExecute(LiveMixin reciever, float healthChange, GameObject dealer)
        {
            Vehicle vehicle = reciever.GetComponent <Vehicle>();
            SubRoot subRoot = reciever.GetComponent <SubRoot>();


            if (vehicle != null || subRoot != null && subRoot.isCyclops)
            {
                NitroxId id = NitroxEntity.GetId(reciever.gameObject);

                bool isOutstandingPresent = outstandingChangeHealth.TryGetValue(id, out Tuple <float, float> healthChangeAndTotal) &&
                                            healthChangeAndTotal.Item1 == healthChange && healthChangeAndTotal.Item2 == reciever.health;
                bool hasOwnership = simulationOwnership.HasAnyLockType(id);

                // We either have a lock or an outstanding health change with the same health change and current total health when we execute the code
                if (!hasOwnership && !isOutstandingPresent)
                {
                    return(new ExecutionAndOwnership(false, false));
                }

                // Remove the outstandingHealthChange if present.
                if (isOutstandingPresent)
                {
                    outstandingChangeHealth.Remove(id);
                }

                if (healthChange > 0)
                {
                    return(new ExecutionAndOwnership(true, hasOwnership));
                }
                // To prevent damage that happens while docking, we check if dealer is the vehicle that is also docked.
                VehicleDockingBay vehicleDockingBay = reciever.GetComponent <VehicleDockingBay>();
                if (!vehicleDockingBay)
                {
                    vehicleDockingBay = reciever.GetComponentInChildren <VehicleDockingBay>();
                }
                Vehicle dealerVehicle = dealer.GetComponent <Vehicle>();
                if (vehicleDockingBay && dealerVehicle)
                {
                    if (vehicleDockingBay.GetDockedVehicle() == dealerVehicle || (Vehicle)vehicleDockingBay.ReflectionGet("interpolatingVehicle") == dealerVehicle ||
                        (Vehicle)vehicleDockingBay.ReflectionGet("nearbyVehicle") == dealerVehicle)
                    {
                        Log.Debug($"Dealer {dealer} is vehicle and currently docked or nearby {reciever}, do not harm it!");
                        return(new ExecutionAndOwnership(false, false));
                    }
                }
                return(new ExecutionAndOwnership(true, hasOwnership));
            }
            return(new ExecutionAndOwnership(true, false));
        }