public override string Init(Player player) { // figrue out who had the button unit last (if any) var lastBUtask = PlayerTask.GetAll().Where(o => o.taskId == "buttonunit").OrderByDescending(o => o.assigned).FirstOrDefault(); return(lastBUtask != null ? lastBUtask.playerId.ToString() : ""); // player id of the last person to have the button unit }
public override bool CheckDependencies(Player player) { // task can't already exist if (PlayerTask.GetAll().Any(o => o.State == Task.TaskState.Waiting && o.taskId == "buttonunit")) { return(false); } // must have a slot return(player.AvailableItemSlots > 0); }
public override bool CheckDependencies(Player player) { // only one at a time if (PlayerTask.GetAll().Any(o => o.taskId == "summit" && o.State == Task.TaskState.Waiting)) { return(false); } // all teams must have active players // AND you must be the mostly highly ranked (or at least tied) return(Team.GetAll().All(o => o.GetPlayers.Count > 0) && player.GetTeam.GetPlayers.Max(o => o.Rank) == player.Rank); }
/// <summary> Check for and manage idle players. </summary> public void CheckIdle() { // already idle, see about transfering possessions if (idle) { if (!IdleUpdate.HasValue) { IdleUpdate = DateTime.Now; } if (DateTime.Now.Subtract(IdleUpdate.Value).TotalMinutes < 2) { return; // wait two minutes between reappropriation } IdleUpdate = DateTime.Now; // give away player's items var otherplayers = GetTeam.GetPlayers.Where(o => o.id != id); foreach (PlayerItem item in GetItems.OrderByDescending(o => o.GetItem.size)) { var possiblereipient = otherplayers.Where(o => o.AvailableItemSlots >= item.GetItem.size).ToList(); if (possiblereipient.Count == 0) { continue; // sadly, no one can take this item } var recipient = possiblereipient[HGameApp.Rnd.Next(possiblereipient.Count)]; recipient.AddItem(item.itemId); Notification.CreatePlayer("You notice your teammate, <b>" + Name + "</b>, taking a nap so you appropriate the unused <b>" + item.GetItem.name + "</b>.", recipient.id); item.Delete(); Notification.CreatePlayer("While you were napping, another agent borrowed your <b>" + item.GetItem.name + "</b>.", id); return; } return; } if (PlayerTask.GetAll(id).Count < 3 || GetTasks.Count > 0) { return; // must have had at least three task and cannot have any current active tasks } if (!PlayerTask.GetAll(id).OrderByDescending(o => o.assigned).Take(3).All(o => o.State == Task.TaskState.Expired)) { return; // 3 most-recent must all be expired } idle = true; Save(); Notification.CreatePlayer("You've apparently decided to take a nap for some reason.", id); IdleUpdate = DateTime.Now; PlayerTask.CreateTask("wakeup", id); }
/// <summary> Assign a new task to this player. Maybe. </summary> public static void AssignTaskMaybe(Guid playerId) { Player player = Player.Load(playerId); player.CheckIdle(); // no slots for new tasks if (GetAll(playerId).Where(o => o.State == Task.TaskState.Waiting).Count() >= player.TaskSlots) { return; } var lastTask = GetLastTask(playerId); TimeSpan timeSinceLastTask = lastTask != null?DateTime.Now.Subtract(lastTask.assigned) : TimeSpan.MaxValue; // the larger the timeSince value is, the more likely we are to get a new task double p = timeSinceLastTask.TotalSeconds * HGameApp.Settings.TaskRate / 100; if (HGameApp.Rnd.Next(100) > p) { return; } // find all suitable tasks var allSuitableTasks = Task.GetAll().Where(o => o.active && !o.manual && player.Rank >= o.minPlayerRank && player.GetTeam.TechLevel >= o.minTechLevel && o.GetTaskDetail().CheckDependencies(player)).ToList(); // remove any tasks that the player has just had (within the past five) var lastFiveTasks = PlayerTask.GetAll(playerId).OrderByDescending(o => o.assigned).Take(5); allSuitableTasks.RemoveAll(o => lastFiveTasks.Select(t => t.taskId).Contains(o.id)); if (allSuitableTasks.Count == 0) { return; } // assign this player a new task Task newTask = allSuitableTasks[HGameApp.Rnd.Next(allSuitableTasks.Count)]; CreateTask(newTask.id, playerId); }
private static List <PlayerTask> GetSummitTasks() { return(PlayerTask.GetAll().Where(o => o.taskId == "summit").OrderByDescending(o => o.assigned).Take(3).ToList()); }