예제 #1
0
		public void parseRecord(String file) {
            Console.WriteLine("read record-file: " + file);
			JsonMessageSplitter jsonms = new JsonMessageSplitter();
			String log = File.ReadAllText(file);
			jsonms.feed(log);
			jsonms.runParsing();
			String line = jsonms.getNextMessage();
			bool searching = true;
			String player1name = null;
			String player2name = null;
			//String enemyId = null;
			String deckName = null;
			ResourceType type = ResourceType.NONE;

			while (line != null && searching)
			{
				try
				{
                    Message msg = MessageFactory.create(MessageFactory.getMessageName(line), line);
					if (msg is GameInfoMessage)
					{
						GameInfoMessage gim = (GameInfoMessage) msg;
						if (gim.white.Equals(App.MyProfile.ProfileInfo.name))
						{
							player1name = gim.white;
							player2name = gim.black;
						}
						else 
						{
							player1name = gim.black;
							player2name = gim.white;
						}
						deckName = ""; //deckname isnt in gameinfomessage anymore
					}
					if (msg is ActiveResourcesMessage)
					{
						type = (msg as ActiveResourcesMessage).types[0];
					}
					if (player2name != null && type != ResourceType.NONE)
					{
						searching = false;
					}
				}
				catch
				{
				}
				jsonms.runParsing();
				line = jsonms.getNextMessage();
			}

			recordList.Add(new Record(File.GetCreationTime(file).ToShortDateString() + " - " + File.GetCreationTime(file).ToShortTimeString(),player1name +  " vs " + player2name + " - " + deckName, /*enemyId,*/ file, type));
			if (recordListPopup != null)
				recordListPopup.SetItemList (recordList);
		}
예제 #2
0
		private void LaunchReplay()
		{
			playing = true;

			String log = File.ReadAllText (fileName).Split(new char[] {'}'}, 2)[1];
			//FIX Profile ID
			JsonMessageSplitter jsonms = new JsonMessageSplitter();
			jsonms.feed(log);
			jsonms.runParsing();
			String line = jsonms.getNextMessage();
			String idWhite = null;
			String idBlack = null;
			String realID = null;
            
            // save log to list:
            this.logList.Clear();
            this.turnToLogLine.Clear();
            this.minTurn = 100000000;
            this.maxTurn = 0;
            
            while (line != null)
            {
                this.logList.Add(line);

                try
                {
                    Message msg = MessageFactory.create(MessageFactory.getMessageName(line), line);
                    if (msg is GameStateMessage)
                    {
                        if ((msg as GameStateMessage).turn > 0)
                        {
                            this.turnToLogLine.Add((msg as GameStateMessage).turn, this.logList.Count - 1);
                            if ((msg as GameStateMessage).turn < minTurn) minTurn = (msg as GameStateMessage).turn;
                            if ((msg as GameStateMessage).turn > maxTurn) maxTurn = (msg as GameStateMessage).turn;
                        }
                    }

                    if (msg is NewEffectsMessage)
                    {
                        foreach (EffectMessage current in NewEffectsMessage.parseEffects(msg.getRawText()))
                        {
                            if (current.type == "TurnBegin")
                            {
                                this.turnToLogLine.Add((current as EMTurnBegin).turn,this.logList.Count-1);
                                if ((current as EMTurnBegin).turn < minTurn) minTurn = (current as EMTurnBegin).turn;
                                if ((current as EMTurnBegin).turn > maxTurn) maxTurn = (current as EMTurnBegin).turn;


                            }
                        }
                    }
                }
                catch { }

                jsonms.runParsing();
                line = jsonms.getNextMessage();
            }

            /*foreach (KeyValuePair<int, int> kvp in this.turnToLogLine)
            {
                Console.WriteLine("turn " + kvp.Key + " line " + kvp.Value);
                Console.WriteLine(logList[kvp.Value]);
            }
            */
            Console.WriteLine("# minturn: " +this.minTurn + ", maxturn: " + this.maxTurn);
            /*
            Console.WriteLine("FIX ID "+line);
			while (line != null) {
				try {
                    Message msg = MessageFactory.create(MessageFactory.getMessageName(line), line); 
					if (msg is GameInfoMessage) {
						idWhite = (msg as GameInfoMessage).getPlayerProfileId (TileColor.white);
						idBlack = (msg as GameInfoMessage).getPlayerProfileId (TileColor.black);
					}
					if (msg is NewEffectsMessage && realID== null) {
                        string strg = "\"HandUpdate\":{\"profileId\":\"";
						if (msg.getRawText ().Contains (strg+idWhite)) {
							realID = idWhite;
                            Console.WriteLine("realid is white");
						}
						if (msg.getRawText ().Contains (strg+idBlack)) {
							realID = idBlack;
                            Console.WriteLine("realid is black");
						}
					}
				} catch {
				}
				jsonms.runParsing();
				line = jsonms.getNextMessage();
			}
			if (realID != null) {
                Console.WriteLine("replace" + realID + "with" + App.MyProfile.ProfileInfo.id);
				log = log.Replace (realID, App.MyProfile.ProfileInfo.id);
			}
            */
            App.SceneValues.battleMode = new SceneValues.SV_BattleMode(GameMode.Replay);//GameMode.Play
			SceneLoader.loadScene("_BattleModeView");


            //jsonms.clear();
            //jsonms.feed(log);
            //jsonms.runParsing();
            //Console.WriteLine("Playing:\r\n" + log);
            //line = jsonms.getNextMessage();

            this.readedGameState = false;
            int lineindex = 0;
            line = this.logList[lineindex];

            

			while (playing)
			{
                
                Console.WriteLine("# nxt replay mssg: "+ lineindex +" "+line );
                Message msg = MessageFactory.create(MessageFactory.getMessageName(line), line);

                if (msg is CardInfoMessage) // CardInfoMessages are not very informative for players :D
                {
                    lineindex++;
                    line = this.logList[lineindex];
                    continue;
                }

                if (msg is GameStateMessage && this.readedGameState)
                {
                    lineindex++;
                    line = this.logList[lineindex];
                    continue;
                }
                else { if (msg is GameStateMessage) this.readedGameState = true; }

                dispatchMessages.Invoke(App.Communicator, new object[] { msg });// <---the whole magic
                if (line.Contains("EndGame") && !(msg is GameChatMessageMessage) && !(msg is RoomChatMessageMessage))
                {
                    playing = false;

                }
                else
                {
                        //jsonms.runParsing();
                        //line = jsonms.getNextMessage();
                    lineindex++;
                    line = this.logList[lineindex];
                }
                readNextMsg = false;
                if (msg is GameChatMessageMessage || msg is PingMessage ) readNextMsg = true;
				if (readNextMsg == false)
				{
					//delay messages otherwise the game rushes through in about a minute.

                    if (msg is GameStateMessage || msg is NewEffectsMessage)
                    {
                        //List<EffectMessage> effects = ((List<EffectMessage>)effectsField.GetValue(this.bm));
                        EffectList effects = ((EffectList)effectsField.GetValue(this.bm));
                        while (effects.Count >= 1)
                        {
                            Thread.Sleep(100);
                            effects = ((EffectList)effectsField.GetValue(this.bm));
                        }
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
					while (paused)
					{
						Thread.Sleep(1000);
					}
					//readNextMsg = true;
				}
                if (this.seekTurn >= 1)
                {
                    try
                    {
                        lineindex = this.turnToLogLine[this.seekTurn];
                        line = this.logList[lineindex];
                    }
                    catch { Console.WriteLine("cant find turn"); }
                    this.seekTurn = 0;
                }
			}
            Console.WriteLine("player stoped");

		}
예제 #3
0
        public override bool BeforeInvoke(InvocationInfo info, out object returnValue)
        {
            if (info.TargetMethod ().Equals ("getButtonRect")) {
                foreach (StackFrame frame in info.StackTrace().GetFrames()) {
                    if (frame.GetMethod ().Name.Contains ("BeforeInvoke"))
                        break;
                    if (frame.GetMethod ().Name.Contains ("drawEditButton")) {
                        returnValue = typeof(ProfileMenu).GetMethod ("getButtonRect", BindingFlags.NonPublic | BindingFlags.Instance).Invoke (info.Target(), new object[] { 2 });
                        return true;
                    }
                }
                returnValue = null;
                return false;
            }
            if (info.Target () is ProfileMenu && info.TargetMethod().Equals("Start") && App.SceneValues.profilePage.isMe()) {

                //list them
                recordList.Clear ();
                foreach (String file in Directory.GetFiles(this.OwnFolder()+Path.DirectorySeparatorChar+"Records")) {
                    if (file.EndsWith("sgr")) {

                        JsonMessageSplitter jsonms = new JsonMessageSplitter ();
                        String log = File.ReadAllText (file);
                        jsonms.feed(log);
                        jsonms.runParsing();
                        String line = jsonms.getNextMessage ();
                        bool searching = true;
                        String enemyName = null;
                        //String enemyId = null;
                        String deckName = null;
                        ResourceType type = ResourceType.NONE;

                        while (line != null && searching) {
                            try {
                                Message msg = Message.createMessage (Message.getMessageName(line), line);
                                if (msg is GameInfoMessage) {
                                    if ((msg as GameInfoMessage).white.Equals(App.Communicator.getUserScreenName())) {
                                        enemyName = (msg as GameInfoMessage).black;
                                        //enemyId = (msg as GameInfoMessage).getPlayerProfileId(TileColor.black);
                                    } else {
                                        enemyName = (msg as GameInfoMessage).white;
                                        //enemyId = (msg as GameInfoMessage).getPlayerProfileId(TileColor.white);
                                    }
                                    deckName = (msg as GameInfoMessage).deck;
                                }
                                if (msg is ActiveResourcesMessage) {
                                    type = (msg as ActiveResourcesMessage).types[0];
                                }
                                if (enemyName != null && type != ResourceType.NONE)
                                    searching = false;
                            } catch {}
                            jsonms.runParsing();
                            line = jsonms.getNextMessage ();
                        }

                        recordList.Add (new Record(File.GetCreationTime(file).ToLongDateString()+" - "+File.GetCreationTime(file).ToLongTimeString(), "VS "+enemyName+" - "+deckName, /*enemyId,*/ file, type));
                    }
                }

                recordListPopup = new GameObject ("Record List").AddComponent<UIListPopup> ();
                recordListPopup.transform.parent = ((ProfileMenu)info.Target()).transform;
                Rect frame = (Rect)typeof(ProfileMenu).GetField ("frameRect", BindingFlags.Instance | BindingFlags.NonPublic).GetValue (info.Target());
                recordListPopup.Init (new Rect(frame.center.x-frame.width/2.0f, frame.center.y-frame.height/2.0f+32.0f, frame.width, frame.height-(float)Screen.height*0.055f*3.0f), false, true, recordList, this, null, null, false, true, false, true, null, true, false);
                recordListPopup.enabled = true;
                recordListPopup.SetOpacity(1f);
            }
            if (info.TargetMethod().Equals("drawEditButton")) {
                Rect rect = (Rect)typeof(ProfileMenu).GetField ("frameRect", BindingFlags.Instance | BindingFlags.NonPublic).GetValue (info.Target());
                //LobbyMenu.drawShadowText (new Rect(rect.center.x-(float)Screen.width/8.0f/2.0f, rect.center.y-rect.height/2.0f-(float)Screen.height*0.055f*3.0f-40.0f, (float)Screen.width/8.0f, 35.0f), "Match History", Color.white);

                if ((bool)typeof(ProfileMenu).GetField ("showEdit", BindingFlags.Instance | BindingFlags.NonPublic).GetValue (info.Target())) {
                    recordListPopup.enabled = false;
                    recordListPopup.SetOpacity(0f);
                } else {
                    new ScrollsFrame (new Rect(rect.center.x-rect.width/2.0f-20.0f, rect.center.y-rect.height/2.0f, rect.width+40.0f, rect.height-(float)Screen.height*0.055f-20.0f)).AddNinePatch (ScrollsFrame.Border.DARK_CURVED, NinePatch.Patches.CENTER).Draw ();
                    recordListPopup.enabled = true;
                    recordListPopup.SetOpacity(1f);
                    GUIStyle labelSkin = (GUIStyle)typeof(ProfileMenu).GetField ("usernameStyle", BindingFlags.Instance | BindingFlags.NonPublic).GetValue (info.Target());
                    labelSkin.fontSize = 32;
                    GUI.Label (new Rect(rect.center.x-(float)Screen.width/6.0f/2.0f, rect.center.y-rect.height/2.0f-40.0f, (float)Screen.width/6.0f, 35.0f), "Match History", labelSkin);
                    if (LobbyMenu.drawButton((Rect)typeof(ProfileMenu).GetMethod ("getButtonRect", BindingFlags.NonPublic | BindingFlags.Instance).Invoke (info.Target(), new object[] { 0 }), "Load Replay", (GUISkin)typeof(ProfileMenu).GetField ("guiSkin", BindingFlags.Instance | BindingFlags.NonPublic).GetValue (info.Target()))) {
                        LoadReplay ();
                    }
                }
            }
            return player.BeforeInvoke (info, out returnValue);
        }