/// <summary> /// Gets and removes the InstanceLog for the given Character /// </summary> /// <param name="character"></param> internal static void RetrieveInstances(Character character) { using (syncLock.EnterReadLock()) { InstanceCollection instancesUnlocked = GetOfflineInstancesUnlocked(character.EntityId.Low, false, true); if (instancesUnlocked == null) { return; } instancesUnlocked.Character = character; character.Instances = instancesUnlocked; } }
protected void Bind(IInstanceHolderSet holder) { if (holder.InstanceLeader.Group != null) { holder.InstanceLeader.Group.ForeachCharacter(chr => { InstanceCollection instances = chr.Instances; if (instances == null) { return; } instances.BindTo(this); }); } else { holder.InstanceLeaderCollection.BindTo(this); } }
private static InstanceCollection GetOfflineInstancesUnlocked(uint lowId, bool autoCreate, bool remove) { InstanceCollection instanceCollection = null; if (OfflineLogs.ContainsKey(lowId)) { instanceCollection = OfflineLogs[lowId]; if (remove) { OfflineLogs.Remove(lowId); } } if (autoCreate) { instanceCollection = new InstanceCollection(lowId); OfflineLogs.Add(lowId, instanceCollection); } return(instanceCollection); }
/// <summary> /// This is called when an area trigger causes entering an instance /// </summary> public static bool EnterInstance(Character chr, MapTemplate mapTemplate, Vector3 targetPos) { if (!mapTemplate.IsInstance) { log.Error("Character {0} tried to enter \"{1}\" as Instance.", chr, mapTemplate); return(false); } bool isRaid = mapTemplate.Type == MapType.Raid; Group group = chr.Group; if (isRaid && !chr.Role.IsStaff && !group.Flags.HasFlag(GroupFlags.Raid)) { InstanceHandler.SendRequiresRaid(chr.Client, 0); return(false); } if (!mapTemplate.MayEnter(chr)) { return(false); } chr.SendSystemMessage("Entering instance..."); InstanceCollection instances = chr.Instances; BaseInstance instance = instances.GetActiveInstance(mapTemplate); if (instance == null) { if (mapTemplate.GetDifficulty(chr.GetInstanceDifficulty(isRaid)).BindingType == BindingType.Soft && !instances.HasFreeInstanceSlot && !chr.GodMode) { MovementHandler.SendTransferFailure(chr.Client, mapTemplate.Id, MapTransferError.TRANSFER_ABORT_TOO_MANY_INSTANCES); return(false); } if (group != null) { instance = group.GetActiveInstance(mapTemplate); if (instance != null && !CheckFull(instance, chr)) { return(false); } } if (instance == null) { instance = CreateInstance(chr, mapTemplate.InstanceTemplate, chr.GetInstanceDifficulty(isRaid)); if (instance == null) { log.Warn("Could not create Instance \"{0}\" for: {1}", mapTemplate, chr); return(false); } } } else if (!chr.GodMode) { if (!CheckFull(instance, chr)) { return(false); } if (isRaid) { if (group == null) { MovementHandler.SendTransferFailure(chr.Client, instance.Id, MapTransferError.TRANSFER_ABORT_NEED_GROUP); return(false); } InstanceBinding binding1 = group.InstanceLeaderCollection.GetBinding(mapTemplate.Id, BindingType.Hard); InstanceBinding binding2 = instances.GetBinding(mapTemplate.Id, BindingType.Hard); if (binding2 != null && binding1 != binding2) { MovementHandler.SendTransferFailure(chr.Client, instance.Id, MapTransferError.TRANSFER_ABORT_NOT_FOUND); return(false); } } } instance.TeleportInside(chr, targetPos); return(true); }