public Story(string storyName, SortedDictionary <int, Chapter> chapters, SortedDictionary <int, BuildInfo> playerBuildInfos, SortedDictionary <int, bool> cardUnlockInfos, GamePlaySettings storyGamePlaySettings, int currentFightingChapterID) { StoryName = storyName; Chapters = chapters; Crystal = DefaultStarterCrystal; PlayerBuildInfos = playerBuildInfos; foreach (KeyValuePair <int, BuildInfo> kv in playerBuildInfos) { Base_CardLimitDict = kv.Value.M_BuildCards.GetBaseCardLimitDict(); break; } CardUnlockInfos = new SortedDictionary <int, bool>(); foreach (KeyValuePair <int, CardInfo_Base> kv in AllCards.CardDict) { CardUnlockInfos.Add(kv.Key, false); } if (cardUnlockInfos != null) { foreach (KeyValuePair <int, bool> kv in cardUnlockInfos) { CardUnlockInfos[kv.Key] = kv.Value; } } StoryGamePlaySettings = storyGamePlaySettings; RefreshLevelPointer(); CurrentFightingChapterID = currentFightingChapterID; }
public static GamePlaySettings GetGamePlaySettingsFromXML(XmlNode node_gps) { int DefaultCoin = int.Parse(node_gps.Attributes["DefaultCoin"].Value); int DefaultLife = int.Parse(node_gps.Attributes["DefaultLife"].Value); int DefaultLifeMax = int.Parse(node_gps.Attributes["DefaultLifeMax"].Value); int DefaultLifeMin = int.Parse(node_gps.Attributes["DefaultLifeMin"].Value); int DefaultEnergy = int.Parse(node_gps.Attributes["DefaultEnergy"].Value); int DefaultEnergyMax = int.Parse(node_gps.Attributes["DefaultEnergyMax"].Value); int DefaultDrawCardNum = int.Parse(node_gps.Attributes["DefaultDrawCardNum"].Value); int MinDrawCardNum = int.Parse(node_gps.Attributes["MinDrawCardNum"].Value); int MaxDrawCardNum = int.Parse(node_gps.Attributes["MaxDrawCardNum"].Value); GamePlaySettings gps = new GamePlaySettings(); gps.DefaultCoin = DefaultCoin; gps.DefaultLife = DefaultLife; gps.DefaultLifeMax = DefaultLifeMax; gps.DefaultLifeMin = DefaultLifeMin; gps.DefaultEnergy = DefaultEnergy; gps.DefaultEnergyMax = DefaultEnergyMax; gps.DefaultDrawCardNum = DefaultDrawCardNum; gps.MinDrawCardNum = MinDrawCardNum; gps.MaxDrawCardNum = MaxDrawCardNum; return(gps); }
public ClientBuildInfosRequest(List <BuildInfo> onlineBuildInfos, GamePlaySettings onlineGamePlaySettings) { foreach (BuildInfo bi in onlineBuildInfos) { OnlineBuildInfos.Add(bi.BuildID, bi); } OnlineGamePlaySettings = onlineGamePlaySettings; HasStory = false; }
public ClientBuildInfosRequest(List <BuildInfo> onlineBuildInfos, GamePlaySettings onlineGamePlaySettings, bool hasStory, Story story) { foreach (BuildInfo bi in onlineBuildInfos) { OnlineBuildInfos.Add(bi.BuildID, bi); } OnlineGamePlaySettings = onlineGamePlaySettings; HasStory = hasStory; Story = story; }
public BuildInfo(int buildID, string buildName, BuildCards buildCards, int drawCardNum, int life, int energy, int beginMetal, GamePlaySettings gamePlaySettings) { BuildID = buildID; BuildName = buildName; M_BuildCards = buildCards.Clone(); DrawCardNum = drawCardNum; Life = life; Energy = energy; BeginMetal = beginMetal; GamePlaySettings = gamePlaySettings; }
public void SetGamePlaySettings(GamePlaySettings gamePlaySettings) { Cur_GamePlaySettings = gamePlaySettings; SetDefaultCoin(Cur_GamePlaySettings.DefaultCoin.ToString(), false); SetDefaultLife(Cur_GamePlaySettings.DefaultLife.ToString(), false); SetDefaultLifeMax(Cur_GamePlaySettings.DefaultLifeMax.ToString(), false); SetDefaultLifeMin(Cur_GamePlaySettings.DefaultLifeMin.ToString(), false); SetDefaultEnergy(Cur_GamePlaySettings.DefaultEnergy.ToString(), false); SetDefaultEnergyMax(Cur_GamePlaySettings.DefaultEnergyMax.ToString(), false); SetDefaultDrawCardNum(Cur_GamePlaySettings.DefaultDrawCardNum.ToString(), false); SetMinDrawCardNum(Cur_GamePlaySettings.MinDrawCardNum.ToString(), false); SetMaxDrawCardNum(Cur_GamePlaySettings.MaxDrawCardNum.ToString(), false); }
public static GamePlaySettings Deserialize(DataStream reader) { GamePlaySettings res = new GamePlaySettings(); res.DefaultCoin = reader.ReadSInt32(); res.DefaultLife = reader.ReadSInt32(); res.DefaultLifeMax = reader.ReadSInt32(); res.DefaultLifeMin = reader.ReadSInt32(); res.DefaultEnergy = reader.ReadSInt32(); res.DefaultEnergyMax = reader.ReadSInt32(); res.DefaultDrawCardNum = reader.ReadSInt32(); res.MinDrawCardNum = reader.ReadSInt32(); res.MaxDrawCardNum = reader.ReadSInt32(); return(res); }
public GamePlaySettings Clone() { GamePlaySettings gps = new GamePlaySettings( defaultCoin: DefaultCoin, defaultLife: DefaultLife, defaultLifeMax: DefaultLifeMax, defaultLifeMin: DefaultLifeMin, defaultEnergy: DefaultEnergy, defaultEnergyMax: DefaultEnergyMax, defaultDrawCardNum: DefaultDrawCardNum, minDrawCardNum: MinDrawCardNum, maxDrawCardNum: MaxDrawCardNum ); return(gps); }
public override void Deserialize(DataStream reader) { base.Deserialize(reader); int count = reader.ReadSInt32(); OnlineBuildInfos = new SortedDictionary <int, BuildInfo>(); for (int i = 0; i < count; i++) { BuildInfo bi = BuildInfo.Deserialize(reader); OnlineBuildInfos.Add(bi.BuildID, bi); } OnlineGamePlaySettings = GamePlaySettings.Deserialize(reader); HasStory = reader.ReadByte() == 0x01; if (HasStory) { Story = Story.Deserialize(reader); } }
public bool EqualsTo(GamePlaySettings o) { if (DefaultCoin != o.DefaultCoin) { return(false); } if (DefaultLife != o.DefaultLife) { return(false); } if (DefaultLifeMax != o.DefaultLifeMax) { return(false); } if (DefaultLifeMin != o.DefaultLifeMin) { return(false); } if (DefaultEnergy != o.DefaultEnergy) { return(false); } if (DefaultEnergyMax != o.DefaultEnergyMax) { return(false); } if (DefaultDrawCardNum != o.DefaultDrawCardNum) { return(false); } if (MinDrawCardNum != o.MinDrawCardNum) { return(false); } if (MaxDrawCardNum != o.MaxDrawCardNum) { return(false); } return(true); }
private void InitBuildInfos() { BuildInfoDict.Clear(); List <BuildInfo> buildInfos = new List <BuildInfo>(); if (CurrentGameMode == GameMode.Single) { buildInfos = StoryManager.Instance.GetStory().PlayerBuildInfos.Values.ToList(); CurrentGamePlaySettings = StoryManager.Instance.GetStory().StoryGamePlaySettings; } else if (CurrentGameMode == GameMode.Online) { buildInfos = OnlineManager.Instance.OnlineBuildInfos.Values.ToList(); CurrentGamePlaySettings = OnlineManager.Instance.OnlineGamePlaySettings; } foreach (BuildInfo buildInfo in buildInfos) { buildInfo.GamePlaySettings = CurrentGamePlaySettings; CheckBuildInfoValid(buildInfo); BuildInfoDict.Add(buildInfo.BuildID, buildInfo); } }
public static void AddAllStories() { Reset(); foreach (string path in Directory.GetFiles(StoriesDirectory, "*.xml", SearchOption.TopDirectoryOnly)) { FileInfo fi = new FileInfo(path); string pureName = fi.Name.Substring(0, fi.Name.LastIndexOf(".")); string text; using (StreamReader sr = new StreamReader(path)) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement story = doc.DocumentElement; BuildInfo buildInfo = BuildInfo.GetBuildInfoFromXML(story.ChildNodes.Item(0), out bool needRefresh, BuildCards.DefaultCardLimitNumTypes.BasedOnZero); NeedReload |= needRefresh; GamePlaySettings gps = GamePlaySettings.GetGamePlaySettingsFromXML(story.ChildNodes.Item(1)); SortedDictionary <int, Chapter> Chapters = new SortedDictionary <int, Chapter>(); XmlNode node_Chapters = story.ChildNodes.Item(2); for (int i = 0; i < node_Chapters.ChildNodes.Count; i++) { Chapter chapter = Chapter.GetChapterFromXML(node_Chapters.ChildNodes[i]); Chapters.Add(chapter.ChapterID, chapter); } SortedDictionary <int, BuildInfo> playerBuildInfos = new SortedDictionary <int, BuildInfo>(); playerBuildInfos.Add(buildInfo.BuildID, buildInfo); SortedDictionary <int, bool> cardUnlockInfos = new SortedDictionary <int, bool>(); foreach (KeyValuePair <int, CardInfo_Base> kv in AllCards.CardDict) { cardUnlockInfos.Add(kv.Key, false); } foreach (KeyValuePair <int, BuildInfo> kv in playerBuildInfos) { foreach (KeyValuePair <int, BuildCards.CardSelectInfo> _kv in kv.Value.M_BuildCards.CardSelectInfos) { if (_kv.Value.CardSelectUpperLimit > 0) { cardUnlockInfos[_kv.Key] = true; } } } Story newStory = new Story(pureName, Chapters, playerBuildInfos, cardUnlockInfos, gps, 0); StoryDict.Add(newStory.StoryName, newStory); } //If any problem, refresh XML and reload if (NeedReload) { NeedReload = false; RefreshAllStoryXML(); ReloadStoryXML(); } }
public static void Init(int type, string[] args) { AppDomain.CurrentDomain.UnhandledException += ServerCore.OnUnhandledExceptionThrown; ServerCore.Type = type; ServerCore.Id = 0; ServerCore.ConfigurationServer = "http://127.0.0.1/supercell/"; if (args.Length > 0) { if (args.Length % 2 == 0) { for (int i = 0; i < args.Length; i += 2) { string name = args[i]; string value = args[i + 1]; switch (name) { case "-conf": if (value.Length > 0) { if (value.StartsWith("http://") || value.StartsWith("https://")) { if (!value.EndsWith("/")) { value += "/"; } ServerCore.ConfigurationServer = value; } else { Logging.Warning("ServerCore.init: invalid server url: " + value); } } else { Logging.Warning("ServerCore.init server url is empty"); } break; case "-id": ServerCore.Id = int.Parse(value); break; } } } else { Logging.Warning("ServerCore.init invalid args length"); } } ServerCore.Random = new LogicRandom((int)DateTime.UtcNow.Ticks); Directory.SetCurrentDirectory(AppContext.BaseDirectory); Logging.Init(); EnvironmentSettings.Init(); ResourceSettings.Init(); GamePlaySettings.Init(); ResourceManager.Init(); ServerRequestManager.Init(); ServerManager.Init(); ServerCore.Socket = ServerManager.GetSocket(ServerCore.Type, ServerCore.Id); }
public static Story Deserialize(DataStream reader) { Story newStory = new Story(); newStory.StoryName = reader.ReadString8(); int chapterCount = reader.ReadSInt32(); newStory.Chapters = new SortedDictionary <int, Chapter>(); for (int i = 0; i < chapterCount; i++) { Chapter chapter = Chapter.Deserialize(reader); if (newStory.Chapters.ContainsKey(chapter.ChapterID)) { Utils.DebugLog("Duplicate! chapter.ChapterID: " + chapter.ChapterID); } else { newStory.Chapters.Add(chapter.ChapterID, chapter); } } int cldCount = reader.ReadSInt32(); newStory.Base_CardLimitDict = new SortedDictionary <int, int>(); for (int i = 0; i < cldCount; i++) { int key = reader.ReadSInt32(); int value = reader.ReadSInt32(); if (newStory.Base_CardLimitDict.ContainsKey(key)) { Utils.DebugLog("Duplicate! Base_CardLimitDict.key: " + key); } else { newStory.Base_CardLimitDict.Add(key, value); } } int cardUnlockInfoCount = reader.ReadSInt32(); SortedDictionary <int, bool> cardUnlockInfos = new SortedDictionary <int, bool>(); for (int i = 0; i < cardUnlockInfoCount; i++) { int cardID = reader.ReadSInt32(); bool unlock = reader.ReadByte() == 0x01; cardUnlockInfos.Add(cardID, unlock); } newStory.CardUnlockInfos = cardUnlockInfos; int buildCount = reader.ReadSInt32(); newStory.PlayerBuildInfos = new SortedDictionary <int, BuildInfo>(); for (int i = 0; i < buildCount; i++) { BuildInfo bi = BuildInfo.Deserialize(reader); if (newStory.PlayerBuildInfos.ContainsKey(bi.BuildID)) { Utils.DebugLog("Duplicate! bi.BuildID: " + bi.BuildID); } else { newStory.PlayerBuildInfos.Add(bi.BuildID, bi); } } newStory.StoryGamePlaySettings = GamePlaySettings.Deserialize(reader); newStory.CurrentFightingChapterID = reader.ReadSInt32(); newStory.Crystal = reader.ReadSInt32(); return(newStory); }