/**A function to spawn in whatever is needed for the quest; to be called from the quest giver on giving the quest.*/ public void SpawnInQuestObjects(Quest quest) { switch ((int)quest.m_QuestType) { case (int)QuestType.KILL_EVERYTHING: { //for each enemy type (though I'm not really sure this would work for more than one enemy type) for (int enemy_type = 0; enemy_type < quest.m_RequisitePrefabs.Count; enemy_type++) { //get the default enemy component and get DefaultEnemy enemy_component = quest.m_RequisitePrefabs[enemy_type].GetComponentInChildren <DefaultEnemy>(); Debug.Log("Enemy component? " + (enemy_component != null) + " Name: " + enemy_component.m_EnemyName); quest.m_KillEverything.SpawnEnemiesAtPosition(this.m_Spawner, quest.m_QuestObjectivePosition, enemy_component.m_EnemyName, quest.m_NumberOfEnemiesToKill); } //end for break; } //end case kill everything case (int)QuestType.FETCH: { //for each item type (though I'm not really sure this would work for more than one item type) for (int item_type = 0; item_type < quest.m_RequisitePrefabs.Count; item_type++) { //get the default enemy component and get quest.m_RequisitePrefabs[item_type].GetComponent <QuestItemPickup>().m_QuestItem = new QuestItem(); QuestItem quest_item = quest.m_RequisitePrefabs[item_type].GetComponent <QuestItemPickup>().m_QuestItem; // Debug.Log ("Quest item exists? " + (quest_item != null)); quest.m_Fetch.SpawnQuestItemsAtPosition(this.m_Spawner, quest.m_QuestObjectivePosition, quest_item.m_QuestItemName, quest.m_NumberOfItemsToFind); } //end for break; } //end case fetch } //end switch } //end f'n void SpawnInQuestObjects(Quest)
} //end f'n void SpawnEnemiesAtPosition(Vector3, GameObject, int) /**A function to spawn the given enemy [prefab] at the given position; if there are more */ public void SpawnEnemiesAtPosition(Spawner enemy_spawner, Vector3 position, EnemyName enemy_name, int number_of_enemies) { // Debug.Log ("Do we make it this far, at least? Enemy name: " + enemy_name.ToString()); if (this.m_EnemyContainer == null) { this.m_EnemyContainer = new GameObject(); this.m_EnemyContainer.name = enemy_name.ToString() + "Container"; } //For consistency, though the empty's position really doesn't matter. this.m_EnemyContainer.transform.position = position; //for however many enemies are needed... for (int index = 0; index < number_of_enemies; index++) { //Spawn the enemy // GameObject enemy_obj = GameObject.Instantiate(prefab, this.m_EnemyContainer.transform); GameObject enemy_obj = enemy_spawner.SpawnEnemy(enemy_name, this.m_EnemyContainer.transform); //Position the enemy enemy_obj.transform.position = position; // this.m_EnemyContainer.transform.enemy_obj //Adjust position with respect to number of enemies //? //Then extract the Enemy component and store it in the target list, to be checked later DefaultEnemy enemy = enemy_obj.GetComponent <DefaultEnemy>(); //if the enemy component isn't in the object, it's in one of the children if (enemy == null) { enemy = enemy_obj.GetComponentInChildren <DefaultEnemy> (); enemy.m_Spawner = this.m_EnemyLootSpawner; } this.m_Targets.Add(enemy); } //end for } //end f'n void SpawnEnemiesAtPosition(Spawner, Vector3, EnemyName, int)
private void OnTriggerStay2D(Collider2D collision) { if (collision.tag == "Enemy") { enemy = collision.gameObject.GetComponent <DefaultEnemy>(); enemy.Health -= damage; Destroy(gameObject); } }
/**A function to apply AOE spells effects to all nearby enemies in a given radius.*/ private void ApplyAOEToAllInRange(Vector3 position) { //Kind of a cool effect? // GameObject test = GameObject.Instantiate (this.m_SpellCube); // test.transform.position = position; // GameObject.Destroy (test, 2.0f); //Get all nearby collisions in a sphere at the specified position, in a radius [this.AOE_Radius] Collider[] all_hit = Physics.OverlapSphere(position, 4.0f); foreach (Collider hit in all_hit) { bool caster_hit = (hit.gameObject == this.gameObject); //if we hit a boxcollider //AND the hit collider belongs to a thing that can be damaged by magic //AND whatever was hit was not the enemy who cast the spell if (hit.gameObject.GetComponent <ICanBeDamagedByMagic> () != null && !caster_hit) { Debug.Log("Applying spell damage to " + hit.gameObject.name); ICanBeDamagedByMagic target_hit = hit.gameObject.GetComponent <ICanBeDamagedByMagic> (); //if the target hit is already affected by magic... if (target_hit.IsAffectedByMagic()) { //...and if the spell affecting the target is NOT the same as the one we're casting now... if (target_hit.SpellAffectingCharacter() != this.m_SpellToCast) { //...then apply spell effects target_hit.ApplySpellEffect(this.m_SpellToCast); } //else if it's the same spell, only apply half damage else { Player player_component = hit.gameObject.GetComponent <Player> (); DefaultEnemy enemy_component = hit.gameObject.GetComponent <DefaultEnemy> (); if (player_component != null) { player_component.AffectHealth(this.m_SpellToCast.m_SpellDamage / 2.0f); } else if (enemy_component != null) { enemy_component.AffectHealth(this.m_SpellToCast.m_SpellDamage / 2.0f); } } } //else if the target is not already affected by magic else { //just apply spell effects hit.gameObject.GetComponent <ICanBeDamagedByMagic> ().ApplySpellEffect(this.m_SpellToCast); } } } //end foreach } //end f'n void ApplyAOEToEnemies(Vector3)
protected virtual void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy") { DefaultEnemy enemy = collision.gameObject.GetComponent <DefaultEnemy>(); if (enemy) { enemy.Shield(); } } }
protected void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "Enemy") { DefaultEnemy enemy = collision.GetComponent <DefaultEnemy>(); if (enemy) { enemy.Unshield(); } } }
protected virtual void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy") { DefaultEnemy enemy = collision.gameObject.GetComponent <DefaultEnemy>(); if (enemy) { Debug.Log("Unshielded!!!"); enemy.Unshield(); } } }
virtual protected void spawn() { DefaultEnemy.createRandomEnemy(m_sizeMin, m_sizeMax, m_speedMin, m_speedMax, m_rotationSpeedMin, m_rotationSpeedMax); if (m_spawnInterval > 2f) { m_spawnInterval *= 0.97f; } if (m_speedMax < 50.0f) { m_speedMin *= 1.0375f; m_speedMax *= 1.0375f; } }
public EnemyMovingState(DefaultEnemy _owner) { owner = _owner; }
public EnemyIdleState(DefaultEnemy _owner) { owner = _owner; }
public EnemyAttackState(DefaultEnemy _owner) { owner = _owner; }