Example #1
0
    //This looks convoluted because it is slightly. The math on determining a spread division has even/odd exceptions which make it look strange.
    //However, notice how isolated this complexity is. This plus a fire sub ability and a source sub ability make a spreadshot.
    //Change it out for a straight shot or a targeted shot or any kind of shot and you would never notice the difference.
    private void CalculateNextSpreadAngle(ProjectileAbility pa)
    {
        float angleIndexMultiplyer = 0f;

        if (pa.numberOfProjectiles % 2 == 0)//if number of prjectiels is even then begin sending one projectile along calculated divided angles
        {
            float valToCeil = (pa.projectilesFired + 1f) / 2f;
            angleIndexMultiplyer = Mathf.Ceil(valToCeil);
        }
        else
        {
            angleIndexMultiplyer = Mathf.Ceil(pa.projectilesFired / 2f); //if number of projectiles is odd, the first angle is right down the middle
        }

        invertingValue = -invertingValue;                                                                      //flip between positive and negative angle for each new projectile for an even spread. so one at +15 and one at -15

        float sizeOfDivisions = (spreadAngle * 2) / (pa.numberOfProjectiles - 1);                              //Calculate how large is the angle between each projectile

        float angleToFireAt = spreadOrientation + ((angleIndexMultiplyer * sizeOfDivisions) * invertingValue); //actual angle for this projectile

        if (float.IsNaN(angleToFireAt))                                                                        //prevent gimble lock
        {
            angleToFireAt = 180f * invertingValue;
        }

        pa.quatProjectileFireAngle = Quaternion.Euler(0f, 0f, angleToFireAt);
    }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     if (delayOverTime <= Time.time)
     {
         EndProjectileSubAbility();
     }
 }
    public void Launch(ProjectileAbility ability)
    {
        RaycastHit hit;
        Vector3    targetRotation = transform.forward;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f))
        {
            targetRotation = hit.point - projectileSpawnPoint.transform.position;
            targetRotation.Normalize();
        }

        GameObject cloneProjectile = Instantiate(ability.projectileToSpawn, projectileSpawnPoint.position + ability.launchOffSet, transform.rotation);

        Rigidbody cloneRB = cloneProjectile.GetComponent <Rigidbody>();

        cloneRB.AddForce(targetRotation * ability.projectileForce);

        Destroy(cloneProjectile, 5f);

        ProjectileAbilityStats pas = cloneProjectile.GetComponent <ProjectileAbilityStats>();

        pas.force           = ability.projectileForce;
        pas.damage          = ability.damage;
        cloneProjectile.tag = "ability";

        //Add ProjectileAbilityCollisionHandler to projectile?
        System.Action <Collision, GameObject, ProjectileAbilityStats> collisionHandlerFunction = OnCollide;
        var onCollisionScript = cloneProjectile.AddComponent <ProjectileAbilityCollisionHandler>();

        onCollisionScript.PrimeProjectile(collisionHandlerFunction, pas);
    }
Example #4
0
    public override void DoProjectileSubAbility(ProjectileAbility pa)
    {
        if (skip == true)
        {
            skip = false;
            return;
        }
        curPowerPercentage   = curPower / maxPower;
        powerHeat.fillAmount = curPowerPercentage;

        curPower += powerIncreaseSpeed * Time.deltaTime;

        if (curPowerPercentage >= 1f)
        {
            curPower = 0f;
        }

        powerContainerInstance.transform.position = ownerTransform.position + mgDisplayOffset;

        if (MultiInput.GetAButtonDown() && pa.ability.IsCurrentSelectedHero(pa.ability.Owner))
        {
            powerContainerInstance.SetActive(false);
            pa.power = curPower;
            EndProjectileSubAbility();
        }
    }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     if (!curProjectile.activeInHierarchy)
     {
         EndProjectileSubAbility();
     }
 }
Example #6
0
 public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
 {
     spreadOrientation = inspectorSpreadOrientation;
     if (pa.sources[0].transform.right.x == -1f)
     {
         spreadOrientation = 180 - inspectorSpreadOrientation;
     }
 }
Example #7
0
    public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
    {
        GameObject tempProjectile;

        tempProjectile = ProjectileFactory.ProduceProjectile(projectilePrefab, pa.ability, pa.sources[0].position, pa.quatProjectileFireAngle);
        pa.projectilesFired++;
        EndProjectileSubAbility();
    }
Example #8
0
    public static ProjectileAbility CreateProjectileAbility()
    {
        ProjectileAbility asset = ScriptableObject.CreateInstance <ProjectileAbility>();

        AssetDatabase.CreateAsset(asset, GetSelectedPathOrFallback() + "/NewProjectileAbility.asset");
        AssetDatabase.SaveAssets();
        return(asset);
    }
Example #9
0
    public override void DoProjectileSubAbility(ProjectileAbility pa)
    {
        Vector3 rot = pa.ability.Owner.transform.rotation.eulerAngles;

        FlipAngleBasedOnFacing(rot);
        pa.quatProjectileFireAngle = Quaternion.Euler(0f, 0f, projectileFireAngle * dirFlip) * Quaternion.Euler(rot.x, rot.y, rot.z);
        EndProjectileSubAbility();
    }
    public override void DoProjectileSubAbility(ProjectileAbility pa)
    {
        goOfSourcePositions.transform.SetParent(pa.ability.Owner.transform);
        goOfSourcePositions.transform.position = Vector3.zero;
        pa.sources.Add(pa.ability.Owner.transform);

        EndProjectileSubAbility();
    }
Example #11
0
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     if (Time.time >= nextFireTime)
     {
         nextFireTime = Time.time + fireInterval;
         EndProjectileSubAbility();
     }
 }
Example #12
0
    private void Start()
    {
        testAbility = Resources.Load <ProjectileAbility>("FireballAbility");

        // Create json
        //dataList = new AbiliyDataList
        //{
        //    dataList = new List<AbilityData>()
        //};

        //for (int i = 0; i < 5; i++)
        //{
        //    AbilityData data = new AbilityData
        //    {
        //        stats = new AbilityStats
        //        {
        //            cooldown = 1,
        //            manaCost = 1,
        //            dotValue = 1,
        //            duration = 1,
        //            hpValue = 1
        //        },

        //        description = new AbilityDescription
        //        {
        //            name = "Test",
        //            casterTeamName = "Team1"
        //        }
        //    };

        //    dataList.dataList.Add(data);
        //}

        //string jsonString = JsonUtility.ToJson(dataList);
        //Debug.Log(jsonString);

        //testData = AbilityDataCache.GetDataForAbility("Test1");

        //string jsonString = JsonUtility.ToJson(data);
        //Debug.Log(jsonString);


        //string dataString = FileHandler.ReadString("Player");
        //Debug.Log(dataString);
        //data = JsonUtility.FromJson<PlayerData>(dataString);


        //string jsonString = JsonUtility.ToJson(data);
        //Debug.Log(jsonString);
        //FileHandler.WriteString(jsonString, "SelectedAbilitiesConfig");

        //string jsonString = JsonUtility.ToJson(list);
        //Debug.Log(jsonString);

        //List<string> l = new List<string>() { "AAA", "BBB" };
        //string jsonString2 = JsonUtility.ToJson(l);
        //Debug.Log(jsonString2);
    }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     //Fireable and my projectile factory gauruntees that projectile will have a rigidbody. ProjectileFactory is hooked up to my pooler which duplicates the functionality of instantiate,
     //but insures that we wont be endlessly instantiating objects that already exist in deactivated states.
     projectileInstance = ProjectileFactory.ProduceProjectile(projectilePrefab.gameObject, pa.ability, pa.sources[0].position, pa.quatProjectileFireAngle);
     projectileInstance.GetComponent <Rigidbody2D>().AddForce(projectileInstance.transform.right * pa.power, ForceMode2D.Impulse);
     pa.projectilesFired++;
     EndProjectileSubAbility();
 }
 public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
 {
     if (curProjectile == null)
     {
         curProjectile = ProjectileFactory.ProduceProjectile(projectilePrefab, pa.ability);
     }
     curProjectile.transform.position = pa.sources[0].position;
     curProjectile.transform.rotation = pa.quatProjectileFireAngle;
     curProjectile.SetActive(true);
     pa.projectilesFired++;
 }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     if (pa.sources.Count == 0)
     {
         pa.sources.Add(pa.ability.Owner.transform);
     }
     else
     {
         pa.sources[0] = pa.ability.Owner.transform;
     }
     EndProjectileSubAbility();
 }
    public void SetCastersProjectileAbilty(ProjectileAbility projectileAbility)
    {
        castersProjectileAbility = projectileAbility;

        ScriptableProjectileAbility scriptableProjectile = (ScriptableProjectileAbility)projectileAbility.Ability;

        damage          = scriptableProjectile.Damage;
        initialForce    = scriptableProjectile.InitialForce;
        gravityAffected = scriptableProjectile.GravityAffected;
        projectileRigidbody.useGravity = gravityAffected;
        RangeCutoff = scriptableProjectile.Range;
    }
Example #17
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        ProjectileAbility script = (ProjectileAbility)target;

        script.residualAOEField = EditorGUILayout.Toggle("AOE Field", script.residualAOEField);
        if (script.residualAOEField)
        {
            script.residualAOEDamage   = EditorGUILayout.IntField("Residual AOE Damage", script.residualAOEDamage);
            script.residualAOEDuration = EditorGUILayout.FloatField("Residual AOE Duration", script.residualAOEDuration);
            script.residualAOEPrefab   = EditorGUILayout.ObjectField("Residual AOE Prefab", script.residualAOEPrefab, typeof(GameObject), true) as GameObject;
        }
    }
Example #18
0
    private void Awake()
    {
        reflect = GetComponentInChildren <ReflectAbility>();
        Assert.IsNotNull(reflect, "Reflect ability was not found.");

        dash = GetComponentInChildren <DashAbility>();
        Assert.IsNotNull(dash, "Dash ability was not found.");

        projectile = GetComponentInChildren <ProjectileAbility>();
        Assert.IsNotNull(projectile, "Projectile ability was not found.");

        chargeManager = GetComponent <ChargeManager>();
        Assert.IsNotNull(chargeManager, "ChargeManager was not found.");
    }
Example #19
0
    protected override void Start()
    {
        base.Start();

        abilityMap = new Dictionary <string, Ability>();

        abilityMap["Fire1"] = new ProjectileAbility(
            name: "Fireball",
            coolDown: fireballCoolDown,
            character: GetComponent <Character>(),
            fireballObj: fireballObj,
            damage: fireballDamage,
            launchSpeed: fireballLaunchSpeed,
            range: fireballRange
            );
    }
    public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
    {
        reported = 0;


        if (projectiles.Count == 0)
        {
            GameObject tempProjectile;
            for (int i = 0; i < pa.numberOfProjectiles; i++)
            {
                tempProjectile   = ProjectileFactory.ProduceProjectile(projectilePrefab.gameObject, pa.ability);
                subbedProjectile = tempProjectile.GetComponent <EffectOnContact>();
                subbedProjectile.SubscribeToObjectsHit(ReceiveObjectsHit);

                tempProjectile.transform.position = pa.sources[0].position;
                projectiles.Add(tempProjectile);
                pa.projectilesFired++;
            }
        }
        ab = pa.ability;
    }
Example #21
0
    public override void DoProjectileSubAbility(ProjectileAbility pa)
    {
        if (clockwise == true)
        {
            invertingValue = -1f;
        }
        else
        {
            invertingValue = 1f;
        }

        float curAngleAmount = ((spreadAngle * 2) / (pa.numberOfProjectiles - 1)) * pa.projectilesFired * invertingValue;

        float startingEdgeOfCone = projectileFireAngle - spreadAngle * invertingValue;

        float angleToFireAt = startingEdgeOfCone + curAngleAmount;

        pa.quatProjectileFireAngle = Quaternion.Euler(0f, 0f, angleToFireAt);

        EndProjectileSubAbility();
    }
Example #22
0
    public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
    {
        ownerTransform = pa.ability.Owner.transform;

        Image[] images;
        if (powerContainerInstance == null)
        {
            powerContainerInstance = pa.ability.InstantiateInWorldSpaceCanvas(powerContainer, ownerTransform.position);
            images = powerContainerInstance.GetComponentsInChildren <Image>();
            foreach (Image im in images)
            {
                if (im.fillMethod == Image.FillMethod.Vertical)
                {
                    powerHeat = im;
                }
            }
        }
        skip = true;

        powerContainerInstance.SetActive(true);
        curPower = 0f;
    }
Example #23
0
        public void Visit(ProjectileAbility ability)
        {
            var vars = new Var(AComponentType.LevelKey, this.level).Get;

            this.range        = int.MaxValue;
            this.isProjectile = true;
            this.targetColony = true;
            this.targetShips  = true;

            this.firePower        = ability.FirePower.Evaluate(vars);
            this.accuracy         = ability.Accuracy.Evaluate(vars);
            this.armorEfficiency  = ability.ArmorEfficiency.Evaluate(vars);
            this.shieldEfficiency = ability.ShieldEfficiency.Evaluate(vars);
            this.planetEfficiency = ability.PlanetEfficiency.Evaluate(vars);

            this.ammo            = ability.Ammo.Evaluate(vars);
            this.speed           = ability.Speed.Evaluate(vars);   //TODO(v0.8) include player techs
            this.projectileImage = ability.ProjectileImage;

            this.splashMaxTargets       = ability.SplashMaxTargets.Evaluate(vars);
            this.splashFirePower        = ability.SplashFirePower.Evaluate(vars);
            this.splashArmorEfficiency  = ability.SplashArmorEfficiency.Evaluate(vars);
            this.splashShieldEfficiency = ability.SplashShieldEfficiency.Evaluate(vars);
        }
 public override void DoInitialProjectileSubAbility(ProjectileAbility pa)
 {
     pa.ability.BattleActorView.StartFlash(numberOfFlashes, intervalBetweenFlashes);
     delayOverTime = Time.time + delay;
 }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     //GameObject.Instantiate(projectilePrefab, pa.sources[0].position, pa.quatProjectileFireAngle);
 }
Example #26
0
 public virtual void DoFinishProjectileSubAbility(ProjectileAbility pa)
 {
 }
Example #27
0
 public virtual void DoProjectileSubAbility(ProjectileAbility projectileAbility)
 {
 }
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     pa.quatProjectileFireAngle = Quaternion.Euler(0f, 0f, projectileFireAngle);
     EndProjectileSubAbility();
 }
Example #29
0
 // Use this for initialization
 void Start()
 {
     fireball = Instantiate(fireball);         //We just copy the settings file.
     movement = GetComponent <Movement>();
 }
Example #30
0
 public override void DoProjectileSubAbility(ProjectileAbility pa)
 {
     CalculateNextSpreadAngle(pa);
     EndProjectileSubAbility();
 }