ChallengeRoom.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Sfs2X.Entities.Data;
  5. public class ChallengeRoom : BARoom
  6. {
  7. public const int TARGET_SCORE = 100;
  8. public ChallengeRoom(BAServer server) : base(server)
  9. {
  10. }
  11. public override void RemoveStation (int id)
  12. {
  13. int numBlue = 0;
  14. int numRed = 0;
  15. int needRemoveKey = -1;
  16. foreach(KeyValuePair<int, BAStation> kvp in stationDict)
  17. {
  18. BAStation station = kvp.Value;
  19. if(station.id == id)
  20. {
  21. needRemoveKey = station.crystalId;
  22. }
  23. else if(station.teamId == TeamUtil.Team.Blue.GetHashCode())
  24. {
  25. numBlue++;
  26. }
  27. else if(station.teamId == TeamUtil.Team.Red.GetHashCode())
  28. {
  29. numRed++;
  30. }
  31. }
  32. Debuger.Log (string.Format("Station {0} {1} {2}", numBlue, numRed, needRemoveKey));
  33. if (needRemoveKey != -1) {
  34. stationDict.Remove (needRemoveKey);
  35. }
  36. }
  37. public ISFSObject GetScoreData(int winTeam)
  38. {
  39. SFSObject data = new SFSObject();
  40. if(isGameOver)
  41. {
  42. return data;
  43. }
  44. int score = 0;
  45. int freeTime = GetFreeTime();
  46. data.PutInt("f", freeTime);
  47. if(freeTime == 0)
  48. score = scoreTaskInterval/1000;
  49. foreach(KeyValuePair<int, BAStation> kvp in stationDict)
  50. {
  51. BAStation station = kvp.Value;
  52. if(station.teamId == TeamUtil.Team.Blue.GetHashCode())
  53. {
  54. blueScore += score;
  55. }
  56. else if(station.teamId == TeamUtil.Team.Red.GetHashCode())
  57. {
  58. redScore += score;
  59. }
  60. }
  61. data.PutInt("b", blueScore);
  62. data.PutInt("r", redScore);
  63. if(blueScore >= TARGET_SCORE)
  64. winTeam = TeamUtil.Team.Blue.GetHashCode();
  65. else if(redScore >= TARGET_SCORE)
  66. winTeam = TeamUtil.Team.Red.GetHashCode();
  67. int time = roundTime - GetGameTime();
  68. if(winTeam != -1)
  69. {
  70. data.PutInt("t", time);
  71. DealGameOver(data, winTeam);
  72. }
  73. else if(time<=0)
  74. {
  75. data.PutInt("t", 0);
  76. //score same, blue team win
  77. winTeam = (blueScore>=redScore?TeamUtil.Team.Blue.GetHashCode():TeamUtil.Team.Red.GetHashCode());
  78. DealGameOver(data, winTeam);
  79. }
  80. else
  81. {
  82. data.PutInt("t", time);
  83. }
  84. return data;
  85. }
  86. public override void Update ()
  87. {
  88. base.Update ();
  89. if(scoreTaskRunning && GetTime() - lastSendScoreTime >= scoreTaskInterval)
  90. {
  91. lastSendScoreTime = GetTime ();
  92. SendBattleInfo (GetScoreData (-1));
  93. }
  94. }
  95. }