Ejemplo n.º 1
0
        /// <summary>
        /// Assings roles for players
        /// </summary>
        void AssignPlayerRoles()
        {
            Random rnd = new Random();

            List <MRKToSPlayer> unassigned = new List <MRKToSPlayer>();

            foreach (MRKToSPlayer player in Players)
            {
                unassigned.Add(player);
            }

            foreach (MRKToSRoleID role in Settings.Gamemode.RoleList)
            {
                Dictionary <MRKToSPlayer, RoleAssignmentContext> ctx = new Dictionary <MRKToSPlayer, RoleAssignmentContext>();
                int   totalLots = 1;
                int[] playerMap = new int[unassigned.Count];

                int idx = 0;
                foreach (MRKToSPlayer player in unassigned)
                {
                    MRKToSScroll scroll     = player.GetScroll(role);
                    int          playerLots = 10 * (scroll.Count > 0 ? Settings.ScrollMultiplier : 1);

                    playerMap[idx++] = totalLots;

                    totalLots += playerLots;

                    ctx[player] = new RoleAssignmentContext {
                        Lots   = playerLots,
                        Scroll = scroll
                    };
                }

                int num = rnd.Next(totalLots) + 1;
                int playerIdxForRole = -1;
                for (int i = unassigned.Count - 1; i > -1; i--)
                {
                    if (num > playerMap[i])
                    {
                        playerIdxForRole = i;
                        break;
                    }
                }

                MRKToSPlayer __player = unassigned[playerIdxForRole];
                if (ctx[__player].Scroll.Count > 0)
                {
                    ctx[__player].Scroll.Count--;
                }

                __player.Role = (MRKToSRole)Activator.CreateInstance(ms_RoleAssignmentMap[role], __player);
                unassigned.Remove(__player);
            }

            MatchListener.OnMatchRolesAssigned();
        }
Ejemplo n.º 2
0
        public MRKToSRole(MRKToSPlayer player)
        {
            m_NightDefence = new List <MRKToSNightDefence>();

            m_TargetsBuffer  = new List <MRKToSPlayer>();
            m_DynamicButtons = new List <MRKToSDynamicButton>();
            m_Visitors       = new List <MRKToSPlayer>();

            Player = player;
        }
Ejemplo n.º 3
0
        public MRKToSDynamicButton CreateDynamicButton(MRKToSPlayer owner, string name, Action <MRKToSDynamicButton, bool> stateDel = null)
        {
            MRKToSDynamicButton button = new MRKToSDynamicButton(owner, name, stateDel);

            m_Buttons[button.ID] = button;

            //handle button creation
            owner.Match.UIListener.OnDynamicButtonCreated(button);

            return(button);
        }
Ejemplo n.º 4
0
        protected override void OnDynamicButtonStateChanged(MRKToSDynamicButton button, bool newState)
        {
            MRKToSPlayer newTarget = GetTargetFromButton(button);

            if (newTarget == Target)
            {
                Target = null;

                Player.SendMessage(MRKToSGameMessages.MRKTOS_GENERIC_TARGETNONE);
                return;
            }

            Player.SendMessage(newTarget == Player ? MRKToSGameMessages.MRKTOS_BODYGUARD_TARGETSELF :
                               string.Format(MRKToSGameMessages.MRKTOS_BODYGUARD_TARGETOTHER, newTarget.Name));

            Target = newTarget;
        }
Ejemplo n.º 5
0
 public MRKToSNightDefence(MRKToSDefenceType defenceType, MRKToSPlayer provider)
 {
     DefenceType     = defenceType;
     DefenceProvider = provider;
 }
Ejemplo n.º 6
0
 public MRKToSRoleBodyguard(MRKToSPlayer player) : base(player)
 {
     m_VestsLeft = 1; //1 bulletproof vest
 }
Ejemplo n.º 7
0
 public void AddNightDefence(MRKToSDefenceType type, MRKToSPlayer provider)
 {
     m_NightDefence.Add(new MRKToSNightDefence(type, provider));
 }