Пример #1
0
    IEnumerator SpawnEnemys()
    {
        int amountToSpawn = Mathf.RoundToInt((float)this.maxEnemys * this.spawnCurve.Evaluate(Mathf.Clamp01((float)this.currWave / (float)this.maxWaves)));

        Debug.Log(this.spawnCurve.Evaluate(Mathf.Clamp01(((float)this.currWave / (float)this.maxWaves))));

        for (int count = 0; count < amountToSpawn; count++)
        {
            Vector3 spawnPoint = vectorZero;

            spawnPoint.x = Random.Range(this.minSpawnPosition.x, this.maxSpawnPosition.x);
            spawnPoint.z = Random.Range(this.minSpawnPosition.z, this.maxSpawnPosition.z);

            GameObject instance = ObjectManager.instance.Instantiate("Enemy1", spawnPoint, Quaternion.identity);

            instance.transform.parent = transform;

            EnemyTemplate controller = instance.GetComponent <EnemyTemplate>();

            if (controller != null)
            {
                controller.Init();
            }

            yield return(this.spawnWait);
        }

        this.IsSpawning = false;
        this.currWave++;
    }
Пример #2
0
    private void SpawnEnemy()
    {
        var           p = Random.Range(0, spawnPoints.Length);
        EnemyTemplate e = null;

        for (int i = 0; i < waves[wave].enemies.Length; i++)
        {
            Debug.Log(waves[wave].enemies.Length);
            var a = waves[wave].enemies[i];
            if (Remaining[a.enemy] > 0)
            {
                Debug.Log("found enemy");
                e = a.enemy;
                Remaining[a.enemy]--;
                break;
            }
        }
        if (e == null)
        {
            return;
        }

        var c = DeadEnemyPool[e].Pop();

        c.transform.position = spawnPoints[p].position;
        c.transform.rotation = spawnPoints[p].rotation;
        c.SetActive(true);
    }
Пример #3
0
    // Use this for initialization
    public virtual void Init(EnemyTemplate _parent)
    {
        this.parent = _parent;

        for (int count = 0; count < this.transitions.Count; count++)
        {
            this.transitions[count].Init(this);
        }
    }
Пример #4
0
 public void Initialize(EnemyType enemyType, Vector3 attackTarget)
 {
     EnemyType = enemyType;
     Template = GameData.enemyTemplates[enemyType];
     CurrentHealth = Template.maxHealth;
     agent.speed = Template.speed;
     AttackTarget = attackTarget;
     CurrentAttackTimer = Template.attackRate;
     PlayWalk(true);
 }
Пример #5
0
 void SpawnEnemy2()
 {
     enemy = ObjectManager.instance.MakeObj(enemyType[indSpawn]);
     enemy.transform.position = spawnPoint[indPos].position;  //~~라는 게임오브젝트에 복제를 합니다
     enemy.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
     rigidEnemy        = enemy.GetComponent <Rigidbody2D>();
     enemyLogic        = enemy.GetComponent <EnemyTemplate>();
     enemyLogic.player = player;
     EnemyMove(enemy, indPos);
 }
Пример #6
0
    public EnemyCharacter(EnemyTemplate template) :


        base(template.Name, new EnemyAttributes(template.Attack, template.Speed), GetExperienceWorth(template.WorthFactor), GetGoldWorth(template.WorthFactor))
    {
        this.possibleCharacterActions.AddRange(template.Factory.SpawnActions());
        this.healthPoints  = new HealthPoints(new WeakReference <ICharacter>(this), template.MaxHp);
        this.template      = template;
        nextActionCooldown = new SimpleTimer(SingletonProvider.MainRandomProvider.RandomFloat(0.5f, 1.5f));
    }
Пример #7
0
    public static void Init(XmlNode xml)
    {
        foreach (XmlElement element in xml.ChildNodes)
        {
            EnemyTemplate template = new EnemyTemplate();
            template.nId = element["nId"] != null?uint.Parse(element["nId"].InnerText) : 0;                     //id

            template.iHp = element["iHp"] != null?int.Parse(element["iHp"].InnerText) : 0;                      //生命

            Data.Add(template.nId, template);
        }
    }
Пример #8
0
    public static EnemyTemplate GetData(uint nId, object className = null)
    {
        if (!Data.ContainsKey(nId))
        {
            if (className != null)
            {
                UnityEngine.Debug.LogError(string.Format("EnemyTemplate is null, Id = {0} @ {1}", "nId=" + nId, className));
            }
            return(null);
        }
        EnemyTemplate template = Data[nId];

        return(template);
    }
Пример #9
0
 //TODO Weapon n'est pas set de base
 public Enemy()
 {
     template      = new EnemyTemplate(EnemiesStat.instance.getEnemy("enemy"));
     currentHealth = template.health;
     //pour eviter le "find" le manager envera le gameObject Player au enemy
     player          = GameObject.FindGameObjectWithTag("Player").transform;
     myRigidbody     = GetComponent <Rigidbody>();
     nav             = GetComponent <NavMeshAgent>();
     myMesh          = GetComponent <MeshRenderer>();
     healthBar       = transform.FindChild("HealthComponent").gameObject;
     healthBarScript = healthBar.GetComponent <HealthRotation>();
     if (GetComponent <Weapon>())
     {
         weapon = GetComponent <Weapon>();
     }
     DoAction = DoActionVoid;
 }
Пример #10
0
    public BoutAction boutAction;   //下一回合要执行的行为

    public EnemyInstance(uint tplId) : base(ObjectType.ENEMY)
    {
        template = EnemyTemplateData.GetData(tplId);
        if (template == null)
        {
            return;
        }
        curHp = maxHp = 55;  //todo 删除测试代码
        armor = 10;
        lstBuffInst.Add(new BuffInst(instId)
        {
            tplId = 4, leftBout = -1, effectVal = 0
        });                                                                                //护甲不消失
        lstBuffInst.Add(new BuffInst(instId)
        {
            tplId = 7, leftBout = -1, effectVal = 3
        });                                                                                //多重护甲
        //curHp = maxHp = template.iHp;
    }
Пример #11
0
 public void ChangeTemplate(EnemyTemplate enemyTemplate)
 {
     if (enemyTemplate != null)
     {
         SpriteRenderer  spriteRenderer  = GetComponent <SpriteRenderer>();
         CharacterHealth characterHealth = GetComponent <CharacterHealth>();
         CharacterLoot   characterLoot   = GetComponent <CharacterLoot>();
         if (spriteRenderer != null)
         {
             spriteRenderer.sprite = enemyTemplate.sprite;
         }
         if (characterHealth != null)
         {
             characterHealth.maxHealth = enemyTemplate.health;
         }
         if (characterLoot != null)
         {
             characterLoot.coins = enemyTemplate.coins;
         }
     }
 }
Пример #12
0
    private IEnumerator SpawnWave()
    {
        Stats.wave++;
        //For many different enemies
        waveIndex++;

        EnemyTemplate temp = target[waveIndex];

        enemyAmount = temp.count;

        for (int i = 0; i < temp.count; i++)
        {
            while (GameManager.isGamePaused)
            {
                yield return(null);
            }

            SpawnEnemy(temp.enemy);
            yield return(new WaitForSeconds(0.5f));
        }
    }
Пример #13
0
    private void MoveTo(GridVector where, GoTypes how)
    {
        transform.position = (Vector2) where;
        enemiesList.OnPlayerMove(where);

        foreach (GridTransform e in enemiesList.ListEnemies(where))
        {
            EnemyTemplate enemy = e.GetComponent <EnemyTemplate>();

            if (how == GoTypes.shield)
            {
                enemy.HitByShield();
            }
            else if (how == GoTypes.sword)
            {
                enemy.HitBySword();
            }
            else
            {
                Debug.LogError("Not Defined!");
            }
        }
    }
Пример #14
0
    protected void StartStatus(EnemyTemplate enemyDB)
    {
        level                   = Mathf.Clamp(level, 1, status.Count);
        currentLife             = status[level - 1].life;
        currentRechargTime      = currentShieldRechargTime = currentMelleAttackDelay = currentMeleeAttackTime = currentFireDelayTime = 0;
        currentBulletsToRecharg = status[level - 1].bulletsToRecharg;

        if (GetComponent <UnityEngine.AI.NavMeshAgent>())
        {
            agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
        }

        switch (enemyType)
        {
        case EnemysType.SUICIDE:
            walk           = true;
            fire           = false;
            rechargFire    = false;
            meleeAttack    = false;
            rangeAttack    = false;
            suicide        = true;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = false;

            status[level - 1].life              = enemyDB.life;
            status[level - 1].movimentSpeed     = enemyDB.movimentSpeed;
            status[level - 1].fireRate          = enemyDB.fireRate;
            status[level - 1].fireDamage        = enemyDB.fireDamage;
            status[level - 1].fireRechargTime   = enemyDB.fireRechargTime;
            status[level - 1].bulletsToRecharg  = enemyDB.bulletsToRecharg;
            status[level - 1].meleeDamage       = enemyDB.meleeDamage;
            status[level - 1].meleeAttackTime   = enemyDB.meleeAttackTime;
            status[level - 1].meleeAttackDelay  = enemyDB.meleeAttackDelay;
            status[level - 1].shieldResistence  = enemyDB.shieldResistence;
            status[level - 1].shieldRechargTime = enemyDB.shieldRechargTime;
            status[level - 1].stunTime          = enemyDB.stunTime;

            break;

        case EnemysType.RANGE:
            walk           = true;
            fire           = true;
            rechargFire    = true;
            meleeAttack    = false;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = false;

            status[level - 1].meleeDamage       = 0;
            status[level - 1].meleeAttackTime   = 0;
            status[level - 1].meleeAttackDelay  = 0;
            status[level - 1].shieldResistence  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.MELEE:
            walk           = true;
            fire           = false;
            rechargFire    = false;
            meleeAttack    = true;
            rangeAttack    = false;
            suicide        = false;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = false;

            status[level - 1].fireRate          = 0;
            status[level - 1].fireDamage        = 0;
            status[level - 1].fireRechargTime   = 0;
            status[level - 1].bulletsToRecharg  = 0;
            status[level - 1].shieldResistence  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.ROCKET:
            walk           = true;
            fire           = true;
            rechargFire    = false;
            meleeAttack    = false;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = false;

            status[level - 1].meleeDamage       = 0;
            status[level - 1].meleeAttackTime   = 0;
            status[level - 1].meleeAttackDelay  = 0;
            status[level - 1].shieldResistence  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.MELEE_RANGE:
            walk           = true;
            fire           = true;
            rechargFire    = true;
            meleeAttack    = true;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = false;

            status[level - 1].shieldResistence  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.MELEE_STUN:
            walk           = true;
            fire           = false;
            rechargFire    = false;
            meleeAttack    = true;
            rangeAttack    = false;
            suicide        = false;
            playerToTarget = true;
            shield         = false;
            rechargShield  = false;
            stun           = true;

            status[level - 1].fireRate          = 0;
            status[level - 1].fireDamage        = 0;
            status[level - 1].fireRechargTime   = 0;
            status[level - 1].bulletsToRecharg  = 0;
            status[level - 1].shieldResistence  = 0;
            status[level - 1].shieldRechargTime = 0;

            break;

        case EnemysType.TOWER_FIRE:
            walk           = false;
            fire           = true;
            rechargFire    = true;
            meleeAttack    = false;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = false;
            shield         = true;
            rechargShield  = false;
            stun           = false;

            status[level - 1].movimentSpeed     = 0;
            status[level - 1].meleeDamage       = 0;
            status[level - 1].meleeAttackTime   = 0;
            status[level - 1].meleeAttackDelay  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.TOWER_RANGE:
            walk           = false;
            fire           = true;
            rechargFire    = true;
            meleeAttack    = false;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = true;
            shield         = true;
            rechargShield  = false;
            stun           = false;

            status[level - 1].movimentSpeed     = 0;
            status[level - 1].meleeDamage       = 0;
            status[level - 1].meleeAttackTime   = 0;
            status[level - 1].meleeAttackDelay  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;

        case EnemysType.TOWER_ROCKET:
            walk           = false;
            fire           = true;
            rechargFire    = true;
            meleeAttack    = false;
            rangeAttack    = true;
            suicide        = false;
            playerToTarget = true;
            shield         = true;
            rechargShield  = false;
            stun           = false;

            status[level - 1].movimentSpeed     = 0;
            status[level - 1].fireRechargTime   = 0;
            status[level - 1].bulletsToRecharg  = 0;
            status[level - 1].meleeDamage       = 0;
            status[level - 1].meleeAttackTime   = 0;
            status[level - 1].meleeAttackDelay  = 0;
            status[level - 1].shieldRechargTime = 0;
            status[level - 1].stunTime          = 0;

            break;
        }
    }