Inheritance: ScriptableObject
Exemple #1
0
        public Turret(GameObject unit, TurretConfig turretConfig, List <Cannon> AllWeapons)
        {
            _maxRanges             = new float[(int)TargetType._SIZE];
            _maxRangesDirectFire   = new float[(int)TargetType._SIZE];
            _maxRangesIndirectFire = new float[(int)TargetType._SIZE];
            _arcHorizontal         = turretConfig.ArcHorizontal;
            _arcUp        = turretConfig.ArcUp;
            _arcDown      = turretConfig.ArcDown;
            _rotationRate = turretConfig.RotationRate;
            _priority     = turretConfig.Priority;
            _turret       = RecursiveFindChild(unit.transform, turretConfig.TurretRef);
            Children      = new List <Turret>();

            if (turretConfig.Children != null && turretConfig.Children.Count > 0)
            {
                foreach (TurretConfig childTurretConfig in turretConfig.Children)
                {
                    Children.Add(new Turret(unit, childTurretConfig, AllWeapons));
                }
            }
            else
            {
                AudioSource shotAudioSource = _turret.gameObject.AddComponent <AudioSource>();

                if (turretConfig.Cannon != null)
                {
                    Transform barrelTip =
                        turretConfig.Cannon.BarrelTipRef == "" ?
                        _turret :
                        RecursiveFindChild(
                            _turret.parent,
                            turretConfig.Cannon.BarrelTipRef);
                    if (barrelTip == null)
                    {
                        barrelTip = _turret;
                    }

                    _weapon = new Cannon(
                        turretConfig.Cannon,
                        shotAudioSource,
                        barrelTip);

                    _maxRanges             = _weapon.CalculateMaxRanges();
                    _maxRangesDirectFire   = _weapon.CalculateMaxRangesDirectFireAmmo();
                    _maxRangesIndirectFire = _weapon.CalculateMaxRangesIndirectFireAmmo();
                    _shellVelocity         = turretConfig.Cannon.Velocity * Constants.MAP_SCALE;

                    AllWeapons.Add(_weapon);
                }
                else
                {
                    Logger.LogConfig(
                        LogLevel.ERROR,
                        "Couldn't create a weapon in a turret without children. " +
                        "No weapon specified in the config?");
                }
            }
        }
Exemple #2
0
 void Start()
 {
     self       = GetComponent <TurretConfig>();
     self.owner = transform.parent.parent.GetComponentInParent <PlayerConfig>();
     model      = self.model;
     targeting  = self.targeting;
     view       = self.view;
     InvokeRepeating("UpdateTarget", self.updateRate, self.updateRate);
 }
    public TurretConfig GetTurretConfigWithUpgrades(TurretConfig turretConfig)
    {
        TurretConfig copy = Instantiate <TurretConfig>(turretConfig);

        copy.strength    = Mathf.CeilToInt(turretConfig.strength * this.aggregatedStats.turretRelativeStrength);
        copy.buyingPrice = Mathf.FloorToInt(turretConfig.buyingPrice * this.aggregatedStats.turretRelativePrice);
        copy.attackRange = Mathf.CeilToInt(turretConfig.attackRange * this.aggregatedStats.turretRelativeRange);
        return(copy);
    }
Exemple #4
0
    public override void SetContent(ScriptableObject scriptableObject)
    {
        if (scriptableObject.GetType() != typeof(TurretConfig))
        {
            return;
        }

        TurretConfig turretConfig = (TurretConfig)scriptableObject;

        this.nameText.text           = turretConfig.turretName;
        this.descriptionText.text    = turretConfig.description;
        this.costsText.text          = turretConfig.buyingPrice.ToString() + " $";
        this.refundText.text         = turretConfig.sellingPrice.ToString() + " $";
        this.specialAbilityText.text = turretConfig.specialAbility;

        this.strengthText.text = turretConfig.strength.ToString();
        this.cooldownText.text = turretConfig.attackCooldown.ToString() + " s";
        this.rangeText.text    = turretConfig.attackRange.ToString();
    }
Exemple #5
0
 void Update()
 {
     if (!this.IsEnemy())
     {
         this.turretConfig = SkillTreeManager.current.GetTurretConfigWithUpgrades(this.turretConfig);
     }
     if (Time.time - this.timeOfPreviousAttack > this.turretConfig.attackCooldown)
     {
         List <Collider2D> enemieColliders = FindAllEnemiesInRange();
         if (enemieColliders.Count > 0)
         {
             if (this.turretConfig.canAttackMultiple)
             {
                 enemieColliders.ForEach(AttackColliderPosition);
             }
             else
             {
                 // TODO the first one is not always the closest one... not sure if I want that
                 AttackColliderPosition(enemieColliders[0]);
             }
             this.timeOfPreviousAttack = Time.time;
         }
     }
 }
 void Awake()
 {
     self = GetComponent <TurretConfig>();
 }
Exemple #7
0
 void Start()
 {
     self     = GetComponent <TurretConfig>();
     fireRate = self.fireRate;
 }
Exemple #8
0
    public int GetTurretCosts(int turretType)
    {
        TurretConfig turretConfig = SkillTreeManager.current.GetTurretConfigWithUpgrades(EpochManager.current.GetTurretsOfCurrentPlayerEpoch()[turretType].GetComponent <TurretBehavior>().turretConfig);

        return(turretConfig.buyingPrice);
    }
        /// <summary>
        /// Creates a new instance of Music Turret bot shard handler.
        /// </summary>
        /// <param name="cfg">Configuration options for the shard.</param>
        /// <param name="shardId">ID of this shard.</param>
        /// <param name="async">Synchronous executor of asynchronous tasks.</param>
        public TurretBot(TurretConfig cfg, int shardId, AsyncExecutor async)
        {
            // assign the properties
            this.ShardId                  = shardId;
            this.BotVersion               = TurretUtilities.GetBotVersion();
            this.Configuration            = cfg;
            this.ConnectionStringProvider = new ConnectionStringProvider(cfg.PostgreSQL);
            this.AsyncExecutor            = async;

            // create discord client instance
            this.Discord = new DiscordClient(new DiscordConfiguration
            {
                Token      = cfg.Discord.Token,
                TokenType  = TokenType.Bot,
                ShardCount = cfg.Discord.ShardCount,
                ShardId    = this.ShardId,
                Intents    = DiscordIntents.All,

                AutoReconnect           = true,
                ReconnectIndefinitely   = true,
                GatewayCompressionLevel = GatewayCompressionLevel.Stream,
                LargeThreshold          = 250
            });

            // attach event handlers
            this.Discord.Ready += this.Discord_Ready;
            this.Discord.GuildDownloadCompleted += this.Discord_GuildDownloadCompleted;
            this.Discord.SocketErrored          += this.Discord_SocketErrored;
            this.Discord.GuildAvailable         += this.Discord_GuildAvailable;
            this.Discord.VoiceStateUpdated      += this.Discord_VoiceStateUpdated;

            // create service provider
            this.Services = new ServiceCollection()
                            .AddTransient <SecureRandom>()
                            .AddSingleton(this.ConnectionStringProvider)
                            .AddSingleton <MusicService>()
                            .AddScoped <DatabaseContext>()
                            .AddSingleton(new RedisClient(cfg.Redis))
                            .AddSingleton(new LavalinkService(cfg.Lavalink, this.Discord))
                            .AddSingleton(new YouTubeSearchProvider(cfg.YouTube))
                            .AddSingleton(this)
                            .BuildServiceProvider(true);

            // create CommandsNext
            this.CommandsNext = this.Discord.UseCommandsNext(new CommandsNextConfiguration
            {
                CaseSensitive        = false,
                EnableDms            = false,
                IgnoreExtraArguments = false,

                EnableDefaultHelp = true,
                DefaultHelpChecks = new[] { new NotBlacklistedAttribute() },

                EnableMentionPrefix = cfg.Discord.EnableMentionPrefix,
                PrefixResolver      = this.ResolvePrefixAsync,

                Services = this.Services
            });

            // set help formatter
            this.CommandsNext.SetHelpFormatter <TurretHelpFormatter>();

            // attach event handlers
            this.CommandsNext.CommandExecuted += this.CommandsNext_CommandExecuted;
            this.CommandsNext.CommandErrored  += this.CommandsNext_CommandErrored;

            // create commands
            this.CommandsNext.RegisterCommands(Assembly.GetExecutingAssembly());

            // create interactivity
            this.Interactivity = this.Discord.UseInteractivity(new InteractivityConfiguration
            {
                Timeout = TimeSpan.FromSeconds(30)
            });

            // create lavalink
            this.Lavalink = this.Discord.UseLavalink();
        }
 void Start()
 {
     self = GetComponent <TurretConfig>();
 }
Exemple #11
0
        public Turret(GameObject unit, TurretConfig turretConfig)
        {
            ArcHorizontal = turretConfig.ArcHorizontal;
            ArcUp = turretConfig.ArcUp;
            ArcDown = turretConfig.ArcDown;
            RotationRate = turretConfig.RotationRate;
            _priority = turretConfig.Priority;
            _turret = RecursiveFindChild(unit.transform, turretConfig.TurretRef);
            _mount = RecursiveFindChild(unit.transform, turretConfig.MountRef);
            Children = new List<Turret>();

            if (turretConfig.Children.Count > 0)
            {
                foreach (TurretConfig childTurretConfig in turretConfig.Children)
                {
                    Children.Add(new Turret(unit, childTurretConfig));
                }
            }
            else
            {
                // Hack: The old tank prefab has a particle system for shooting 
                // that we want to remove,
                // so instead of adding it to the models or having it in the config 
                // we hardcode it in here.
                // TODO might have to use a different object for the old arty effect.
                if (!_shotEmitterResource)
                {
                    _shotEmitterResource = Resources.Load<GameObject>("shot_emitter");
                }
                if (!_muzzleFlashResource)
                {
                    _muzzleFlashResource = Resources.Load<GameObject>("muzzle_flash");
                }
                if (!_gunSoundResource)
                {
                    _gunSoundResource = Resources.Load<AudioClip>("Tank_gun");
                }

                GameObject shotGO = GameObject.Instantiate(
                        _shotEmitterResource, _turret);
                AudioSource shotAudioSource = _turret.gameObject.AddComponent<AudioSource>();

                // The Unit json parser creates objects even when there are none,
                // so instead of testing for null we have to test for a 0 value..
                if (turretConfig.Howitzer.FireRange != 0)
                {
                    _isHowitzer = true;
                    _weapon = new Howitzer(
                            turretConfig.Howitzer,
                            shotAudioSource,
                            shotGO.GetComponent<ParticleSystem>(),
                            _gunSoundResource,
                            _turret,
                            SHOT_VOLUME);
                    _fireRange =
                            turretConfig.Howitzer.FireRange * Constants.MAP_SCALE;
                }
                else if (turretConfig.Cannon.FireRange != 0)
                {
                    GameObject muzzleFlashGO = GameObject.Instantiate(
                            _muzzleFlashResource, _turret);

                    _weapon = new Cannon(
                            turretConfig.Cannon,
                            shotAudioSource,
                            shotGO.GetComponent<ParticleSystem>(),
                            _gunSoundResource,
                            muzzleFlashGO.GetComponent<ParticleSystem>(),
                            SHOT_VOLUME);
                    _fireRange =
                            turretConfig.Cannon.FireRange * Constants.MAP_SCALE;
                }
                else
                {
                    Debug.LogError("Couldn't create a weapon in a turret without children. " +
                            "No weapon specified in the config?");
                }
            }
        }