public void SpawnEnemy(ZombieInfo zombieInfo)
    {
        GameObject prefab = null;

        if (zombieInfo is NormalZombieInfo)
        {
            prefab = NormalZombiePrefab;
        }
        else if (zombieInfo is BucketZombieInfo)
        {
            prefab = BucketZombiePrefab;
        }
        GameObject enemy = Instantiate(prefab, GetRandomPosition(), prefab.transform.rotation);

        RotateEnemy(enemy);
        EnemyStatistics enemyStatistics = enemy.GetComponent <EnemyStatistics>();

        enemyStatistics.MovementSpeed   = zombieInfo.MovementSpeed;
        enemyStatistics.HealtPoints     = zombieInfo.MaxHealtPoints;
        enemyStatistics.MaxHealtPoints  = zombieInfo.MaxHealtPoints;
        enemyStatistics.AttackDamage    = zombieInfo.AttackDamage;
        enemyStatistics.Weight          = zombieInfo.Weight;
        enemyStatistics.MinimalDistance = zombieInfo.MinimalDistance;
        AliveEnemies.Add(enemy);
    }
 private void Awake()
 {
     enemyStatistics = GetComponent <EnemyStatistics>();
     enemyMovement   = GetComponent <EnemyMovement>();
     enemyActions    = GetComponent <EnemyActions>();
     brain           = GameObject.FindGameObjectWithTag(Tags.Brain);
 }
示例#3
0
 private void Awake()
 {
     enemyMovement   = GetComponent <EnemyMovement>();
     enemyStatistics = GetComponent <EnemyStatistics>();
     animator        = GetComponentInChildren <Animator>();
     brain           = GameObject.FindGameObjectWithTag(Tags.Brain);
     IsPaused        = false;
 }
 void Awake()
 {
     combatController = GameObject.Find("GameManager").GetComponent<CombatController>();
     anim = GetComponent<Animator>();
     col = GetComponent<CapsuleCollider>();
     enemyInference = GetComponent<EnemyInference>();
     enemyStatistics = GetComponent<EnemyStatistics>();
     animHashes = GetComponent<HashIDs>();
     spawnPosition = transform.position;
     atSpawn = true;
 }
    // Damages the enemy
    public void Attack(GameObject enemy)
    {
        attackSound.Play();

        if (attackRange >= Vector3.Distance(transform.position, enemy.transform.position))
        {
            EnemyStatistics enemyStats = enemy.GetComponent <EnemyStatistics>();
            float           damage     = itemEquipper.EquippedItem != null?itemEquipper.EquippedItem.Properties.Damage.GetValueOrDefault(attackDamage) : attackDamage;

            enemyStats.ChangeEnemyHealth(-damage);
        }
    }
示例#6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            _target = (EnemyStatistics)target;

            _showDetails = EditorGUILayout.Foldout(_showDetails, "Detailed info");

            if (_showDetails)
            {
                foreach (var pair in _target.EnemiesByAttribute)
                {
                    EditorGUILayout.LabelField(pair.Key.Name, pair.Value.ToString());
                }
            }
        }
    public virtual EnemyStatistics ToNonSerializable()
    {
        EnemyStatistics enemyStatistics = ScriptableObject.CreateInstance <EnemyStatistics>();

        enemyStatistics.color                   = new Color(this.color[0], this.color[1], this.color[2]);
        enemyStatistics.health.BaseValue        = this.health;
        enemyStatistics.speed.BaseValue         = this.speed;
        enemyStatistics.attack.BaseValue        = this.attack;
        enemyStatistics.chaseDistance.BaseValue = this.chaseDistance;
        enemyStatistics.lootTable               = this.lootTable.ToNonSerializable();
        enemyStatistics.name            = this.name;
        enemyStatistics.enemyPrefabName = this.enemyPrefabName;
        enemyStatistics.nightEnemy      = this.nightEnemy;
        enemyStatistics.inGame          = this.inGame;
        enemyStatistics.power           = this.power;
        return(enemyStatistics);
    }
    /* public int GetAttack()
     * {
     *   return (int)attack.Value;
     * }*/

    public EnemyStatisticsSerializable(EnemyStatistics enemyStatistics)
    {
        color                = new float[3];
        this.health          = enemyStatistics.health.BaseValue;
        this.speed           = enemyStatistics.speed.BaseValue;
        this.attack          = enemyStatistics.attack.BaseValue;
        this.chaseDistance   = enemyStatistics.chaseDistance.BaseValue;
        this.lootTable       = new LootTableSerializable(enemyStatistics.lootTable);
        this.color[0]        = enemyStatistics.color.r;
        this.color[1]        = enemyStatistics.color.g;
        this.color[2]        = enemyStatistics.color.b;
        this.enemyPrefabName = enemyStatistics.enemyPrefabName;
        this.name            = enemyStatistics.name;
        this.nightEnemy      = enemyStatistics.nightEnemy;
        this.inGame          = enemyStatistics.inGame;
        this.power           = enemyStatistics.power;
    }
    void OnGUI()
    {
        if (enemyData == null)
        {
            enemyData = new EnemyStatistics();
        }
        GUI.skin.textField.wordWrap = true;
        enemyData.enemyName         = EditorGUILayout.TextField("Nazwa przeciwnika", enemyData.enemyName);

        enemyData.damage     = EditorGUILayout.IntField(enemyData.damage);
        enemyData.attackRate = EditorGUILayout.FloatField(enemyData.attackRate);

        GUILayout.BeginHorizontal();
        bool save  = GUILayout.Button("Zapisz");
        bool clear = GUILayout.Button("Wyczyść okno");
        bool load  = GUILayout.Button("Załaduj");

        if (save)
        {
            SetPath();
            CreateDirectoryIfDontExist();
            DataManager.SaveToJson <EnemyStatistics>(path, enemyData);
        }
        else if (load)
        {
            SetPath();
            enemyData = DataManager.LoadFromJson <EnemyStatistics>(path);
        }
        else if (clear)
        {
            SetPath();
            enemyData.enemyName        = "";
            enemyData.damage           = 0;
            enemyData.attackRate       = 0f;
            GUIUtility.keyboardControl = 0;
        }
        GUILayout.EndHorizontal();
    }
	public void CalculateCombatExchange(EnemyController enemyController)
    {
        //Get a reference to the enemies' controller
        enemyStats = enemyController.GetComponentInParent<EnemyStatistics>();

        //PLAYER SLASH
        //strength vs weakness = -5hp, normal vs normal = 8hp, weakness vs strength = -10hp
        if (PlayerAttacking() && !EnemyDefending(enemyController))
        {
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-10, 0.6f);
        }

        else if ((!PlayerAttacking() && !PlayerDefending()) && (EnemyAttacking(enemyController)))
        {
            playerStatistics.Aggression.UpdateStatistic(-40, 0.6f);
            playerStatistics.Health.UpdateStatistic(-10, 1.2f);
        }

        else if (playerAnimator.CurrentAction == animHashes.slashState && enemyController.CurrentAction == animHashes.slashState)
        {
            playerStatistics.Health.UpdateStatistic(-8, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-8, 0.6f);
        }

        else if (playerAnimator.CurrentAction == animHashes.slashState && enemyController.CurrentAction == animHashes.lungeState)
        {
            playerStatistics.Health.UpdateStatistic(-5, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-10, 0.6f);
        }

        else if (playerAnimator.CurrentAction == animHashes.slashState && enemyController.CurrentAction == animHashes.swipeState)
        {
            playerStatistics.Health.UpdateStatistic(-10, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-5, 0.6f);
        }

        else if (playerAnimator.CurrentAction == animHashes.slashState && enemyController.CurrentAction == animHashes.blockState)
        {
            //nothing happens yet
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
        }

        //PLAYER LUNGE
        else if (playerAnimator.CurrentAction == animHashes.lungeState && enemyController.CurrentAction == animHashes.slashState)
        {
            playerStatistics.Health.UpdateStatistic(-10, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-5, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.lungeState && enemyController.CurrentAction == animHashes.lungeState)
        {
            playerStatistics.Health.UpdateStatistic(-8, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-8, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.lungeState && enemyController.CurrentAction == animHashes.swipeState)
        {
            playerStatistics.Health.UpdateStatistic(-5, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-10, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.lungeState && enemyController.CurrentAction == animHashes.blockState)
        {
            //nothing happens yet
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
        }

        //PLAYER SWIPE
        else if (playerAnimator.CurrentAction == animHashes.swipeState && enemyController.CurrentAction == animHashes.slashState)
        {
            playerStatistics.Health.UpdateStatistic(-5, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-10, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.swipeState && enemyController.CurrentAction == animHashes.lungeState)
        {
            playerStatistics.Health.UpdateStatistic(-10, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-5, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.swipeState && enemyController.CurrentAction == animHashes.swipeState)
        {
            playerStatistics.Health.UpdateStatistic(-8, 1.2f);
            playerStatistics.Aggression.UpdateStatistic(40, 0.6f);
            playerStatistics.Adrenaline.UpdateStatistic(-10, 0.6f);
            enemyStats.EnemyHealth.UpdateStatistic(-8, 0.6f);
        }
        else if (playerAnimator.CurrentAction == animHashes.swipeState && enemyController.CurrentAction == animHashes.blockState)
        {
            playerStatistics.Adrenaline.UpdateStatistic(-10, 1);
        }

        //PLAYER BLOCK
        else if (playerAnimator.CurrentAction == animHashes.blockState)
        {
            playerStatistics.Aggression.UpdateStatistic(-20, 0.6f);
        }
    }
示例#11
0
 public void Reset(EnemyStatistics sharedStatistics)
 {
     health = sharedStatistics.maxHealth;
 }
示例#12
0
 public Instance(EnemyStatistics origin)
 {
     Reset(origin);
 }
示例#13
0
 private void Awake()
 {
     enemyStatistics = GetComponent <EnemyStatistics>();
     enemySpawner    = GameObject.FindGameObjectWithTag(Tags.EnemiesSpawner).GetComponent <EnemySpawner>();
     boxCollider2D   = GetComponent <BoxCollider2D>();
 }
示例#14
0
    public static void LoadEnemy()
    {
        string path = Application.persistentDataPath + "/Enemies.inf";

        if (File.Exists(path))
        {
            foreach (Transform item in GameObject.FindGameObjectWithTag("EnemiesSystem").transform)
            {
                GameObject.Destroy(item.gameObject);
            }

            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);
            List <EnemyStatisticsSerializable> enemyStatisticsSerializables = formatter.Deserialize(stream) as List <EnemyStatisticsSerializable>;
            stream.Close();

            List <GameObject>      nightEnemyInGame      = new List <GameObject>();
            List <EnemyStatistics> nightEnemyNon         = new List <EnemyStatistics>();
            List <GameObject>      nightEnemyGameObjects = new List <GameObject>();

            List <GameObject>      normalEnemyInGame      = new List <GameObject>();
            List <EnemyStatistics> normalEnemyNon         = new List <EnemyStatistics>();
            List <GameObject>      normalEnemyGameObjects = new List <GameObject>();
            foreach (EnemyStatisticsSerializable item in enemyStatisticsSerializables)
            {
                EnemyStatistics enemyStatistics = item.ToNonSerializable();
                GameObject      enemy;
                if (item.nightEnemy)
                {
                    nightEnemyNon.Add(enemyStatistics);
                    enemy = GameObject.Instantiate(GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().FindNightEnemyByName(item.enemyPrefabName));
                }
                else
                {
                    normalEnemyNon.Add(enemyStatistics);
                    enemy = GameObject.Instantiate(GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().FindNormalEnemyByName(item.enemyPrefabName));
                }
                enemy.GetComponent <Enemy>().enemyStatistics = enemyStatistics;
                enemy.name = item.name;
                enemy.transform.SetParent(GameObject.FindGameObjectWithTag("EnemiesSystem").transform);
                if (item.nightEnemy)
                {
                    nightEnemyGameObjects.Add(enemy);
                    if (item.inGame)
                    {
                        nightEnemyInGame.Add(enemy);
                    }
                }
                else
                {
                    normalEnemyGameObjects.Add(enemy);
                    if (item.inGame)
                    {
                        normalEnemyInGame.Add(enemy);
                    }
                }
            }
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNormalEnemiesInGame   = normalEnemyInGame;
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNightEnemiesInGame    = nightEnemyInGame;
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNightEnemyStatistics  = nightEnemyNon;
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNightEnemies          = nightEnemyGameObjects;
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNormalEnemyStatistics = normalEnemyNon;
            GameObject.FindGameObjectWithTag("EnemiesSystem").GetComponent <EnemiesSystem>().playerNormalEnemies         = normalEnemyGameObjects;
        }
        else
        {
            Debug.LogWarning("Save file not found in " + path);
        }
    }