Example #1
0
        public async Task EnterBuilding(CommandContext c,
                                        [Description("Name of the building"), RemainingText]
                                        string buildingName)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(loc => loc.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync($"{c.User.Mention}, {Realm.GetMessage("not_registered")}");

                    await c.RejectMessage();

                    return;
                }

                if (player.IsIdle == false)
                {
                    await c.RespondAsync(string.Format(Realm.GetMessage("player_not_idle"), c.User.Mention, player.CurrentActionDisplay));

                    await c.RejectMessage();

                    return;
                }

                var location = await session.LoadAsync <Location>(player.CurrentLocation);

                var building =
                    location.Buildings.FirstOrDefault(b => b.Name.Equals(buildingName, System.StringComparison.OrdinalIgnoreCase));

                if (building == null)
                {
                    await c.RespondAsync($"{c.User.Mention}. No building called {buildingName} is located in {location.DisplayName}");

                    await c.RejectMessage();

                    return;
                }

                var bType = Realm.GetBuildingImplementation(building.BuildingImpl);
                if (bType == null)
                {
                    await c.RespondAsync("An error occured. Contact one of the admins and (Error_BuildingImplNotFound)");

                    await c.RejectMessage();

                    return;
                }

                var bImpl = (Buildings.IBuilding)System.Activator.CreateInstance(bType);
                await bImpl.EnterBuilding(c, building);

                await c.ConfirmMessage();
            }
        }