private void Process(ClientLiveMixinChange msg) { var target = GuidHelper.FindComponent <LiveMixin>(msg.targetGuid, false); if (target == null) { return; } using (new MessageBlocker()) { if (msg.force || msg.health == 0f) { target.health = msg.health; } if (Mathf.Abs(target.health - msg.health) > target.maxHealth * 0.15f) { target.health = msg.health; } if (msg.amount < 0f) { target.TakeDamage(msg.amount, msg.position, msg.type); } else if (msg.amount > 0f) { target.AddHealth(msg.amount); } if (target.health > target.maxHealth) { target.health = target.maxHealth; } } }
private void Process(Client client, ClientLiveMixinChange msg) { SavedVehicle vehicle; if (state.history.vehicles.TryGetValue(msg.targetGuid, out vehicle)) { vehicle.health = msg; } msg.force = false; SendToAll(client.peer, msg); msg.force = true; }
public static void SendLiveMixinChange(LiveMixin mixin, float amount, Vector3 position = default(Vector3), DamageType type = DamageType.Normal) { if (amount == 0f) { return; } if (Multiplayer.main.blocked) { return; } if (mixin.health < 0f) { return; } if (mixin.invincible) { return; } if (mixin.health == mixin.maxHealth && amount > 0f) { return; } if (GameModeUtils.IsInvisible() && mixin.invincibleInCreative) { return; } if (mixin.gameObject.GetComponent <Creature>() != null) { return; } var uid = mixin.gameObject.GetComponent <UniqueIdentifier>(); if (uid == null) { return; } var sync = mixin.gameObject.GetComponent <SyncedVehicle>(); if (sync != null && sync.activePlayer != null) { return; } var res = new ClientLiveMixinChange(); res.targetGuid = uid.Id; res.health = mixin.health; res.amount = amount; res.type = type; res.position = position; res.force = false; Multiplayer.main.Send(res); }