private void SetCurrentHealth(IHealthController healthController, IReadOnlyDictionary <EBodyPart, BodyPartHealth> dictionary, EBodyPart bodyPart) { var bodyPartHealth = healthController.GetBodyPartHealth(bodyPart); dictionary[bodyPart].Initialize(bodyPartHealth.Current, bodyPartHealth.Maximum); // set effects if (healthController.IsBodyPartBroken(bodyPart)) { dictionary[bodyPart].AddEffect(BodyPartEffect.BreakPart); } }
/// <summary> /// Initialize HealthListener. /// This method is executed on loading profile in menu (on load game, on raid finish, on error...), /// and on raid start /// </summary> /// <param name="healthController">player health controller</param> /// <param name="inRaid">true - when executed from raid</param> public void Init(IHealthController healthController, bool inRaid) { // cleanup if (_disposable != null) { _disposable.Dispose(); } // init dependencies _healthController = healthController; _inRaid = inRaid; _simpleTimer.isSyncHealthEnabled = !inRaid; CurrentHealth.IsAlive = true; // init current health SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.Head); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.Chest); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.Stomach); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.LeftArm); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.RightArm); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.LeftLeg); SetCurrentHealth(_healthController, CurrentHealth.Health, EBodyPart.RightLeg); CurrentHealth.Energy = _healthController.Energy.Current; CurrentHealth.Hydration = _healthController.Hydration.Current; // subscribe to events _healthController.DiedEvent += OnDiedEvent; _healthController.HealthChangedEvent += OnHealthChangedEvent; _healthController.EffectAddedEvent += OnEffectAddedEvent; _healthController.EffectRemovedEvent += OnEffectRemovedEvent; _healthController.HydrationChangedEvent += OnHydrationChangedEvent; _healthController.EnergyChangedEvent += OnEnergyChangedEvent; // don't forget to unsubscribe _disposable = new Disposable(() => { _healthController.DiedEvent -= OnDiedEvent; _healthController.HealthChangedEvent -= OnHealthChangedEvent; _healthController.EffectAddedEvent -= OnEffectAddedEvent; _healthController.EffectRemovedEvent -= OnEffectRemovedEvent; _healthController.HydrationChangedEvent -= OnHydrationChangedEvent; _healthController.EnergyChangedEvent -= OnEnergyChangedEvent; }); }