123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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<int, BAStation> 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<int, BAStation> 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));
- }
- }
- }
|