Пример #1
0
    public void AddGemToWeapon(string weaponName, int socketNumber, Gem gem)
    {
        Weapon weapon = this.GetWeapon(weaponName);

        if (weapon != null)
        {
            weapon.AddGem(gem, socketNumber);
        }
    }
        public override void Execute()
        {
            string weaponName = Data[1];
            int    index      = int.Parse(Data[2]);

            string[] gemInfo = Data[3].Split();
            Gem      gem     = gemFactory.CreateGem(gemInfo);
            Weapon   weapon  = weaponRepository.GetWeapon(weaponName);

            weapon.AddGem(index, gem);
        }
Пример #3
0
        public void Execute()
        {
            string[] gemInfo = this.data[3].Split();
            string   gemType = gemInfo[1];
            string   clarity = gemInfo[0];

            Type classType = typeof(Add).Assembly.GetTypes().FirstOrDefault(x => x.Name == gemType);

            var gem = (Gem)Activator.CreateInstance(classType, new object[] { (ClarityModified)Enum.Parse(typeof(ClarityModified), clarity) });

            string name     = this.data[1];
            int    index    = int.Parse(this.data[2]);
            Weapon instance = list.FirstOrDefault(x => x.Name == name);

            instance.AddGem(index, gem);
        }
Пример #4
0
    public void Add(List <Weapon> weaponList, string[] arguments)
    {
        string wepName = arguments[1];

        int socketIndex = int.Parse(arguments[2]);

        string clarityType =
            arguments[3]
            .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[0];

        string gemType =
            arguments[3]
            .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1];

        Type realGemType = Type.GetType(gemType);
        Gem  gem         = (Gem)Activator.CreateInstance(Type.GetType(gemType));

        GemsClarity clarity = (GemsClarity)Enum.Parse(typeof(GemsClarity), clarityType);

        MethodInfo neededClarityField = realGemType.GetMethod("set_Clarity", (BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance));

        neededClarityField.Invoke(gem, new object[] { (int)clarity });

        bool DoesWeaponExist = weaponList.Any(w => w.Name == wepName);

        if (DoesWeaponExist == true)
        {
            Weapon neededWep = weaponList.First(w => w.Name == wepName);

            if (socketIndex < 0 || socketIndex > neededWep.Gems.Length - 1)
            {
            }
            else
            {
                if (neededWep.Gems[socketIndex] != null)
                {
                    Gem oldGem = neededWep.Gems[socketIndex];
                    neededWep.OverwriteGem(oldGem, gem, socketIndex);
                }
                else
                {
                    neededWep.AddGem(gem, socketIndex);
                }
            }
        }
    }
Пример #5
0
        private static void AddGem(string[] cmdArgs)
        {
            string weaponName = cmdArgs[1];

            Weapon weapon = weapons.Where(w => w.WeaponName.Equals(weaponName)).FirstOrDefault();

            if (weapon == null)
            {
                return;
            }

            int socketNumber = int.Parse(cmdArgs[2]);

            string[] typeAndClarity = cmdArgs[3].Split(' ');
            string   gemType        = typeAndClarity[1];
            string   levelOfClarity = typeAndClarity[0];

            weapon.AddGem(gemType, levelOfClarity, socketNumber);
        }
Пример #6
0
        public void Execute(string[] parameters, IList <Weapon> weaponsCollection)
        {
            string name = parameters[1];

            int index = int.Parse(parameters[2]);

            string [] gem = parameters[3].Split(' ');

            string gemType = gem[0];

            string gemName = gem[1];

            var assemblyTypes = Assembly.GetExecutingAssembly().GetTypes();

            var sbType = assemblyTypes.FirstOrDefault(x => x.Name.Contains(gemName));

            LevelOfClarity levelOfClarity = (LevelOfClarity)Enum.Parse(typeof(LevelOfClarity), gemType);

            Gem gemToAdd = (Gem)Activator.CreateInstance(sbType, new object[] { levelOfClarity });

            Weapon weapon = weaponsCollection.FirstOrDefault(x => x.Name == name);

            weapon.AddGem(gemToAdd, index);
        }
Пример #7
0
    static void Main()
    {
        List <Weapon> weapons             = new List <Weapon>();
        var           customInfoAttribute = typeof(Weapon).GetCustomAttribute <CustomInfoAttribute>();
        string        input;

        while ((input = Console.ReadLine()) != "END")
        {
            var    args    = input.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string command = args[0];

            switch (command)
            {
            case "Create":
            {
                var           type       = args[1].Split(" ");
                string        rarity     = type[0];
                string        typeWeapon = type[1];
                string        name       = args[2];
                LevelOfRarity rarityEnum = (LevelOfRarity)Enum.Parse(typeof(LevelOfRarity), rarity);
                weapons.Add(WeaponFactories.GetWeapon(typeWeapon, name, rarityEnum));
                break;
            }

            case "Add":
            {
                string weaponName    = args[1];
                int    soketIndex    = int.Parse(args[2]);
                var    gemTypeArgs   = args[3].Split(" ");
                string clarityString = gemTypeArgs[0];
                string type          = gemTypeArgs[1];

                LevelOfClarity clarity = (LevelOfClarity)Enum.Parse(typeof(LevelOfClarity), clarityString);

                Weapon currWeapon = weapons.FirstOrDefault(w => w.Name == weaponName);
                //check

                Gem gem = GemFactory.GetGem(type, clarity);

                currWeapon.AddGem(gem, soketIndex);
                break;
            }

            case "Print":
            {
                string name   = args[1];
                Weapon weapon = weapons.FirstOrDefault(w => w.Name == name);
                Console.WriteLine(weapon);
                break;
            }

            case "Remove":
            {
                string name   = args[1];
                int    index  = int.Parse(args[2]);
                Weapon weapon = weapons.FirstOrDefault(w => w.Name == name);
                if (weapon != null)
                {
                    weapon.RemoveGem(index);
                }
                break;
            }

            case "Author": Console.WriteLine($"Author: {customInfoAttribute.Author}");
                break;

            case "Revision": Console.WriteLine($"Revision: {customInfoAttribute.Revision}");
                break;

            case "Description": Console.WriteLine($"Class description: {customInfoAttribute.Description}");
                break;

            case "Reviewers": Console.WriteLine($"Reviewers: {string.Join(", ",customInfoAttribute.Reviewers)}");
                break;
            }
        }
    }