Esempio n. 1
0
        public PlayerObject(S.ObjectPlayer info)
        {
            CharacterIndex = info.Index;

            ObjectID = info.ObjectID;

            Name       = info.Name;
            NameColour = info.NameColour;

            Class  = info.Class;
            Gender = info.Gender;

            Poison = info.Poison;

            foreach (BuffType type in info.Buffs)
            {
                VisibleBuffs.Add(type);
            }

            Title = info.GuildName;

            CurrentLocation = info.Location;
            Direction       = info.Direction;

            HairType   = info.HairType;
            HairColour = info.HairColour;

            ArmourShape        = info.Armour;
            ArmourColour       = info.ArmourColour;
            LibraryWeaponShape = info.Weapon;
            HorseShape         = info.HorseShape;
            HelmetShape        = info.Helmet;
            ShieldShape        = info.Shield;

            ArmourImage = info.ArmourImage;


            Light = info.Light;

            Dead  = info.Dead;
            Horse = info.Horse;

            UpdateLibraries();

            SetFrame(new ObjectAction(!Dead ? MirAction.Standing : MirAction.Dead, MirDirection.Up, CurrentLocation));

            GameScene.Game.MapControl.AddObject(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to create a new horse in the horse manager.
        /// </summary>
        /// <returns>The new horse that has been created.</returns>
        /// <exception cref="TooManyHorsesException">Thrown if there are too many horses.</exception>
        public async Task <Horse> Create(HorseType type)
        {
            // Check if the maximum number of horses is already met
            if (this.Horses.Count == HorseManager.MAX_HORSES)
            {
                throw new TooManyHorsesException();
            }

            // Create a new horse entity with default values and add it to the
            // database (this will give it an Id automatically).
            Horse horse = new Horse()
            {
                Type = type,
            };
            await AppDatabase.GetInstance().Save <Horse>(horse);

            // Add the horse to the list of horses and set it as the active
            // horse in the application.
            this.Horses.Add(horse);
            this.ActiveHorse = horse;

            // Return the new horse
            return(horse);
        }
Esempio n. 3
0
        /// <summary>
        /// Method to be called when the "add horse" button is pressed.
        /// </summary>
        /// <param name="sender">The item that triggers the event.</param>
        /// <param name="e">The event args for the event.</param>
        private void AddHorseButton_Clicked(object sender, EventArgs e)
        {
            // If the current modal page is set to be locked, do not render a
            // horse modal page
            if (this.locked)
            {
                return;
            }

            // Lock the main thread from opening another page until the current
            // modal display has been closed
            this.locked = true;

            // Invoke a separate operation to create a horse.
            Device.BeginInvokeOnMainThread(async() => {
                try {
                    // Prompt the user for the type of horse that they want to
                    // create, from the types that are available.
                    const string StandardHorseString  = "Standard";
                    const string MiniatureHorseString = "Miniature";
                    const string CancelString         = "Cancel";
                    string result = await this.DisplayActionSheet(
                        "Select A Horse Type",
                        CancelString,
                        null,
                        StandardHorseString,
                        MiniatureHorseString);

                    // Handle the result accordingly
                    HorseType type = HorseType.Standard;
                    switch (result)
                    {
                    // Handle when a standard horse is selected
                    case StandardHorseString:
                        type = HorseType.Standard;
                        break;

                    // Handle when a miniature horse is selected
                    case MiniatureHorseString:
                        type = HorseType.Miniature;
                        break;

                    // Handle when the "cancel" button was pressed, or the
                    // user selects outside the bounds of the select.
                    case CancelString:
                    default:
                        return;
                    }

                    // Get a new horse from the horse manager
                    Horse horse = await HorseManager.GetInstance()
                                  .Create(type);

                    // Push a modal to the top of the navigation stack to
                    // display the selected horse's information
                    Page horsePage = new HorseEditPage(horse);
                    await this.Navigation.PushAsync(horsePage);
                } catch (TooManyHorsesException) {
                    // Show a toast indicating that the horse could not be found
                    ToastController.ShortToast("Cannot create any more horses.");
                } finally {
                    // Unlock the page after the modal has been created
                    this.locked = false;
                }
            });
        }