Ejemplo n.º 1
0
    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player");

        ani       = GetComponent <Animator>();
        moveAgent = GetComponent <MoveAgent>();

        waitSeconds = new WaitForSeconds(refreshAICycle);
        pCtrl       = player.GetComponent <PlayerCtrl>();

        ea    = GetComponent <EnemyAttack>();
        eItem = GetComponent <EnemyItem>();
    }
Ejemplo n.º 2
0
 void UpdateEnemys()
 {
     if (enemyCount > 0)
     {
         GameObject newEnemy     = GenerateEnemy();
         EnemyItem  newEnemyItem = new EnemyItem(newEnemy, enemylife);
         enemyList.Add(newEnemyItem);
         enemyCount--;
     }
     else
     {
     }
 }
Ejemplo n.º 3
0
    void Start()
    {
        eAi   = GetComponent <EnemyAI>();
        eItem = GetComponent <EnemyItem>();

        ani         = GetComponent <Animator>();
        audioSource = GetComponent <AudioSource>();

        player = GameObject.FindGameObjectWithTag("Player");
        pCtrl  = player.GetComponent <PlayerCtrl>();

        weaponholder = GameObject.FindGameObjectWithTag("WeaponHolder").transform;
        shaker       = GameObject.Find("Main Camera").GetComponent <Shaker>();
    }
Ejemplo n.º 4
0
    public void Setup(EnemyItem config)
    {
        spriteRenderer.sprite = config.sprite;
        navComponent.speed    = config.speed;
        hp       = config.hp;
        points   = config.points;
        airborne = config.airborne;

        activeFires  = 0;
        defaultSpeed = config.speed;
        multipliers.Clear();
        currentMultiplier = 1;
        SetSpeed();
        spriteRenderer.color = Color.white;
    }
Ejemplo n.º 5
0
    public void Setup(EnemyItem item)
    {
        this.item       = item;
        this.Params     = new Params(item);
        MaxHP           = this.Params[Param.HP];
        MaxMP           = this.Params[Param.MP];
        this.Race       = item.Familiar.Race;
        this.Attributes = new Attributes(item.Familiar.Attribute);
        this.Level      = item.Level;

        level.text  = $"Lv.{Level}";
        hpText.text = $"{Params[Param.HP]}/{MaxHP}";

        Setup(item.id);
        character.sprite = Resources.Load <Sprite>($"Familiar/{ item.Familiar.Image}/base");
        side             = Side.Enemy;
    }
Ejemplo n.º 6
0
    /// <summary>
    /// 生成初始敌人配置
    /// </summary>
    private void SetEnemyList()
    {
        int       enemyId   = PlayerPrefs.GetInt(Globals.PP_BattleEnemyId);
        EnemyItem enemyItem = EnemyManager.Instance().GetEnemyById(enemyId);

        int pointIndex = 0;     //敌人生成点数组的下标

        foreach (EnemyItem.Enemy enemy in enemyItem.BattleEnemys)
        {
            GameObject enemyPrefab = RolePrefabDic.Instance.GetEnemyPrefabById(enemy.EnemyId);
            for (int i = 0; i < enemy.EnemyNum; i++)
            {
                GameObject tempEnemy = GameObject.Instantiate(enemyPrefab, RolePoints.Instance.enemyPoints[pointIndex].position, RolePoints.Instance.enemyPoints[pointIndex].rotation, RolePoints.Instance.enemyParent);
                enemys.Add(tempEnemy);
                pointIndex++;
            }
        }
    }
Ejemplo n.º 7
0
    private void SpawnEnemy(EnemyItem type)
    {
        GameObject newEnemy = enemyPool.GetObject(null, false);

        newEnemy.GetComponent <Enemy>().Setup(type);
        newEnemy.transform.position = spawnPosition.position;
        newEnemy.SetActive(true);
        if (type.airborne)
        {
            newEnemy.GetComponent <Enemy>().StartMoving(goal.position);
        }
        else
        {
            newEnemy.GetComponent <Enemy>().StartMoving(MyGrid.Instance.startingPosition);
        }

        activeEnemies.Add(newEnemy.GetComponent <Enemy>());
    }
Ejemplo n.º 8
0
    public void DeleteEnemyByBullet(GameObject deleteEnemy)
    {
        EnemyItem damageEnemy = getItem(deleteEnemy);

        damageEnemy.setLife(damageEnemy.getlife() - 1);
        if (damageEnemy.getlife() <= 0)
        {
            enemyList.Remove(damageEnemy);
            Destroy(damageEnemy.getEnemy());
            if (gameModeNum == 0)
            {
                destroyAfter();
            }
            else
            {
                destroyAfterEternal();
            }
        }
    }
    /// <summary>
    /// 显示奖励物品,同时向玩家发放奖励
    /// </summary>
    /// <param name="enemyId"></param>
    public void SetRewardItems(int enemyId)
    {
        EnemyItem enemyItem = EnemyManager.Instance().GetEnemyById(enemyId);

        string temp = "";

        temp += enemyItem.EnemyRewards.Gold + "\n";

        //发放金钱
        GlobalPlayerData.Instance.AddGoldInOtherScene(enemyItem.EnemyRewards.Gold);

        foreach (EnemyItem.RewardItem item in enemyItem.EnemyRewards.RewardItems)
        {
            string itemName = GlobalInventoryItemManager.Instance.GetItemNameById(item.ItemId);
            temp += itemName + " x" + item.ItemNum + "\n";

            //发放物品
            for (int i = 0; i < item.ItemNum; i++)
            {
                InventoryManager.Instance.AddItem(item.ItemId);
            }
        }
        rewardText.text = temp;
    }
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);
        }