Пример #1
0
        //a method to change the animator state
        public void SetAnimState(UnitAnimState newState)
        {
            if (LockAnimState == true || animator == null) //if our animation state is locked or there's no animator assigned then don't proceed.
            {
                return;
            }

            if ((newState == UnitAnimState.takingDamage && HealthComp.IsDamageAnimationEnabled() == false) || //if taking damage animation is disabled
                (HealthComp.IsDamageAnimationActive() && newState != UnitAnimState.dead))     //or if it's enabled and it's in progress
            {
                return;
            }

            currAnimatorState = newState; //update the current animator state

            animator.SetBool("TookDamage", currAnimatorState == UnitAnimState.takingDamage);
            animator.SetBool("IsIdle", currAnimatorState == UnitAnimState.idle); //stop the idle animation in case take damage animation is played since the take damage animation is broken by the idle anim

            if (currAnimatorState == UnitAnimState.takingDamage)                 //because we want to get back to the last anim state after the taking damage anim is done
            {
                return;
            }

            animator.SetBool("IsBuilding", currAnimatorState == UnitAnimState.building);
            animator.SetBool("IsCollecting", currAnimatorState == UnitAnimState.collecting);
            animator.SetBool("IsMoving", currAnimatorState == UnitAnimState.moving);
            animator.SetBool("IsAttacking", currAnimatorState == UnitAnimState.attacking);
            animator.SetBool("IsHealing", currAnimatorState == UnitAnimState.healing);
            animator.SetBool("IsConverting", currAnimatorState == UnitAnimState.converting);
            animator.SetBool("IsDead", currAnimatorState == UnitAnimState.dead);
        }
Пример #2
0
    public static void DealDamage(GameObject DamagedObject, int DamageAmount, EDamageType DamageType, GameObject Instigator)
    {
        HealthComp health = DamagedObject.GetComponent <HealthComp>();

        if (health)
        {
            health.ApplyDamage(DamageAmount, DamageType, Instigator);
        }
    }
Пример #3
0
        public override void Init(Game game)
        {
            Game = (RogueskivGame)game;
            var playerComp = Game.Entities.GetWithComponent <PlayerComp>().Single();

            PlayerHealthComp    = playerComp.GetComponent <HealthComp>();
            CurrentPositionComp = playerComp.GetComponent <CurrentPositionComp>();
            LastPositionComp    = playerComp.GetComponent <LastPositionComp>();
            TimerComp           = Game.Entities.GetSingleComponent <TimerComp>();
        }
Пример #4
0
    private void Start()
    {
        if (Powerups.Length <= 0)
        {
            return;
        }

        Health = GetComponent <HealthComp>();

        Health.OnDeath += SpawnPickup;
    }
Пример #5
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            HealthComp PlayerHealthComponent = collision.gameObject.GetComponent <HealthComp>();

            if (PlayerHealthComponent)
            {
                PlayerHealthComponent.OnHit(Damage);
            }
        }
    }
Пример #6
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Enemy")
     {
         HealthComp EnemyHealthComponent = collision.gameObject.GetComponent <HealthComp>();
         if (EnemyHealthComponent && bCanAttack)
         {
             bCanAttack = false;
             EnemyHealthComponent.OnHit(1);
             Debug.Log("End Health Enemy: " + EnemyHealthComponent.GetCurrentHealth());
         }
     }
 }
Пример #7
0
        public override void Init(Game game)
        {
            Game = (RogueskivGame)game;

            BoardComp = Game.Entities.GetSingleComponent <BoardComp>();

            var player = Game
                         .Entities
                         .GetWithComponent <PlayerComp>()
                         .Single();

            PlayerId = player.Id;

            PlayerPosComp      = player.GetComponent <CurrentPositionComp>();
            PlayerHealthComp   = player.GetComponent <HealthComp>();
            PlayerMovementComp = player.GetComponent <MovementComp>();
        }
Пример #8
0
    void SetEnemyData(EnemyData data)
    {
        if (!SpawnedEnemy)
        {
            Debug.Log("SpawnedEnemy is null");
            return;
        }

        Enemy EnemyData = SpawnedEnemy.GetComponent <Enemy>();

        if (EnemyData)
        {
            EnemyData.SetEnemyName(data.Name);
            EnemyData.SetEnemyDamage(data.Damage);
        }
        HealthComp EnemyHealth = SpawnedEnemy.GetComponent <HealthComp>();

        if (EnemyHealth)
        {
            EnemyHealth.SetMaxHealth(data.Health);
        }
    }
Пример #9
0
 public Character(int health)
 {
     Health = AddEntityComponent <HealthComp>();
     Health.HealthPoints = health;
 }
Пример #10
0
 // This will only be executed once when the data is inserted in the filter instance
 public void InitData(Entity entity)
 {
     Health = entity.GetEntityComponent <HealthComp>();
 }
Пример #11
0
 private void OnDamagedEvent(HealthComp healthComp)
 {
     ExecuteValidation(healthComp.Parent);
 }
Пример #12
0
        public override void Init(GameManager gameMgr, int fID, bool free)
        {
            base.Init(gameMgr, fID, free);

            //get the building-specifc components:
            PlacerComp       = GetComponent <BuildingPlacer>();
            HealthComp       = GetComponent <BuildingHealth>();
            NavObstacle      = GetComponent <NavMeshObstacle>();
            BoundaryCollider = GetComponent <Collider>();
            BorderComp       = GetComponent <Border>();
            DropOffComp      = GetComponent <BuildingDropOff>();
            WorkerMgr        = GetComponent <WorkerManager>();
            PortalComp       = GetComponent <Portal>();
            GeneratorComp    = GetComponent <ResourceGenerator>();
            AllAttackComp    = GetComponents <BuildingAttack>();

            //initialize them:
            PlacerComp.Init(gameMgr, this);
            foreach (BuildingAttack comp in AllAttackComp) //init all attached attack components
            {
                if (AttackComp == null)
                {
                    AttackComp = comp;
                }

                comp.Init(gameMgr, this, MultipleAttackMgr);
            }
            if (MultipleAttackMgr)
            {
                MultipleAttackMgr.Init(this);
            }
            WorkerMgr.Init();

            if (BoundaryCollider == null) //if the building collider is not set.
            {
                Debug.LogError("[Building]: The building parent object must have a collider to represent the building's boundaries.");
            }
            else
            {
                BoundaryCollider.isTrigger = true; //the building's main collider must always have "isTrigger" is true.
            }
            RallyPoint = gotoPosition;             //by default the rally point is set to the goto position
            if (gotoPosition != null)              //Hide the goto position
            {
                gotoPosition.gameObject.SetActive(false);
            }

            if (Placed == false) //Disable the player selection collider object if the building has not been placed yet.
            {
                selection.gameObject.SetActive(false);
            }

            if (placedByDefault == false)                   //if the building is not placed by default.
            {
                PlaneRenderer.material.color = Color.green; //start by setting the selection texture color to green which implies that it's allowed to place building at its position.
            }
            //if this is no plaement instance:
            if (!PlacementInstance)
            {
                PlacerComp.PlaceBuilding();                                      //place the building
                if (GodMode.Enabled && FactionID == GameManager.PlayerFactionID) //if god mode is enabled and this is the local player's building
                {
                    placedByDefault = true;
                }
            }

            if (placedByDefault) //if the building is supposed to be placed by default or we're in god mode and this is the player's building -> meaning that it is already in the scene
            {
                HealthComp.AddHealthLocal(HealthComp.MaxHealth, null);
            }
        }