public virtual void Damage(float value)
        {
            if (IsDead)
            {
                return;
            }

            if (!loadedHPBar)
            {
                GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create(
                                         (int)EnumEntity.HPBar,
                                         typeof(EntityHPBar),
                                         OnLoadHpBarSuccess,
                                         EntityDataFollower.Create(hpBarRoot)));

                loadedHPBar = true;
            }

            hp -= value;

            if (entityHPBar)
            {
                entityHPBar.UpdateHealth(hp / MaxHP);
            }


            if (hp <= 0)
            {
                hp = 0;
                Dead();
            }
        }
        public static ShowEntityInLevelEventArgs Create(int entityId, Type entityType, Action <Entity> showSuccess, EntityData entityData, object userData = null)
        {
            ShowEntityInLevelEventArgs ShowEntityInLevelEventArgs = ReferencePool.Acquire <ShowEntityInLevelEventArgs>();

            ShowEntityInLevelEventArgs.EntityId    = entityId;
            ShowEntityInLevelEventArgs.Type        = entityType;
            ShowEntityInLevelEventArgs.ShowSuccess = showSuccess;
            ShowEntityInLevelEventArgs.EntityData  = entityData;
            return(ShowEntityInLevelEventArgs);
        }
        public override void Launch(EntityTargetable target, AttackerData attackerData, ProjectileData projectileData, Vector3 origin, Transform firingPoint)
        {
            GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create(
                                     attackerData.ProjectileEntityId,
                                     TypeUtility.GetEntityType(attackerData.ProjectileType),
                                     null,
                                     EntityDataProjectile.Create(target, projectileData, origin, firingPoint, firingPoint.position, firingPoint.rotation)));

            PlayParticles(fireParticleSystem, firingPoint.position, target.transform.position);
        }
        private void OnShowEntityInLevel(object sender, GameEventArgs e)
        {
            ShowEntityInLevelEventArgs ne = (ShowEntityInLevelEventArgs)e;

            if (ne == null)
            {
                return;
            }

            levelControl.ShowEntity(ne.EntityId, ne.Type, ne.ShowSuccess, ne.EntityData);
        }
        protected virtual void OnShowTowerLevelSuccess(Entity entity)
        {
            entityTowerLevel      = entity;
            entityLogicTowerLevel = entityTowerLevel.Logic as EntityTowerLevel;
            GameEntry.Entity.AttachEntity(entityTowerLevel, this.Entity);

            GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create(
                                     (int)EnumEntity.BuildPfx,
                                     typeof(EntityParticleAutoHide),
                                     null,
                                     EntityData.Create(transform.position, transform.rotation)));

            GameEntry.Sound.PlaySound(EnumSound.TDTowerUpgrade);
        }
        protected virtual void Dead()
        {
            if (OnDead != null)
            {
                OnDead(this);
            }

            if (deadEffect != null)
            {
                GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create(
                                         (int)deadEffect.deadEffectEntity,
                                         typeof(EntityParticleAutoHide),
                                         null,
                                         EntityDataFollower.Create(randomSound ? randomSound.GetRandomSound() : EnumSound.None, transform.position + DeadEffectOffset, transform.rotation)));
            }
        }
Пример #7
0
        protected void SpawnCollisionParticles()
        {
            if (collisionParticlesEntityId <= 0 || UnityEngine.Random.value > chanceToSpawnCollisionPrefab)
            {
                return;
            }

            if (!entityDataProjectile.EntityTargetable.IsDead)
            {
                Vector3 pos = entityDataProjectile.EntityTargetable.transform.position + entityDataProjectile.EntityTargetable.ApplyEffectOffset;
                GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create(
                                         collisionParticlesEntityId,
                                         typeof(EntityParticleAutoHide),
                                         null,
                                         EntityData.Create(pos, transform.rotation)));
            }
        }
        private void ApplySlowEffect()
        {
            if (slowDownEffect == null && !loadSlowDownEffect)
            {
                GameEntry.Event.Fire(this, ShowEntityInLevelEventArgs.Create((int)EnumEntity.SlowFx,
                                                                             typeof(EntityAnimation),
                                                                             OnLoadSlowEffectSuccess,
                                                                             EntityDataFollower.Create(transform,
                                                                                                       ApplyEffectOffset,
                                                                                                       Vector3.one * ApplyEffectScale,
                                                                                                       EnumSound.None,
                                                                                                       transform.position,
                                                                                                       transform.rotation)
                                                                             )
                                     );

                loadSlowDownEffect = true;
            }
        }