123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using Sfs2X.Entities.Data;
- public class ChallengeService : GameRoomService
- {
- public const int SEND_SCORE_INTERVAL = 5*1000;
- protected Dictionary<int, CrystalBaseData> crystalBaseMap;
- public ChallengeService (ResponseDelegate callBack):base(callBack)
- {
- }
-
- override protected void InitGame()
- {
- List<int> list = new List<int>();
- list.Add(0);
- list.Add(1);
- list.Add(2);
- int index = Random.Range(0, list.Count);
- int blueCrystalIndex = list[index];
- list.RemoveAt(index);
- index = Random.Range(0, list.Count);
- int redCrystalIndex = list[index];
- AttempAddStation(blueCrystalIndex, TeamUtil.Team.Blue.GetHashCode());
- AttempAddStation(redCrystalIndex, TeamUtil.Team.Red.GetHashCode());
- }
- public override void RemoveStation (int stationId)
- {
- int numBlue = 0;
- int numRed = 0;
- int needRemoveKey = -1;
- foreach(KeyValuePair<int, ServiceStation> kvp in stationDict)
- {
- ServiceStation station = kvp.Value;
- if(station.id == stationId)
- {
- needRemoveKey = station.crystalId;
- }
- else if(station.teamId == TeamUtil.Team.Blue.GetHashCode())
- {
- numBlue++;
- }
- else if(station.teamId == TeamUtil.Team.Red.GetHashCode())
- {
- numRed++;
- }
- }
- if(needRemoveKey != -1)
- {
- stationDict.Remove(needRemoveKey);
- }
- if(numBlue == 0)
- {
- SendBattleInfo(GetScoreData(TeamUtil.Team.Red.GetHashCode()), null, null);
- }
- else if(numRed == 0)
- {
- SendBattleInfo(GetScoreData(TeamUtil.Team.Blue.GetHashCode()), null, null);
- }
- }
- public SFSObject GetScoreData(int winTeam)
- {
- SFSObject data = new SFSObject();
- if(isGameOver)
- {
- return data;
- }
- int score = 0;
- if(GetFreeTime() == 0)
- score = SEND_SCORE_INTERVAL/1000;
- foreach(KeyValuePair<int, ServiceStation> kvp in stationDict)
- {
- ServiceStation 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);
- int time = roundTime - GetGameTime();
- if(winTeam > 0)
- {
- data.PutInt("t", time);
- DealGameOver(data, winTeam);
- }
- else if(time <= 0)
- {
- data.PutInt("t", 0);
- winTeam = blueScore >= redScore ? TeamUtil.Team.Blue.GetHashCode() : TeamUtil.Team.Red.GetHashCode();
- DealGameOver(data, winTeam);
- }
- else
- {
- data.PutInt("t", time);
- }
- int freeTime = GetFreeTime();
- data.PutInt("f", freeTime);
- return data;
- }
- override protected void DoTask()
- {
- SendBattleInfo(GetScoreData(-1), GetPlayerChangeData(), GetAiTakerChangeData());
- }
- override protected void SavePlayerScore(SFSObject data, int winTeam)
- {
- SFSArray stats = new SFSArray();
- int roundMin = roundTime/60/1000;
- if(roundMin <= 0)
- {
- roundMin = 1;
- }
- List<ServicePlayer> list = new List<ServicePlayer>();
- list.Add(myPlayer);
- for(int i=0; i<list.Count; i++)
- {
- ServicePlayer player = list[i];
- SFSObject statsInfo = new SFSObject();
- statsInfo.PutInt("u", player.userId);
- statsInfo.PutInt("k", player.kill);
- statsInfo.PutInt("a", player.assists);
- statsInfo.PutInt("d", player.death);
- int rankScore = player.kill * 10 + player.assists * 2;
- int expScore = rankScore;
- int time = (roundTime - player.joinTime)/60/1000 + 1;
- int win = 0;
- int lose = 0;
- int coinGet = 0;
- if(time > roundMin)
- time = roundMin;
- if(player.teamId == winTeam)
- {
- rankScore += 300*time/roundMin;
- expScore += 300*time/roundMin;
- coinGet = 100*time/roundMin;
- win = 1;
- }
- else
- {
- rankScore -= 300*time/roundMin;
- expScore += 100*time/roundMin;
- coinGet = 80*time/roundMin;
- lose = 1;
- }
- statsInfo.PutInt("t", time);
- statsInfo.PutInt("r", rankScore);
- statsInfo.PutInt("e", expScore);
- statsInfo.PutInt("c", coinGet);
- stats.AddSFSObject(statsInfo);
- }
- data.PutSFSArray("s", stats);
- }
- }
|