Пример #1
0
 public void Awake()
 {
     SpawnMobs();
     dropWeapon    = new EnemyWeaponDrop();
     SW            = new SpawnWeapon();
     wT            = FindObjectOfType <WeaponTable>();
     xpPool        = FindObjectOfType <ExpParticlesPool>();
     expController = FindObjectOfType <ExpController>();
 }
Пример #2
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();

            PrisonerHelpers = new PrisonerUnificationHelpers();

            InternalExpController = new ExpController();

            _harmony.PatchAll();
        }
Пример #3
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();
    }
Пример #4
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT = FindObjectOfType <WeaponTable>();

        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();
        for (int i = 0; i < dropList.Count; i++)
        {
            DicToUseInDrop.Add(dropList[i].iD, dropChanceList[i]);
        }
    }
Пример #5
0
 //function aim to check if current fill level is ready for state change
 void CheckColorStateChange()
 {
     //print("curLevel: " + curPaintLevel + "  " + myPaintState);
     //call change state function to change the state to clean when curPaintLevel is 0
     if (curPaintLevel == 0 && myPaintState != ColorState.Clean)
     {
         //print("get cleaned canRecoverTIle: " + canTileRecover);
         isStateChangedTF = true;
         ChangePaintState(ColorState.Clean);
         curColorState   = ColorState.Clean;
         curRecoverTimer = 0.0f;
         CheckTileRecover();
         isOwned = false;
         //set spill effect to false
         TowerSpillEffect.SetActive(false);
     }
     //call change state function to change the state to the target color when curPaintLevel is full
     if (curPaintLevel == fullPaintLevel && myPaintState == ColorState.Clean)
     {
         isStateChangedTF = true;
         ChangePaintState(curColorState);
         //add exp to player when it is colored to another state
         if (curColorState == ColorState.Blue)
         {
             ExpController expSc = bluePlayer.GetComponent <ExpController>();
             if (expSc != null)
             {
                 expSc.AddExp(100);
             }
             mMetricsManager.setTowersPainted(0, 1);
             //set blue spill color
             TurnOnTowerSpill(blueSpillColor);
         }
         else
         {
             ExpController expSc = redPlayer.GetComponent <ExpController>();
             if (expSc != null)
             {
                 expSc.AddExp(100);
             }
             mMetricsManager.setTowersPainted(1, 1);
             TurnOnTowerSpill(redSpillColor);
         }
         CheckTileRecover();
         //print("*isstatechangedTF: " + isStateChangedTF);
     }
 }
Пример #6
0
 void Awake()
 {
     instance = this;
 }
Пример #7
0
    public void Start()
    {
        dropWeapon    = new EnemyWeaponDrop();
        SW            = new SpawnWeapon();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();
        zoneRunAttack.SetActive(false);
        trialRun.SetActive(false);

        var idle     = new State <OnCondition>("Idle");
        var persuit  = new State <OnCondition>("Persuit");
        var attack   = new State <OnCondition>("Attack");
        var skill    = new State <OnCondition>("Skill");
        var resetRun = new State <OnCondition>("ResetSkill");
        var die      = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timerSecuence += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timerSecuence   += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    transform.forward   = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    transform.position += transform.forward * 5 * Time.deltaTime;
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timerAttack = 0;
            attacked    = false;
        };
        attack.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;
            timerSkill    += Time.deltaTime;
            if (timerAttack <= timeToAttack - 1)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 1);
            }

            if (timerAttack >= timeToAttack && !attacked)
            {
                attacked = true;
                anim.SetBool("Run", false);
                anim.SetTrigger("Attack");
            }
            if (timerAttack > timeToAttack + 1)
            {
                fsm.Feed(OnCondition.Idle);
            }
            if (timerSkill >= cooldownSequence)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
        };

        skill.OnEnter += () =>
        {
            Patrol();
            timerSkill  = 0;
            timerAttack = 0;
            anim.speed  = 5;
            trialRun.SetActive(true);
        };
        skill.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;

            if (timerAttack <= timeToAttack - 1)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 0.8f);
            }
            if (timerAttack >= timeToAttack - 1 && timerAttack < timeToAttack)
            {
                zoneRunAttack.SetActive(true);
            }

            if (timerAttack >= timeToAttack)
            {
                zoneRunAttack.SetActive(false);
                anim.SetBool("Run", false);
                anim.SetTrigger("Attack");
                transform.position += transform.forward * 30 * Time.deltaTime;
                inRage              = true;
            }
            //anim.SetFloat("Attack", 1);
            //anim.SetBool("Run", false);
            if (timerAttack > timeToAttack + 1f)
            {
                fsm.Feed(OnCondition.ResetRun);
            }
        };
        skill.OnExit += () =>
        {
            zoneRunAttack.SetActive(false);
            trialRun.SetActive(false);
            timerSkill  = 0;
            timerAttack = 0;
            anim.speed  = 1;
            inRage      = false;
        };

        resetRun.OnEnter += () =>
        {
            runsQuantity++;
            Patrol();
        };
        resetRun.OnUpdate += () =>
        {
            timerToRun += Time.deltaTime;
            if (runsQuantity > runsPerSequence)
            {
                fsm.Feed(OnCondition.Idle);
            }
            else if (timerToRun > 0.5f)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
        };
        resetRun.OnExit += () =>
        {
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.SkillReady, skill);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.SkillReady, skill);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.SkillReady, skill);
        attack.AddTransition(OnCondition.Die, die);

        skill.AddTransition(OnCondition.Idle, idle);
        skill.AddTransition(OnCondition.Die, die);
        skill.AddTransition(OnCondition.ResetRun, resetRun);

        resetRun.AddTransition(OnCondition.Idle, idle);
        resetRun.AddTransition(OnCondition.SkillReady, skill);
        resetRun.AddTransition(OnCondition.Die, die);

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #8
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        var idle    = new State <OnCondition>("Idle");
        var persuit = new State <OnCondition>("Persuit");
        var attack  = new State <OnCondition>("Attack");
        var skill   = new State <OnCondition>("Skill");
        var die     = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSkill >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSkill += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSkill     += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSkill  += Time.deltaTime;
            timeToAttack += Time.deltaTime;
            if (timeToSkill >= cooldownSequence)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            else
            {
                if (timeToAttack >= 0.5f)
                {
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1.5f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };

        skill.OnEnter += () =>
        {
            cooldownSequence *= 1.5f;
            timeToSkill       = 0;
            Clone();
            fsm.Feed(OnCondition.Idle);
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        //////////////////

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.SkillReady, skill);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Idle, idle);
        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.SkillReady, skill);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.Persuit, persuit);
        attack.AddTransition(OnCondition.SkillReady, skill);
        attack.AddTransition(OnCondition.Die, die);

        skill.AddTransition(OnCondition.Idle, idle);
        skill.AddTransition(OnCondition.Die, die);

        ///////////////

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #9
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        bossSword = GetComponentInChildren <BossSword>();
        var idle          = new State <OnCondition>("Idle");
        var persuit       = new State <OnCondition>("Persuit");
        var attack        = new State <OnCondition>("Attack");
        var skill         = new State <OnCondition>("Skill");
        var teletransport = new State <OnCondition>("Teletransport");
        var summon        = new State <OnCondition>("Summon");
        var heal          = new State <OnCondition>("Heal");
        var die           = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSequence >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.TP);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSequence += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSequence  += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSequence += Time.deltaTime;
            timeToAttack   += Time.deltaTime;
            timeSkill      += Time.deltaTime;
            if (timeSkill >= 3)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            else
            {
                if (timeToAttack >= 0.5f)
                {
                    zoneAttack.gameObject.SetActive(false);
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1.5f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };

        skill.OnEnter += () =>
        {
            zoneAttack.gameObject.SetActive(true);
            Patrol();
            timeSkill = 0;
        };
        skill.OnUpdate += () =>
        {
            timeToSequence += Time.deltaTime;
            timeToAttack   += Time.deltaTime;

            if (timeToAttack >= 3f)
            {
                zoneAttack.gameObject.SetActive(false);
                bossSword.Attack(transform.position + transform.forward.normalized, transform.rotation, 10, target);
                //anim.SetFloat("Attack", 1);
                //anim.SetBool("Run", false);
            }
            if (timeToAttack > 4f)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };

        teletransport.OnEnter += () =>
        {
            Patrol();
            Instantiate(tpParticle, transform.position, transform.rotation);
        };
        teletransport.OnUpdate += () =>
        {
            StartCoroutine(ToState(OnCondition.Summon, 0.3f));
        };
        teletransport.OnExit += () =>
        {
            transform.position = tpPos.position;
            Instantiate(smoke, transform.position, Quaternion.Euler(-90, 0, 0));
        };

        summon.OnEnter += () =>
        {
        };
        summon.OnUpdate += () => StartCoroutine(ToState(OnCondition.Heal, 0.5f));
        summon.OnExit   += () =>
        {
            if (target != null)
            {
                transform.forward = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
            }

            Instantiate(littleSmoke, transform.position + transform.forward.normalized, transform.rotation);
            Instantiate(littleSmoke, transform.position + transform.forward.normalized + transform.right.normalized, transform.rotation);
            Instantiate(littleSmoke, transform.position + transform.forward.normalized - transform.right.normalized, transform.rotation);
            Vector3 posToSpawn = new Vector3(transform.position.x, 1.5f, transform.position.z);
            Instantiate(enemySummon, posToSpawn + transform.forward.normalized, transform.rotation);
            timeToSequence   = 0;
            cooldownSequence = cooldownSequence * 2;
        };

        heal.OnEnter  += () => Instantiate(healSpell, transform.position, transform.rotation);
        heal.OnUpdate += () =>
        {
            TakeDamage(-5, false);
            StartCoroutine(ToState(OnCondition.Idle, 4f));
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            portal.Invoke();
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.TP, teletransport);
        idle.AddTransition(OnCondition.Summon, teletransport);
        idle.AddTransition(OnCondition.Heal, heal);
        idle.AddTransition(OnCondition.Die, die);


        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.TP, teletransport);
        persuit.AddTransition(OnCondition.Summon, summon);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.TP, teletransport);
        attack.AddTransition(OnCondition.SkillReady, skill);
        attack.AddTransition(OnCondition.Die, die);

        skill.AddTransition(OnCondition.Idle, idle);
        skill.AddTransition(OnCondition.Die, die);

        teletransport.AddTransition(OnCondition.Idle, idle);
        teletransport.AddTransition(OnCondition.Summon, summon);
        teletransport.AddTransition(OnCondition.Die, die);

        summon.AddTransition(OnCondition.Idle, idle);
        summon.AddTransition(OnCondition.Heal, heal);
        summon.AddTransition(OnCondition.Attack, attack);
        summon.AddTransition(OnCondition.Die, die);

        heal.AddTransition(OnCondition.Idle, idle);
        heal.AddTransition(OnCondition.Die, idle);

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #10
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo key;

            var culture         = CultureInfo.CreateSpecificCulture("ru-ru");
            var resourceManager = new ResourceManager("CasloFirstProject.CMD.Languages.Messages", typeof(Program).Assembly);

            Console.WriteLine(resourceManager.GetString("Welcom", culture));

            Console.WriteLine(resourceManager.GetString("EnterName", culture));
            var name = Console.ReadLine();

            var userController    = new UserController(name);
            var expController     = new ExpController(userController.CurrentUser);
            var dungeonController = new DungeonController(userController.CurrentUser);

            if (userController.IsNewUser)
            {
                Console.WriteLine("Создайте имя персонажа");
                var character = Console.ReadLine();

                Console.Write("Количество персонажей ");
                var quantity = ParseInt("Количество персонажей ");
                Console.Write("Уровень персонажа ");
                var lvl = ParseInt("Уровень персонажа ");


                userController.SetNewUserData(character, quantity, lvl);
            }

            Console.WriteLine(userController.CurrentUser);


            while (true)
            {
                Console.WriteLine("Вы хотите добавить побеждённого противника? ");
                Console.WriteLine("Нажмите Y чтобы добавить побеждённого противника");
                Console.WriteLine("Нажмите D чтобы добавить пройденное подземелье");
                Console.WriteLine("Нажмите Q чтобы выйти");

                key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                case ConsoleKey.Y:
                    var unites = EnterUnits();
                    expController.Add(unites.Units, unites.Exp);

                    foreach (var item in expController.lvlUps.Unites)
                    {
                        Console.WriteLine($"\t {item.Key} - {item.Value}");
                    }
                    break;

                case ConsoleKey.D:
                    var dung = EnterDungeon();

                    dungeonController.Add(dung.Play, dung.Begin, dung.End);

                    foreach (var item in dungeonController.Dungeons)
                    {
                        Console.WriteLine($"\t {item.Play} - {item.Start} - {item.Finish}");
                    }

                    break;

                case ConsoleKey.Q:
                    Environment.Exit(0);
                    break;
                }

                Console.ReadLine();
            }
        }
Пример #11
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();


        var idle    = new State <OnCondition>("Idle");
        var persuit = new State <OnCondition>("Persuit");
        var attack  = new State <OnCondition>("Attack");
        var dig     = new State <OnCondition>("Dig");
        var appear  = new State <OnCondition>("Appear");
        var die     = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSkill >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.Dig);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSkill += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSkill     += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    //dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSkill  += Time.deltaTime;
            timeToAttack += Time.deltaTime;
            if (timeToSkill >= cooldownSequence)
            {
                fsm.Feed(OnCondition.Dig);
            }
            else
            {
                if (timeToAttack < 0.3f)
                {
                    Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, 0.09f);
                }

                if (timeToAttack >= 0.5f)
                {
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };
        attack.OnExit += () =>
        {
            Patrol();
        };

        dig.OnEnter += () =>
        {
            timeToSkill       = 0;
            booleano          = true;
            myRedZoneInstance = Instantiate(redZone, transform.position - Vector3.up * 1.7f, transform.rotation);
            myRedZoneInstance.transform.Rotate(90, 0, 0);
            //transform.position = new Vector3(transform.position.x, 100000, transform.position.z);
            GetComponentInChildren <SkinnedMeshRenderer>().enabled = false;
            GetComponentInChildren <Weapon>().GetComponent <MeshRenderer>().enabled = false;
        };
        dig.OnUpdate += () =>
        {
            followingTime += Time.deltaTime;
            myRedZoneInstance.transform.position = Vector3.Lerp(myRedZoneInstance.transform.position, target.transform.position, 0.015f);
            if (followingTime >= timeToAppear)
            {
                fsm.Feed(OnCondition.Appear);
            }
        };
        dig.OnExit += () =>
        {
            GetComponentInChildren <SkinnedMeshRenderer>().enabled = true;
            GetComponentInChildren <Weapon>().GetComponent <MeshRenderer>().enabled = true;

            followingTime = 0;
        };

        appear.OnEnter += () =>
        {
            Instantiate(smoke, transform.position - Vector3.up * 1.5f, transform.rotation);
            transform.position = myRedZoneInstance.transform.position + Vector3.up * 30;
            Destroy(myRedZoneInstance);
        };
        appear.OnUpdate += () =>
        {
            //transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, 2.5f, transform.position.z), 0.08f);
            int        floorLayer = 1 << 9;
            RaycastHit hit;
            if (Physics.Raycast(transform.position, Vector3.down, out hit, 3, floorLayer))
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        appear.OnExit += () =>
        {
            if (Vector3.Distance(target.transform.position, transform.position) < 3)
            {
                Shake.instance.shake       = 0.08f;
                Shake.instance.shakeAmount = 0.1f;
                target.GetComponent <PlayerLife>().TakeDamage(500, false);
                Instantiate(smoke, transform.position - Vector3.up * 1.5f, transform.rotation);
                var exp = Instantiate(expansion, transform.position - Vector3.up * 1.5f, transform.rotation);
                //exp.transform.Rotate(90, 0, 0);
            }
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        //////////////////

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Dig, dig);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Idle, idle);
        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.Dig, dig);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.Persuit, persuit);
        attack.AddTransition(OnCondition.Dig, dig);
        attack.AddTransition(OnCondition.Die, die);

        dig.AddTransition(OnCondition.Idle, idle);
        dig.AddTransition(OnCondition.Appear, appear);
        dig.AddTransition(OnCondition.Die, die);

        appear.AddTransition(OnCondition.Idle, idle);
        appear.AddTransition(OnCondition.Die, die);

        ///////////////

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #12
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = weaponTable.GetComponent <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        var idle           = new State <OnCondition>("Idle");
        var persuit        = new State <OnCondition>("Persuit");
        var attack         = new State <OnCondition>("Attack");
        var meteorSkill    = new State <OnCondition>("Skill");
        var explotionSkill = new State <OnCondition>("Explotion");
        var die            = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timerSecuence += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timerSecuence   += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    transform.forward   = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    transform.position += transform.forward * 5 * Time.deltaTime;
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timerAttack = 0;
            attacked    = false;
        };
        attack.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;
            timerSkill    += Time.deltaTime;
            if (timerAttack <= timeToAttack - 0.3f)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 1);
            }
            if (timerAttack >= timeToAttack && !attacked)
            {
                attacked = true;
                anim.SetBool("Run", false);
                anim.SetTrigger("Attack");
            }
            if (timerAttack > timeToAttack + 1)
            {
                fsm.Feed(OnCondition.Idle);
            }

            if (timerSkill > cooldownSequence && Vector3.Distance(target.transform.position, transform.position) < 3.5f)
            {
                fsm.Feed(OnCondition.ExplotionSkill);
            }
            else if (timerSkill >= cooldownSequence && meteoritesCount < 3)
            {
                fsm.Feed(OnCondition.Meteorites);
            }
        };

        meteorSkill.OnEnter += () =>
        {
            Patrol();
            timerSkill  = 0;
            timerAttack = 0;
            anim.speed  = 2;
        };
        meteorSkill.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;

            if (timerAttack <= timeToAttack - 1)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 0.8f);
            }

            if (timerAttack > timeToAttack)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        meteorSkill.OnExit += () =>
        {
            var met = Instantiate(meteorite, target.transform.position + Vector3.up * 10, transform.rotation);
            met.GetComponent <Bomb>().dir     = (target.transform.position - met.transform.position).normalized;
            met.GetComponent <Bomb>().speed   = 0.05f;
            met.GetComponent <Bomb>().myLayer = 10;
            meteoritesCount++;
            cooldownSequence *= 2;
            timerSkill        = 0;
            timerAttack       = 0;
            anim.speed        = 1;
        };

        explotionSkill.OnEnter += () =>
        {
            Patrol();
            cirlceZone.SetActive(true);
        };
        explotionSkill.OnUpdate += () =>
        {
            timerToIdle += Time.deltaTime;
            if (timerToIdle >= 1f)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        explotionSkill.OnExit += () =>
        {
            cirlceZone.SetActive(false);
            var fire = Instantiate(explotionFire, new Vector3(transform.position.x, 0.5f, transform.position.z), transform.rotation);
            fire.transform.Rotate(90, 0, 0);
            fire.GetComponent <MakeAreaDamage>().myLayer = 10;
            Shake.instance.shake       = 0.1f;
            Shake.instance.shakeAmount = 0.1f;
            timerToIdle = 0;
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            portal.Invoke();
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Meteorites, meteorSkill);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.Meteorites, meteorSkill);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.ExplotionSkill, explotionSkill);
        attack.AddTransition(OnCondition.Meteorites, meteorSkill);
        attack.AddTransition(OnCondition.Die, die);

        meteorSkill.AddTransition(OnCondition.Idle, idle);
        meteorSkill.AddTransition(OnCondition.Die, die);
        meteorSkill.AddTransition(OnCondition.ExplotionSkill, explotionSkill);

        explotionSkill.AddTransition(OnCondition.Idle, idle);
        explotionSkill.AddTransition(OnCondition.Die, die);

        fsm = new StateMachine <OnCondition>(idle);
    }