Example #1
0
    //add element preview of a group of value modifications
    void addPreviewValueChanges(modifierGroup modsGroup, bool randomIndependent = true)
    {
        if (modsGroup.valueChanges == null)
        {
            Debug.LogError("Can not show preview, modifier group is null.");
            return;
        }

        foreach (resultModifier rm in  modsGroup.valueChanges)
        {
            resultModifierPreview rmp = new resultModifierPreview();
            rmp.resultModification = new resultModifier();

            switch (rm.modificationType)
            {
            case E_ModificationType.add:
                rmp.resultModification.valueAdd     = rm.valueAdd;
                rmp.modificationIsRandomIndependant = randomIndependent;
                break;

            case E_ModificationType.set:
                ValueScript vs = valueManager.instance.getFirstFittingValue(rm.modifier);
                rmp.resultModification.valueAdd     = rm.valueSet - vs.value;
                rmp.modificationIsRandomIndependant = randomIndependent;
                break;

            case E_ModificationType.addRandInt:
            case E_ModificationType.setRandInt:
            case E_ModificationType.addRandom:
            case E_ModificationType.setRandom:
            default:
                rmp.resultModification.valueAdd     = 0f;
                rmp.modificationIsRandomIndependant = false;
                break;
            }

            rmp.resultModification.modifier = rm.modifier;

            previewModifiers.Add(rmp);
        }
    }
Example #2
0
    public void DisplayTileValue(ValueToDisplay ToDisplay)
    {
        if (ThisTileType == TileType.LevelStart)
        {
            return;
        }

        if (!TileText)
        {
            TileText = Instantiate(ValueOnCanvas, CanvasObject.transform);
            TileText.SetOwner(this);
        }

        TileText.transform.SetPositionAndRotation(Camera.main.WorldToScreenPoint(transform.position), Quaternion.Euler(new Vector3(0, 0, 0)));

        if (ThisTileType == TileType.LevelEnd)
        {
            TileText.GetComponent <Text>().text = "" + TileValues.FirstValue;
            if (ThisTileRole == TileRoles.Value)
            {
                TileText.GetComponent <Text>().text = "<color=white>" + TileText.GetComponent <Text>().text + "</color>";
            }
            return;
        }

        switch (ToDisplay)
        {
        case ValueToDisplay.Both:
            TileText.GetComponent <Text>().text = "<size=60>" + TileValues.FirstValue + "</size>|" + "<size=30>" + TileValues.SecondValue + "</size>";
            break;

        case ValueToDisplay.First:
            TileText.GetComponent <Text>().text = "" + TileValues.FirstValue;
            break;

        case ValueToDisplay.Second:
            TileText.GetComponent <Text>().text = "" + TileValues.SecondValue;
            break;
        }
    }
 void getVSscript()
 {
     vs = ValueManager.나자신.첫번째피팅값가져오기(valueType);
 }
Example #4
0
 void getVSscript()
 {
     vs = valueManager.instance.getFirstFittingValue(valueType);
 }
Example #5
0
    public static void ComputeResultTypeDependant(result res, bool actualizeFollowUpCard = true)
    {
        switch (res.resultType)
        {
        case resultTypes.simple:
            //If the result is configured as 'simple' just execute the value modifiers.
            executeValueChanges(res.modifiers, actualizeFollowUpCard);
            break;

        case resultTypes.conditional:
            //If the result is configured as 'conditional' validate the conditions and
            //execute the depending modifiers.
            if (AreConditinsForResultMet(res.conditions))
            {
                executeValueChanges(res.modifiersTrue, actualizeFollowUpCard);
            }
            else
            {
                executeValueChanges(res.modifiersFalse, actualizeFollowUpCard);
            }
            break;

        case resultTypes.randomConditions:
            //If the result is configured as 'randomConditions':
            //1. Randomize the borders of predefined value-typ dependencies.
            //2. Validate the new conditions.
            //3. Execute outcome dependent value changes.

            float       rndCResult = 1f;
            ValueScript v          = null;
            foreach (condition c in res.conditions)
            {
                rndCResult = Random.Range(0f, 1f);
                v          = valueManager.instance.getFirstFittingValue(c.value);

                if (v != null)
                {
                    //set the minimum border for the conditon between min and max,
                    //if the real value is over min, the path 'true' is executed
                    c.valueMin = c.valueMin + rndCResult * (c.valueMax - c.valueMin);     // <-This is now really input depending.
                    c.valueMax = 999f;
                }
                else
                {
                    Debug.LogWarning("Missing value type: " + c.value);
                }
            }

            if (AreConditinsForResultMet(res.conditions))
            {
                executeValueChanges(res.modifiersTrue, actualizeFollowUpCard);
            }
            else
            {
                executeValueChanges(res.modifiersFalse, actualizeFollowUpCard);
            }
            break;

        case resultTypes.random:
            //If the result is configured as 'random':
            //Select randomly a modifier-group out of the defined pool and execute the value changes.
            if (res.randomModifiers.Length != 0)
            {
                int rndResult = Random.Range(0, res.randomModifiers.Length);
                executeValueChanges(res.randomModifiers[rndResult], actualizeFollowUpCard);
            }
            else
            {
                Debug.LogWarning("Missing random results-list");
            }
            break;

        default:
            Debug.LogError("Path not reachable?");
            break;
        }
    }
Example #6
0
    //Test a condition for a card. Example condition: draw this card only, if the age (or any other value) inside the game is between 10-16.
    //the methode returns true, if the condition is met. False if not.
    public bool getConditionMet(EventScript.condition cond, bool showDebug = false)
    {
        foreach (ValueScript vs in values)
        {
            //get the matching value for the value
            if (vs.valueType == cond.value)
            {
                //condition evalution is depending on type of condition
                switch (cond.type)
                {
                case EventScript.E_ConditionType.standard:

                    if ((vs.value <= cond.valueMax && vs.value >= cond.valueMin))
                    {
                        if (showDebug == true)
                        {
                            Debug.Log("True: " + cond.valueMin.ToString() + " " + vs.value.ToString() + " " + cond.valueMax.ToString());
                            Debug.Log(vs.gameObject.name);
                        }
                        return(true);
                    }
                    else
                    {
                        if (showDebug == true)
                        {
                            Debug.Log("False: " + cond.valueMin.ToString() + " " + vs.value.ToString() + " " + cond.valueMax.ToString());
                            Debug.Log(vs.gameObject.name);
                        }
                        return(false);
                    }

                //break;
                case EventScript.E_ConditionType.compareValues:

                    //for the value compare the second value (=rValue) is needed.
                    ValueScript rValue = getFirstFittingValue(cond.rValue);

                    //The condition is false, if value was not found.
                    if (rValue == null)
                    {
                        if (showDebug == true)
                        {
                            Debug.LogError("The value '" + cond.rValue.ToString() + "' is null.");
                        }
                        return(false);
                    }

                    //compare value to value depending on compare type
                    switch (cond.compareType)
                    {
                    case EventScript.E_ConditionCompareType.greaterThan:
                        if (vs.value > rValue.value)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ConditionCompareType.greaterThanOrEqual:
                        if (vs.value >= rValue.value)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ConditionCompareType.equals:
                        if (vs.value == rValue.value)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ConditionCompareType.equalsAsInt:
                        if (Mathf.RoundToInt(vs.value) == Mathf.RoundToInt(rValue.value))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ConditionCompareType.lessThan:
                        if (vs.value < rValue.value)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ConditionCompareType.lessThanOrEqual:
                        if (vs.value <= rValue.value)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    break;

                case EventScript.E_ConditionType.items:
                    int itemCnt = Inventory.instance.GetItemCount(cond.item);
                    switch (cond.itemCompareType)
                    {
                    case EventScript.E_ItemCompareType.greaterThan:
                        if (itemCnt > cond.itemCmpValue)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ItemCompareType.lessThan:
                        if (itemCnt < cond.itemCmpValue)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }

                    case EventScript.E_ItemCompareType.equals:
                        if (itemCnt == cond.itemCmpValue)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;

                case EventScript.E_ConditionType.dictionaryEquals:
                    return(GameDictionary.EqualsValue(cond.gamedictionary_key, cond.gamedictionary_comparer));

                default:

                    Debug.LogError("The evaluation type '" + cond.type.ToString() + "' for the condition is not implemented yet.");
                    break;
                }
            }
        }

        return(false);
    }
Example #7
0
 //access for value scripts to register in the manager
 public void registerValueScript(ValueScript vs)
 {
     values.Add(vs);
 }
Example #8
0
    /// <summary>
    /// Enhance a string by replacing place holders with values.
    /// This should be done after translations, else the translation term is not recognized anymore.
    /// To enshure the correct order use 'TranslateAndReplace(string txt)' instead of this method.
    ///
    /// Actual keywords are:
    /// item
    ///     - can be followed by format
    ///     - should not be followed by preview (not supported yet, gives wrong results)
    /// value
    ///     - can be followed by preview, format
    /// dictionary
    ///     - replaces dictionary entry with string, format is not supported
    /// change
    ///     - similar to preview but shows the change of the value
    ///     - value should be declared first
    ///     - can have the parameters:
    ///         * up,down,left,right,add0,add1
    ///     - can differ from value preview because an other method for determing randomness for the value is used
    /// result
    ///     - similar to change but shows the possible result of the value
    ///     - value should be declared first
    ///     - can have the parameters:
    ///         * up,down,left,right,add0,add1
    ///     - can differ from value preview because an other method for determing randomness for the value is used
    /// format
    ///     - can be used every time and defines the formatter of the string cast e.g. '0.0', '##' etc.
    ///
    ///
    /// Examples for place holders:
    ///  {value=army}              -> is replaced by the actual value of army (if defined in value definitions), e.g. 75
    ///  {value=army,format=0.0}   -> is replace like before but with formatting, e.g. 75.0
    ///  {value=army,preview=up}   -> is replaced by the preview for army when swiping up
    ///  {item=sword}              -> is replaced by the number of swords in the inventory
    ///  {dictionary=name}         -> is replaced by the value for the key 'name'.
    /// </summary>
    /// <param name="input">Input string with place holder(s).</param>
    /// <returns>String with replaced parts.</returns>
    public static string ReplaceStringPlaceHolders(string input)
    {
        string output       = string.Copy(input);
        string query        = input;
        string match        = "";
        string matchNoSpace = "";
        string pattern      = @"\{(.*?)\}";

        string[] commandSeqences;
        string[] commandSplit;
        var      matches = Regex.Matches(query, pattern); //e.g. "your army strenth is {army,format=0.0}." returns "army,format=0.0" in the first element (not a string yet)

        foreach (Match m in matches)
        {
            //found a command/place holder
            match = m.Groups[1].ToString();

            //remove space characters
            matchNoSpace = match.Replace(" ", string.Empty);

            commandSeqences = matchNoSpace.Split(',');    //e.g. "army,format=0.0" is split into "army" and "format=0.0"

            //variables resulting from different commands
            string      format = "";
            ValueScript vs     = null;
            bool        valueChangePreviewRequested = false;
            bool        valueResultPreviewRequested = false;
            bool        randomIndependent           = true;
            float       previewValue         = 0f;
            EventScript es                   = null;
            string      SwipeDirectionString = "";
            string      dictionaryValue      = "";
            bool        dictionaryRequested  = false;

            Inventory.C_ItemAmount ia = null;
            int  itemAmount           = 0;
            bool itemAmountRequested  = false;

            //parse the parameters
            foreach (string parameter in commandSeqences)
            {
                commandSplit = parameter.Split('='); //e.g. split "format=0.0" into "format" and "0.0". Can't use ':' here, because this can also be within the string format.
                switch (commandSplit[0])
                {
                case "value":
                    if (commandSplit.Length > 1)
                    {
                        //parse the matching value
                        if (valueDefinitions.values.IsDefined(typeof(valueDefinitions.values), commandSplit[1]))
                        {
                            //matching place holder was found
                            valueDefinitions.values valueType = (valueDefinitions.values)System.Enum.Parse(typeof(valueDefinitions.values), commandSplit[1], true);
                            vs = valueManager.instance.getFirstFittingValue(valueType);
                        }
                        else
                        {
                            //command/place holder is unknown
                            Debug.LogWarning("The value '" + commandSplit[1] + "' for the place holder {" + match + "} is unknown.");
                        }
                    }
                    else
                    {
                        Debug.LogWarning("The keyword 'value' for the place holder {" + match + "} is not followed by a selections, e.g. 'value=years'");
                    }
                    break;

                case "format":
                    if (commandSplit.Length > 1)
                    {
                        format = commandSplit[1];
                    }
                    else
                    {
                        Debug.LogWarning("Command 'format' in text '" + match + "' is not followed by a valid parameter, e.g. format=0.0.");
                    }
                    break;

                case "item":
                    itemAmountRequested = true;
                    if (commandSplit.Length > 1)
                    {
                        //find the matching item
                        if (Inventory.instance != null)
                        {
                            ia = Inventory.instance.GetItemByKey(commandSplit[1]);
                            //command/place holder is unknown
                            if (ia != null)
                            {
                                itemAmount = ia.amount;
                            }
                            else
                            {
                                //if the item is not within the inventory it still can be in the catalog (amount is 0)
                                InventoryItem item = Inventory.instance.GetItemFromCatalogByKey(commandSplit[1]);
                                itemAmount = 0;
                                if (item != null)
                                {
                                    //item is ok an known, amount is 0
                                }
                                else
                                {
                                    Debug.LogWarning("The item '" + commandSplit[1] + "' for the place holder {" + match + "} is unknown.");
                                }
                            }
                        }
                        else
                        {
                            Debug.LogWarning("The item '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no script 'LocalInventory.cs' found in the scene.");
                        }
                    }
                    else
                    {
                        Debug.LogWarning("The keyword 'item' for the place holder {" + match + "} is not followed by a selections, e.g. 'item=sword'");
                    }

                    break;

                case "dict":        /*short writing for dictionary is the same case as */
                case "dictionary":
                    dictionaryRequested = true;
                    dictionaryValue     = GameDictionary.GetValue(commandSplit[1]);
                    break;

                case "change":
                    if (vs != null && commandSplit.Length > 1)
                    {
                        //get the reference to the actual card
                        if (CardStack.instance != null)
                        {
                            if (CardStack.instance.spawnedCard != null)
                            {
                                es = CardStack.instance.spawnedCard.GetComponent <EventScript>();
                                if (es != null)
                                {
                                    SwipeDirectionString = commandSplit[1];
                                    //Debug.Log("Card is " + CardStack.instance.spawnedCard.name);
                                    if (!string.IsNullOrEmpty(SwipeDirectionString))
                                    {
                                        es.computeTextPreview(SwipeDirectionString, vs.valueType, ref previewValue, ref randomIndependent);
                                        valueChangePreviewRequested = true;
                                    }
                                    else
                                    {
                                        Debug.LogWarning("Command 'direction' in text '" + match + "' is not defined yet, e.g. 'direction=left'.");
                                    }
                                }
                                else
                                {
                                    Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no 'EventScrip' attached to the actual spawned card.");
                                }
                            }
                            else
                            {
                                Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no actual spawned card.");
                            }
                        }
                        else
                        {
                            Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no script 'CardStack.cs' found in the scene.");
                        }
                    }
                    else
                    {
                        Debug.LogWarning("The keyword 'preview' for the place holder {" + match + "} is not followed by a selections or no value was defined yet.");
                    }
                    break;

                case "result":
                    if (vs != null && commandSplit.Length > 1)
                    {
                        //get the reference to the actual card
                        if (CardStack.instance != null)
                        {
                            if (CardStack.instance.spawnedCard != null)
                            {
                                es = CardStack.instance.spawnedCard.GetComponent <EventScript>();
                                if (es != null)
                                {
                                    SwipeDirectionString = commandSplit[1];
                                    //Debug.Log("Card is " + CardStack.instance.spawnedCard.name);
                                    if (!string.IsNullOrEmpty(SwipeDirectionString))
                                    {
                                        es.computeTextPreview(SwipeDirectionString, vs.valueType, ref previewValue, ref randomIndependent);
                                        //calculate the result
                                        previewValue += vs.value;
                                        if (previewValue < vs.limits.min)
                                        {
                                            previewValue = vs.limits.min;
                                        }
                                        if (previewValue > vs.limits.max)
                                        {
                                            previewValue = vs.limits.max;
                                        }
                                        valueResultPreviewRequested = true;
                                    }
                                    else
                                    {
                                        Debug.LogWarning("Command 'direction' in text '" + match + "' is not defined yet, e.g. 'direction=left'.");
                                    }
                                }
                                else
                                {
                                    Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no 'EventScrip' attached to the actual spawned card.");
                                }
                            }
                            else
                            {
                                Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no actual spawned card.");
                            }
                        }
                        else
                        {
                            Debug.LogWarning("The preview for value '" + commandSplit[1] + "' for the place holder {" + match + "} can't be searched because there is no script 'CardStack.cs' found in the scene.");
                        }
                    }
                    else
                    {
                        Debug.LogWarning("The keyword 'preview' for the place holder {" + match + "} is not followed by a selections or no value was defined yet.");
                    }
                    break;

                default:
                    Debug.LogWarning("Command '" + commandSplit[0] + "' in place holder '" + match + "' is not recognized.");
                    break;
                }
            }

            //replace the original match
            if (valueChangePreviewRequested == true)
            {
                //replace place holder with change preview
                if (randomIndependent == true)
                {
                    output = output.Replace("{" + match + "}", previewValue.ToString(format));
                }
                else
                {
                    output = output.Replace("{" + match + "}", "?");
                }
            }
            else if (valueResultPreviewRequested == true)
            {
                //replace place holder with result preview
                if (randomIndependent == true)
                {
                    output = output.Replace("{" + match + "}", previewValue.ToString(format));
                }
                else
                {
                    output = output.Replace("{" + match + "}", "?");
                }
            }
            else if (dictionaryRequested == true)
            {
                //repalce place holder with dictionary entry
                output = output.Replace("{" + match + "}", dictionaryValue);
            }
            else if (vs != null)
            {
                //replace place holder with value
                output = output.Replace("{" + match + "}", vs.value.ToString(format));
            }
            else if (itemAmountRequested == true)
            {
                //replace place holder with item amount
                output = output.Replace("{" + match + "}", itemAmount.ToString(format));
            }
            else
            {
                //If nothing matches: replace placeholder with escape-string. User should not see internal structure like {value:....}.
                output = output.Replace("{" + match + "}", "<?>");
            }
        }


        return(output);
    }
Example #9
0
 /// <summary>
 /// 'ValueScript' 스크립트를 리스트에 등록되도록 하는 메서드.
 /// 결과적으로 Game씬의 Values오브젝트 밑의 자식 오브젝트들이 이 리스트에 모두 등록된다.
 /// </summary>
 /// <param name="볼륨스크립트">ValueScript 클래스 타입의 객체</param>
 public void ValueScript리스트에추가(ValueScript 볼륨스크립트)
 {
     볼륨스크립트리스트.Add(볼륨스크립트);
 }
Example #10
0
    //Computation logic for executing a result.
    //Depending on the configuration of the card the corresponding results are selected.
    void computeResult(result res)
    {
        if (res.resultType == resultTypes.simple)
        {
            //If the result is configured as 'simple' just execute the value modifiers.
            executeValueChanges(res.modifiers);
        }
        else if (res.resultType == resultTypes.conditional)
        {
            //If the result is configured as 'conditional' validate the conditions and
            //execute the depending modifiers.
            if (AreConditinsForResultMet(res.conditions))
            {
                executeValueChanges(res.modifiersTrue);
            }
            else
            {
                executeValueChanges(res.modifiersFalse);
            }
        }
        else if (res.resultType == resultTypes.randomConditions)
        {
            //If the result is configured as 'randomConditions':
            //1. Randomize the borders of predefined value-typ dependencies.
            //2. Validate the new conditions.
            //3. Execute outcome dependent value changes.

            float       rndResult = 1f;
            ValueScript v         = null;
            foreach (condition c in res.conditions)
            {
                rndResult = Random.Range(0f, 1f);
                v         = valueManager.instance.getFirstFittingValue(c.value);

                if (v != null)
                {
                    //set the minimum border for the conditon between min and max,
                    //if the real value is over min, the path 'true' is executed
                    c.valueMin = v.limits.min + rndResult * (v.limits.max - v.limits.min);
                    c.valueMax = v.limits.max;
                }
                else
                {
                    Debug.LogWarning("Missing value type: " + c.value);
                }
            }

            if (AreConditinsForResultMet(res.conditions))
            {
                executeValueChanges(res.modifiersTrue);
            }
            else
            {
                executeValueChanges(res.modifiersFalse);
            }
        }
        else if (res.resultType == resultTypes.random)
        {
            //If the result is configured as 'random':
            //Select randomly a modifier-group out of the defined pool and execute the value changes.
            if (res.randomModifiers.Length != 0)
            {
                int rndResult = Random.Range(0, res.randomModifiers.Length);
                executeValueChanges(res.randomModifiers[rndResult]);
            }
            else
            {
                Debug.LogWarning("Missing random results-list");
            }
        }
        else
        {
            Debug.LogError("Path not reachable?");
        }

        foreach (resultModifier rm in  changeValueOnCardDespawn)
        {
            valueManager.instance.changeValue(rm.modifier, rm.valueAdd);
        }

        OnCardDespawn.Invoke();
    }
Example #11
0
 void Awake()
 {
     dir     = GameObject.Find("BattleDirecter");
     csv     = dir.GetComponent <ReadCSV>();
     VScript = dir.GetComponent <ValueScript>();
 }