using UnityEngine; using System.Collections; using System.Collections.Generic; using Sfs2X.Entities.Data; public class ChallengeRoom : BARoom { public const int TARGET_SCORE = 100; public ChallengeRoom(BAServer server) : base(server) { } public override void RemoveStation (int id) { int numBlue = 0; int numRed = 0; int needRemoveKey = -1; foreach(KeyValuePair kvp in stationDict) { BAStation station = kvp.Value; if(station.id == id) { needRemoveKey = station.crystalId; } else if(station.teamId == TeamUtil.Team.Blue.GetHashCode()) { numBlue++; } else if(station.teamId == TeamUtil.Team.Red.GetHashCode()) { numRed++; } } Debuger.Log (string.Format("Station {0} {1} {2}", numBlue, numRed, needRemoveKey)); if (needRemoveKey != -1) { stationDict.Remove (needRemoveKey); } } public ISFSObject GetScoreData(int winTeam) { SFSObject data = new SFSObject(); if(isGameOver) { return data; } int score = 0; int freeTime = GetFreeTime(); data.PutInt("f", freeTime); if(freeTime == 0) score = scoreTaskInterval/1000; foreach(KeyValuePair kvp in stationDict) { BAStation station = kvp.Value; if(station.teamId == TeamUtil.Team.Blue.GetHashCode()) { blueScore += score; } else if(station.teamId == TeamUtil.Team.Red.GetHashCode()) { redScore += score; } } data.PutInt("b", blueScore); data.PutInt("r", redScore); if(blueScore >= TARGET_SCORE) winTeam = TeamUtil.Team.Blue.GetHashCode(); else if(redScore >= TARGET_SCORE) winTeam = TeamUtil.Team.Red.GetHashCode(); int time = roundTime - GetGameTime(); if(winTeam != -1) { data.PutInt("t", time); DealGameOver(data, winTeam); } else if(time<=0) { data.PutInt("t", 0); //score same, blue team win winTeam = (blueScore>=redScore?TeamUtil.Team.Blue.GetHashCode():TeamUtil.Team.Red.GetHashCode()); DealGameOver(data, winTeam); } else { data.PutInt("t", time); } return data; } public override void Update () { base.Update (); if(scoreTaskRunning && GetTime() - lastSendScoreTime >= scoreTaskInterval) { lastSendScoreTime = GetTime (); SendBattleInfo (GetScoreData (-1)); } } }