/// <summary> /// If fakeThinking parameter is true, AI will wait random amount of time /// between MIN_THINKING_TIME and MAX_THINKING_TIME measured in milliseconds before the execution continues. /// </summary> async Task <MoveData> CalculateMove() { // How to make a game-changing move in 3 steps: // 1. choose a random card from your deck int fromSlotNumber = UnityEngine.Random.Range(0, _myDeck.Count); // 2. excellent choice, now pick randomly a line PlayerLine line = UnityEngine.Random.Range(0, 2) == 0 ? PlayerLine.Backline : PlayerLine.Frontline; // 3. brilliant! Finally choose a random slot and play that card there int maxSlotNumber = line == PlayerLine.Backline ? _myBackline.Count : _myFrontline.Count; int targetSlotNumber = maxSlotNumber == 0 ? 0 : UnityEngine.Random.Range(0, maxSlotNumber); if (_fakeThinking) // pretend it took you some time to come up with such an amazing idea { await Task.Delay(UnityEngine.Random.Range(MIN_THINKING_TIME, MAX_THINKING_TIME)); } int c = _gameLogic.GetLine(_myIndicator, line).Count; if (targetSlotNumber > c || targetSlotNumber < 0) { targetSlotNumber = 0; } return(new MoveData(_myDeck[fromSlotNumber], _myIndicator, fromSlotNumber, line, targetSlotNumber)); }
internal LineIndicator MapPlayerLine(PlayerIndicator player, PlayerLine line) { if (player == PlayerIndicator.Top) { switch (line) { case PlayerLine.Deck: return(LineIndicator.TopDeck); case PlayerLine.Backline: return(LineIndicator.TopBackline); case PlayerLine.Frontline: return(LineIndicator.TopFrontline); } } else if (player == PlayerIndicator.Bot) { switch (line) { case PlayerLine.Deck: return(LineIndicator.BotDeck); case PlayerLine.Backline: return(LineIndicator.BotBackline); case PlayerLine.Frontline: return(LineIndicator.BotFrontline); } } throw new Exception("Unreachable code reached! " + "PlayerIndicator or PlayerLine enumerator must have been extended without extending the MapPlayerLine function."); }
void SerializeJson() { //Get all the presentation lines fitting with the current scene string scene = Application.loadedLevelName; string json = DataReader.GetAllText ("Assets/"+ scene +"cs.json"); //Convert the lines data to a managable format JSONNode data = JSON.Parse (json); var cutsjs = data ["scenes"]; _cutscenes = new Dictionary<string, SceneModel> (); //Loop trough all sentences and place them in the _lines member for (int i = 0; i < cutsjs.Count; i++) { var cutscenejs = cutsjs [i]; string key = cutscenejs["SceneName"]; var cutscene = new List<Interaction>(); var interactions = cutscenejs["Interaction"]; //Loop through interactions for(int j = 0; j < interactions.Count; j++) { var interaction = interactions[j]; //Check what kind of interaction it is Interaction part = null; switch (interaction["Type"]) { case "Event": part = SceneEvent.GetScript(interaction["ScriptKey"], interaction["Duration"].AsFloat); break; case "NPCLine": part = new NPCLine(interaction["NpcName"], interaction["VoiceKey"], interaction["Duration"].AsFloat); break; case "PlayerLine": part = new PlayerLine(interaction["Hint"], interaction["Duration"].AsFloat, GoToNextPart); break; } if(part == null) throw new Exception("JSON format exception in cutscene controller. Unknown type used. Input: " + interaction["Type"]); if(part != null) cutscene.Add(part); } _cutscenes.Add(key, new SceneModel(cutscenejs["Range"].AsFloat ,cutscene)); } }
public Dictionary<string, PlayerLine> GetAnswers(string alist) { Dictionary<string, PlayerLine> choices; // Player lines choices = new Dictionary<string, PlayerLine> (); var answers= alist.Split(' '); XmlNodeList answlist = doc.SelectNodes ("dialog/answer"); int count = 0; choices.Clear (); foreach (XmlNode answnode in answlist) { //Debug.Log("Checking "+answnode.Attributes.GetNamedItem("id").Value); foreach (string answer in answers){ //is this one of the answers Im loking for? if (answnode.Attributes.GetNamedItem("id").Value==answer) { //Debug.Log("Found answer "+answer); PlayerLine l = new PlayerLine(); var anschoices = answnode.ChildNodes; foreach (XmlNode cnode in anschoices) { if (cnode.Name== "option") { //it is text l.text = cnode.InnerText; l.link = cnode.Attributes.GetNamedItem("link").Value; } else if (cnode.Name== "action") { //action description Action a = new Action(); a.ActionType = cnode.Attributes.GetNamedItem("type").Value; a.id = cnode.Attributes.GetNamedItem("id").Value; a.value = cnode.Attributes.GetNamedItem("value").Value; l.actions.Add(a); } } //Debug.Log("answer text is "+anschoices.Item(0).InnerText); choices.Add(answnode.Attributes.GetNamedItem("id").Value, l); //choicelinks.Add(count,anschoices.Item(0).Attributes.GetNamedItem("link").Value); //count++; break; }//if }//for each answer } //foreach answer list return choices; }
public void CreateLine(GameObject linePrefab, LineDataClass lineAsset) { playerLine = Instantiate(linePrefab).GetComponent <PlayerLine>(); playerLine.transform.parent = gameObject.transform; if (lineAsset) { playerLine.InitWithPoints(lineAsset.points); } if (playerBall) { Renderer ballRenderer = playerBall.GetComponent <Renderer>(); float ballWidth = ballRenderer.bounds.size.x; float lineX = playerBall.transform.position.x; float lineY = playerBall.transform.position.y - ballWidth / 2; if (lineData) { lineX += lineData.startBallOffset.x; lineY += lineData.startBallOffset.y; } playerLine.transform.position = new Vector3(lineX, lineY, playerLine.transform.position.z); } }
internal LineIndicator GetLineIndicator(PlayerIndicator player, PlayerLine line) => player == PlayerIndicator.Top ? (LineIndicator)(int)line : (LineIndicator)(5 - (int)line);
internal List <CardModel> GetLine(PlayerIndicator player, PlayerLine line) => player == PlayerIndicator.Top ? _lines[(int)line] : _lines[5 - (int)line];
// AI uses abstractions and requires mapping public MoveData(CardModel card, PlayerIndicator playerIndicator, int fromSlotNumber, PlayerLine targetLine, int targetSlotNumber) { Card = card; FromLine = playerIndicator == PlayerIndicator.Top ? LineIndicator.TopDeck : LineIndicator.BotDeck; TargetLine = playerIndicator == PlayerIndicator.Bot ? (LineIndicator)(5 - (int)targetLine) : (LineIndicator)(int)targetLine; FromSlotNumber = fromSlotNumber; TargetSlotNumber = targetSlotNumber; }