Inheritance: MonoBehaviour
Example #1
0
    public IEnumerator UsePotionSequence()
    {
        battleState = BattleState.TakingAction;
        Services.battleMenuManager.AllowInput(false);

        // I guess play an animation where the player uses a potion or whatever and then you know like sparkly particles etc etc it'll look real cool yeah
        yield return(new WaitForSeconds(0.75f));

        // Use the thingy majingy :-)
        Services.potionManager.Use();

        for (int i = 0; i < battleSelves.Length; i++)
        {
            DamageNumber healNumber = Instantiate(damageNumberPrefab).GetComponent <DamageNumber>();
            healNumber.transform.position  = battleSelves[i].transform.position;
            healNumber.transform.position += damageNumberOffset;
            healNumber.Initialize(Services.potionManager.healthValue, DamageNumber.HitType.Heal);
        }

        yield return(new WaitForSeconds(0.75f));

        battleState = BattleState.AwaitingInput;
        Services.battleMenuManager.AllowInput(true);

        yield return(null);
    }
Example #2
0
    protected void CreateDamageNumber(int damage)
    {
        GameObject   o  = Instantiate(Resources.Load("Prefabs/UIPrefabs/Damage_Number", typeof(GameObject))) as GameObject;
        DamageNumber dn = o.AddComponent <DamageNumber> ();

        dn.ShowDamageNumber(damage, battleCamera.GetComponent <Camera>(), transform.position, tag == "Player");
    }
Example #3
0
    public void CreateDamageNumber(string number, Transform location)
    {
        DamageNumber instance = Instantiate(damageNumber);

        instance.transform.SetParent(canvas.transform, false);
        instance.setLocation(location);
        instance.SetText(number);
    }
    public static DamageNumber CreateFromPrefab(DamageNumber prefab,
        int amount,
        Vector3 pos,
        DamageNumbers parent)
    {
        var number = Instantiate(prefab);

        pos.x += Random.Range(-JITTER_X, JITTER_X);

        number.GetComponent<Text>().text = amount.ToString();
        number.spawned = Time.time;
        number.transform.SetParent(parent.transform, false);
        number.transform.position = pos;

        return number;
    }
 public void Repool(DamageNumber damageNumber)
 {
     _pool.Enqueue(damageNumber);
 }
Example #6
0
    public IEnumerator AttackSequence()
    {
        battleState = BattleState.TakingAction;
        Services.battleMenuManager.AllowInput(false);

        foreach (BattleSelf battleSelf in battleSelves)
        {
            battleSelf.m_Animator.SetTrigger("Attack Trigger");
        }

        yield return(new WaitForSeconds(1.5f));

        // Show damage numbers
        int deaths = 0;

        foreach (BattleSelf battleSelf in battleSelves)
        {
            // Get damage
            DamageNumber.HitType hitType = DamageNumber.HitType.Normal;
            int damageValue = GetDamageValue(out hitType);

            // Display critical hit effects
            if (hitType == DamageNumber.HitType.Critical)
            {
                // Add more shit here later
            }

            // Test for miss
            if (Services.playerStats.accuracy <= Random.value)
            {
                hitType     = DamageNumber.HitType.Miss;
                damageValue = 0;
            }

            DamageNumber damageNumber = Instantiate(damageNumberPrefab).GetComponent <DamageNumber>();
            damageNumber.transform.position = battleSelf.transform.position + damageNumberOffset;
            damageNumber.Initialize(damageValue, hitType);
            battleSelf.HP -= damageValue;

            if (battleSelf.HP <= 0)
            {
                deaths++;
            }
        }

        // If at least one battleSelf has died.
        if (deaths > 0)
        {
            // If both players die, trigger their death animation without spawning a corpse.
            foreach (BattleSelf battleSelf in battleSelves)
            {
                if (battleSelf.HP <= 0)
                {
                    if (deaths == 2)
                    {
                        battleSelf.Die(false);
                    }
                    else
                    {
                        battleSelf.Die(true);
                    }
                }
            }

            yield return(new WaitForSeconds(2.5f));

            StartCoroutine(BattleEndSequence());
            yield return(null);
        }
        else
        {
            battleState = BattleState.AwaitingInput;
            Services.battleMenuManager.AllowInput(true);
        }

        yield return(null);
    }
    // Static class devoted to methods that were originally in SyncGameState that involve the interpreting & representing of byte data into objects.


    public static object interpretObject(byte[] data, ref int bytePosition, object type, SyncGameState sgg, int tickNumber, bool isPlayerOwner)
    {
        object returnObject = null;

        if (type is float)
        {
            returnObject  = BitConverter.ToSingle(data, bytePosition);
            bytePosition += 4;
        }
        else if (type is int)
        {
            returnObject  = BitConverter.ToInt32(data, bytePosition);
            bytePosition += 4;
        }
        else if (type is short)
        {
            returnObject  = BitConverter.ToInt16(data, bytePosition);
            bytePosition += 2;
        }
        else if (type is byte)
        {
            returnObject  = data [bytePosition];
            bytePosition += 1;
        }
        else if (type is Vector3)             // Equals feels like good usage here.
        {
            returnObject  = OperationNetwork.getVector3(data, bytePosition);
            bytePosition += 12;
        }
        else if (type is bool)
        {
            returnObject  = BitConverter.ToBoolean(data, bytePosition);
            bytePosition += 1;
        }
        else if (type is Quaternion)
        {
            returnObject  = OperationNetwork.getQuaternion(data, bytePosition);
            bytePosition += 16;
        }
        else if (type is string)
        {
            // All strings have max 255 length.
            // Just because.
            byte length = data [bytePosition];
            bytePosition += 1;

            returnObject  = Encoding.ASCII.GetString(data, bytePosition, length);
            bytePosition += length;
        }
        else if (type is float[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new float[length];
            for (int i = 0; i < length; i++)
            {
                ((float[])returnObject) [i] = BitConverter.ToSingle(data, bytePosition);
                bytePosition += 4;
            }
        }
        else if (type is Vector3[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new Vector3[length];
            for (int i = 0; i < length; i++)
            {
                ((Vector3[])returnObject) [i] = OperationNetwork.getVector3(data, bytePosition);
                bytePosition += 12;
            }
        }
        else if (type is Vector3[][])
        {
            // Hitscan data:
            byte length = data [bytePosition];
            bytePosition += 1;
            returnObject  = new Vector3[length][];
            for (int i = 0; i < length; i++)
            {
                ((Vector3[][])returnObject) [i] = (Vector3[])interpretObject(data, ref bytePosition, new Vector3[0], null, -1, false);
            }
        }
        else if (type is SyncableType)
        {
            returnObject = ((SyncableType)type).createThis(data, ref bytePosition, sgg, tickNumber, isPlayerOwner);
        }
        else if (type is DamageNumber[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new DamageNumber[length];
            for (int i = 0; i < length; i++)
            {
                ((DamageNumber[])returnObject) [i] = new DamageNumber(data, ref bytePosition);
            }
        }
        else if (type is byte[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;
            returnObject  = new byte[length];
            for (int i = 0; i < length; i++)
            {
                ((byte[])returnObject) [i] = data[bytePosition];
                bytePosition += 1;
            }
        }
        return(returnObject);
    }