Пример #1
0
        public void ProcessRemoteHealthChange(NitroxId id, float LifeChanged, Optional <DamageTakenData> opDamageTakenData, float totalHealth)
        {
            if (simulationOwnership.HasAnyLockType(id))
            {
                Log.Error($"Got LiveMixin change health for {id} but we have the simulation already. This should not happen!");
                return;
            }
            LiveMixin liveMixin = NitroxEntity.RequireObjectFrom(id).GetComponent <LiveMixin>();

            // For remote processing, we add an outstanding health change that makes it possible to pass execution
            outstandingChangeHealth.Add(id, new Tuple <float, float>(LifeChanged, liveMixin.health));
            if (LifeChanged < 0)
            {
                DamageTakenData       damageTakenData = opDamageTakenData.OrElse(null);
                Optional <GameObject> opDealer        = damageTakenData.DealerId.HasValue ? NitroxEntity.GetObjectFrom(damageTakenData.DealerId.Value) : Optional.Empty;
                GameObject            dealer          = opDealer.HasValue ? opDealer.Value : null;
                if (!dealer && damageTakenData.DealerId.HasValue)
                {
                    Log.Warn($"Could not find entity {damageTakenData.DealerId.Value} for damage calculation. This could lead to problems.");
                }
                liveMixin.TakeDamage(-LifeChanged, damageTakenData.Position.ToUnity(), (DamageType)damageTakenData.DamageType, dealer);
            }
            else
            {
                liveMixin.AddHealth(LifeChanged);
            }

            // Check if the health calculated by the game is the same as the calculated damage from the simulator
            if (liveMixin.health != totalHealth)
            {
                Log.Warn($"Calculated health and send health for {id} do not align (Calculated: {liveMixin.health}, send:{totalHealth}). This will be correted but should be investigated");
                liveMixin.health = totalHealth;
            }
        }
Пример #2
0
        public static float AddHealthOverride(LiveMixin live, float addHealth, Welder welder)
        {
            float result = 0f;

            if ((live.IsAlive() || live.canResurrect) && live.health < live.maxHealth)
            {
                float num       = live.health;
                float newHealth = Math.Min(live.health + addHealth, live.maxHealth);
                result = newHealth - num;

                SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();
                NitroxId            id = NitroxEntity.GetId(live.gameObject);

                // For now, we only control the LiveMixin for vehicles (not even repair nodes at a cyclops)
                // If we change that, this if should be removed!
                Vehicle vehicle = live.GetComponent <Vehicle>();
                if (vehicle)
                {
                    if (simulationOwnership.HasAnyLockType(id))
                    {
                        result = live.AddHealth(addHealth);
                    }
                    else
                    {
                        // Another player simulates this entity. Send the weld info
                        Log.Debug($"Broadcast weld action for {id}");
                        NitroxServiceLocator.LocateService <LocalPlayer>().BroadcastWeld(id, addHealth);
                    }
                }
                else
                {
                    result = live.AddHealth(addHealth);
                }
            }
            return(result);
        }
Пример #3
0
        public override void Process(WeldAction packet)
        {
            GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);

            if (!simulationOwnership.HasAnyLockType(packet.Id))
            {
                Log.Error($"Got WeldAction packet for {packet.Id} but did not find the lock corresponding to it");
                return;
            }

            LiveMixin liveMixin = gameObject.GetComponent <LiveMixin>();

            if (!liveMixin)
            {
                Log.Error($"Did not find LiveMixin for GameObject {packet.Id} even though it was welded.");
                return;
            }
            // If we add other player sounds/animations, this is the place to do it for welding
            liveMixin.AddHealth(packet.HealthAdded);
        }