Beispiel #1
0
    public void Print(CRCombatType combatType)
    {
        int[] precedenceTable = new int[] { (int)CRCombatEvent.HIT };

        switch (combatType)
        {
        case CRCombatType.MELEE:
            precedenceTable = _meleePrecedence;
            break;

        case CRCombatType.MAGIC:
            precedenceTable = _magicPrecedence;
            break;
        }

        Debug.Log ("-----CombatTable-----");

        for (int i=0; i<precedenceTable.Length; i++)
        {
            int combatEvent = precedenceTable[i];

            if (_chances[combatEvent] != 0)
                Debug.Log (((CRCombatEvent)combatEvent).ToString() + ": " + _chances[combatEvent]);
        }

        Debug.Log ("--------------------");
    }
Beispiel #2
0
    public CRCombatEvent Roll(CRCombatType combatType)
    {
        int[] precedenceTable = new int[] { (int)CRCombatEvent.HIT };

        switch (combatType)
        {
        case CRCombatType.MELEE:
            precedenceTable = _meleePrecedence;
            break;

        case CRCombatType.MAGIC:
            precedenceTable = _magicPrecedence;
            break;
        }

        float roll = UnityEngine.Random.value;

        float accumulated = 0;
        for (int i=0; i<precedenceTable.Length; i++)
        {
            int combatEvent = precedenceTable[i];

            accumulated += _chances[combatEvent];
            if (accumulated > 0 && roll <= accumulated)
                return (CRCombatEvent)combatEvent;
        }

        return CRCombatEvent.HIT;
    }