コード例 #1
0
        public Task TeleportSubCommandHandler(CommandContext context, string command, string[] parameters)
        {
            string name = parameters.Length == 0 ? context.Session.Player.Name : string.Join(" ", parameters);

            Residence residence = ResidenceManager.GetResidence(name).GetAwaiter().GetResult();

            if (residence == null)
            {
                if (parameters.Length == 0)
                {
                    residence = ResidenceManager.CreateResidence(context.Session.Player);
                }
                else
                {
                    context.SendMessageAsync("A residence for that character doesn't exist!");
                    return(Task.CompletedTask);
                }
            }

            ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);

            context.Session.Player.TeleportTo(entrance.Entry, entrance.Position, 0u, residence.Id);

            return(Task.CompletedTask);
        }
コード例 #2
0
        public void HandleHouseTeleport(ICommandContext context,
                                        [Parameter("", ParameterFlags.Optional)]
                                        string name)
        {
            Player target = context.GetTargetOrInvoker <Player>();

            if (!target.CanTeleport())
            {
                context.SendMessage("You have a pending teleport! Please wait to use this command.");
                return;
            }

            Residence residence = ResidenceManager.Instance.GetResidence(name ?? target.Name).GetAwaiter().GetResult();

            if (residence == null)
            {
                if (name == null)
                {
                    residence = ResidenceManager.Instance.CreateResidence(target);
                }
                else
                {
                    context.SendMessage("A residence for that character doesn't exist!");
                    return;
                }
            }

            ResidenceEntrance entrance = ResidenceManager.Instance.GetResidenceEntrance(residence);

            target.TeleportTo(entrance.Entry, entrance.Position, 0u, residence.Id);
        }
コード例 #3
0
        public static void HandleHousingReturn(WorldSession session, ClientHousingReturn _)
        {
            // housing return button will only be visible on other residence maps
            Residence residence = session.Player.ResidenceManager.Residence;

            if (session.Player.Map is not ResidenceMapInstance ||
                session.Player.Map == residence?.Map)
            {
                throw new InvalidPacketValueException();
            }

            // return player to correct residence instance
            ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId);

            session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
            session.Player.TeleportTo(new MapPosition
            {
                Info = new MapInfo
                {
                    Entry      = entrance.Entry,
                    InstanceId = residence.Parent?.Id ?? residence.Id
                },
                Position = entrance.Position
            });
        }
コード例 #4
0
        public static void HandleHousingVisit(WorldSession session, ClientHousingVisit housingVisit)
        {
            if (!(session.Player.Map is ResidenceMap))
            {
                throw new InvalidPacketValueException();
            }

            if (!session.Player.CanTeleport())
            {
                return;
            }

            Task <Residence> residenceTask;

            if (housingVisit.TargetResidenceName != "")
            {
                residenceTask = ResidenceManager.Instance.GetResidence(housingVisit.TargetResidenceName);
            }
            else if (housingVisit.TargetResidence.ResidenceId != 0ul)
            {
                residenceTask = ResidenceManager.Instance.GetResidence(housingVisit.TargetResidence.ResidenceId);
            }
            else
            {
                throw new NotImplementedException();
            }

            session.EnqueueEvent(new TaskGenericEvent <Residence>(residenceTask,
                                                                  residence =>
            {
                if (residence == null)
                {
                    // TODO: show error
                    return;
                }

                switch (residence.PrivacyLevel)
                {
                case ResidencePrivacyLevel.Private:
                    {
                        // TODO: show error
                        return;
                    }

                // TODO: check if player is either a neighbour or roommate
                case ResidencePrivacyLevel.NeighborsOnly:
                    break;

                case ResidencePrivacyLevel.RoommatesOnly:
                    break;
                }

                // teleport player to correct residence instance
                ResidenceEntrance entrance = ResidenceManager.Instance.GetResidenceEntrance(residence);
                session.Player.TeleportTo(entrance.Entry, entrance.Position, 0u, residence.Id);
            }));
        }
コード例 #5
0
        public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect)
        {
            Character character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId);

            if (character == null)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.Failed
                });
                return;
            }

            session.Player = new Player(session, character);

            WorldEntry entry = GameTableManager.World.GetEntry(character.WorldId);

            if (entry == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            switch (entry.Type)
            {
            // housing map
            case 5:
            {
                // characters logging in to a housing map are returned to their own residence
                session.EnqueueEvent(new TaskGenericEvent <Residence>(ResidenceManager.GetResidence(session.Player.Name),
                                                                      residence =>
                    {
                        if (residence == null)
                        {
                            residence = ResidenceManager.CreateResidence(session.Player);
                        }

                        ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);
                        var mapInfo = new MapInfo(entrance.Entry, 0u, residence.Id);
                        MapManager.AddToMap(session.Player, mapInfo, entrance.Position);
                    }));

                break;
            }

            default:
            {
                var mapInfo = new MapInfo(entry);
                var vector3 = new Vector3(character.LocationX, character.LocationY, character.LocationZ);
                MapManager.AddToMap(session.Player, mapInfo, vector3);
                break;
            }
            }
        }
コード例 #6
0
        public static void HandleHousingCommunityRemoval(WorldSession session, ClientHousingCommunityRemoval housingCommunityRemoval)
        {
            if (session.Player.Map is not ResidenceMapInstance)
            {
                throw new InvalidPacketValueException();
            }

            Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community);

            if (community?.Residence == null)
            {
                throw new InvalidPacketValueException();
            }

            ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(PropertyInfoId.Residence);

            if (entrance == null)
            {
                throw new InvalidOperationException();
            }

            ResidenceChild child = community.Residence.GetChild(session.Player.CharacterId);

            if (child == null)
            {
                throw new InvalidOperationException();
            }

            if (child.Residence.Map != null)
            {
                child.Residence.Map.RemoveChild(child.Residence);
            }
            else
            {
                child.Residence.Parent.RemoveChild(child.Residence);
            }

            child.Residence.PropertyInfoId = PropertyInfoId.Residence;

            // shouldn't need to check for existing instance
            // individual residence instances are unloaded when transfered to a community
            // if for some reason the instance is still unloading the residence will be initalised again after
            session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
            session.Player.TeleportTo(entrance.Entry, entrance.Position, child.Residence.Id);
        }
コード例 #7
0
        public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect)
        {
            CharacterModel character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId);

            if (character == null)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.Failed
                });
                return;
            }

            if (PlayerCleanupManager.HasPendingCleanup(session.Account))
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.FailedCharacterInWorld
                });
                return;
            }

            session.Player = new Player(session, character);

            WorldEntry entry = GameTableManager.Instance.World.GetEntry(character.WorldId);

            if (entry == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            switch ((MapType)entry.Type)
            {
            case MapType.Residence:
            case MapType.Community:
            {
                // characters logging in to a housing map are returned to their own residence
                Residence residence = session.Player.ResidenceManager.Residence;
                residence ??= GlobalResidenceManager.Instance.CreateResidence(session.Player);

                ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId);
                session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
                MapManager.Instance.AddToMap(session.Player, new MapPosition
                    {
                        Info = new MapInfo
                        {
                            Entry      = entrance.Entry,
                            InstanceId = residence.Parent?.Id ?? residence.Id
                        },
                        Position = entrance.Position
                    });

                break;
            }

            default:
            {
                session.Player.Rotation = new Vector3(character.RotationX, character.RotationY, character.RotationZ);
                MapManager.Instance.AddToMap(session.Player, new MapPosition
                    {
                        Info = new MapInfo
                        {
                            Entry = entry
                        },
                        Position = new Vector3(character.LocationX, character.LocationY, character.LocationZ)
                    });
                break;
            }
            }
        }
コード例 #8
0
        public static void HandleHousingCommunityPlacement(WorldSession session, ClientHousingCommunityPlacement housingCommunityPlacement)
        {
            if (session.Player.Map is not ResidenceMapInstance)
            {
                throw new InvalidPacketValueException();
            }

            Community community = session.Player.GuildManager.GetGuild <Community>(GuildType.Community);

            if (community?.Residence == null)
            {
                throw new InvalidPacketValueException();
            }

            ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance((PropertyInfoId)(housingCommunityPlacement.PropertyIndex + 100));

            if (entrance == null)
            {
                throw new InvalidPacketValueException();
            }

            Residence residence = session.Player.ResidenceManager.Residence;

            if (residence == null)
            {
                throw new InvalidPacketValueException();
            }

            if (residence.Parent != null)
            {
                if (community.Residence.GetChild(session.Player.CharacterId) == null)
                {
                    throw new InvalidPacketValueException();
                }

                // for residences on a community just remove the residence
                // any players on the map at the time can stay in the instance
                if (residence.Map != null)
                {
                    residence.Map.RemoveChild(residence);
                }
                else
                {
                    residence.Parent.RemoveChild(residence);
                }

                session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
                session.Player.TeleportTo(entrance.Entry, entrance.Position, community.Residence.Id);
            }
            else
            {
                // move owner to new instance only if not on the same instance as the residence
                // otherwise they will be moved to the new instance during the unload
                if (residence.Map != session.Player.Map)
                {
                    session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
                    session.Player.TeleportTo(entrance.Entry, entrance.Position, community.Residence.Id);
                }

                // for individual residences remove the entire instance
                // move any players on the map at the time to the community
                residence.Map?.Unload(new MapPosition
                {
                    Info = new MapInfo
                    {
                        Entry      = entrance.Entry,
                        InstanceId = community.Residence.Id,
                    },
                    Position = entrance.Position
                });
            }

            // update residence with new plot location and add to community
            residence.PropertyInfoId = (PropertyInfoId)(housingCommunityPlacement.PropertyIndex + 100);

            if (community.Residence.Map != null)
            {
                community.Residence.Map.AddChild(residence, true);
            }
            else
            {
                community.Residence.AddChild(residence, true);
            }
        }
コード例 #9
0
        public static void HandleHousingVisit(WorldSession session, ClientHousingVisit housingVisit)
        {
            if (!(session.Player.Map is ResidenceMapInstance))
            {
                throw new InvalidPacketValueException();
            }

            if (!session.Player.CanTeleport())
            {
                return;
            }

            Residence residence;

            if (!string.IsNullOrEmpty(housingVisit.TargetResidenceName))
            {
                residence = GlobalResidenceManager.Instance.GetResidenceByOwner(housingVisit.TargetResidenceName);
            }
            else if (!string.IsNullOrEmpty(housingVisit.TargetCommunityName))
            {
                residence = GlobalResidenceManager.Instance.GetCommunityByOwner(housingVisit.TargetCommunityName);
            }
            else if (housingVisit.TargetResidence.ResidenceId != 0ul)
            {
                residence = GlobalResidenceManager.Instance.GetResidence(housingVisit.TargetResidence.ResidenceId);
            }
            else if (housingVisit.TargetCommunity.NeighbourhoodId != 0ul)
            {
                ulong residenceId = GlobalGuildManager.Instance.GetGuild <Community>(housingVisit.TargetCommunity.NeighbourhoodId)?.Residence?.Id ?? 0ul;
                residence = GlobalResidenceManager.Instance.GetResidence(residenceId);
            }
            else
            {
                throw new NotImplementedException();
            }

            if (residence == null)
            {
                //session.Player.SendGenericError();
                // TODO: show error
                return;
            }

            switch (residence.PrivacyLevel)
            {
            case ResidencePrivacyLevel.Private:
            {
                // TODO: show error
                return;
            }

            // TODO: check if player is either a neighbour or roommate
            case ResidencePrivacyLevel.NeighborsOnly:
                break;

            case ResidencePrivacyLevel.RoommatesOnly:
                break;
            }

            // teleport player to correct residence instance
            ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId);

            session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
            session.Player.TeleportTo(new MapPosition
            {
                Info = new MapInfo
                {
                    Entry      = entrance.Entry,
                    InstanceId = residence.Parent?.Id ?? residence.Id
                },
                Position = entrance.Position
            });
        }
コード例 #10
0
        private GuildResultInfo GuildOperationCommunityPlotReservation(GuildMember member, Player player, ClientGuildOperation operation)
        {
            if (!member.Rank.HasPermission(GuildRankPermission.ReserveCommunityPlot))
            {
                return(new GuildResultInfo(GuildResult.RankLacksSufficientPermissions));
            }

            if (operation.Data.Int32Data < -1 || operation.Data.Int32Data > 4)
            {
                throw new InvalidPacketValueException();
            }

            Residence residence = player.ResidenceManager.Residence;

            if (residence == null)
            {
                throw new InvalidPacketValueException();
            }

            ResidenceChild sourceResidence = Residence.GetChild(member.CharacterId);

            if (operation.Data.Int32Data != -1)
            {
                ResidenceChild targetResidence = Residence.GetChild((PropertyInfoId)(100 + operation.Data.Int32Data));
                if (targetResidence == null)
                {
                    ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance((PropertyInfoId)(100 + operation.Data.Int32Data));
                    if (entrance == null)
                    {
                        throw new InvalidPacketValueException();
                    }

                    if (sourceResidence != null)
                    {
                        // current plot reservation must be temporary to reserve a new plot
                        if (!sourceResidence.IsTemporary)
                        {
                            throw new InvalidPacketValueException();
                        }

                        // for residences on a community just remove the residence
                        // any players on the map at the time can stay in the instance
                        if (residence.Map != null)
                        {
                            residence.Map.RemoveChild(residence);
                        }
                        else
                        {
                            residence.Parent.RemoveChild(residence);
                        }

                        player.Rotation = entrance.Rotation.ToEulerDegrees();
                        player.TeleportTo(entrance.Entry, entrance.Position, Residence.Id);
                    }
                    else
                    {
                        // move owner to new instance only if not on the same instance as the residence
                        // otherwise they will be moved to the new instance during the unload
                        if (residence.Map != player.Map)
                        {
                            player.Rotation = entrance.Rotation.ToEulerDegrees();
                            player.TeleportTo(entrance.Entry, entrance.Position, Residence.Id);
                        }

                        // for individual residences remove the entire instance
                        // move any players on the map at the time to the community
                        residence.Map?.Unload(new MapPosition
                        {
                            Info = new MapInfo
                            {
                                Entry      = entrance.Entry,
                                InstanceId = Residence.Id,
                            },
                            Position = entrance.Position
                        });
                    }

                    // update residence with new plot location and add to community
                    residence.PropertyInfoId = (PropertyInfoId)(100 + operation.Data.Int32Data);

                    if (Residence.Map != null)
                    {
                        Residence.Map.AddChild(residence, false);
                    }
                    else
                    {
                        Residence.AddChild(residence, false);
                    }
                }
                else
                {
                    // can only remove reservation if one already exists
                    if (targetResidence != sourceResidence)
                    {
                        throw new InvalidPacketValueException();
                    }

                    targetResidence.IsTemporary = false;
                }
            }
            else
            {
                // can only remove reservation if one already exists
                if (sourceResidence == null)
                {
                    throw new InvalidPacketValueException();
                }

                // removing the reservation does not remove the plot only removes the permanent status
                sourceResidence.IsTemporary = true;
            }

            member.CommunityPlotReservation = operation.Data.Int32Data;
            AnnounceGuildMemberChange(member);

            return(new GuildResultInfo(GuildResult.Success));
        }