public Error RemoveTribesman(uint playerId, bool wasKicked, bool doNotRemoveIfOwner = true) { ITribesman tribesman; if (!tribesmen.TryGetValue(playerId, out tribesman)) { return(Error.TribesmanNotFound); } IPlayer player = tribesman.Player; if (IsOwner(player)) { if (doNotRemoveIfOwner) { return(Error.TribesmanIsOwner); } Owner = null; } DefaultMultiObjectLock.ThrowExceptionIfNotLocked(tribesman); player.Tribesman = null; dbManager.Delete(tribesman); tribesmen.Remove(playerId); // Keep logs of who entered/left tribe. First clean up the list of no longer needed records though. LeavingTribesmates.RemoveAll(p => p.PlayerId == player.PlayerId || SystemClock.Now.Subtract(p.TimeLeft).TotalDays > DAYS_BEFORE_REJOIN_ALLOWED); LeavingTribesmates.Add(new LeavingTribesmate { PlayerId = player.PlayerId, TimeLeft = SystemClock.Now }); // Save to save owner and leaving tribesmates dbManager.Save(this); // TODO: Move event out if (player.Session != null) { channel.Unsubscribe(player.Session, "/TRIBE/" + Id); if (wasKicked) { player.Session.Write(new Packet(Command.TribesmanKicked)); } } TribesmanRemoved.Raise(this, new TribesmanRemovedEventArgs { Player = player }); return(Error.Ok); }
public Error AddTribesman(ITribesman tribesman, bool ignoreRequirements = false) { if (tribesmen.ContainsKey(tribesman.Player.PlayerId)) { return(Error.TribesmanAlreadyInTribe); } if (!ignoreRequirements) { if (LeavingTribesmates.Any(p => p.PlayerId == tribesman.Player.PlayerId && SystemClock.Now.Subtract(p.TimeLeft).TotalDays < DAYS_BEFORE_REJOIN_ALLOWED)) { return(Error.TribeCannotRejoinYet); } var totalSlots = Level * MEMBERS_PER_LEVEL - LeavingTribesmates.Count(p => SystemClock.Now.Subtract(p.TimeLeft).TotalHours < HOURS_BEFORE_SLOT_REOPENS); if (tribesmen.Count >= totalSlots) { return(Error.TribeFull); } } DbLoaderAdd(tribesman); DefaultMultiObjectLock.ThrowExceptionIfNotLocked(tribesman); dbManager.Save(tribesman); if (tribesman.Player.Session != null) { channel.Subscribe(tribesman.Player.Session, "/TRIBE/" + Id); } TribesmanJoined.Raise(this, new TribesmanEventArgs { Tribe = this, Player = tribesman.Player }); return(Error.Ok); }