Esempio n. 1
0
    public Projectile SpawnProjectile(Vector2 pPosition, Player pOwner, ProjectileConfig pConfig, EDirection pDirection = EDirection.None)
    {
        Projectile newProjectile = InstanceFactory.Instantiate(prefab.gameObject, pPosition).GetComponent <Projectile>();

        newProjectile.Spawn(pOwner, pConfig, pDirection);
        return(newProjectile);
    }
Esempio n. 2
0
 void Awake()
 {
     projectileConfig          = new ProjectileConfig();
     projectileConfig.speed    = 40f;
     projectileConfig.lifetime = 4f;
     projectileConfig.maxScale = 1f;
 }
Esempio n. 3
0
    public LevelConfig()
    {
        WorldScreenHeight = Camera.main.orthographicSize * 2f;
        WorldScreenWidth  = WorldScreenHeight / Screen.height * Screen.width;

        PlayerConfig       = new PlayerConfig();
        PlayerConfig.Scale = WorldScreenWidth * PlayerConfig.Scale;
        PlayerConfig.Speed = WorldScreenWidth * PlayerConfig.Speed;

        LocationConfig        = new LocationConfig();
        LocationConfig.Height = WorldScreenHeight * 2 * LocationConfig.Height;
        LocationConfig.Width  = WorldScreenWidth * 2 * LocationConfig.Width;

        CameraConfig            = new CameraConfig();
        CameraConfig.BorderMove = 1 - 2 * CameraConfig.BorderMove;

        EnemyConfig                = new EnemyConfig();
        EnemyConfig.Scale          = WorldScreenWidth * EnemyConfig.Scale;
        EnemyConfig.Speed          = WorldScreenWidth * EnemyConfig.Speed;
        EnemyConfig.AggroRadius    = WorldScreenWidth * EnemyConfig.AggroRadius;
        EnemyConfig.BounceDistance = WorldScreenWidth * EnemyConfig.BounceDistance;

        ProjectileConfig        = new ProjectileConfig();
        ProjectileConfig.Width  = WorldScreenWidth * ProjectileConfig.Width;
        ProjectileConfig.Height = WorldScreenWidth * ProjectileConfig.Height;
        ProjectileConfig.Speed  = WorldScreenWidth * ProjectileConfig.Speed;
    }
Esempio n. 4
0
    /// <summary>
    /// Called on owner and image side
    /// </summary>
    public void SetSpawn(Vector2 pProjectileDirection, EWeaponId pId, EDirection pPlayerDirection)
    {
        SetActive(true);         //has to be called before animator.SetFloat

        //projectile type is based on weapon
        //their condition in animator must match the weapon id
        const string ANIM_KEY_WEAPON = "weapon";

        animator.SetFloat(ANIM_KEY_WEAPON, (int)pId);

        config = brainiacs.ItemManager.GetProjectileConfig(pId);

        boxCollider2D.size    = config.Visual.GetCollider().size;
        boxCollider2D.offset  = config.Visual.GetCollider().offset;
        boxCollider2D.enabled = false;

        Direction = pProjectileDirection;

        transform.Rotate(Utils.GetRotation(pPlayerDirection, 180));

        isInited = true;

        game.ProjectileManager.RegisterProjectile(this);

        Photon.Send(EPhotonMsg.Projectile_Spawn, pProjectileDirection, pId, pPlayerDirection);
    }
Esempio n. 5
0
 public ProjectilePool(ProjectileConfig config, IPlayer player, float size)
 {
     _size = size;
     _projectilePosition = player.View.transform;
     _poolSize           = config.PoolSize;
     _projectileFactory  = new ProjectileFactory(config);
 }
Esempio n. 6
0
        private static void LoadProjectileConfig(DataFormat dataFormat)
        {
            ProjectileConfigDict.Clear();

            DirectoryInfo di = new DirectoryInfo(ProjectileConfigFolder_Build);

            if (di.Exists)
            {
                foreach (FileInfo fi in di.GetFiles("*.config", SearchOption.AllDirectories))
                {
                    byte[]           bytes  = File.ReadAllBytes(fi.FullName);
                    ProjectileConfig config = SerializationUtility.DeserializeValue <ProjectileConfig>(bytes, dataFormat);
                    if (ProjectileConfigDict.ContainsKey(config.ProjectileName))
                    {
                        Debug.LogError($"投掷物重名:{config.ProjectileName}");
                    }
                    else
                    {
                        ProjectileConfigDict.Add(config.ProjectileName, config);
                    }
                }
            }
            else
            {
                Debug.LogError("投掷物表不存在");
            }
        }
Esempio n. 7
0
    protected override void DoWeaponBehavior()
    {
        BowWeaponConfig  bowConfig           = m_WeaponConfig as BowWeaponConfig;
        ProjectileConfig bowProjectileConfig = bowConfig.GetProjectileConfig();

        GameObject spawnedProjectile = Instantiate(bowProjectileConfig.GetProjectilePrefab(), transform.position, m_WeaponOwner.transform.rotation);
    }
Esempio n. 8
0
    public void Init(ProjectileConfig projectileConfig, Vector2 direction, Vector2 newPosition, Transform origin)
    {
        config = projectileConfig;
        spriteRenderer.sprite = config.RealWorldSprite;
        transform.position    = newPosition;

        if (projectileConfig.Mine)
        {
            transform.SetParent(GameManager.main.WorldParent);
            SoundManager.main.PlaySound(SoundType.C4Plant);
        }
        else if (projectileConfig.Melee)
        {
            transform.SetParent(origin);
            transform.rotation = origin.rotation;
            myDirection        = direction;
            SoundManager.main.PlaySound(SoundType.SwingBat);
        }
        else
        {
            transform.SetParent(GameManager.main.WorldParent);
            Shoot(direction);
            myDirection = direction;
        }
    }
Esempio n. 9
0
 public void AddProjectile(EWeaponId pWeapon, ProjectileConfig pConfig)
 {
     if (allProjectiles.ContainsKey(pWeapon))
     {
         return;
     }
     allProjectiles.Add(pWeapon, pConfig);
 }
Esempio n. 10
0
    //protected override void Awake()
    //{
    //	//projectile has to be registered so we know its config.
    //	//it is the same as Curie basic (but can be changed in P_Projectile animator and config)
    //	brainiacs.ItemManager.AddProjectile(EWeaponId.Special_Curie, projectile);

    //	base.Awake();

    //}

    protected override void OnInit()
    {
        projectile = brainiacs.ItemManager.GetProjectileConfig(EWeaponId.Special_Curie);
        if (projectile == null)
        {
            Debug.LogError("SpecialCurieTruck projectile not found");
        }
        Physics2D.IgnoreCollision(boxCollider2D, owner.Collider);
    }
Esempio n. 11
0
    public override void ApplyAbilityEffect()
    {
        ProjectileConfig projectileConfig = (m_AbilityConfig as SlowingShotAbilityConfig).GetProjectileConfig();

        //REMEMBER TO REMOVE GETPROJECTILETOSPAWN
        GameObject spawnedProjectile = Instantiate(projectileConfig.GetProjectilePrefab(), transform.position, transform.rotation);

        projectileConfig.SetupProjectile(spawnedProjectile);
    }
Esempio n. 12
0
    public static ProjectileConfig Instance()
    {
        if (null == mProjectileCfg)
        {
            mProjectileCfg = new ProjectileConfig();
        }

        return mProjectileCfg;
    }
Esempio n. 13
0
 public void Set(ProjectileConfig config, Entity entity, Vector3 target, Vector3 spawnPos, Quaternion spawnRot, ActionFx actionFx)
 {
     SourcePrefab = config.Prefab;
     _config      = config;
     _entity      = entity;
     _target      = target;
     _spawnPos    = spawnPos;
     _spawnRot    = spawnRot;
     _actionFx    = actionFx;
 }
Esempio n. 14
0
        public static Projectile CreateProjectile(string name, ProjectileDef def, Character owner)
        {
            ProjectileConfig config        = ConfigReader.Parse <ProjectileConfig>(FileReader.Read("Projectiles/" + name + "/" + name + ".def"));
            ActionsConfig    actionsConfig = ConfigReader.Parse <ActionsConfig>(FileReader.Read(config.action));

            config.SetActions(actionsConfig.actions.ToArray());
            Projectile pro = new Projectile(def, config, owner);

            return(pro);
        }
Esempio n. 15
0
    public void Attack(ProjectileConfig _config, WeaponController _parent, CharacterController _character, bool _isFromPlayer = false)
    {
        TimeManager.Instance.onLateUpdate += Instance_OnLateUpdate;
        character            = _character;
        weapon               = _parent;
        configData           = _config;
        isFromPlayer         = _isFromPlayer;
        transform.position   = weapon.transform.position;
        transform.localScale = Vector3.one;

        //transform.forward = character.transform.forward;
        isAttacking = true;
    }
Esempio n. 16
0
 public void Instantiate(ProjectileConfig config)
 {
     this.config = config;
     rb          = GetComponent <Rigidbody2D>();
     collider    = GetComponent <Collider2D>();
     this.config = config;
     audioSource = GetComponent <AudioSource>();
     if (ps != null)
     {
         ps.Play();
     }
     BOUNCE_LAYER = LayerMask.NameToLayer("MagicBounce");
 }
Esempio n. 17
0
    /// <summary>
    /// Hero basic projectile info is in hero weapon config
    /// </summary>
    public ProjectileWeaponInfo(HeroBasicWeaponConfig pConfig) : this()
    {
        Projectile = pConfig.Projectile;

        //CHANGE: hero projectiles may differ

        //Projectile.Visual = pConfig.ProjectileVisual;

        //Projectile.Damage = 5;
        //Projectile.Dispersion = 0.5f;
        //Projectile.Speed = 2;

        //Projectile.WeaponId = pConfig.Id;
    }
Esempio n. 18
0
        public static void SpawnProjectile(Entity owner, ProjectileConfig config, Vector3 target, Vector3 spawnPos, Quaternion spawnRot, ActionFx actionFx = null)
        {
            var entity = Main.GetProjectile(config);

            entity.ParentId = owner.Id;
            var projectileEvent = _loadPool.New();

            if (config.Type == ProjectileType.SpriteAnimation)
            {
                config.Animation.LoadAsset();
            }
            projectileEvent.Set(config, entity, target, spawnPos, spawnRot, actionFx);
            ItemPool.Spawn(projectileEvent);
        }
Esempio n. 19
0
    public void Initialize(ProjectileConfig config, ProjectilePool pool)
    {
        Speed    = config.Speed;
        Width    = config.Width;
        Height   = config.Height;
        LifeTime = config.LifeTime;

        _config = config;
        _pool   = pool;

        float ratioScaleH = _config.Height / GetComponent <SpriteRenderer>().sprite.bounds.size.y;
        float ratioScaleW = _config.Width / GetComponent <SpriteRenderer>().sprite.bounds.size.x;

        transform.localScale = new Vector3(ratioScaleW, ratioScaleH, 1);
    }
Esempio n. 20
0
 public void TakeDamage(ProjectileConfig projectileConfig)
 {
     followPlayer.GetHit();
     health -= projectileConfig.Damage;
     if (health <= 0)
     {
         Debug.Log("Killing enemy: " + gameObject);
         if (!dead)
         {
             dead = true;
             GameManager.main.KillEnemy(projectileConfig);
             Destroy(gameObject);
         }
     }
     SoundManager.main.PlaySound(SoundType.EnemyHit);
 }
Esempio n. 21
0
 public void TakeDamage(ProjectileConfig projectileConfig, Vector2 pushBack)
 {
     health -= projectileConfig.Damage;
     followPlayer.GetPushed();
     followPlayer.GetHit();
     rb.AddForce(pushBack * 10f, ForceMode.Impulse);
     if (health <= 0)
     {
         if (!dead)
         {
             dead = true;
             GameManager.main.KillEnemy(projectileConfig);
             Destroy(gameObject);
         }
     }
     SoundManager.main.PlaySound(SoundType.EnemyHit);
 }
Esempio n. 22
0
		public WeaponThrown SetDefault()
		{
			itemName         = "Unique Name";
			rarity           = "common";
			inventoryIcon    = "inventoryIcon.png";
			image            = "image.png";
			shortdescription = "Description of the weapon.";
			description      = "Name of the weapon";
			ammoUsage        = 1;
			edgeTrigger      = true;
			windupTime       = 1;
			cooldown         = 0.25;
			projectileType   = "Projectile type";
			projectileConfig = new ProjectileConfig(30, 5);

			return this;
		}
Esempio n. 23
0
    public void Initialize(PlayerConfig playerConfig, ProjectileConfig projectileConfig)
    {
        Speed       = playerConfig.Speed;
        HealthPoint = playerConfig.HealthPoint;
        _immuneTime = playerConfig.ImmuneTime;
        _fireВelay  = playerConfig.FireDelay;

        GameObject gameObject = Object.Instantiate(Resources.Load("Prefabs/Player")) as GameObject;

        View = gameObject.GetComponent <PlayerView>();
        View.Initialize(this);

        float heightInPixels = gameObject.GetComponent <SpriteRenderer>().bounds.size.y;

        gameObject.transform.localScale = new Vector3(playerConfig.Scale / heightInPixels, playerConfig.Scale / heightInPixels, 1);

        _projectilePool = new ProjectilePool(projectileConfig, this, playerConfig.Scale);
        _projectilePool.Initialize();
    }
Esempio n. 24
0
    public void KillEnemy(ProjectileConfig projectile)
    {
        numberOfEnemies -= 1;
        if (numberOfEnemies <= 0)
        {
            inGame = false;
            wellDoneScreen.SetActive(true);
            if (config.CurrentLevel.NextLevel == null)
            {
                txtNicelyDone.text = "The end!";
            }

            /*
             * InventoryManager.main.ResetHealth();
             * InventoryManager.main.ResetPurchasedItems();
             * InventoryManager.main.ProcessPurchasedItems();
             * InventoryManager.main.UpdateHealth();
             * UIShop.main.SetCurrency(InventoryManager.main.GetHealth());*/
        }
    }
Esempio n. 25
0
    /// <summary>
    /// Called only at owner side
    /// </summary>
    public void Spawn(Player pOwner, ProjectileConfig pConfig, EDirection pDirection = EDirection.None)
    {
        Owner = pOwner;
        //Network.Init(this);

        //projectile type is based on weapon
        //their condition in animator must match the weapon id
        //animator.SetFloat(ANIM_KEY_WEAPON, (int)pConfig.WeaponId);

        //owner == null => it is remote projectile and has to have direction set
        if (pDirection == EDirection.None && !pOwner)
        {
            Debug.LogError("Projectile doesnt have owner or direction set");
        }

        //if direction is not specified, use players current direction
        EDirection direction = pDirection == EDirection.None ?
                               pOwner.Movement.CurrentDirection : pDirection;

        Vector2 projectileDirection = GetDirectionVector(direction, pConfig.Dispersion);

        SetSpawn(projectileDirection, pConfig.WeaponId, direction);

        //config = pConfig;
        boxCollider2D.enabled = true;

        //pOwner => local projectile, else => remote -> dont detect collisions
        if (pOwner)
        {
            Physics2D.IgnoreCollision(GetComponent <Collider2D>(), pOwner.Movement.PlayerCollider);
            //todo: call UpdateOrderInLayer after network message is received?
            UpdateOrderInLayer(pOwner);
        }
        else
        {
            boxCollider2D.enabled = false;
        }


        boxCollider2D.enabled = true;
    }
Esempio n. 26
0
    public void UpdateTier(int tier)
    {
        tier += 1;
        ProjectileConfig config = shooter.Config.GetProjectileConfig(tier);

        if (config == null)
        {
            txtCost.text   = "-";
            maxTierReached = true;
            DisableButton();
        }
        else
        {
            cost         = config.Cost;
            txtCost.text = cost.ToString();
            if (cost > currentMana)
            {
                DisableButton();
            }
        }
    }
Esempio n. 27
0
    public void Shoot(Vector2 direction)
    {
        if (cooldownTimer > 0f || UIManager.main.ShopIsOpen)
        {
            return;
        }
        Projectile projectile = GetProjectile();

        projectileConfig = config.GetProjectileConfig(tier);
        projectile.Instantiate(projectileConfig);

        if (projectileContainer != null)
        {
            projectile.transform.SetParent(projectileContainer);
        }

        projectile.transform.position = transform.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        projectile.transform.rotation = Quaternion.Euler(0, 0, angle);
        projectile.Shoot(direction);
        UpdateCooldown(projectileConfig.Cooldown);
    }
Esempio n. 28
0
        private static void ExportProjectileConfig(DataFormat dataFormat)
        {
            string folder = ProjectileConfigFolder_Build;

            if (Directory.Exists(folder))
            {
                Directory.Delete(folder, true);
            }
            Directory.CreateDirectory(folder);

            DirectoryInfo di = new DirectoryInfo(Application.dataPath + DesignRoot + ProjectileConfigFolder_Relative);

            foreach (FileInfo fi in di.GetFiles("*.asset"))
            {
                string relativePath           = CommonUtils.ConvertAbsolutePathToProjectPath(fi.FullName);
                Object configObj              = AssetDatabase.LoadAssetAtPath <Object>(relativePath);
                ProjectileConfigSSO configSSO = (ProjectileConfigSSO)configObj;
                ProjectileConfig    config    = configSSO.ProjectileConfig;
                string path  = folder + configSSO.name + ".config";
                byte[] bytes = SerializationUtility.SerializeValue(config, dataFormat);
                File.WriteAllBytes(path, bytes);
            }
        }
Esempio n. 29
0
 public Projectile(ProjectileDef def, ProjectileConfig config, Character owner) : base(config, owner)
 {
     this.projDef = def;
     Init();
 }
Esempio n. 30
0
 public Projectile(ProjectileConfig config)
 {
     m_config = config;
 }
Esempio n. 31
0
 public void SetConfig(ProjectileConfig config, Entity entity)
 {
     SetColor(config.MainColor, config.OffsetColor);
     SetSize(config.Size, config.Length);
 }
Esempio n. 32
0
        private Entity GetProjectile(ProjectileConfig data)
        {
            if (_poolDict.TryGetValue(data.ID, out var stack))
            {
                if (stack.UsedCount > 0)
                {
                    var pooled = stack.Pop();
                    if (pooled != null)
                    {
                        pooled.Pooled = false;
                        return(pooled);
                    }
                }
            }
            else
            {
                stack = new ManagedArray <Entity>(_defaultPool);
                _poolDict.Add(data.ID, stack);
            }
            var entity = GetDefaultEntity(data.ID);

            //var prefab = data.GetValue<string>(DatabaseFields.Model);
            entity.Add(new TypeId(data.ID));
            switch (data.Type)
            {
            default:
            case ProjectileType.Simple:
                break;

            case ProjectileType.SpriteAnimation:
                entity.Add(new CollisionCheckForward(data.CollisionDistance));
                break;

            case ProjectileType.VolumeLaser:
                entity.Add(new CollisionCheckForward(data.CollisionDistance));
                break;
            }
            switch (data.Movement)
            {
            case ProjectileMovement.Forward:
                entity.Add(new ForwardMover());
                break;

            case ProjectileMovement.Arc:
                entity.Add(new ArcMover());
                break;
            }
            entity.Get <DespawnTimer>().Length = data.Timeout;
            entity.Get <MoveSpeed>().Speed     = data.Speed;
            entity.Get <RotationSpeed>().Speed = data.Rotation;
            if (data.ActionFx != null)
            {
                entity.Add(new ActionFxComponent(data.ActionFx));
                if (data.ActionFx.TryGetColor(out var actionColor))
                {
                    entity.Add(new HitParticlesComponent(actionColor));
                }
            }
            if (data.TrailAmount > 0)
            {
                entity.Add(new ParticleTrailComponent(data.TrailAmount, data.TrailFrequency, data.TrailColor, ParticleGravityStatus.Default));
            }
            return(entity);
        }