예제 #1
0
 private void makeSureHealthComponentIsNotNull()
 {
     if (healthComponent == null)
     {
         healthComponent = character.getHealthComponent();
     }
 }
예제 #2
0
        private void ApplyProcHealthChange(IHealthComponent healthComp, Buff buff)
        {
            if (healthComp == null)
            {
                return;
            }
            SmartEntity source = null;
            int         health = healthComp.Health;
            int         num    = health;

            buff.ApplyStacks(ref num, healthComp.MaxHealth);
            int num2 = num - health;

            if (num2 > 0)
            {
                HealthFragment fragment = new HealthFragment(source, HealthType.Healing, num2);
                this.ApplyHealthFragment(healthComp, fragment, false);
                return;
            }
            if (num2 < 0)
            {
                HealthFragment fragment2 = new HealthFragment(source, HealthType.Damaging, -num2);
                this.ApplyHealthFragment(healthComp, fragment2, false);
            }
        }
예제 #3
0
파일: Hurtbox.cs 프로젝트: mikhomak/Erbium
 private void MakeSureHealthComponentIsNotNull()
 {
     if (_healthComponent == null)
     {
         _healthComponent = _character.getHealthComponent();
     }
 }
예제 #4
0
        public override void Initialize()
        {
            IHealthComponent healthComponent = ParentGameObject.GetComponent <IHealthComponent>();

            healthComponent.OnHealthDepleted += OnDeath;
            base.Initialize();
        }
예제 #5
0
        public int ApplyHealthFragment(IHealthComponent healthComponent, HealthFragment fragment, List <int> damageMultipliers, int damagePercentage, bool fromSplash, bool fromBeam, SmartEntity source)
        {
            if (healthComponent == null || healthComponent.IsDead() || damagePercentage == 0)
            {
                return(0);
            }
            int health = healthComponent.Health;
            int num    = fragment.Quantity;

            if (fromSplash)
            {
                num = fragment.SplashQuantity;
            }
            int rawDamage = num;

            if (damageMultipliers != null)
            {
                int healthMultiplier = this.GetHealthMultiplier(healthComponent, damageMultipliers);
                num = num * healthMultiplier / 100;
            }
            SmartEntity    target         = (SmartEntity)((ComponentBase)healthComponent).Entity;
            BuffController buffController = Service.Get <BuffController>();

            if (fragment.Type == HealthType.Healing)
            {
                buffController.ApplyActiveBuffs(target, BuffModify.HealDefense, ref damagePercentage, 100);
            }
            else
            {
                buffController.ApplyActiveBuffs(target, BuffModify.Defense, ref damagePercentage, 100);
                if (fromSplash)
                {
                    buffController.ApplyActiveBuffs(target, BuffModify.SplashDefense, ref damagePercentage, 100);
                }
            }
            num = IntMath.GetPercent(damagePercentage, num);
            if (fragment.Type == HealthType.Healing)
            {
                healthComponent.Health += num;
                if (healthComponent.Health > healthComponent.MaxHealth)
                {
                    healthComponent.Health = healthComponent.MaxHealth;
                }
            }
            else
            {
                healthComponent.Health -= num;
                if (healthComponent.Health <= 0)
                {
                    healthComponent.Health = 0;
                }
            }
            int num2 = healthComponent.Health - health;
            EntityHealthChangedData cookie = new EntityHealthChangedData(source, target, num2, rawDamage, fromBeam);

            Service.Get <EventManager>().SendEvent(EventId.EntityHealthChanged, cookie);
            this.HandleHealthChange(healthComponent, num2);
            return(num2);
        }
예제 #6
0
 public Meteor(GameContext gameContext, IMeteorStrategy meteorStrategy, IHealthComponent healthComponent, IComponent <IGameObject> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent)
 {
     _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
     _meteorStrategy    = meteorStrategy ?? throw new ArgumentNullException(nameof(meteorStrategy));
     _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
     _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
     _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
 }
예제 #7
0
        public HealthSystem(IHealthComponent owner)
        {
            this.owner  = owner;
            ZeroHealth += owner.OnZeroHealth;

            if (owner is EnemySystem enemy)
            {
                maxHealth = enemy.Data.Get(Enums.Enemy.MaxHealth).Sum;
            }
        }
        public override void Initialize()
        {
            healthComponent = ParentGameObject.GetComponent <IHealthComponent>();

            if (healthComponent != null)
            {
                healthComponent.OnHealthDepleted += OnHealthDepleted;
            }

            base.Initialize();
        }
        public override void Initialize()
        {
            healthComponent = ParentGameObject.GetComponent<IHealthComponent>();

            if (healthComponent != null)
            {
                healthComponent.OnHealthDepleted += OnHealthDepleted;    
            }

            base.Initialize();
        }
예제 #10
0
        private void HealthOnOnHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            var pointsAction = Parent.ActionFactory.GetAction<GivePointsAction>();
            pointsAction.Points = 10f;

            IGameObject playerPaddle = GameServiceManager.GetService<IGameObjectManager>().FindWithMetadata("player");

            Parent.FireAction(pointsAction, playerPaddle);

            ParentGameObject.Destroy();
        }
예제 #11
0
 private void Start()
 {
     _rbd               = GetComponent <Rigidbody>();
     _stats             = GetComponent <Stats>();
     _movementDirection = SetCameraDirection(cameraView);
     _animatorFacade    = new AnimatorFacade(GetComponentInChildren <ICharacterAnimator>(), this);
     InitMovements();                                    // creating all movements
     _movement        = _movements[MovementEnum.Ground]; // setting the current movement as Ground One
     _healthComponent = new HealthComponent(this);
     _armour          = new Armour(this);
     _attackManager   = new AttackManager(_animatorFacade, this);
 }
예제 #12
0
 private int GetHealthMultiplier(IHealthComponent healthComp, List <int> damageMultipliers)
 {
     if (damageMultipliers != null)
     {
         int num = damageMultipliers[(int)healthComp.ArmorType];
         if (num >= 0)
         {
             return(num);
         }
     }
     return(100);
 }
예제 #13
0
 private void Start()
 {
     rbd               = GetComponent <Rigidbody>();
     stats             = GetComponent <Stats>();
     movementDirection = setCameraDirection(cameraView);
     animatorFacade    = new AnimatorFacade(GetComponentInChildren <ICharacterAnimator>(), this);
     initMovements();
     movement        = movements[MovementEnum.Ground];
     healthComponent = new HealthComponent(this);
     armour          = new Armour(this);
     attackManager   = new AttackManager(animatorFacade, this);
 }
예제 #14
0
        public Enemy(GameContext gameContext, int initialMaxHealth, int initialCollisionDamage, int scoreValue, float aggroRange, IHealthComponent healthComponent, IComponent <IEnemy> physicsComponent, IDrawableComponent <IGameObject> graphicsComponent, PlayerManager playerManager)
        {
            _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
            _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
            _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
            _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
            _playerManager     = playerManager ?? throw new ArgumentNullException(nameof(playerManager));

            _initialMaxHealth       = initialMaxHealth;
            _initialCollisionDamage = initialCollisionDamage;
            _scoreValue             = scoreValue;
            _aggroRange             = aggroRange;
        }
 public void Construct(IHealthComponent healthComponent, IDefensiveStats stats, Transform transform,
                       AuraHolderComponent auraComponent, GameplayEventCombatActionDetails onCombatActionEvent,
                       SpriteDisplayComponent spriteDisplay, System.Collections.Generic.List <Color> tintColours) //TODO : Replace list with struct/so and set up scriptable object to hold values
 {
     _healthComponent = healthComponent;
     _stats           = stats;
     _tr = transform;
     _onCombatActionEvent = onCombatActionEvent;
     _spriteDisplay       = spriteDisplay;
     _auraComponent       = auraComponent;
     _damageTintColour    = tintColours[0];
     _evadedTintColour    = tintColours[1];
 }
        public override void Reallocate()
        {
            if (Parent != null)
            {
                IHealthComponent healthComponent = Parent.GetComponent <IHealthComponent>();

                if (healthComponent != null)
                {
                    healthComponent.OnHealthChanged -= HealthChanged;
                }
            }

            base.Reallocate();
        }
예제 #17
0
        private void Awake()
        {
            healthComponent = GetComponent <IHealthComponent>();
            Assert.IsNotNull(healthComponent, "нет компонента Health у " + gameObject.name);

            if (TryGetComponent <ICanSetBehaviour>(out var behaviourOwner))
            {
                behaviourOwner.AddBehaviour(this);
            }
            else
            {
                Debug.LogError("нет актора у " + gameObject.name);
            }
        }
예제 #18
0
        public Player(GameContext gameContext, IHealthComponent healthComponent, IComponent <IPlayer> inputComponent, IPlayerPhysicsComponent physicsComponent, IDrawableComponent <IPlayer> graphicsComponent, IProjectilesManager projectileManager)
        {
            _gameContext       = gameContext ?? throw new ArgumentNullException(nameof(gameContext));
            _inputComponent    = inputComponent ?? throw new ArgumentNullException(nameof(inputComponent));
            _healthComponent   = healthComponent ?? throw new ArgumentNullException(nameof(healthComponent));
            _physicsComponent  = physicsComponent ?? throw new ArgumentNullException(nameof(physicsComponent));
            _graphicsComponent = graphicsComponent ?? throw new ArgumentNullException(nameof(graphicsComponent));
            _projectileManager = projectileManager ?? throw new ArgumentNullException(nameof(projectileManager));

            _acceleratingSoundEffect    = _gameContext.GameAudio.CreateSoundEffect(_gameContext.AssetManager.GetSoundEffect(GameConstants.ThrusterConstants.Thruster1Constants.Audio.ThrustingSoundEffectName));
            _invulnerabilitySoundEffect = _gameContext.GameAudio.CreateSoundEffect(_gameContext.AssetManager.GetSoundEffect(GameConstants.PlayerConstants.Audio.InvulnerableSoundEffectName));

            _invulnerableStopwatch = new Stopwatch();
            _flashingStopwatch     = new Stopwatch();
        }
예제 #19
0
        private void ProcBuffOnTarget(Buff buff, SmartEntity target)
        {
            BuffModify modify = buff.BuffType.Modify;

            if (modify != BuffModify.Health)
            {
                if (modify != BuffModify.Shield)
                {
                    if (modify == BuffModify.MaxHealth)
                    {
                        HealthComponent healthComp = target.HealthComp;
                        this.ApplyProcMaxHealthChange(healthComp, buff);
                        return;
                    }
                }
                else
                {
                    IHealthComponent healthComp2 = null;
                    if (target.ShieldBorderComp != null)
                    {
                        healthComp2 = target.HealthComp;
                    }
                    else if (target.TroopShieldComp != null && target.TroopShieldComp.IsActive())
                    {
                        healthComp2 = target.TroopShieldHealthComp;
                    }
                    this.ApplyProcHealthChange(healthComp2, buff);
                }
                return;
            }
            IHealthComponent arg_4F_0;

            if (target.TroopShieldComp == null || !target.TroopShieldComp.IsActive())
            {
                IHealthComponent healthComponent = target.HealthComp;
                arg_4F_0 = healthComponent;
            }
            else
            {
                IHealthComponent healthComponent = target.TroopShieldHealthComp;
                arg_4F_0 = healthComponent;
            }
            IHealthComponent healthComp3 = arg_4F_0;

            this.ApplyProcHealthChange(healthComp3, buff);
        }
        private void OnEnemyHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            //Make sure that the damage initiator was something owned by the player...
            if (!damageInitator.Layer.ToLowerInvariant().Equals("playerlayer")) 
                return;

            sender.OnHealthDepleted -= OnEnemyHealthDepleted;

            if (player.HasMetadata("score"))
            {
                var metadataValue = int.Parse(player.GetMetadata("score").ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture);
                metadataValue++;
                player.UpdateMetadata("score", metadataValue);

                scoreText.Text = metadataValue.ToString(CultureInfo.InvariantCulture);
            }
        }
        public override void Initialize()
        {
            IHealthComponent healthComponent = null;

            //Track down the IHealthComponent for our parent object and attach ourselves to the health-changed
            //event so we can correctly function when the health changes!
            if (Parent != null)
            {
                healthComponent = Parent.GetComponent <IHealthComponent>();

                if (healthComponent != null)
                {
                    healthComponent.OnHealthChanged += HealthChanged;
                }
            }

            base.Initialize();
        }
예제 #22
0
        private bool ShowHealthView(Entity entity, IHealthComponent health, GameObjectViewComponent viewToAttachTo, bool hasPrimary, bool hasSecondary, bool showAtFullHealth, bool isUpdatingPrimary)
        {
            SmartEntity smartEntity = (SmartEntity)entity;

            if (smartEntity.TrapComp != null)
            {
                return(false);
            }
            bool flag = health != null && health.Health >= health.MaxHealth;

            if (health == null || (!showAtFullHealth && flag))
            {
                if (smartEntity.HealthViewComp != null)
                {
                    smartEntity.HealthViewComp.TeardownElements();
                }
                return(false);
            }
            if (viewToAttachTo == null)
            {
                if (smartEntity.HealthViewComp != null)
                {
                    smartEntity.HealthViewComp.TeardownElements();
                }
                return(false);
            }
            HealthViewComponent healthViewComponent = smartEntity.HealthViewComp;

            if (healthViewComponent == null)
            {
                healthViewComponent = new HealthViewComponent();
                entity.Add(healthViewComponent);
            }
            if (!healthViewComponent.IsInitialized)
            {
                healthViewComponent.SetupElements(viewToAttachTo, hasPrimary, hasSecondary);
            }
            healthViewComponent.UpdateHealth(health.Health, health.MaxHealth, !isUpdatingPrimary);
            if (!flag || !healthViewComponent.WillFadeOnTimer())
            {
                healthViewComponent.GoAwayIn(4f);
            }
            return(true);
        }
        private void OnEnemyHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            //Make sure that the damage initiator was something owned by the player...
            if (!damageInitator.Layer.ToLowerInvariant().Equals("playerlayer"))
            {
                return;
            }

            sender.OnHealthDepleted -= OnEnemyHealthDepleted;

            if (player.HasMetadata("score"))
            {
                var metadataValue = int.Parse(player.GetMetadata("score").ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture);
                metadataValue++;
                player.UpdateMetadata("score", metadataValue);

                scoreText.Text = metadataValue.ToString(CultureInfo.InvariantCulture);
            }
        }
예제 #24
0
        private void HandleHealthChange(IHealthComponent healthComponent, int delta)
        {
            if (healthComponent == null)
            {
                return;
            }
            SmartEntity smartEntity = (SmartEntity)((ComponentBase)healthComponent).Entity;

            if (smartEntity == null)
            {
                return;
            }
            LootController lootController = Service.BattleController.LootController;

            if (lootController == null)
            {
                return;
            }
            if (healthComponent is HealthComponent && delta < 0)
            {
                lootController.UpdateLootOnHealthChange(smartEntity, healthComponent as HealthComponent, delta);
            }
            if (healthComponent.IsDead())
            {
                if (healthComponent != null && healthComponent.ArmorType == ArmorType.Shield && smartEntity.TroopShieldComp != null)
                {
                    smartEntity.TroopShieldComp.Deactiviate();
                }
                else
                {
                    if (smartEntity.TrapComp != null)
                    {
                        Service.TrapController.DestroyTrap(smartEntity);
                    }
                    this.KillEntity(smartEntity);
                }
            }
            else
            {
                Service.EntityViewManager.CheckHealthView(smartEntity);
            }
        }
예제 #25
0
        // Start is called before the first frame update
        void Start()
        {
            // If the healthbar hasn't already been assigned, then automatically assign it.
            if (healthbarDisplay == null)
            {
                healthbarDisplay = GetComponent <Slider>();
            }

            var playerObj = GameObject.Find("Player");

            Health = (IHealthComponent)playerObj.GetComponent(BarType);
            Health.OnAfterValueChangedEvent += new Health.DamageHandler(OnAfterValueChanged);

            // Set the minimum and maximum health on the healthbar to be equal to the 'minimumHealth' and 'maximumHealth' variables:
            healthbarDisplay.minValue = 0;
            healthbarDisplay.maxValue = Health.MaxValue;
            healthPercentage          = Health.MaxValue;
            CurrentHealth             = Health.CurrentValue;
            // Change the starting visible health to be equal to the variable:
            UpdateUI();
        }
        protected override void OnHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            var renderComponent = ParentGameObject.GetComponent<IRenderComponent>();

            var particleAction = Parent.ActionFactory.GetAction<OneShotEmitParticleAction>();
            particleAction.ParticleName = ParticleEffectName;

            //Find the correct spot on the IRenderComponent if it's available.
            if (renderComponent != null)
            {
                float x = (ParentGameObject.Position.X + (renderComponent.Width / 2f));
                float y = (ParentGameObject.Position.Y + (renderComponent.Height / 2f));
                particleAction.TargetLocation = new Vector2(x, y);

                Parent.FireAction(particleAction, null);
            }
            else //No render component, just set the target to be this game object.
            {
                Parent.FireAction(particleAction, sender.Parent);
            }

            base.OnHealthDepleted(sender, damageInitator);
        }
예제 #27
0
        protected override void OnHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            var renderComponent = ParentGameObject.GetComponent <IRenderComponent>();

            var particleAction = Parent.ActionFactory.GetAction <OneShotEmitParticleAction>();

            particleAction.ParticleName = ParticleEffectName;

            //Find the correct spot on the IRenderComponent if it's available.
            if (renderComponent != null)
            {
                float x = (ParentGameObject.Position.X + (renderComponent.Width / 2f));
                float y = (ParentGameObject.Position.Y + (renderComponent.Height / 2f));
                particleAction.TargetLocation = new Vector2(x, y);

                Parent.FireAction(particleAction, null);
            }
            else //No render component, just set the target to be this game object.
            {
                Parent.FireAction(particleAction, sender.Parent);
            }

            base.OnHealthDepleted(sender, damageInitator);
        }
 public void Construct(HealthBarUI.Factory factory, IHealthComponent healthComponent)
 {
     _healthBarFactory = factory;
     _healthComponent  = healthComponent;
 }
예제 #29
0
 protected abstract void OnDeath(IHealthComponent sender, IGameObject damageInitator);
예제 #30
0
 private void OnUnitDamaged(IHealthComponent unit, IBullet bullet)
 {
     unit.TakeDamage(bullet.Damage, bullet.UnitID);
 }
 protected abstract void OnDeath(IHealthComponent sender, IGameObject damageInitator);
예제 #32
0
 private void Start()
 {
     character       = GetComponentInParent <ICharacter>();
     healthComponent = character.getHealthComponent();
 }
        protected virtual void OnHealthDepleted(IHealthComponent sender, IGameObject damageInitator)
        {
            healthComponent.OnHealthDepleted -= OnHealthDepleted;

            ParentGameObject.Destroy();
        }
        private void InitialiseVitality()
        {
            IHealthComponent healthComponent = this.GetComponent <IHealthComponent>();

            healthComponent.InitialiseHealth(shipData.MaxHealth);
        }
예제 #35
0
 public Player(int damage, int health)
 {
     DamageComponent = new DamageComponent(damage);
     HealthComponent = new HealthComponent(health);
 }
예제 #36
0
 public DamageEventArgs(IHealthComponent target, (double value, int critCount, DamageType type) damageInstance)
        public void HealthChanged(IHealthComponent sender, IGameObject damageInitiator, float oldHealth, float newHealth)
        {
            float maxHealth = sender.MaxHealth;

            Filled = newHealth / maxHealth;
        }