コード例 #1
0
        private void MoveFleetMemberToFirstSquadWithRoom(FleetMember fleetMember)
        {
            var methodName = "MoveFleetMemberToFirstSquadWithRoom";

            LogTrace(methodName, "{0}", fleetMember.ID);

            var wings          = StealthBot.MeCache.Me.Fleet.GetWings();
            var squadsWithRoom = new List <long>();
            var wingsBySquadId = new Dictionary <long, long>();

            foreach (var wing in wings)
            {
                var squads = StealthBot.MeCache.Me.Fleet.GetSquads(wing);
                foreach (var squad in squads)
                {
                    wingsBySquadId.Add(squad, wing);

                    var freeSpaceInSquad = 10 - StealthBot.MeCache.FleetMembersById.Values.Count(fm => fm.SquadID == squad);
                    if (freeSpaceInSquad > 0)
                    {
                        squadsWithRoom.Add(squad);
                    }
                }
            }

            if (squadsWithRoom.Count == 0)
            {
                ExpandFleet(wings);
                return;
            }

            var squadToMoveTo = squadsWithRoom.Last();
            var wingToMoveTo  = wingsBySquadId[squadToMoveTo];

            LogMessage(methodName, LogSeverityTypes.Debug, "Moving fleet member {0} to wing {1}, squad {2}.",
                       fleetMember.CharID, wingToMoveTo, squadToMoveTo);
            fleetMember.Move(wingToMoveTo, squadToMoveTo);
        }
コード例 #2
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);
            }
        }