123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using Sfs2X.Entities.Data;
- public class DefenceRoom : BARoom
- {
- public const int SEND_ITEM_INTERVAL = 20 * 1000;
- private int lastAddItemTime = 0;
- public DefenceRoom(BAServer server) : base(server)
- {
- lastAddItemTime = GetTime ();
- // lastAddItemTime -= SEND_ITEM_INTERVAL;
- AttempAddStation (0, TeamUtil.Team.Blue.GetHashCode ());
- AttempAddStation (1, TeamUtil.Team.Red.GetHashCode());
- AddDoor (0, TeamUtil.Team.Blue.GetHashCode());
- AddDoor (1, TeamUtil.Team.Blue.GetHashCode());
- AddDoor (2, TeamUtil.Team.Red.GetHashCode());
- AddDoor (3, TeamUtil.Team.Red.GetHashCode());
- itemPosDict.Add (0, new BAItemPos (0));
- }
- private void SendItem()
- {
- SFSArray items = new SFSArray();
- foreach(KeyValuePair<int, BAItemPos> kvp in itemPosDict)
- {
- BAItemPos itemPos = kvp.Value;
- if(itemPos.itemId == -1)
- {
- itemPos.itemId = MapItem.BIGGER;
- ISFSObject itemObj = new SFSObject ();
- itemObj.PutInt ("i", itemPos.id);
- itemObj.PutInt ("t", itemPos.itemId);
- items.AddSFSObject (itemObj);
- }
- }
- if (items.Size () > 0) {
- ISFSObject data = new SFSObject ();
- data.PutSFSArray ("l", items);
- server.Send (new Message(Command.AddMapItem, data));
- }
- }
- public override void RemoveStation (int id)
- {
- foreach(KeyValuePair<int, BAStation> kvp in stationDict)
- {
- BAStation station = kvp.Value;
- if(station.id == id)
- {
- stationDict.Remove (station.crystalId);
- keyStationDestroyed (station.teamId);
- return;
- }
- }
- }
- private void keyStationDestroyed(int teamId)
- {
- int oppTeamId = TeamUtil.GetOpponentTeam(teamId).GetHashCode();
- SendBattleInfo(GetScoreData(oppTeamId));
- }
- public SFSObject GetScoreData(int winTeam)
- {
- if(isGameOver)
- {
- return null;
- }
- int freeTime = GetFreeTime();
- int time = roundTime-GetGameTime();
- if(time<=0)
- {
- winTeam = FindWinTeam();
- }
- SFSObject data = new SFSObject();
- data.PutInt("t", time);
- data.PutInt("f", freeTime);
- if(winTeam > 0)
- DealGameOver(data, winTeam);
- return data;
- }
- private int FindWinTeam()
- {
- int blueDoorCount = 0;
- int redDoorCount = 0;
- foreach(KeyValuePair<int, BADoor> kvp in doorDict)
- {
- BADoor door = kvp.Value;
- if (door.teamId == TeamUtil.Team.Blue.GetHashCode ())
- blueDoorCount++;
- else if (door.teamId == TeamUtil.Team.Red.GetHashCode ())
- redDoorCount++;
- }
- if(blueDoorCount > redDoorCount)
- return TeamUtil.Team.Blue.GetHashCode();
- else if(blueDoorCount < redDoorCount)
- return TeamUtil.Team.Red.GetHashCode();
- return TeamUtil.Team.Yellow.GetHashCode();
- }
- public override void Update ()
- {
- base.Update ();
- if(scoreTaskRunning)
- {
- if (GetTime () - lastSendScoreTime >= scoreTaskInterval) {
- lastSendScoreTime = GetTime ();
- SendBattleInfo (GetScoreData (-1));
- }
- if(GetGameTime() - lastAddItemTime >= SEND_ITEM_INTERVAL)
- {
- lastAddItemTime = GetGameTime ();
- SendItem ();
- }
- }
- }
- }
|