Пример #1
0
        public override void Created(PlayerTask playerTask)
        {
            Guid opponentId = new Guid(playerTask.data);             // take the opponent id from the temp data value

            // by specifying the data param we avoid unwanted recursion in player task creation
            PlayerTask oppoTask = PlayerTask.CreateTask("prisonersdilemma", opponentId, playerTask.id + ",");

            playerTask.data = oppoTask.id + ",";             // from now on, the data values will be: "{opponent task id},{my chosen state}"
            playerTask.Save();
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        public override void Created(PlayerTask playerTask)
        {
            PlayerItem finalAssemblyItem = playerTask.GetPlayer.GetItems.SingleOrDefault(o => o.GetItem.size == 3);

            // other final assembly items on your team (excluding yours) // assign them all this task
            foreach (PlayerItem item in playerTask.GetPlayer.GetTeam.GetPlayers.SelectMany(o => o.GetItems).Where(o => o.GetItem.size == 3).Where(o => o.itemId != finalAssemblyItem.itemId))
            {
                // if they do not already have this task, then assign it to them
                if (!item.GetPlayer.GetTasks.Any(o => o.taskId == "final"))
                {
                    PlayerTask.CreateTask("final", item.playerId);
                }
            }
        }
Пример #4
0
        public override void Created(PlayerTask playerTask)
        {
            // other teams
            foreach (Team team in Team.GetAll().Where(o => o.id != playerTask.GetPlayer.teamId))
            {
                var highestRankedAgent = team.GetPlayers.OrderByDescending(o => o.Rank).First();
                if (highestRankedAgent == null)
                {
                    continue;
                }
                PlayerTask.CreateTask("summit", highestRankedAgent.id, _primes[HGameApp.Rnd.Next(_primes.Length)] + ",0");
            }

            Newsfeed.Create("The once-every-century Earth Plutocratic Congress Interagency Technology Summit has commenced. Best of luck to the company representatives.", Newsfeed.Context.success);
        }
Пример #5
0
        public override void UpdateTask(PlayerTask playerTask, System.Web.Mvc.FormCollection form)
        {
            Player player = Player.Load(playerTask.playerId);

            // all players on other teams with items (non-unique, 2 or smaller)
            int maxSize          = Math.Max(2, player.AvailableItemSlots);
            var playersWithItems = Team.GetAll().Where(o => o.id != playerTask.GetPlayer.teamId).SelectMany(o => o.GetPlayers).Where(o => o.GetItems.Count(i => i.GetItem.size <= maxSize && !i.GetItem.unique) > 0).ToList();

            if (player.AvailableItemSlots < 1)
            {
                // do nothing, I guess
            }
            else if (playersWithItems.Count == 0)
            {
                // no one to steal from, so just give them an item
                player.GiveRandomItem(1);
            }
            else
            {
                Player victim        = playersWithItems[HGameApp.Rnd.Next(playersWithItems.Count)];
                var    possibleItems = victim.GetItems.Where(o => o.GetItem.size <= maxSize).ToList();
                var    victimItem    = possibleItems[HGameApp.Rnd.Next(possibleItems.Count)];

                player.AddItem(victimItem.itemId);

                victimItem.Delete();
                Notification.CreatePlayer("Your <b>" + victimItem.GetItem.name + "</b> dissappears under mysterious circumstances.", victim.id);

                // 20% of the time just stop
                if (HGameApp.Rnd.Next(100) > 20)
                {
                    PlayerTask.CreateTask("buttonunit", victim.id);
                }
            }

            Notification.CreatePlayer("The strange man returns, reclaims the Button Unit, and explains that it will be offered to someone whom you don't know.", player.id);

            playerTask.State = Task.TaskState.Completed;
            playerTask.Save();
        }
Пример #6
0
        public override void UpdateTask(PlayerTask playerTask, System.Web.Mvc.FormCollection form)
        {
            Player player = Player.Load(playerTask.playerId);

            if (player.GetTeam.GetPlayers.Min(o => o.Rank) == player.Rank)
            {
                // lowest rank just does it
                player.Rank += 9;
                player.Save();

                player.GetTeam.score += 8;
                player.GetTeam.Save();

                playerTask.State = Task.TaskState.Completed;
                playerTask.Save();

                return;
            }

            Player transferPlayer = Player.Load(form["data"]);

            if (transferPlayer == null || transferPlayer.Rank > player.Rank)
            {
                return;
            }

            player.Rank += 8;
            player.Save();

            PlayerTask.CreateTask("delegatedown", transferPlayer.id);
            transferPlayer.GenerateNewAgentCode();

            player.GetTeam.score += 5;
            player.GetTeam.Save();

            playerTask.State = Task.TaskState.Completed;
            playerTask.Save();
        }