public GameObject FindClosetToFollow(FollowerJob newJob, BeliefControler beliefControler, FactionCom factionCom) { var applcableFactions = _factionLst.Values.Where(i => i.Leader.beliefControler.LeftLeaning == beliefControler.LeftLeaning && i.Leader.normalPersonAI.HasJob); if (applcableFactions.Count() == 0) { return(null); } SortedList <float, Faction> canadiets = new SortedList <float, Faction>(); Faction tMin = null; foreach (var go in applcableFactions) { float diff = Mathf.Abs(go.Leaning - beliefControler.TotalLeaning); canadiets.Add(diff, go); } int n = (int)System.Math.Max(canadiets.Count * 0.3f, 1); while (canadiets.Count > n) { canadiets.RemoveAt(canadiets.IndexOfValue(canadiets.Last().Value)); } tMin = Helper.FindClosest(canadiets.Values.Select(i => i.Leader), factionCom.normalPersonAI.Home.door).Faction; factionCom.Faction = tMin; tMin.AddMember(factionCom); return(tMin.Leader.beliefControler.gameObject); }
void OnFactionJoinCommand(User user, string[] args) { if (args.Length != 1) { user.SendChatMessage(Messages.Usage, "/faction join FACTION"); return; } if (user.Faction != null) { user.SendChatMessage(Messages.AlreadyMemberOfFaction); return; } Faction faction = Factions.Get(args[0]); if (faction == null) { user.SendChatMessage(Messages.FactionDoesNotExist, args[0]); return; } if (!faction.HasInvite(user)) { user.SendChatMessage(Messages.CannotJoinFactionNotInvited, faction.Id); return; } user.SendChatMessage(Messages.YouJoinedFaction, faction.Id); PrintToChat(Messages.FactionMemberJoinedAnnouncement, user.UserName, faction.Id); Log($"{Util.Format(user)} joined faction {faction.Id}"); faction.AddMember(user); user.SetFaction(faction); }
public void SetFaction(Faction faction) { if (_faction != null) { _faction.RemoveMember(this); } _faction = faction; _faction.AddMember(this); UpdateColors(); }