/// <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(); }
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; }
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); }
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; }
public MRKToSNightDefence(MRKToSDefenceType defenceType, MRKToSPlayer provider) { DefenceType = defenceType; DefenceProvider = provider; }
public MRKToSRoleBodyguard(MRKToSPlayer player) : base(player) { m_VestsLeft = 1; //1 bulletproof vest }
public void AddNightDefence(MRKToSDefenceType type, MRKToSPlayer provider) { m_NightDefence.Add(new MRKToSNightDefence(type, provider)); }