public async Task <JsonResult> DelGame(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); var user = await _userManager.GetUserAsync(HttpContext.User); if (user != null) { GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id); if (gameInfoModel != null) { GaiaGame gaiaGame = GameMgr.GetGameByName(gameInfoModel.name); foreach (string username in gaiaGame.Username) { //如果不是自己 if (username != user.UserName) { this.dbContext.GameDeleteModel.Add(new GameDeleteModel() { gameinfo_id = gameInfoModel.Id, gameinfo_name = gameInfoModel.name, username = username, state = 0, }); } } gameInfoModel.isDelete = 1; this.dbContext.SaveChanges(); jsonData.info.state = 200; } } return(new JsonResult(jsonData)); }
public static bool ReportBug(string id) { var gg = GetGameByName(id); if (gg == null) { return(false); } string[] newUserName = new string[4]; for (int i = 0; i < 4; i++) { if (string.IsNullOrEmpty(gg.Username[i])) { newUserName[i] = null; } else { newUserName[i] = "*****@*****.**"; } } var ggNew = new GaiaGame(newUserName); ggNew.UserActionLog = gg.UserActionLog; RestoreGameWithActionLog(new KeyValuePair <string, GaiaGame>(id + "Debug" + DateTime.Now.ToString("yyyyMMddHHmmss"), ggNew)); return(true); }
public IActionResult LeechPower(string name, FactionName factionName, int power, FactionName leechFactionName, bool isLeech, bool?isPwFirst) { if (ServerStatus.IsStopSyntax == true) { return(Redirect("/home/serverdown")); } var task = _userManager.GetUserAsync(HttpContext.User); Task[] taskarray = new Task[] { task }; Task.WaitAll(taskarray, millisecondsTimeout: 1000); var faction = GameMgr.GetGameByName(name).FactionList.Find(x => x.FactionName.ToString().Equals(name)); var leech = isLeech ? "leech" : "decline"; var syntax = string.Format("{0}:{1} {2} from {3}", factionName, leech, power, leechFactionName); if (isPwFirst.HasValue) { var pwFirst = isPwFirst.GetValueOrDefault() ? "pw" : "pwt"; syntax = syntax + " " + pwFirst; } GaiaGame gaiaGame = GameMgr.GetGameByName(name); try { //GameMgr.WriteUserActionLog(syntax, task.Result.UserName); } catch { } gaiaGame.Syntax(syntax, out string log, dbContext: this.dbContext); //如果是即时制游戏,进行通知 if (gaiaGame.IsSocket) { NoticeWebSocketMiddleware.GameActive(gaiaGame, HttpContext.User); } return(Redirect("/home/viewgame/" + System.Net.WebUtility.UrlEncode(name))); }
public Firaks(GaiaGame gg) : base(FactionName.Firaks, gg) { this.ChineseName = "章鱼人"; base.SetColor(5); m_knowledge -= 1; m_ore -= 1; }
public Lantida(GaiaGame gg) : base(FactionName.Lantida, gg) { this.ChineseName = "亚特兰斯星人"; base.SetColor(0); PowerToken1 += 2; PowerToken2 -= 4; Credit -= 2; }
public Itar(GaiaGame gg) : base(FactionName.Itar, gg) { this.ChineseName = "伊塔星人"; base.SetColor(6); m_ore += 1; m_powerToken1 += 2; }
public string Syntax(string name, string syntax, string factionName) { if (ServerStatus.IsStopSyntax == true) { return("error:" + "服务器维护中"); } var task = _userManager.GetUserAsync(HttpContext.User); Task[] taskarray = new Task[] { task }; Task.WaitAll(taskarray, millisecondsTimeout: 1000); if (task.Result != null) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(syntax)) { return("error:空语句"); } else if (syntax.Contains("drop")) { return("error:系统命令"); } if (!string.IsNullOrEmpty(factionName)) { syntax = string.Format("{0}:{1}", factionName, syntax); } //游戏结束,发送邮件赋值, GaiaCore.Gaia.Game.DbGameSave._emailSender = this._emailSender; //执行命令 GaiaGame gaiaGame = GameMgr.GetGameByName(name); try { GameMgr.WriteUserActionLog(syntax, task.Result.UserName); } catch { _logger.LogInformation(syntax); } gaiaGame.Syntax(syntax, out string log, task.Result.UserName, dbContext: this.dbContext); if (!string.IsNullOrEmpty(log)) { return("error:" + log); } else { //如果是即时制游戏,进行通知 if (gaiaGame.IsSocket) { NoticeWebSocketMiddleware.GameActive(gaiaGame, HttpContext.User); } return("ok"); } } else { ModelState.AddModelError(string.Empty, "没有获取到用户名"); return("error:未登入用户"); } }
public override void InvokeAction() { var gamelist = GameMgr.GetAllGameName(); foreach (var item in gamelist) { GaiaGame gaiaGame = GameMgr.GetGameByName(item); //删除结束游戏 if (gaiaGame.GameStatus.stage == Stage.GAMEEND) { GameMgr.RemoveAndBackupGame(item); continue; } //判断上次行动时间是否大于设置drop时间 int hours = gaiaGame.dropHour == 0 ? 240 : gaiaGame.dropHour; #if false hours = 10; #endif if (DateTime.Now.AddDays(-hours / 24) > gaiaGame.LastMoveTime) { //GameMgr.RemoveAndBackupGame(item); //不需要备份直接删除 //GameMgr.DeleteOneGame(item); //记录用户drop 次数 //drop String userName = gaiaGame.GetCurrentUserName(); //如果没有用户 //或者时2人游戏 //没有用户 //用户数量不等 //第0回合 //一场多个用户 if (String.IsNullOrEmpty(userName) || gaiaGame.UserCount == 2 || gaiaGame.UserGameModels == null || gaiaGame.UserGameModels.Count != gaiaGame.UserCount || gaiaGame.GameStatus.RoundCount == 0 || gaiaGame.UserGameModels.FindAll(user => user.username == userName).Count > 1) { GameMgr.DeleteOneGame(item); continue; } else { try { Faction faction = gaiaGame.FactionList.SingleOrDefault((Faction fac) => fac.UserName == userName); gaiaGame.Syntax(faction.FactionName.ToString() + ":drop", out string _, "", null); } catch (Exception e) { Console.WriteLine(e); } } } } }
public Geoden(GaiaGame gg) : base(FactionName.Geoden, gg) { this.ChineseName = "晶矿星人"; base.SetColor(2); if (gg != null) { IncreaseTech("tf"); } }
public Ambas(GaiaGame gg) : base(FactionName.Ambas, gg) { this.ChineseName = "大使星人"; base.SetColor(4); if (gg != null) { IncreaseTech("ship"); } }
public string UpdateFromDb(Func <GameInfoModel, bool> func) { List <GameInfoModel> list = this.dbContext.GameInfoModel.Where(func).ToList();//item => item.GameStatus != 8 foreach (GameInfoModel gameInfoModel in list) { //如果日志不是空的 if (!string.IsNullOrEmpty(gameInfoModel.loginfo)) { NewGameViewModel newGameViewModel = new NewGameViewModel() { dropHour = 72, IsAllowLook = gameInfoModel.IsAllowLook, isHall = gameInfoModel.isHall, IsRandomOrder = gameInfoModel.IsRandomOrder, IsRotatoMap = gameInfoModel.IsRotatoMap, IsSocket = false, IsTestGame = gameInfoModel.IsTestGame == 1, jinzhiFaction = gameInfoModel.jinzhiFaction, MapSelction = gameInfoModel.MapSelction, Name = gameInfoModel.name }; GameMgr.CreateNewGame(gameInfoModel.userlist.Split('|'), newGameViewModel, out GaiaGame result); // GameMgr.CreateNewGame(gameInfoModel.name, gameInfoModel.userlist.Split('|'), out GaiaGame result, gameInfoModel.MapSelction, isTestGame: gameInfoModel.IsTestGame == 1 ? true : false,version:gameInfoModel.version); GaiaGame gg = GameMgr.GetGameByName(gameInfoModel.name); //gg.dbContext = this.dbContext; gg.GameName = gameInfoModel.name; if (gameInfoModel.saveState == 0) { gg.dbContext = this.dbContext; gg.IsSaveToDb = true; gameInfoModel.saveState = 1; } gg.UserActionLog = gameInfoModel.loginfo.Replace("|", "\r\n"); gg = GameMgr.RestoreGame(gameInfoModel.name, gg); //是否应该结束 if (this.FinishGame(gameInfoModel, gg)) { this.dbContext.GameInfoModel.Update(gameInfoModel); //没有找到任何的种族信息 if (!this.dbContext.GameFactionModel.Any(item => item.gameinfo_id == gameInfoModel.Id)) { //保存种族信息 DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel); } else { //总局计分问题,需要重新计算 #if DEBUG DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel); #endif } } //GameMgr.DeleteOneGame(gameInfoModel.name); } } this.dbContext.SaveChanges(); return("success"); }
public MadAndroid(GaiaGame gg) : base(FactionName.MadAndroid, gg) { this.ChineseName = "疯狂机器"; base.SetColor(5); IsMadAndroidAbilityUsed = false; Knowledge -= 2; StrongHold = new MadAndroidSpecialBuildings.StrongHold(); Academy1 = new MadAndroidSpecialBuildings.Academy(); Academy2 = new MadAndroidSpecialBuildings.Academy(); }
public HadschHalla(GaiaGame gg) : base(FactionName.HadschHalla, gg) { this.ChineseName = "圣禽族"; base.SetColor(1); if (gg != null) { IncreaseTech("eco"); } }
public Xenos(GaiaGame gg) : base(FactionName.Xenos, gg) { this.ChineseName = "异空族"; base.SetColor(3); if (gg != null) { IncreaseTech("ai"); } }
public Terraner(GaiaGame gg) : base(FactionName.Terraner, gg) { this.ChineseName = "人类"; base.SetColor(0); m_powerToken1 += 2; if (gg != null) { IncreaseTech("gaia"); } }
public Nevla(GaiaGame gg) : base(FactionName.Nevla, gg) { this.ChineseName = "超星人"; base.SetColor(6); Knowledge -= 1; IsStrongBuild = false; if (gg != null) { IncreaseTech("sci"); } }
/// <summary> /// 游戏行动提醒 /// </summary> /// <param name="gaiaGame"></param> /// <param name="user"></param> public static async void GameActive(GaiaGame gaiaGame, ClaimsPrincipal user) { WebSocket socket; try { string gameName = gaiaGame.GameName; //gameName = "test"; //包含游戏 if (gameList.ContainsKey(gameName)) { ConcurrentDictionary <string, WebSocket> socketInfo = gameList[gameName]; //遍历用户 foreach (string socketInfoKey in socketInfo.Keys) { //不是当前用户,发送提醒 if (socketInfoKey != user.Identity.Name) { //发送信息 try { socket = socketInfo[socketInfoKey]; if (socket.State != WebSocketState.Open) { continue; } //socket.CloseAsync(WebSocketCloseStatus.Empty, "", cancellationToken: new CancellationToken()); //socket = new WebSocket(); await SendStringAsync(socket, "200"); } //发送失败,删除链接 catch (Exception e) { try { socketInfo.TryRemove(socketInfoKey, out WebSocket s1); } catch (Exception exception) { Console.WriteLine(exception.Message); } Console.WriteLine(e.Message); } } } } } catch (Exception e) { Console.WriteLine(e); } }
public BalTak(GaiaGame gg) : base(FactionName.BalTak, gg) { this.ChineseName = "炽炎族"; base.SetColor(2); if (gg != null) { IncreaseTech("gaia"); } QICs -= 1; m_powerToken2 -= 2; TempGaias = new List <GaiaBuilding>(); GaiasGaiaArea = new List <GaiaBuilding>(); }
public Gleen(GaiaGame gg) : base(FactionName.Gleen, gg) { this.ChineseName = "格伦星人"; base.SetColor(3); m_QICs -= 1; IsOreReplaceQICSIncome = true; if (gg != null) { IncreaseTech("ship"); } //Set Green Planet 会多加两分 Score -= 2; }
public async Task <JsonResult> DropFaction(string id, string factionName = null) { GaiaGame gaiaGame = GameMgr.GetGameByName(id); gaiaGame.Syntax(factionName + ":drop", out string log, "", dbContext); return(new JsonResult(new GaiaProject.Models.Data.UserFriendController.JsonData { data = "", info = new GaiaProject.Models.Data.UserFriendController.Info { state = 200 } })); }
/// <summary> /// 跳过回合 /// </summary> public void SkipRound(string id, int round = 6) { GaiaGame gaiaGame = GameMgr.GetGameByName(id); for (int i = gaiaGame.GameStatus.RoundCount; i < 6; i++) { for (int count = 0; count < gaiaGame.UserCount; count++) { gaiaGame.Syntax( string.Format("{1}:pass {0}", gaiaGame.RBTList[0].name, gaiaGame.FactionList[gaiaGame.GameStatus.PlayerIndex].FactionName), out string log, dbContext: this.dbContext); } } }
public async Task <JsonResult> AddGameChat(string id, string contents) { string username = User.Identity.Name; GaiaGame gaiaGame = GameMgr.GetGameByName(id); //判断玩家是否存在 if (!gaiaGame.UserGameModels.Exists(item => item.username == username)) { return(new JsonResult(new GaiaProject.Models.Data.UserFriendController.JsonData { data = "", info = new GaiaProject.Models.Data.UserFriendController.Info { state = 200, message = "不能在其他玩家的游戏中发表留言." } })); } Faction faction = gaiaGame.FactionList.Find(item => item.UserName == username); GameChatModel gameChatModel = new GameChatModel(); gameChatModel.addtime = DateTime.Now; gameChatModel.username = username; gameChatModel.contents = contents; gameChatModel.gameinfo_name = id; gameChatModel.factionname = faction.FactionName.ToString(); //gameChatModel.gameinfo_name //添加到游戏内容中 if (gaiaGame.ListChatModels == null) { gaiaGame.ListChatModels = new List <GameChatModel>(); } gaiaGame.ListChatModels.Add(gameChatModel); return(new JsonResult(new GaiaProject.Models.Data.UserFriendController.JsonData { data = "", info = new GaiaProject.Models.Data.UserFriendController.Info { state = 200 } })); }
/// <summary> /// 修改游戏 /// </summary> /// <param name="id"></param> /// <param name="row"></param> /// <param name="code"></param> /// <returns></returns> public IActionResult ModifyGameSyntax(string id, int row, string code) { GaiaGame gaiaGame = GameMgr.GetGameByName(id); List <LogEntity> logList = gaiaGame.LogEntityList.OrderBy(x => x.Row).ToList(); //string[] syntaxList = gaiaGame.UserActionLog.Split("\r\n"); LogEntity logEntity = logList[row - 1]; logEntity.Syntax = code; StringBuilder stringBuilder = new StringBuilder(); logList.ForEach(item => stringBuilder.Append($"{item.Syntax}\r\n")); gaiaGame.UserActionLog = stringBuilder.ToString(); //重置游戏 GameMgr.RestoreGame(gaiaGame.GameName, gaiaGame, isToDict: true); return(View("ViewGame", gaiaGame)); }
/// <summary> /// 创建游戏,从内存 /// </summary> private GaiaGame CreateGame(string[] username, NewGameViewModel model, out GaiaGame result) { //删除空白玩家 username = username.Where(x => !string.IsNullOrEmpty(x)).ToArray(); //随机排序 if (model.IsRandomOrder) { username = this.RandomSortList <string>(username).ToArray(); } //创建游戏 bool create = GameMgr.CreateNewGame(username, model, out result, _userManager: _userManager); if (!string.IsNullOrEmpty(model.jinzhiFaction)) { var list = new List <Faction>() { new Terraner(null), new Lantida(null), new Hive(null), new HadschHalla(null), new BalTak(null), new Geoden(null), new Gleen(null), new Xenos(null), new Ambas(null), new Taklons(null), new Firaks(null), new MadAndroid(null), new Itar(null), new Nevla(null) }; result.JinzhiFaction = new List <Faction>(); foreach (string name in model.jinzhiFaction.Split(',')) { result.JinzhiFaction.Add(list.Find(fac => fac.FactionName.ToString() == name)); } } return(result); }
public static GaiaGame GetGameByName(string name) { if (name == null) { return(null); } if (m_dic.ContainsKey(name)) { GaiaGame gaiaGame = m_dic[name]; if (gaiaGame.GameName == null) { gaiaGame.GameName = name; } return(gaiaGame); } else { return(null); } }
/// <summary> /// 创建游戏 /// </summary> /// <param name="username"></param> /// <param name="model"></param> /// <param name="result"></param> /// <returns></returns> public static bool CreateNewGame(string[] username, NewGameViewModel model, out GaiaGame result, bool isSaveGame = false, UserManager <ApplicationUser> _userManager = null) { bool create = CreateNewGame(model.Name, username, out result, model.MapSelction, isTestGame: model.IsTestGame, isSocket: model.IsSocket, IsRotatoMap: model.IsRotatoMap, version: 4); if (_userManager != null) { //用户列表 List <UserGameModel> listUser = new List <UserGameModel>(); //判断用户不存在 foreach (var item in username) { var user = _userManager.FindByNameAsync(item); if (user.Result == null) { //ModelState.AddModelError(string.Empty, item + "用户不存在"); //return View("NewGame"); result = null; return(false); } else { listUser.Add(new UserGameModel() { username = item, isTishi = true, paygrade = user.Result.paygrade, scoreUserStart = user.Result.scoreUser, }); } } //赋值用户信息 result.UserGameModels = listUser; } result.dropHour = model.dropHour; if (isSaveGame) { } return(create); }
public async Task <JsonResult> SaveRemark(string id, string remark, bool isTishi) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); GaiaGame gaiaGame = GameMgr.GetGameByName(id); if (gaiaGame != null) { UserGameModel userGameModel = gaiaGame.UserGameModels.Find(x => x.username.ToString() == HttpContext.User.Identity.Name); //备忘 userGameModel.remark = remark; userGameModel.isTishi = isTishi; jsonData.info.state = 200; } else { jsonData.info.state = 0; jsonData.info.message = "保存失败"; } return(new JsonResult(jsonData)); }
/// <summary> /// 还原游戏 /// </summary> public IActionResult RestoreGame(int id, int?row) { GaiaGame gaiaGame = this.RestoreGame(id, out int type, row); if (type == 200)//从日志恢复的 { ViewData["row"] = row; return(View("ViewGame", gaiaGame)); } else if (type == 1)//内存中的游戏 { //var name= Encoding. //return Redirect("/Home/ViewGame/" + gaiaGame.GameName); return(View("ViewGame", gaiaGame)); //return Redirect("/Home/ViewGame/" + gaiaGame.GameName); } else { return(View("Index")); } //GameMgr.UndoOneStep(id); }
/// <summary> /// 创建游戏 /// </summary> /// <param name="name"></param> /// <param name="username"></param> /// <param name="result"></param> /// <param name="MapSelection"></param> /// <param name="seed"></param> /// <param name="isTestGame"></param> /// <param name="isSocket"></param> /// <param name="IsRotatoMap"></param> /// <param name="version"></param> /// <returns></returns> private static bool CreateNewGame(string name, string[] username, out GaiaGame result, string MapSelection, int seed = 0, bool isTestGame = false, bool isSocket = false, bool IsRotatoMap = false, int version = 3) { if (m_dic.ContainsKey(name)) { result = null; return(false); } else { seed = seed == 0 ? RandomInstance.Next(int.MaxValue) : seed; result = new GaiaGame(username, name); result.IsTestGame = isTestGame; result.GameName = name; //游戏名称 result.IsSocket = isSocket; //即时制 result.IsRotatoMap = IsRotatoMap; //旋转地图 result.version = version; //开局的两条命令 result.Syntax(GameSyntax.setupmap + " " + MapSelection, out string log); result.Syntax(GameSyntax.setupGame + seed, out log); m_dic.Add(name, result); return(true); } }
public Faction(FactionName name, GaiaGame gg) { FactionName = name; if (gg == null) { gg = new GaiaGame(new string[] { }); return; } m_powerToken1 = 2; m_powerToken2 = 4; m_powerTokenGaia = 0; m_TransformLevel = 0; m_AILevel = 0; m_EconomicLevel = 0; m_GaiaLevel = 0; m_ScienceLevel = 0; if (gg.IsTestGame) { m_credit = 30; m_knowledge = 15; m_ore = 15; m_QICs = 15; m_powerToken3 = 30; m_ShipLevel = 3; this.m_powerToken1 = 0; this.m_powerToken2 = 0; } else { m_credit = 15; m_knowledge = 3; m_ore = 4; m_QICs = 1; m_powerToken3 = 0; m_ShipLevel = 0; } Mines = new List <Mine>(); for (int i = 0; i < GameConstNumber.MineCount; i++) { Mines.Add(new Mine()); } TradeCenters = new List <TradeCenter>(); for (int i = 0; i < GameConstNumber.TradeCenterCount; i++) { TradeCenters.Add(new TradeCenter()); } ResearchLabs = new List <ResearchLab>(); for (int i = 0; i < GameConstNumber.ResearchLabCount; i++) { ResearchLabs.Add(new ResearchLab()); } Academy1 = new Academy(); Academy2 = new Academy(); StrongHold = new StrongHold(); Gaias = new List <GaiaBuilding>(); GameTileList = new List <GameTiles>(); GameTileListCovered = new List <GameTiles>(); LeechPowerQueue = new List <Tuple <int, FactionName> >(); Score = 10; GaiaGame = gg; ActionQueue = new Queue <Action>(); UnDoActionQueue = new Queue <Action>(); ActionList = new Dictionary <string, Func <Faction, bool> >(); PredicateActionList = new Dictionary <string, Func <Faction, bool> >(); GaiaGame.MapActionMrg.AddMapActionList(ActionList, PredicateActionList); GaiaPlanetNumber = 0; m_allianceMagicLevel = 7; PowerPreview = new List <Tuple <int, int, int> >(); TempQICs = 0; ClockPerid = TimeSpan.Zero; }