Esempio n. 1
0
        /******************************************** PRIMITIVES **********************************************
        * This section holds all our primitives, which are the functions that the FSM will be allowed to use.*
        * In principle, any unit's main loop should only call primitives.                                    *
        ******************************************************************************************************/

        /// <summary>
        /// Place une unité dans la zone d'apparition en faisant attention au collisions
        /// </summary>
        /// <param name="type">type de l'unité</param>
        public bool SpawnUnit(BotType type)
        {
            if (!this.CanCreate(type))
            {
                return(false);
            }
            GameObject unit = Instantiate(type.PrefabByType(), this.transform.position + this.transform.forward * 2.0f, this.transform.rotation * Quaternion.Euler(0.0f, Random.Range(-20.0f, 20.0f), 0.0f), this.GetComponent <WarBotController>().TeamManager.GetComponent <TeamManager>().transform);

            this.GetComponent <WarBotController>().TeamManager.GetComponent <TeamManager>().InitUnit(unit, type);
            this.GetComponent <InventoryController>().Remove((int)type.UnitCost());
            this.last_spawn = Time.time;
            return(true);
        }
Esempio n. 2
0
        public bool CanCreate(BotType type)
        {
            if ((this.GetComponent <InventoryController>().CurrentInventory < type.UnitCost()) || (this.last_spawn + this.spawn_delay >= Time.time))
            {
                return(false);
            }
            BotType self = this.GetComponent <WarBotController>().Type;

            if (self == BotType.WarBase)
            {
                return(
                    type == BotType.WarEngineer ||
                    type == BotType.WarExplorer ||
                    type == BotType.WarHeavy
                    );
            }
            if (self == BotType.WarEngineer)
            {
                return(type == BotType.WarTurret);
            }
            return(false);
        }