コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
            }

            var isRaid = (mapTemplate.Type == MapType.Raid);
            var 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...");

            // Find out if we've been here before
            var instances = chr.Instances;
            var instance  = instances.GetActiveInstance(mapTemplate);

            if (instance == null)
            {
                var difficulty = mapTemplate.GetDifficulty(chr.GetInstanceDifficulty(isRaid));

                // Check whether we were in too many normal dungeons recently
                if (difficulty.BindingType == BindingType.Soft && !instances.HasFreeInstanceSlot && !chr.GodMode)
                {
                    MovementHandler.SendTransferFailure(chr.Client, mapTemplate.Id, MapTransferError.TRANSFER_ABORT_TOO_MANY_INSTANCES);
                    return(false);
                }

                // Check whether we can join a group-owned instance
                if (group != null)
                {
                    instance = group.GetActiveInstance(mapTemplate);
                    if (instance != null)
                    {
                        if (!CheckFull(instance, chr))
                        {
                            return(false);
                        }
                    }
                }

                if (instance == null)
                {
                    // create new instance
                    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);
                }

                // Check that the Raid member has the same instance as the leader
                if (isRaid)
                {
                    if (group == null)
                    {
                        MovementHandler.SendTransferFailure(chr.Client, instance.Id, MapTransferError.TRANSFER_ABORT_NEED_GROUP);
                        return(false);
                    }

                    var leaderRaid = group.InstanceLeaderCollection.GetBinding(mapTemplate.Id, BindingType.Hard);
                    var playerRaid = instances.GetBinding(mapTemplate.Id, BindingType.Hard);

                    if (playerRaid != null && leaderRaid != playerRaid)
                    {
                        // Player has a different instance than the leader
                        MovementHandler.SendTransferFailure(chr.Client, instance.Id, MapTransferError.TRANSFER_ABORT_NOT_FOUND);
                        return(false);
                    }
                }
            }

            instance.TeleportInside(chr, targetPos);
            return(true);
        }