Ejemplo n.º 1
0
    /// <summary>
    /// Init the health bar with the specified enemy.
    /// </summary>
    /// <param name="enemy">Enemy.</param>
    public void Init(Enemy enemy)
    {
        gameObject.SetActive(true);
        abilityIconBar.SetActive(true);

        this.enemy      = enemy;
        slider.maxValue = enemy.maxHealth;
        if (!fixedPos)
        {
            slider.transform.localPosition = enemy.healthBarOffset;
        }
        foreach (GameObject o in icons)
        {
            o.SetActive(false);
        }
        for (int i = 0; i < enemy.abilities.Count; i++)
        {
            EnemyAbility ability = enemy.abilities [i];
            if (ability.icon != null)
            {
                icons [i].GetComponent <Image> ().sprite = ability.icon;
                icons [i].SetActive(true);
            }
        }
    }
Ejemplo n.º 2
0
 public override void CastingTimeCheck()
 {
     if (currentAbility != null)
     {
         currentCastingTime += Time.deltaTime;
         if (currentCastingTime > currentAbility.enemyAbilityStats.castTime)
         {
             var newA = currentAbility.CreateWorldAbility(unitID);
             newA.gameObject.layer = 11;
             if (newA.enemyAbilityStats.behavior == EnemyAbilityStats.Behavior.Projectile)
             {
                 newA.transform.position = transform.position;
                 Vector3 leadPosition = UtilityService.FirstOrderIntercept(transform.position, new Vector3(), newA.enemyAbilityStats.speed, currentTarget.transform.position, currentTarget.GetComponent <Rigidbody>().velocity);
                 newA.transform.LookAt(leadPosition + new Vector3(0, currentTarget.GetComponent <CapsuleCollider>().height / 2, 0));
             }
             else if (newA.enemyAbilityStats.behavior == EnemyAbilityStats.Behavior.Area_Hit)
             {
                 newA.transform.position = currentTargetPoint;
             }
             currentCastingTime = 0;
             currentAbility     = null;
             return;
         }
     }
 }
Ejemplo n.º 3
0
    public void AddAbility(GameObject abilityPrefab)
    {
        GameObject o = Instantiate(abilityPrefab);

        o.transform.position = this.transform.position;
        o.transform.SetParent(this.transform);
        EnemyAbility enemyAbility = o.GetComponent <EnemyAbility> ();

        abilities.Add(enemyAbility);
    }
Ejemplo n.º 4
0
    public void Enter(EnemyBehaviour parent)
    {
        Vector2 direction = (parent.Target.position - parent.transform.position).normalized;

        //vars = parent.Vars;
        abilityInstance           = parent.AbilityInstance;
        abilityInstance.direction = direction;
        abilityInstance.Activate();
        parent.ChangeState(new IdleState());
    }
Ejemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     _player       = GameObject.FindWithTag("Player").transform;
     _navMeshAgent = GetComponent <NavMeshAgent>();
     _ability      = gameObject.GetComponentInChildren <EnemyAbility>();
     isPaused      = false;
     _killCounter  = GameObject.FindWithTag("KillCounter").GetComponent <KillCounter>();
     _loot         = GetComponent <DropLoot>();
     _animator     = GetComponent <Animator>();
     _audioManager = GameObject.FindWithTag("AudioManager").GetComponent <AudioManagerScript>();
 }
Ejemplo n.º 6
0
    public void Enter(EnemyBehaviour parent)
    {
        numOfAbilities = parent.BossAbillites.Length;
        currentAbility = (int)Random.Range(0, numOfAbilities);

        //Debug.Log("enter boss");
        Vector2 direction = (parent.Target.position - parent.transform.position).normalized;

        abilityInstance           = parent.BossAbilityInstance;
        abilityInstance.direction = direction;
        abilityInstance.Activate();
        parent.setAbility(currentAbility);
        parent.ChangeState(new IdleState());
    }
Ejemplo n.º 7
0
 public void ChaseTarget()
 {
     if (knownAbilities.Count > 0 && currentTarget != null && currentAbility == null && Vector3.Distance(transform.position, currentTarget.transform.position) < 15)
     {
         if (UtilityService.LineOfSightCheckRootUnit(transform.position + eyesOffset, currentTarget) != new Vector3())
         {
             currentTargetPoint = currentTarget.transform.position;
             currentAbility     = knownAbilities[0];
         }
         else
         {
             currentAbility     = null;
             currentCastingTime = 0;
         }
     }
 }
Ejemplo n.º 8
0
    public void PerformCombatAction()
    {
        TakeDotDamage();
        EnemyAbility ab = WeightedRandomizer.From(enemyData.EnemyAbilities).TakeOne();

        abName = ab.Name;
        Invoke(nameof(UpdateText), 1);

        if (ab.MinHeal > 0)
        {
            EnemyBehavior enemyToHeal = Game.CurrentCombatSystem.Enemies.First(e => e.health == Game.CurrentCombatSystem.Enemies.Max(b => b.health));
            enemyToHeal.ReceiveHealing(Random.Range(ab.MinHeal, ab.MaxHeal));
        }

        if (ab.MinDamage > 0)
        {
            this.ApplyDamage(Random.Range(ab.MinDamage, ab.MaxDamage + 1), Game.Player, ab.ArmorPiercing);
        }

        if (ab.MinBlock > 0)
        {
            this.IncreaseShield(Random.Range(ab.MinBlock, ab.MaxBlock));
        }

        if (ab.Stun)
        {
            Game.Player.stunned = true;
        }

        if (ab.DamageReduction > 0)
        {
            this.ApplyDamageDebuff(-ab.DamageReduction, Game.Player);
        }

        if (ab.SelfDamage > 0)
        {
            this.ReceiveDamage(ab.SelfDamage);
        }

        if (ab.Dot)
        {
            this.ReceiveDot(ab.DotDamage, ab.Time);
        }

        UpdateBars();
    }
Ejemplo n.º 9
0
    // Use this for initialization
    public virtual void Start()
    {
        enemy    = GetComponent <Enemy>();
        Animator = GetComponent <AnimationManager>();
        ChangeState(new IdleState());
        movement           = GetComponent <Movement>();
        myStartPosition    = this.transform.position;
        attackCDtmp        = attackCD;
        defaultDirection   = Vector2.down;
        AttackAnimatiomTMP = attackAnimationLenght;



        if (isRanged)
        {
            demonAbility    = GetComponent <DemonAbility>();
            ability         = demonAbility.Ability;
            AbilityInstance = Ability.CreateInstance(enemy) as EnemyAbility;
            AbilityInstance.transform.SetParent(this.transform);
        }
        else if (isHeadbutt)
        {
            vars = GetComponent <VariousEnemyVars>();
        }
        else if (isBoss)
        {
            BossVars      = GetComponent <BossVars>();
            BossAbillites = BossVars.ability;
            for (int i = 0; i < 2; i++)
            {
                BossAbilityInstance = BossAbillites[i].CreateInstance(enemy) as EnemyAbility;
                BossAbilityInstance.transform.SetParent(this.transform);
            }
            setAbility(0);
        }
    }
Ejemplo n.º 10
0
        public Enemy(BattleState battle, XmlNode node, int x, int y, int row, int e, string designation = "")
            : base(battle)
        {
            _x = x;
            _y = y;

            _weak   = new List <Element>();
            _halve  = new List <Element>();
            _void   = new List <Element>();
            _absorb = new List <Element>();
            _immune = new List <Status>();

            _win   = new List <EnemyItem>();
            _steal = new List <EnemyItem>();

            Attacks   = new Dictionary <string, EnemyAbility>();
            Variables = new Dictionary <string, object>();

            _name           = node.SelectSingleNode("name").InnerText;
            _attack         = Int32.Parse(node.SelectSingleNode("atk").InnerText);
            _defense        = Int32.Parse(node.SelectSingleNode("def").InnerText);
            _defensePercent = Int32.Parse(node.SelectSingleNode("defp").InnerText);
            _dexterity      = Int32.Parse(node.SelectSingleNode("dex").InnerText);
            _magicAttack    = Int32.Parse(node.SelectSingleNode("mat").InnerText);
            _magicDefense   = Int32.Parse(node.SelectSingleNode("mdf").InnerText);
            _luck           = Int32.Parse(node.SelectSingleNode("lck").InnerText);

            _level = Int32.Parse(node.SelectSingleNode("lvl").InnerText);
            _maxhp = _hp = Int32.Parse(node.SelectSingleNode("hp").InnerText);
            _maxmp = _mp = Int32.Parse(node.SelectSingleNode("mp").InnerText);

            Exp = Int32.Parse(node.SelectSingleNode("exp").InnerText);
            AP  = Int32.Parse(node.SelectSingleNode("ap").InnerText);
            Gil = Int32.Parse(node.SelectSingleNode("gil").InnerText);

            _row = row;

            if (!String.IsNullOrEmpty(designation))
            {
                _name += " " + designation;
            }

            foreach (XmlNode weak in node.SelectNodes("weaks/weak"))
            {
                _weak.Add((Element)Enum.Parse(typeof(Element), weak.InnerText));
            }
            foreach (XmlNode halve in node.SelectNodes("halves/halve"))
            {
                _halve.Add((Element)Enum.Parse(typeof(Element), halve.InnerText));
            }

            foreach (XmlNode v in node.SelectNodes("voids/void"))
            {
                _void.Add((Element)Enum.Parse(typeof(Element), v.InnerText));
            }
            foreach (XmlNode absorb in node.SelectNodes("absorbs/absorb"))
            {
                _absorb.Add((Element)Enum.Parse(typeof(Element), absorb.InnerText));
            }
            foreach (XmlNode immunity in node.SelectNodes("immunities/immunity"))
            {
                _immune.Add((Status)Enum.Parse(typeof(Status), immunity.InnerText));
            }

            foreach (XmlNode win in node.SelectNodes("win/item"))
            {
                _win.Add(new EnemyItem(win));
            }
            foreach (XmlNode steal in node.SelectNodes("steal/item"))
            {
                _steal.Add(new EnemyItem(steal));
            }
            foreach (XmlNode morph in node.SelectNodes("morph/item"))
            {
                _morph = new EnemyItem(morph);
            }

            foreach (XmlNode attackNode in node.SelectNodes("attacks/attack"))
            {
                EnemyAbility attack = new EnemyAbility(attackNode, battle.Lua);

                Attacks.Add(attack.Name, attack);
            }


            // AI: Setup

            XmlNode setupNode = node.SelectSingleNode("ai/setup");

            if (setupNode != null)
            {
                string setup = String.Format("return function (self) {0} end", setupNode.InnerText);

                try
                {
                    AISetup = (LuaFunction)battle.Lua.DoString(setup).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI setup script; enemy = " + Name, ex);
                }
            }


            // AI: Main

            string main = String.Format("return function (self) {0} end", node.SelectSingleNode("ai/main").InnerText);

            try
            {
                AIMain = (LuaFunction)battle.Lua.DoString(main).First();
            }
            catch (Exception ex)
            {
                throw new ImplementationException("Error loading enemy AI main script; enemy = " + Name, ex);
            }


            // AI: Counter

            XmlNode counterNode = node.SelectSingleNode("ai/counter");

            if (counterNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterNode.InnerText);

                try
                {
                    AICounter = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Physical

            XmlNode counterPhysicalNode = node.SelectSingleNode("ai/counter-physical");

            if (counterPhysicalNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterPhysicalNode.InnerText);

                try
                {
                    AICounterPhysical = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-physical script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Magical

            XmlNode counterMagicalNode = node.SelectSingleNode("ai/counter-physical");

            if (counterMagicalNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterMagicalNode.InnerText);

                try
                {
                    AICounterMagical = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-magical script; enemy = " + Name, ex);
                }
            }


            // AI: Counter - Death

            XmlNode counterDeathNode = node.SelectSingleNode("ai/counter-death");

            if (counterDeathNode != null)
            {
                string counter = String.Format("return function (self) {0} end", counterDeathNode.InnerText);

                try
                {
                    AICounterDeath = (LuaFunction)battle.Lua.DoString(counter).First();
                }
                catch (Exception ex)
                {
                    throw new ImplementationException("Error loading enemy AI counter-death script; enemy = " + Name, ex);
                }
            }


            // Confusion Attack

            XmlNode confuAttackNode = node.SelectSingleNode("ai/confuAttack");

            if (confuAttackNode != null)
            {
                string confuAttack = confuAttackNode.InnerText;

                if (!Attacks.ContainsKey(confuAttack))
                {
                    throw new GameDataException("Specified confu attack '{0}' is not configured; enemy = {1}", confuAttack, Name);
                }

                AIConfu = (LuaFunction)battle.Lua.DoString(String.Format("return function (self) a = chooseRandomEnemy(); self:Attack(\"{0}\", a) end", confuAttack)).First();
            }
            else
            {
                if (!Immune(Status.Confusion))
                {
                    throw new GameDataException("No confusion attack specified and not immune to confusion: {0}", Name);
                }
            }



            // Berserk Attack

            XmlNode berserkAttackNode = node.SelectSingleNode("ai/berserkAttack");

            if (berserkAttackNode != null)
            {
                string berserkAttack = berserkAttackNode.InnerText;

                if (!Attacks.ContainsKey(berserkAttack))
                {
                    throw new GameDataException("Specified berserk attack '{0}' is not configured; enemy = {1}", berserkAttack, Name);
                }

                AIBerserk = (LuaFunction)battle.Lua.DoString(String.Format("return function (self) a = chooseRandomAlly(); self:Attack(\"{0}\", a) end", berserkAttack)).First();
            }
            else
            {
                if (!Immune(Status.Berserk))
                {
                    throw new GameDataException("No berserk attack specified and not immune to berserk: {0}", Name);
                }
            }


            // Timers


            V_Timer   = new BattleClock(battle.SpeedValue * 2);
            TurnTimer = new EnemyTurnTimer(this, e);
        }
Ejemplo n.º 11
0
    private static void LoadEnemies()
    {
        var enemies = new List <Enemy>();
        var xml     = (TextAsset)Resources.Load("EnemyList", typeof(TextAsset));

        using (XmlReader reader = XmlReader.Create(new StringReader(xml.text)))
        {
            string name    = string.Empty,
                   ability = String.Empty;
            int health     = 0,
                chance     = 0;
            bool isBoss    = false;
            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.EndElement)
                {
                    switch (reader.Name)
                    {
                    case "Name":
                        name = reader.ReadInnerXml();
                        break;

                    case "Health":
                        health = Int32.Parse(reader.ReadInnerXml());
                        break;

                    case "Ability":
                        ability = reader.ReadInnerXml();
                        break;

                    case "Chance":
                        chance = Int32.Parse(reader.ReadInnerXml());
                        break;

                    case "IsBoss":
                        isBoss = bool.Parse(reader.ReadInnerXml());
                        break;

                    case "Enemy":
                        if (name != String.Empty)
                        {
                            Enemy enemy = enemies.FirstOrDefault(e => e.Name == name);
                            if (enemy == null)
                            {
                                enemy = new Enemy()
                                {
                                    Name           = name,
                                    Health         = health,
                                    EnemyAbilities = new Dictionary <EnemyAbility, int>(),
                                    IsBoss         = isBoss
                                };
                                EnemyAbility ab = Game.AllAbilities.First(e => e.Name == ability);
                                enemy.EnemyAbilities.Add(ab, chance);
                                enemies.Add(enemy);
                            }
                            else
                            {
                                enemy.EnemyAbilities.Add(Game.AllAbilities.First(e => e.Name == ability), chance);
                            }
                        }

                        break;
                    }
                }
            }
        }
        Game.EnemyPool = enemies.Where(e => e.IsBoss == false).ToList();
    }