예제 #1
0
        public bool Organize(object[] Params)
        {
            FinishedCycle = false;
            if (CurrentGroup != null)
            {
                //check for group members who haven't checked it, keep waiting if there are
                RelayAll("active", Self.CharacterName, Self.LeadershipValue.ToString(), Self.Role.ToString());
                RelayAll("available", Self.CharacterName, Self.Available.ToString());

                if (!Session.InFleet)
                {
                    //i'm not in a fleet, should i wait for an invite or create a fleet?
                    if (!CurrentGroup.ActiveMembers.Any(a => a.InFleet) &&
                        !CurrentGroup.ActiveMembers.Any(a => a.CharacterName == Me.Name && a.Role == Role.Booster && Local.Pilots.Any(b => b.Name == a.CharacterName)))
                    {
                        //nobody else is in a fleet, i can make one
                        Log.Log("|oCreating fleet");
                        Fleet.CreateFleet();
                        RelayAll("joinedfleet", Self.CharacterName);
                        Self.InFleet = true;
                        return(false);
                    }
                    else
                    {
                        //someone else is in a fleet , wait for an invite from another group member
                        if (CurrentGroup.ActiveMembers.Any(a => Window.All.OfType <PopupWindow>().Any(b => b.Message.Contains(a.CharacterName))))
                        {
                            Log.Log("|oAccepting fleet invite");
                            Window FleetInviteWindow = Window.All.OfType <PopupWindow>().FirstOrDefault(a => CurrentGroup.ActiveMembers.Any(b => a.Message.Contains(b.CharacterName)));
                            if (FleetInviteWindow != null)
                            {
                                FleetInviteWindow.ClickButton(Window.Button.Yes);
                                return(false);
                            }
                        }
                        return(false);
                    }
                }
                else if (!Self.InFleet)
                {
                    RelayAll("joinedfleet", Self.CharacterName);
                    Self.InFleet = true;
                    return(false);
                }
                //am i the only person in the fleet?
                if (Fleet.Members.Count == 1)
                {
                    //hand out invites!
                    Pilot ToInvite = Local.Pilots.FirstOrDefault(a => !InFleet(a.Name) && CurrentGroup.ActiveMembers.Any(b => b.CharacterName == a.Name && b.Active && b.Available));
                    if (ToInvite != null)
                    {
                        Log.Log("|oInviting fleet member");
                        Log.Log(" |-g{0}", ToInvite.Name);
                        Fleet.Invite(ToInvite, Fleet.Wings[0], Fleet.Wings[0].Squads[0], FleetRole.SquadMember);
                        return(false);
                    }
                }

                //who should be squad leader
                ActiveMember newLeader = CurrentGroup.ActiveMembers.Where(a => a.Active && a.Role != Role.Hauler).OrderByDescending(a => a.LeadershipValue).ThenBy(b => b.CharacterName).FirstOrDefault(a => a.Active && a.Available && Fleet.Members.Any(fleetmember => fleetmember.Name == a.CharacterName));
                if (newLeader != null)
                {
                    if (Leader != newLeader)
                    {
                        //oh shit we got a new leader , if it's not me i should check i wasn't the old one
                        Log.Log("|oSelecting new leader");
                        Log.Log(" |-g{0}", newLeader.CharacterName);
                        //check if the new leader isnt me
                        if (newLeader.CharacterName != Self.CharacterName)
                        {
                            //it's not me check if i have to hand boss over
                            if (FleetBoss.Name == Self.CharacterName)
                            {
                                //i'm the squad leader but no the leader!! better give boss to new leader
                                Log.Log("|oPassing boss to new leader");
                                Log.Log(" |-g{0}", newLeader.CharacterName);
                                Fleet.Members.First(a => a.Name == newLeader.CharacterName).MakeBoss();
                                Leader = newLeader;
                                return(false);
                            }
                        }
                        Leader = newLeader;
                    }

                    //Am I the leader?
                    if (Leader.CharacterName == Self.CharacterName)
                    {
                        //am I da boss
                        if (FleetBoss.Name == Me.Name)
                        {
                            //am i the squad leader?
                            FleetMember commander = Fleet.Wings[0].Members.FirstOrDefault(a => a.Role == FleetRole.SquadCommander);
                            if (commander != null)
                            {
                                //someone is squad leader, is it me?
                                if (commander.Name != Me.Name)
                                {
                                    //it's not me! , demote that guy
                                    commander.Move(Fleet.Wings[0], Fleet.Wings[0].Squads[0], FleetRole.SquadMember);
                                    return(false);
                                }
                            }
                            else
                            {
                                //nobody is squad leader, make me squad leader!
                                Fleet.Members.First(a => a.Name == Me.Name).Move(Fleet.Wings[0], Fleet.Wings[0].Squads[0], FleetRole.SquadCommander);
                                return(false);
                            }

                            //are there invites to do?
                            Pilot ToInvite = Local.Pilots.FirstOrDefault(a => !InFleet(a.Name) && CurrentGroup.ActiveMembers.Any(b => b.CharacterName == a.Name && b.Available && b.Active));
                            if (ToInvite != null)
                            {
                                Log.Log("|oInviting fleet member");
                                Log.Log(" |-g{0}", ToInvite.Name);
                                Fleet.Invite(ToInvite, Fleet.Wings[0], Fleet.Wings[0].Squads[0], FleetRole.SquadMember);
                                return(false);
                            }

                            //Is there a booster?
                            FleetMember fleetbooster = Fleet.Wings[0].Squads[0].Members.FirstOrDefault(a => a.RoleBooster == BoosterRole.SquadBooster);
                            if (fleetbooster == null && Fleet.Wings[0].Squads[0].Commander.RoleBooster == BoosterRole.SquadBooster)
                            {
                                fleetbooster = Fleet.Wings[0].Squads[0].Commander;
                            }
                            ActiveMember booster = CurrentGroup.ActiveMembers.FirstOrDefault(a => a.Role == Role.Booster);
                            if (booster != null)
                            {
                                FleetMember newBooster = Fleet.Members.FirstOrDefault(a => a.Name == booster.CharacterName);
                                if (newBooster != null)
                                {
                                    if (fleetbooster == null)
                                    {
                                        Log.Log("|oSetting squad booster");
                                        Log.Log(" |-g{0}", booster.CharacterName);
                                        newBooster.SetBooster(BoosterRole.SquadBooster);
                                        return(false);
                                    }
                                    if (fleetbooster.Name != booster.CharacterName)
                                    {
                                        Log.Log("|oRevoking squad booster");
                                        Log.Log(" |-g{0}", fleetbooster.Name);
                                        fleetbooster.SetBooster(BoosterRole.NonBooster);
                                        return(false);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //im not the boss, hopefully the old boss will make me the boss
                            return(false);
                        }
                    }
                }

                // Don't mark cycle finished if there are more pilots to invite
                Pilot PendingInvite = Local.Pilots.FirstOrDefault(a => !InFleet(a.Name) && CurrentGroup.ActiveMembers.Any(b => b.CharacterName == a.Name && b.Available && b.Active));
                if (PendingInvite != null)
                {
                    return(false);
                }

                FinishedCycle = true;
                return(false);
            }
            else
            {
                QueueState(InitializeSelf);
                return(true);
            }
        }
예제 #2
0
        void UpdateGroupControl(object sender, LSEventArgs args)
        {
            try
            {
                switch (args.Args[0])
                {
                case "active":
                    if (CurrentGroup != null)
                    {
                        ActiveMember activeMember = CurrentGroup.ActiveMembers.FirstOrDefault(a => a.CharacterName == args.Args[1]);
                        if (activeMember != null)
                        {
                            if (!activeMember.Active)
                            {
                                activeMember.Active = true;
                            }
                            activeMember.LeadershipValue = Convert.ToInt32(args.Args[2]);
                            activeMember.Role            = (Role)Enum.Parse(typeof(Role), args.Args[3]);
                        }
                    }
                    break;

                case "available":
                    if (CurrentGroup != null)
                    {
                        ActiveMember availableMember = CurrentGroup.ActiveMembers.FirstOrDefault(a => a.CharacterName == args.Args[1]);
                        if (availableMember != null)
                        {
                            availableMember.Available = Convert.ToBoolean(args.Args[2]);
                        }
                    }
                    break;

                case "joinedfleet":
                    if (CurrentGroup != null)
                    {
                        ActiveMember joinedFleet = CurrentGroup.ActiveMembers.FirstOrDefault(a => a.CharacterName == args.Args[1]);
                        if (joinedFleet != null)
                        {
                            if (!joinedFleet.InFleet)
                            {
                                joinedFleet.InFleet = true;
                            }
                        }
                    }
                    break;

                case "reloadConfig":
                    LoadConfig();
                    break;

                case "forceupdate":
                    if (Self.CharacterName != null)
                    {
                        RelayAll("active", Self.CharacterName, Self.LeadershipValue.ToString(), Self.Role.ToString());
                        RelayAll("available", Self.CharacterName, Self.Available.ToString());
                        if (Self.InFleet)
                        {
                            RelayAll("joinedfleet", Self.CharacterName);
                        }
                    }
                    break;
                }
            }
            catch
            {
                // ignored
            }
        }