Пример #1
0
        void WelcomeFirstTimePlayer()
        {
            WUMoney.AwardCurrency(100, WULogin.CurrencyNames [1]);

            Stock        = new CMLData();
            AmmoLevels   = new CMLData();
            DamageLevels = new CMLData();
            RangeLevels  = new CMLData();
            Settings     = new CMLData();
            Unlocked     = new CMLData();
            Settings.Seti("bgm", 1);
            Settings.Seti("sfx", 1);
            Stock.Seti(Ammo[0].Weapon.WeaponName, Ammo [0].MaxAmmo);
            SavePlayerData();
        }
Пример #2
0
        /// <summary>
        /// Makes this weapon available for use. The "Ammo" array lists the weapons in the same order as the weapon type enum so the int value passed
        /// as a parameter to this function correlates 1:1 with the weapon's name in the enum as well as the array index. We thus use the int value
        /// to fetch the weapon from the Ammo array and then use the weapon definition contained therein to fetch the weapon name.
        /// Since the weapon name just returns the string value of the enum we could also have said ((WeaponType)index).ToString() but casting
        /// an int to an enum only to immediately cast it to a string... I simply felt that fetching a string value from the definitioon directly
        /// would look a bit easier onthe eyes and HELP with the comprehension of what was going on, rather than adding confusion to the procedings.
        /// </summary>
        /// <param name="weapon_type">Which weapon are we unlocking?</param>
        void UnlockWeapon(int weapon_type)
        {
            WeaponInstance weapon = Ammo [weapon_type];
            CMLData        update = new CMLData();
            CMLData        unlock = new CMLData();

            update.Seti(weapon.Weapon.WeaponName, 0);
            unlock.Seti(weapon.Weapon.WeaponName, 1);
            Unlocked.Seti(weapon.Weapon.WeaponName, 1);
            Stock.Seti(weapon.Weapon.WeaponName, 0);
            WUData.UpdateCategory(category_name_unlocked, unlock);
            WUData.UpdateCategory(category_name_inventory, update);


            //display a notification of a successful unlock
            MBSNotification.SpawnInstance(FindObjectOfType <Canvas>(), new Vector2(200f, -50f), new Vector2(0f, -50f), "Unlock Successful", $"You can now use {weapon.Weapon.WeaponName}s", weapon.Weapon.Icon);
        }
Пример #3
0
        // Special case! If user paid for the game, make sure he always starts with max ammo for his current weapon level
        public void SetAmmoToMax(EWeaponType weaponType)
        {
            WeaponInstance weapon = Ammo [(int)weaponType];
            CMLData        update = new CMLData();

            //update the value locally also
            Stock.Seti(weapon.Weapon.WeaponName, weapon.MaxAmmo);
            update.Seti(weapon.Weapon.WeaponName, weapon.MaxAmmo);
            WUData.UpdateCategory(category_name_inventory, update);
        }
Пример #4
0
        //NOTE: Possible exploit! User can play on multiple devices at once and if the price is set to 100 on all devices then a check to see if
        //the user has 100 currency and based on that the level is upgraded by 1 means they can upgrade to max and only pay the lowest price for each
        //upgrade level. The correct course of action would be to first fetch the inventory again, check what the current level is of whatever is being
        //upgraded, make sure the current cost is the correct cost for the item being purchased (updating the GUI if not the case) and only then attempt
        //to buy the item.
        //When dealing with money this would be the safest course of action but since this is just a demo made for a fun passtime I am not being that strict
        void _updateAmmo(CML response)
        {
            //see what was already stored online and add one. Make sure you don't exceed the max level or you'll get array index out of bounds errors
            WeaponInstance weapon    = Ammo [temp_storage.x];
            int            new_value = Mathf.Min(weapon.MaxAmmo, weapon.Ammo + temp_storage.y);

            //update the value locally so we can play then update it online for future games also
            CMLData update = new CMLData();

            update.Seti(weapon.Weapon.WeaponName, new_value);
            Stock.Seti(weapon.Weapon.WeaponName, new_value);
            WUData.UpdateCategory(category_name_inventory, update);

            //display a notification of a successful purchase
            MBSNotification.SpawnInstance(FindObjectOfType <Canvas>(), new Vector2(200f, -50f), new Vector2(0f, -50f), "Purchase Successful", $"You now have {Stock.Int(weapon.Weapon.WeaponName)} {weapon.Weapon.WeaponName}s", weapon.Weapon.Icon);
        }
Пример #5
0
        /// <summary>
        /// Weapon's stats can only be upgraded to a certain level. This function updates the stat level
        /// </summary>
        /// <param name="stat">Which stat is being updated?</param>
        /// <param name="to_value">What will the new value be?</param>
        /// <param name="weapon_type">What weapon are we upgrading the stat for?</param>
        void UpgradeStat(string stat, int to_value, int weapon_type)
        {
            WeaponInstance weapon = Ammo [weapon_type];
            CMLData        update = new CMLData();

            update.Seti(weapon.Weapon.WeaponName, to_value);
            string message = "";

            //update the value locally so we can play then also update the stat online for future play sessions
            switch (stat.ToLower().Trim())
            {
            case "ammo":
                if (weapon.LevelAmmo >= to_value)
                {
                    return;
                }
                AmmoLevels.Seti(weapon.Weapon.WeaponName, to_value);
                WUData.UpdateCategory(category_name_max_ammo, update);
                message = $"Ammo slots updated to hold {weapon.MaxAmmo} {(weapon.Weapon.Type == EWeaponType.Gun ? "bullets" : $"{weapon.Weapon.Type.ToString()}'s")}";
                break;

            case "range":
                if (weapon.LevelRange >= to_value)
                {
                    return;
                }
                RangeLevels.Seti(weapon.Weapon.WeaponName, to_value);
                WUData.UpdateCategory(category_name_max_range, update);
                message = $"{weapon.Weapon.Type} now has an attack range of {weapon.Range}";
                break;

            case "damage":
                if (weapon.LevelDamage >= to_value)
                {
                    return;
                }
                DamageLevels.Seti(weapon.Weapon.WeaponName, to_value);
                WUData.UpdateCategory(category_name_max_damage, update);
                message = $"{weapon.Weapon.Type} now deals {weapon.Damage} points of damage";
                break;
            }
            //display an on screen notification of the transaction being completed
            MBSNotification.SpawnInstance(FindObjectOfType <Canvas>(), new Vector2(200f, -50f), new Vector2(0f, -50f), "Purchase Successful", message, weapon.Weapon.Icon);

            //and now tell the game it's done also so the GUI can update itself and whatever else you want to happen at this point
            Events.Trigger(Events.onStatUpgraded);
        }