Exemplo n.º 1
0
    /**
     * Apply a given turn effect
     *
     * Arguments
     * - TurnEffect effect - The turn effect to apply
     */
    void applyTurnEffect(Effect effect)
    {
        Stat stat; // The stat to effect
        int mode; // The mode of this turn effect

        if (effect.TurnsRemaining() == 0) { // Remove turn effect
            DetachTurnEffect(effect);
            return;
        }

        if (effect.IsAppliedPerTurn()) { // Apply per turn
            switch (effect.GetTurnEffectType()) {
            case TurnEffectType.STATMULTIPLIEREFFECT: // Stat multiplier effect
                stat = effect.GetStatAffected();
                mode = effect.GetMode();
                Debug.LogWarning("Stat affected: " + EnumsToString.ConvertStatEnum(stat));
                Debug.LogWarning("Previous value: " + playerClass.GetStat(stat));
                switch (mode) {
                case 0: // Increment
                    playerClass.IncreaseStatMultiplierValue(stat, effect.GetValue());
                    break;
                case 1: // Set stat
                    playerClass.SetMultiplierStat(stat, effect.GetValue());
                    break;
                case 2: // Decrement
                    playerClass.DecreaseStatMultiplierValue(stat, effect.GetValue());
                    break;
                default:
                    throw new System.NotSupportedException("Invalid mode");
                }
                Debug.LogWarning("Current value: " + playerClass.GetStat(stat));
                break;
            case TurnEffectType.STATEFFECT: // Stat effect
                stat = effect.GetStatAffected();
                mode = effect.GetMode();
                Debug.LogWarning("Stat affected: " + EnumsToString.ConvertStatEnum(stat));
                Debug.LogWarning("Previous value: " + stats[stat]);
                switch (mode) {
                case 0: // Increment to stat
                    IncreaseStatValue(stat, effect.GetValue());
                    break;
                case 1: // Set stat
                    SetStatValue(stat, effect.GetValue());
                    break;
                case 2: // Multiply stat
                    SetStatValue(stat, stats[stat] * effect.GetValue());
                    break;
                default: // Invalid mode. Do nothing
                    throw new System.NotSupportedException("Invalid mode");
                }
                Debug.LogWarning("Current value: " + stats[stat]);
                break;
            case TurnEffectType.MATERIALEFFECT:
                // Only replace material if not already set
                if (!PlayerObject.GetComponentInChildren<Renderer>().material.Equals(effect.GetMaterial())) {
                    GetComponent<PhotonView>().RPC("SetNewMaterial", PhotonTargets.All,
                            new object[] {
                                effect.GetMaterialPath()
                            }
                    );
                }
                break;// Change material
            case TurnEffectType.COMPONENTEFFECT: // Component effect. Handled by component
                break;
            default: break; // Unknown
            }
        }

        effect.ReduceTurnsRemaining();
    }