private void UseItem(Item item, Character targetCharacter)
    {
        targetCharacter.currentHealth -= item.damage;

        //for damageIndicator
        GameObject target;

        if (targetCharacter.team == 0) //friendly
        {
            int targetIndex = friendlyParty.IndexOf(targetCharacter);
            target = friendlyTargets["FriendlyTarget" + (targetIndex + 1)];
        }
        else //enemy
        {
            int targetIndex = enemyParty.IndexOf(targetCharacter);
            target = enemyTargets["EnemyTarget" + (targetIndex + 1)];
        }
        GameObject damageIndicator = Instantiate(damageIndicatorPrefab, target.transform.position, new Quaternion(0, 0, 0, 0));

        cloneList.Add(damageIndicator);
        damageIndicator.transform.SetParent(canvas.transform);
        TextMeshProUGUI textMeshProUGUI = damageIndicator.GetComponent <TextMeshProUGUI>();

        textMeshProUGUI.text = System.Math.Abs(item.damage).ToString();
        if (item.damage > 0)
        {
            textMeshProUGUI.color = new Color(1, 0, 0, textMeshProUGUI.color.a);
        }
        else if (item.damage < 0)
        {
            textMeshProUGUI.color = new Color(0, 1, 0, textMeshProUGUI.color.a);
        }
        else
        {
            textMeshProUGUI.color = new Color(1, 1, 0, textMeshProUGUI.color.a);
        }

        foreach (StatusEffect statusEffect in item.statusEffects)
        {
            targetCharacter.statusEffects.Add(new StatusEffect(statusEffect.name, statusEffect.dot, statusEffect.element, statusEffect.stun, statusEffect.strength, statusEffect.maxTurnsRemaining, statusEffect.currentTurnsRemaining));
        }

        if (item.damage >= 0)
        {
            combatAudio.PlayOneShot(hitSound, 1);
        }
        else
        {
            combatAudio.PlayOneShot(healSound, 1);
        }

        RefreshHealth(targetCharacter);

        StaticStorage.UsePlayerItem(item.name); //reduced the number of items the player has, if 0 are left the item is removed from choices
    }
        public void GetStorageExpression()
        {
            var field   = ObjectMother.GetFieldInfo(attributes: FieldAttributes.Static);
            var storage = new StaticStorage(field);

            var result = storage.CreateStorageExpression(null);

            Assert.That(result, Is.InstanceOf <MemberExpression>());
            var memberExpression = (MemberExpression)result;

            Assert.That(memberExpression.Member, Is.SameAs(field));
            Assert.That(memberExpression.Expression, Is.Null);
        }
    private void DepetrificationButtonListener()
    {
        TextMeshProUGUI textMeshProUGUI = GetComponentInChildren <TextMeshProUGUI>();

        string characterName = textMeshProUGUI.text;

        Debug.Log(characterName);

        if (StaticStorage.GetItemCount(StaticStorage.allItems["Depetrification Crystal"]) > 0)
        {
            StaticStorage.UsePlayerItem("Depetrification Crystal");
            StaticStorage.allCharacters[characterName].isDead        = false;
            StaticStorage.allCharacters[characterName].currentHealth = StaticStorage.allCharacters[characterName].maxHealth;
            playerController.UpdateDepetrificationWindow();
        }
    }
예제 #4
0
    public void UpdateDepetrificationWindow()
    {
        depetrificationCount.GetComponent <TextMeshProUGUI>().text = "Crystals: " + StaticStorage.GetItemCount(StaticStorage.allItems["Depetrification Crystal"]);
        int i = 1;

        foreach (Character character in playerParty)
        {
            if (character.isDead)
            {
                TextMeshProUGUI textMeshProUGUI = characters["Character" + i].GetComponentInChildren <TextMeshProUGUI>();
                textMeshProUGUI.SetText(character.name);
                i++;
            }
        }
        for (int j = i; j <= 4; j++) //getting rid of buttons for characters we dont have
        {
            characters["Character" + j].SetActive(false);
        }
    }
예제 #5
0
        public WatsonAResponse Query([FromBody] WatsonCQuery query)
        {
            var data = StaticStorage.GetData <TempData>(query.SessionId);
            // wir müsen zuerst prüfen, ob der ankommende text ein neuer Intent ist
            var result = new WatsonProvider().Query(query.Text, null, null);

            if (data != null && result.intents.Count > 0 && result.intents.Max(x => x.confidence) > 0.7 && data.Intent != result.intents.OrderByDescending(x => x.confidence).First().intent)
            {
                // es gab einen vorherigen intent und der neue intent ist anders + signifikant
                // lösche den alten Intent
                StaticStorage.AddData(query.SessionId, null);
                data = null;
            }
            else if (data == null)
            {
                // es gab keinen vorherigen intent
                data = new TempData();
            }
            else
            {
                // es gab einen vorherigen intent und der neue ist nicht signifikant oder der neue ist der gleiche wie der alte oder der neue ist nicht existent
                // dann frage nochmal watson ab, jetzt aber mit den temporären daten
                result = new WatsonProvider().Query(query.Text, new List <WatsonAIntent> {
                    new WatsonAIntent {
                        intent = data.Intent, confidence = 1
                    }
                }, data.Entities);

                // im idealfall wurden mit der Usereingabe bestimmte entitäten befüllt und im dialogflow wurde ein step vorangeschritten
                if (result.entities.Count > 0)
                {
                    // dann speichere die angaben für später
                    data.Entities.AddRange(result.entities);
                    // für was habe ich diese zeule eingebaut?? result = new WatsonProvider().Query(query.Text, new List<WatsonAIntent> { new WatsonAIntent { intent = data.Intent, confidence = 1} }, data.Entities);
                }
            }

            // baue ein neues storage objekt, welches den intent und die entitäten (später = context) beinhaltet
            var newData = new TempData
            {
                Intent   = data?.Intent ?? result.intents.OrderByDescending(x => x.confidence).First().intent,
                Entities = result.entities ?? new List <WatsonAEntity>()
            };

            //newData.Entities.AddRange(result.entities);
            //newData.Entities = newData.Entities.Distinct().ToList();
            StaticStorage.AddData(query.SessionId, newData);

            // jetzt könnte folgendes passieren;:
            // a) wir haben einen spezielle intent welcher eine Validierung benötigt oder eine Serverseitige Aktion -> Schnittstelle für Wissensmanager
            if (result.intents[0].intent == "math.request.binary2")
            {
                if (Calculator.IsValid(result.input.text))
                {
                    var items = Calculator.Extract(result.input.text);

                    var    left = Double.Parse(result.context.ContainsKey("left") ? result.context["left"].ToString() : items.Item1.ToString());
                    var    op   = result.context.ContainsKey("operator") ? result.context["operator"] : items.Item2;
                    double?res;

                    if (result.context.ContainsKey("operator"))
                    {
                        // wir kommen von einem vorherigen invaliden berechnungsergebnis
                        res = Calculator.Calc(left, result.input.text, op.ToString());
                        newData.Entities.Add(new WatsonAEntity {
                            entity = "right", value = result.input.text.ToString()
                        });
                    }
                    else
                    {
                        res = Calculator.Calc(result.input.text);
                        newData.Entities.Add(new WatsonAEntity {
                            entity = "right", value = items.Item3.ToString()
                        });
                    }

                    newData.Entities.Add(new WatsonAEntity {
                        entity = "math_request_success", value = "true"
                    });
                    newData.Entities.Add(new WatsonAEntity {
                        entity = "result", value = res.ToString()
                    });
                    newData.Entities.Add(new WatsonAEntity {
                        entity = "left", value = left.ToString()
                    });

                    newData.Entities.Add(new WatsonAEntity {
                        entity = "operator", value = op.ToString()
                    });

                    StaticStorage.AddData(query.SessionId, null);



                    result = new WatsonProvider().Query(query.Text, new List <WatsonAIntent> {
                        new WatsonAIntent {
                            intent = newData.Intent, confidence = 1
                        }
                    }, newData.Entities);
                }
                else
                {
                    StaticStorage.AddData(query.SessionId, null);
                    var context = new List <WatsonAEntity>(newData.Entities);
                    context.Add(new WatsonAEntity {
                        entity = "math_request_failed_right", value = "true"
                    });
                    var items = Calculator.Extract(result.input.text);
                    newData.Entities.Add(new WatsonAEntity {
                        entity = "left", value = items.Item1.ToString()
                    });
                    newData.Entities.Add(new WatsonAEntity {
                        entity = "right", value = items.Item3.ToString()
                    });
                    newData.Entities.Add(new WatsonAEntity {
                        entity = "operator", value = items.Item2
                    });
                    result = new WatsonProvider().Query(query.Text, new List <WatsonAIntent> {
                        new WatsonAIntent {
                            intent = newData.Intent, confidence = 1
                        }
                    }, context);
                }
            }
            // b) der schritt im dialogflow wurde mit "final" gekennzeichnet, was für uns heißt: Schließe diese Konversation ab ( = Lösche Daten) und führe eine Aktion durch
            //      Diese Aktion ist im idealfall im context im dialogflow spezifiziert und abhängig vom intent
            if (result.intents[0].intent == "math.request.binary" && result.context.ContainsKey("final"))
            {
                StaticStorage.AddData(query.SessionId, null);
                // Der Wissensmanager möchte, dass nun dieser Intent beendet ist. Wir führen die von ihmn spezifizierte Aktion durch. Mögliche Werte: "createLinkBasedOnContext" oder "createSolutionBasedOnCo´ntext"
                if (result.context["userResponse"].ToString() == "createLink")
                {
                    result.output.text = new List <string> {
                        "Hier finden Sie die Lösung für ihr Problem <a href='http://google.de?q=BlaBlub'>Lösung</a>"
                    };
                }
                else
                {
                    result.output.text = new List <string> {
                        "Machen Sie dies und jenes um ihr Passwort zurückzusetzen"
                    };
                }
            }

            if (result.intents[0].intent == "conversation.end")
            {
                result.context["dialog"] = new Dialog().AddTextPanel("Konnte ich Ihnen helfen?", "p1").AddButton("Ja", "yes").AddButton("Nein", "no").AddTextInput("reason");
            }

            if (result.intents[0].intent == "intent.with.selection" && result.context.ContainsKey("provideSelection") && query.PressedButton == null)
            {
                var values = (Newtonsoft.Json.Linq.JArray)result.context["value"];
                var dialog = new Dialog();
                Func <string, string> js = name =>
                {
                    if (result.context.ContainsKey("setVariable"))
                    {
                        return(@"

                            $('a[name=""" + name + @"""]').parent().click(function() {
                                window.pressedButton='" + name + @"';
return false;
                            });");
                    }

                    return("");
                };

                values.Select(x => ((Newtonsoft.Json.Linq.JValue)x).Value.ToString()).ToList().ForEach(x => dialog = dialog.AddButton(x, x, js(x)));
                result.context["dialog"] = dialog;
            }
            else if (query.PressedButton != null)
            {
                result.context[result.context["setVariable"].ToString()] = query.PressedButton;
                result.context["system"] = null; // "system" is a NewtoinSoft Json object. ignore it because we do not need it
                result = new WatsonProvider().Query(query.Text, new List <WatsonAIntent> {
                    new WatsonAIntent {
                        intent = newData.Intent, confidence = 1
                    }
                }, result.context.Select(x => new WatsonAEntity {
                    entity = x.Key, value = x.Value?.ToString()
                }).ToList());
            }

            var possibleKey = result.output
                              .nodes_visited_details[result.output.nodes_visited_details.Count - 1].title;

            if (possibleKey != null && TranslationRepository.Instance.ContainsKey(possibleKey))
            {
                result.output.text = new List <string>
                {
                    TranslationRepository.Instance[result.output
                                                   .nodes_visited_details[result.output.nodes_visited_details.Count - 1].title]
                };
            }
            return(result);
        }
 public PersonRepository(StaticStorage <string, PersonState> staticStorage, IMapper mapper)
 {
     _staticStorage = staticStorage;
     _mapper        = mapper;
 }
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case "end":     //end of battle
            //SceneManager.LoadScene("Overworld");
            foreach (GameObject clone in cloneList)
            {
                Destroy(clone);
            }
            mainCameraCombat.SetActive(false);
            SceneManager.UnloadSceneAsync("CombatScene");
            player.mainCamera.SetActive(true);
            player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
            inCombat = false;
            if (isLastFight)
            {
                StoryStaticStorage.storySwitch("wonLastFight");
            }
            break;

        case "start":     // Prepare the player's selection, or prepare and complete the turn for ai
        {
            contextMenu.SetActive(false);

            //check to see if all of one team are dead, if all players team dies at the same time as the enemy, they lose
            bool friendlyAlive = false;
            foreach (Character character in friendlyParty)
            {
                if (!character.isDead)
                {
                    friendlyAlive = true;
                    break;
                }
            }
            bool enemyAlive = false;
            foreach (Character character in enemyParty)
            {
                if (!character.isDead)
                {
                    enemyAlive = true;
                    break;
                }
            }

            if (!enemyAlive && friendlyAlive)
            {
                if (allCharacters["Toa"].isDead == true)
                {
                    if (GetItemCount(allItems["Depetrification Crystal"]) > 0)
                    {
                        StaticStorage.UsePlayerItem("Depetrification Crystal");
                        StaticStorage.allCharacters["Toa"].isDead        = false;
                        StaticStorage.allCharacters["Toa"].currentHealth = StaticStorage.allCharacters["Toa"].maxHealth;
                        state = "end";
                        Debug.Log("You won");
                    }
                    else
                    {
                        //restorePlayerToSave();
                        Debug.Log("You lost");
                        SceneManager.LoadScene("LoseScene");
                    }
                }
                else
                {
                    state = "end";
                    Debug.Log("You won");
                }
            }
            else if (!friendlyAlive)
            {
                //restorePlayerToSave();
                state = "end";
                Debug.Log("You lost");
                SceneManager.LoadScene("LoseScene");
            }
            else
            {
                Character playerTakingTurn = turnOrder.Peek();         //which character is taking the turn
                playerTakingTurnName = playerTakingTurn.name;

                string tempTurnOrderText = "Turn Order: ";
                int    turnOrderI        = 0;
                foreach (Character c in turnOrder)
                {
                    if (turnOrderI == turnOrder.Count - 1)
                    {
                        tempTurnOrderText += c.name;
                    }
                    else
                    {
                        tempTurnOrderText += c.name + ", ";
                    }
                    turnOrderI++;
                }
                turnOrderText.text = tempTurnOrderText;

                if (playerTakingTurn.isInterrupt)
                {
                    turnOrder.Dequeue();         //dont put them at the back of the queue
                }
                else
                {
                    turnOrder.Enqueue(turnOrder.Dequeue());         //put them at the back of the queue
                }

                if (!playerTakingTurn.isDead)
                {
                    //check for status effects
                    bool stunned = false;         //stun wears off each turn
                    currentlyStunned = false;
                    List <StatusEffect> statusEffects = playerTakingTurn.statusEffects;
                    currentStrength = 0;
                    foreach (StatusEffect statusEffect in statusEffects)
                    {
                        if (!(statusEffect.currentTurnsRemaining <= 0))
                        {
                            playerTakingTurn.currentHealth -= statusEffect.dot;

                            currentStrength = statusEffect.strength;

                            //for damageIndicator
                            if (!(statusEffect.strength != 0 && statusEffect.dot == 0 && statusEffect.stun == false))
                            {
                                GameObject target;
                                if (playerTakingTurn.team == 0)         //friendly
                                {
                                    int targetIndex = friendlyParty.IndexOf(playerTakingTurn);
                                    target = friendlyTargets["FriendlyTarget" + (targetIndex + 1)];
                                }
                                else         //enemy
                                {
                                    int targetIndex = enemyParty.IndexOf(playerTakingTurn);
                                    target = enemyTargets["EnemyTarget" + (targetIndex + 1)];
                                }
                                GameObject damageIndicator = Instantiate(damageIndicatorPrefab, target.transform.position, new Quaternion(0, 0, 0, 0));
                                cloneList.Add(damageIndicator);
                                damageIndicator.transform.SetParent(canvas.transform);
                                TextMeshProUGUI textMeshProUGUI = damageIndicator.GetComponent <TextMeshProUGUI>();
                                textMeshProUGUI.text = System.Math.Abs(statusEffect.dot).ToString();
                                if (statusEffect.dot > 0)
                                {
                                    textMeshProUGUI.color = new Color(1, 0, 0, textMeshProUGUI.color.a);
                                }
                                else if (statusEffect.dot < 0)
                                {
                                    textMeshProUGUI.color = new Color(0, 1, 0, textMeshProUGUI.color.a);
                                }
                                else
                                {
                                    textMeshProUGUI.color = new Color(1, 1, 0, textMeshProUGUI.color.a);
                                }
                            }
                            //end damageIndicator

                            statusEffect.currentTurnsRemaining -= 1;

                            RefreshHealth(playerTakingTurn);
                            if (playerTakingTurn.isDead)
                            {
                                break;
                            }

                            if (statusEffect.stun)
                            {
                                stunned          = true;
                                currentlyStunned = true;
                            }
                        }
                    }
                    if (!playerTakingTurn.isDead)
                    {
                        if (!stunned)
                        {
                            if (enemyParty.Contains(playerTakingTurn))         //enemy automatically takes action
                            {
                                int randomMoveNum = Random.Range(0, playerTakingTurn.moves.Count);
                                int randomTargetNum;
                                if (playerTakingTurn.moves[randomMoveNum].appliedToTeam)
                                {
                                    currentlySelectedMoveOrItem     = "move";
                                    currentlySelectedMoveOrItemName = playerTakingTurn.moves[randomMoveNum].name;
                                    while (true)
                                    {
                                        List <string> targetableCharacters = new List <string>();
                                        if (playerTakingTurn.moves[randomMoveNum].statusEffects.Length == 0)         // if the applied to team move has no lasting effects eg: HoT or a buff, the ai will never heal a full health friend
                                        {
                                            int i = 1;
                                            foreach (Character character in enemyParty)         //finding characters in need of healing
                                            {
                                                string targetName = "EnemyTarget" + i;
                                                if (character.currentHealth < character.maxHealth && !character.isDead)
                                                {
                                                    targetableCharacters.Add(targetName);
                                                }
                                                i++;
                                            }
                                            if (targetableCharacters.Count == 0)         //if no one needs healing, heal a random alive character
                                            {
                                                int j = 1;
                                                foreach (Character character in enemyParty)
                                                {
                                                    if (!character.isDead)
                                                    {
                                                        string targetName = "EnemyTarget" + j;
                                                        targetableCharacters.Add(targetName);
                                                    }
                                                    j++;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            int i = 1;
                                            foreach (Character character in enemyParty)         //cast on a random allied character instead of specifically people who need healing
                                            {
                                                if (!character.isDead)
                                                {
                                                    string targetName = "EnemyTarget" + i;
                                                    targetableCharacters.Add(targetName);
                                                }
                                                i++;
                                            }
                                        }
                                        randomTargetNum = Random.Range(0, targetableCharacters.Count);
                                        string tempChosenTargetName = targetableCharacters[randomTargetNum];
                                        SetChosenTargetName(tempChosenTargetName);
                                        if (!StaticStorage.allCharacters[chosenTargetName].isDead)
                                        {
                                            break;
                                        }
                                    }
                                    StartCoroutine("WaitEndTurn");
                                    StartCoroutine("WaitUseMoveOrItem");
                                }
                                else
                                {
                                    currentlySelectedMoveOrItem     = "move";
                                    currentlySelectedMoveOrItemName = playerTakingTurn.moves[randomMoveNum].name;
                                    while (true)
                                    {
                                        randomTargetNum = Random.Range(0, friendlyParty.Count);
                                        string tempChosenTargetName = "FriendlyTarget" + (randomTargetNum + 1);
                                        SetChosenTargetName(tempChosenTargetName);
                                        if (!StaticStorage.allCharacters[chosenTargetName].isDead)
                                        {
                                            break;
                                        }
                                    }
                                    StartCoroutine("WaitEndTurn");
                                    StartCoroutine("WaitUseMoveOrItem");
                                }
                            }
                            else if (friendlyParty.Contains(playerTakingTurn))         //player is given a selection of their possible actions
                            {
                                turnMenuText.text = playerTakingTurn.name;
                                //Adding the the player's items to their selection
                                int         i         = 1;
                                List <Item> seenItems = new List <Item>();
                                foreach (Item item in playerItems)
                                {
                                    if (!seenItems.Contains(item))
                                    {
                                        TextMeshProUGUI textMeshProUGUI = items["Item" + i].GetComponentInChildren <TextMeshProUGUI>();
                                        textMeshProUGUI.SetText(item.name + " (" + StaticStorage.GetItemCount(item) + ")");
                                        seenItems.Add(item);
                                        i++;
                                    }
                                }
                                for (int j = i; j <= 4; j++)         //getting rid of buttons for items we dont have
                                {
                                    items["Item" + j].SetActive(false);
                                }

                                //Adding the the player's moves to their selection
                                int m = 1;
                                foreach (Move move in playerTakingTurn.moves)
                                {
                                    TextMeshProUGUI textMeshProUGUI = moves["Move" + m].GetComponentInChildren <TextMeshProUGUI>();
                                    textMeshProUGUI.SetText(move.name);
                                    moves["Move" + m].SetActive(true);
                                    m++;
                                }
                                for (int j = m; j <= 4; j++)         //getting rid of buttons for moves we dont have
                                {
                                    moves["Move" + j].SetActive(false);
                                }

                                turnMenu.SetActive(true);

                                //all actions are taken by the listeners
                            }
                            else if (playerTakingTurn.isInterrupt)
                            {
                                currentlySelectedMoveOrItem     = "move";
                                currentlySelectedMoveOrItemName = playerTakingTurn.moves[0].name;
                                SetChosenTargetName(currentInterruptTargetName);
                                StartCoroutine("WaitEndTurn");
                                if (!allCharacters[chosenTargetName].isDead)
                                {
                                    StartCoroutine("WaitUseMoveOrItem");
                                }
                            }

                            state = "waiting"; //wait for user or ai to activate button listeners to progress + time for turn to animate etc
                        }
                        else                   //the ai or player is stunned
                        {
                            state = "waiting";
                            StartCoroutine("WaitEndTurn");
                        }
                    }
                }
            }
            break;
        }

        default:
            break;
        }
    }