private async Task OfflineLogin(string documents)
        {
            var       localLogged = Path.Combine(documents, "Logged.dt");
            var       localLogin  = Path.Combine(documents, _UserModel.Username + "Login.dt");
            var       localTimers = Path.Combine(documents, _UserModel.Username + "Timer.dt");
            var       localItems  = Path.Combine(documents, _UserModel.Username + "Inv.dt");
            var       localStats  = Path.Combine(documents, _UserModel.Username + "Stats.dt");
            UserModel local       = new UserModel(); local.file = localLogged;
            await Task.Run(() =>
            {
                try
                {
                    File.ReadAllText(localLogin);
                    File.ReadAllText(localTimers);
                    File.ReadAllText(localItems);
                    File.ReadAllText(localStats);
                }
                catch { throw new Exception("Local Account doesn't exist"); }//if logging in and files dont exist then log in
                local.Getfile(localLogin, localItems, localStats, localTimers);
                local.Character = UserModel.CheckForstring(localLogin, "Character:");
                UserModel.Rewrite("Username:"******"Password:", _UserModel.Password, local.file);
            });

            InventoryItemsModel localitem = new InventoryItemsModel(localItems);
            StatsModel          localstat = new StatsModel(localStats);

            Device.BeginInvokeOnMainThread(() =>
            {
                Application.Current.MainPage = new NavigationPage(new AddView(local, localitem, localstat));
            });
        }
        private async Task LoadUserLogged(FirebaseUser client, string documents, string file, string Logged)// This automatically logs in user.
        {
            var                 Login   = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Login.dt");
            var                 Timers  = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Timer.dt");
            var                 Items   = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Inv.dt");
            var                 Stats   = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Stats.dt");
            UserModel           newuser = new UserModel(client.UserLogin, client.UserStats, client.UserItems, client.Client, client.UserTimes); newuser.file = Logged;
            InventoryItemsModel item    = new InventoryItemsModel(newuser.UserItems, newuser.Token, newuser.UserLogin.Object.Username, Items);
            StatsModel          stat    = new StatsModel(newuser.UserStats, newuser.Token, newuser.UserLogin.Object.Username, Stats);
            await Task.Run(async() =>
            {
                newuser.Getfile(Login, Items, Stats, Timers);
                UserModel.Rewrite("Username:"******"Username:"******"Password:"******"Password:"******"Character:");
                newuser.UserLogin.Object.Logged = "True";
                await newuser.RewriteDATA();
                Globals.LOGGED = client.UserLogin;
                Globals.CLIENT = client.Client;
                await newuser.UpdateAll();
            });

            Device.BeginInvokeOnMainThread(() =>
            {
                Application.Current.MainPage = new NavigationPage(new AddView(newuser, item, stat));
            });
        }
Example #3
0
 /*
  * Contructor for Masterpage, initialize all components and BindingContext
  *
  * PARAM
  * page: encapsulate page
  * user: encapsulate user
  * items: encapsulate items
  * weapon: encapsulate weapon
  * truth: encapsulate truth
  * mainpage: encapsulate mainpage
  * ContentPage: encapsulate display
  *
  * RETURNS Nothing
  */
 public MasterPageViewModel(Page page, UserModel user, InventoryItemsModel items, WeaponInfoModel weapon, logged truth,
                            MasterPageView mainpage, ContentPage display, DungeonView dungeon, ItemInfoModel ItemInv, ShopModel Shop, CharacterInfoModel Characters)
 {
     this.page       = page;
     this.user       = user;
     this.items      = items;
     this.truth      = truth;
     this.weapon     = weapon;
     this.ItemInv    = ItemInv;
     this.Characters = Characters;
     this.mainpage   = mainpage;
     this.dungeon    = dungeon;
     this.Shop       = Shop;
     weapon.SetWeaponAsync(display, UserModel.CheckForstring(items.Localfile, "Equipped:"));
     Tasks_Clicked     = new Command(async() => await TaskNavAsync());
     Inventory_Clicked = new Command(async() => await InventoryNavAsync());
     Dungeon_Clicked   = new Command(async() => await DungeonNavAsync());
     About_Clicked     = new Command(async() => await AboutNavAsync());
     Settings_Clicked  = new Command(async() => await SettingsNavAsync());
     Stats_Clicked     = new Command(async() => await StatsNavAsync());
     Shop_Clicked      = new Command(async() => await ShopNavAsync());
     PageOn            = new PageOpenModel();
     PageOn.Tasks      = true;
     dungeon.Shop      = this.Shop;
 }
        private async Task OfflineLoginLogged(string documents, string file, string Logged)
        {
            var       localLogin  = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Login.dt");
            var       localTimers = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Timer.dt");
            var       localItems  = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Inv.dt");
            var       localStats  = Path.Combine(documents + "/Users", UserModel.CheckForstring(file, "Username:"******"Stats.dt");
            UserModel local       = new UserModel(); local.file = Logged;
            await Task.Run(() =>
            {
                try
                {
                    File.ReadAllText(localLogin);
                }
                catch { throw new Exception("Error reading local data"); }
                local.Getfile(localLogin, localItems, localStats, localTimers);
                local.Character = UserModel.CheckForstring(localLogin, "Character:");
                UserModel.Rewrite("Username:"******"Username:"******"Password:"******"Password:"), local.file);
            });

            InventoryItemsModel localitem = new InventoryItemsModel(localItems);
            StatsModel          localstat = new StatsModel(localStats);

            Device.BeginInvokeOnMainThread(() =>
            {
                Application.Current.MainPage = new NavigationPage(new AddView(local, localitem, localstat));
            });
        }
Example #5
0
 /*
  * Constructor for Dungeon
  * Encapsulates UserModel,InventoryItems,WeaponInfo,Stats objects + the bool variable
  *
  * PARAM
  * UserModel:parse UserModel,
  * items: parse items,
  * weapon: parse weapon ,
  * stats: parse stats,
  * tut: true of false if the tutorial display alert is wished to be displayed
  *
  * RETURN Nothing
  */
 public DungeonView(UserModel user, InventoryItemsModel items, WeaponInfoModel weapon, ItemInfoModel itemInv, StatsModel stats, bool tut, DungeonModel realdungeon)
 {
     this.realdungeon = realdungeon;
     this.user        = user;
     this.items       = items;
     this.weapon      = weapon;
     this.stats       = stats;
     this.tut         = tut;
     this.itemInv     = itemInv;
     InitializeComponent();
     InitializeBoss();
 }
Example #6
0
        public void CheckUserModelCharacterShop()
        {
            string tempFile = Path.GetTempFileName();//create a temporary file

            File.WriteAllText(tempFile, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:");
            InventoryItemsModel info = new InventoryItemsModel(tempFile);
            UserModel           user = new UserModel();

            user.Character = "(0_0)";

            ShopViewModel test = new ShopViewModel(new ShopModel(info), new ItemInfoModel(info), new WeaponInfoModel(info), new CharacterInfoModel(info, tempFile), user, true);

            Assert.Equal(user.Character, test.Character);//Test for character check
        }
Example #7
0
        logged truth = new logged();// Used for telling threads of the application to stop running whenever this is false

        /*
         * Initialize all components and classes for traversing through both details page and masterpage
         * PARAM
         * user: the user data
         * items: the items data
         * RETURNS Nothing
         */
        public AddView(UserModel user, InventoryItemsModel items, StatsModel stats)
        {
            InitializeComponent();
            WeaponInfoModel    weapon      = new WeaponInfoModel(items);
            ItemInfoModel      Invitem     = new ItemInfoModel(items);
            CharacterInfoModel Characters  = new CharacterInfoModel(items, user.LocalLogin);
            ShopModel          Shop        = new ShopModel(items);
            DungeonModel       realDungeon = new DungeonModel();

            Xamarin.Forms.NavigationPage.SetHasNavigationBar(this, false);
            DungeonView dungeon = new DungeonView(user, items, weapon, Invitem, stats, false, realDungeon);

            this.Detail = new NavigationPage(new TasksView(user, items, truth, dungeon, new InventoryView(items, weapon, user, Invitem, Characters))); // Set Detailspage arguments with user information and truth value.
            this.Master = new MasterPageView(Detail, user, items, weapon, truth, dungeon, Invitem, Shop, Characters);                                  // set the masterpage information with user, items, and truth values.
        }
Example #8
0
        /*
         * Contructor for DetailsPage to encapsulate current user information and truth value
         *
         * PARAM
         * user: parse the user to be used within this class
         * truth: parse truth to notify Device.StartTimer to stop whenever truthtime is off
         * items: parse items model
         * dungeon: parse dungeon object to open tutorial page.
         *
         * RETURN Nothing
         */
        public TasksView(UserModel user, InventoryItemsModel items, logged truth, DungeonView dungeon, InventoryView Inventory)
        {
            this.Currentuser = user;
            this.items       = items;
            this.truthtime   = truth;
            this.dungeon     = dungeon;
            this.inventory   = Inventory;
            TasksViewModel VM = new TasksViewModel(user, this)
            {
                Navigation = Navigation
            };

            BindingContext = VM;
            InitializeComponent();
        }
        private List <string> ValidateInventory(InventoryItemsModel inventory)
        {
            var errors = new List <string>();

            if (String.IsNullOrWhiteSpace(inventory.Description))
            {
                errors.Add("Description is required");
            }
            if (inventory.ItemTypeId <= 0)
            {
                errors.Add("Item Type is required");
            }


            return(errors);
        }
Example #10
0
        public void BuyWeapon()                       //Test buying a weapon
        {
            string tempFile = Path.GetTempFileName(); //create a temporary file

            File.WriteAllText(tempFile, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:");
            InventoryItemsModel info = new InventoryItemsModel(tempFile);
            UserModel           user = new UserModel();

            user.Character = "(0_0)";
            ShopViewModel test = new ShopViewModel(new ShopModel(info), new ItemInfoModel(info), new WeaponInfoModel(info), new CharacterInfoModel(info, "test"), user, true);

            test.BuyAsync(info, 0, "SteelSword", true);
            Assert.Equal(3, test.Weapon.weapons.Count);
            Assert.Equal("489", test.Gold);
            Assert.Equal("IronDagger,IronBow,SteelSword,", UserModel.CheckForstring(tempFile, "Weapons:"));
        }
Example #11
0
        public void BuyItem()                         //Test buying an item
        {
            string tempFile = Path.GetTempFileName(); //create a temporary file

            File.WriteAllText(tempFile, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:");
            InventoryItemsModel info = new InventoryItemsModel(tempFile);
            UserModel           user = new UserModel();

            user.Character = "(0_0)";
            ShopViewModel test = new ShopViewModel(new ShopModel(info), new ItemInfoModel(info), new WeaponInfoModel(info), new CharacterInfoModel(info, "test"), user, true);

            test.BuyAsync(info, 1, "HealthPotion", true);
            Assert.Single(test.Inv.pots);
            Assert.Equal("485", test.Gold);
            Assert.Equal("HealthPotion,", UserModel.CheckForstring(tempFile, "Items:"));
        }
Example #12
0
        public List <string> SaveDetail(InventoryItemsModel inventory)
        {
            var errors = ValidateInventory(inventory);

            if (errors.Count == 0)
            {
                var existingPerson = new InventoryItems();
                if (inventory.Id > 0)
                {
                    existingPerson = _inventoryRepository.GetInventory(inventory.Id);
                }

                _mapper.Map <InventoryItemsModel, InventoryItems>(inventory, existingPerson);
                _inventoryRepository.SaveDetail(existingPerson);
            }

            return(errors);
        }
 /*
  * Constructor for Inventory
  * PARAM items to be used by the class
  * RETURNS Nothing
  */
 public InventoryView(InventoryItemsModel items, WeaponInfoModel weapon, UserModel user, ItemInfoModel ItemInv, CharacterInfoModel characters)
 {
     tutorial        = false;
     this.items      = items;
     this.weapon     = weapon;
     this.User       = user;
     this.ItemInv    = ItemInv;
     this.pots       = ItemInv.pots;
     this.weapons    = weapon.weapons;
     this.characters = characters.Characters;
     InitializeComponent();
     DisplayInventory();
     DisplayKey();
     DisplayGold();
     DisplayEquipped();
     DisplayNoWep();
     DisplayNoItem();
     Character.Text = User.Character;
 }
        private async Task LoadUser(FirebaseUser client, string documents)// Load user from login mainscreen
        {
            bool      skip    = false;
            var       Logged  = Path.Combine(documents, "Logged.dt");
            var       Login   = Path.Combine(documents, _UserModel.Username + "Login.dt");
            var       Timers  = Path.Combine(documents, _UserModel.Username + "Timer.dt");
            var       Items   = Path.Combine(documents, _UserModel.Username + "Inv.dt");
            var       Stats   = Path.Combine(documents, _UserModel.Username + "Stats.dt");
            UserModel newuser = new UserModel(client.UserLogin, client.UserStats, client.UserItems, client.Client, client.UserTimes); newuser.file = Logged;
            await Task.Run(async() =>
            {
                if (!File.Exists(Login) || !File.Exists(Items) || !File.Exists(Stats) || !File.Exists(Timers))
                {
                    skip = true;
                    File.Delete(Login);
                    File.Delete(Items);
                    File.Delete(Stats);
                    File.Delete(Timers);
                    File.WriteAllText(Login, string.Format("Updated:\nUsername:\nPassword:\nFullname:\nCharacter:(ง’̀-‘́)ง\nLogged:false\nTutorial:True"));
                    File.WriteAllText(Items, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:(ง’̀-‘́)ง,\nTOTAL_KEYS:0");
                    File.WriteAllText(Stats, "HEALTH:100\nMANA:40\nLEVEL:1\nEXP:0\nTOTAL_BOSSES:0");
                    File.WriteAllText(Timers, "");
                }
                newuser.Getfile(Login, Items, Stats, Timers);
                newuser.Character = UserModel.CheckForstring(newuser.LocalLogin, "Character:");
                newuser.UserLogin.Object.Logged = "True";
                await newuser.RewriteDATA();
                await newuser.UpdateAll(skip);
                UserModel.Rewrite("Username:"******"Password:", _UserModel.Password, newuser.file);
                Globals.LOGGED = client.UserLogin;
                Globals.CLIENT = client.Client;
            });

            InventoryItemsModel item = new InventoryItemsModel(newuser.UserItems, newuser.Token, newuser.UserLogin.Object.Username, Items);
            StatsModel          stat = new StatsModel(newuser.UserStats, newuser.Token, newuser.UserLogin.Object.Username, Stats);

            Device.BeginInvokeOnMainThread(() =>
            {
                Application.Current.MainPage = new NavigationPage(new AddView(newuser, item, stat));
            });
        }
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                if (InventoryId > 0)
                {
                    await Task.WhenAll(_inventoryTask, _itemTypesTask);

                    _inventory = _inventoryTask.Result;
                    _itemTypes = _itemTypesTask.Result;
                }
                else
                {
                    await Task.WhenAll(_itemTypesTask);

                    _itemTypes = _itemTypesTask.Result;
                }

                this.StateHasChanged();
            }
        }
        public IActionResult UpdateInventory([FromBody] InventoryItemsModel inventory)
        {
            var errorList = new List <string>();

            try
            {
                errorList = _service.SaveDetail(inventory);
                if (errorList.Count > 0)
                {
                    return(BadRequest(errorList));
                }
            }
            catch (Exception ex)
            {
                errorList = new List <string>()
                {
                    "Error in saving"
                };
                return(BadRequest(errorList));
            }

            return(Ok(errorList));
        }
Example #17
0
        public async System.Threading.Tasks.Task <bool> BuyAsync(InventoryItemsModel items, int typecase, string ChoItem, bool test = false)
        {
            foreach (ItemModel item in Characters.Characters)
            {
                if (ChoItem == item.item)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Already have this Character", "Close");

                    return(false);
                }
            }

            int CurrentGold = CurrentGold = Int32.Parse(UserModel.CheckForstring(items.Localfile, "Gold:"));
            int Price       = 0;
            int TotalGold;

            if (typecase == 0)
            {
                Price = WeaponInfoModel.ObtainWeaponValue(ChoItem);
            }
            else if (typecase == 1)
            {
                Price = ItemInfoModel.ObtainItemValue(ChoItem);
            }
            else
            {
                Price = 50;
            }
            TotalGold = CurrentGold - Price;
            if (CurrentGold - Price >= 0)
            {
                if (typecase == 0)
                {
                    UserModel.AddOntoLine("Weapons:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Weapons += ChoItem + ",";
                    }catch { }
                    Weapon.Rebuild();
                }
                else if (typecase == 1)
                {
                    UserModel.AddOntoLine("Items:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Items += ChoItem + ",";
                    }catch { }
                    Inv.Rebuild();
                }
                else
                {
                    UserModel.AddOntoLine("Characters:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Characters += ChoItem + ",";
                    }
                    catch { }
                    Characters.Rebuild();
                }
                UserModel.Rewrite("Gold:", TotalGold.ToString(), items.Localfile); //Rewrite the gold values
                try
                {
                    items.Invfile.Object.Gold = TotalGold.ToString();
                    await items.UpdateInv();
                }
                catch { }
                Gold = UserModel.CheckForstring(items.Localfile, "Gold:");
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Success", string.Format("You bought a {0}.", ChoItem), "Close");
                }
                return(true);
            }
            else
            {
                int remainder = CurrentGold - Price;
                remainder = remainder * -1;
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", string.Format("You need {0} more gold to purchase this item", remainder.ToString()), "Close");
                }
                return(false);
            }
        }
 /*
  * Contructor for Masterpage, initialize all components and BindingContext
  *
  * PARAM
  * page: encapsulate page
  * user: encapsulate user
  * items: encapsulate items
  * weapon: encapsulate weapon
  * truth: encapsulate truth
  *
  * RETURNS Nothing
  */
 public MasterPageView(Page page, UserModel user, InventoryItemsModel items, WeaponInfoModel weapon,
                       logged truth, DungeonView dungeon, ItemInfoModel itemInv, ShopModel Shop, CharacterInfoModel Characters)
 {
     InitializeComponent();
     BindingContext = new MasterPageViewModel(page, user, items, weapon, truth, this, this, dungeon, itemInv, Shop, Characters);
 }