Пример #1
0
        public static bool SetComplexValue(UnitObject unit, string valueName, UnitObjectStats.Stat stat)
        {
            //if (!initialized) return;

            foreach (UnitObjectStats.Stat unitStats in unit.Stats.Stats.Values)
            {
                if (unitStats.Name != valueName)
                {
                    continue;
                }

                return(true);
            }

            //for (int counter = 0; counter < unit.Stats.Stats.Count; counter++)
            //{
            //    UnitObjectStats.Stat unitStats = unit.Stats[counter];

            //    if (unitStats.Name != valueName) continue;

            //    unitStats = stat;
            //    return true;
            //}

            return(false);
        }
Пример #2
0
        public CharacterSkills(UnitObject unitObject, FileManager fileManager, IEnumerable <int> skillTabs) : base(unitObject, fileManager)
        {
            _skillTabs = new List <SkillTab>();

            //to make things easier, let's add all available character skills to the list
            List <UnitObjectStats.Stat.StatValue> availableSkills = new List <UnitObjectStats.Stat.StatValue>();

            ////get the skills the character already knows
            UnitObjectStats.Stat skills = UnitHelpFunctions.GetComplexValue(unitObject, ItemValueNames.skill_level);
            ////add them to the complete skill list
            availableSkills.AddRange(skills.Values);

            DataTable skillTable = fileManager.GetDataTable("SKILLS");

            //let's add all the skills the character doesn't know yet
            foreach (int skillTab in skillTabs)
            {
                DataRow[] skillRows = skillTable.Select("skillTab = " + skillTab);

                SkillTab skillsInSkillTab = CreateSkillsFromRow(availableSkills, skillTable, skillRows);

                if (skillsInSkillTab.Skills.Count > 0)
                {
                    _skillTabs.Add(skillsInSkillTab);
                }
            }


            // select the general skill tab
            DataRow[] generalSkillRows = skillTable.Select("skillTab = " + 0);
            _generalSkills = CreateSkillsFromRow(availableSkills, skillTable, generalSkillRows);

            //add all skills back to the savegame
            availableSkills.Clear();

            foreach (Skill skill in _generalSkills.Skills)
            {
                availableSkills.Add(skill.SkillBlock);
            }

            foreach (SkillTab skillTab in _skillTabs)
            {
                foreach (Skill skill in skillTab.Skills)
                {
                    availableSkills.Add(skill.SkillBlock);
                }
            }

            //skills.repeatCount = availableSkills.Count;

            //skills.Values = availableSkills;
            skills.Values.Clear();
            skills.Values.AddRange(availableSkills);
        }
Пример #3
0
        private void b_addAffix_Click(object sender, EventArgs e)
        {
            if (_characterUnit == null || _selectedItem == null)
            {
                return;
            }

            UnitObjectStats.Stat value = UnitHelpFunctions.GetComplexValue(_selectedItem.Item.UnitObject, ItemValueNames.applied_affix.ToString());
            if (value != null)
            {
                MessageBox.Show(value.ToString());
            }
        }
Пример #4
0
        // not needed anymore (name is obtained automatically)
        //private void GenerateUnitNameStrings(UnitObject[] units, Hashtable hash)
        //{
        //    if (hash == null) hash = new Hashtable();

        //    try
        //    {
        //        UnitObjectStats.Stat stat;
        //        foreach (UnitObject unit in units)
        //        {
        //            for (int counter = 0; counter < unit.Stats.Stats.Count; counter++)
        //            {
        //                stat = unit.Stats.Stats[counter];

        //                String name;
        //                if (hash.Contains(stat.Code))
        //                {
        //                    name = (string)hash[stat.Code];
        //                }
        //                else
        //                {
        //                    DataRow[] statRows = statsTable.Select("code = " + stat.Code);
        //                    name = (string)statRows[0]["stat"];

        //                    if (name != null)
        //                    {
        //                        hash.Add(stat.Code, name);
        //                    }
        //                }

        //                unit.Stats[counter].Name = name;
        //            }

        //            GenerateUnitNameStrings(unit.Items.ToArray(), hash);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message, "GenerateUnitNameStrings");
        //    }
        //}

        public string MapIdToString(UnitObjectStats.Stat stat, Xls.TableCodes tableId, int lookupId)
        {
            string value = string.Empty;

            if (stat.Values.Count != 0)
            {
                String    select = String.Format("code = '{0}'", lookupId);
                DataTable table  = null;// todo: rewrite  _dataSet.GetExcelTableFromCode((uint)tableId);
                DataRow[] row;

                if (table != null)
                {
                    row = table.Select(select);

                    if (row != null && row.Length != 0)
                    {
                        value = (string)row[0][1];
                    }
                }
            }

            return(value);
        }
Пример #5
0
        /// <summary>
        /// Adds a new simple value (entry that holds only one value) to the stats table
        /// </summary>
        /// <param name="unit">The unit to add this stat to</param>
        /// <param name="valueName">The name/id of the value to add</param>
        /// <param name="value">The actual value to add</param>
        /// <param name="bitCount">The bitCount of this value (possibly defines the maximum value of the "value" entry)</param>
        public static void AddSimpleValue(UnitObject unit, ItemValueNames valueName, int value, int bitCount)
        {
            List <UnitObjectStats.Stat> newStats = new List <UnitObjectStats.Stat>();

            //copies the existing values to a new array
            newStats.AddRange(unit.Stats.Stats.Values);

            //check if the value already exists
            if (newStats.Find(tmp => tmp.Code == (int)valueName) != null)
            {
                return;
            }

            //generates a new stat
            UnitObjectStats.Stat newStat = new UnitObjectStats.Stat();
            //generates the entry that holds the stat value
            UnitObjectStats.Stat.StatValue newValue = new UnitObjectStats.Stat.StatValue();
            //newStat.Values = new List<UnitObjectStats.Stat.StatValue>();
            //adds the entry to the new stat
            newStat.Values.Add(newValue);
            //sets the bitCOunt value (maximum stat value defined by the number of bits?)
            //newStat.BitCount = bitCount;
            //sets the length of the stat array (may be unnecessary)
            //newStat.Length = 1;
            //sets the Id of the new stat
            //newStat.Code = (short)valueName;
            //newStat.SkipResource = 1;
            //newStat.repeatCount = 1;

            //adds the new value to the array
            newStats.Add(newStat);

            //assigns the new array to the unit
            unit.Stats.Stats.TryAdd(newStat.Code, newStat);// = newStats.ToArray();
            //unit.Stats.statCount = newStats.Count;
        }
Пример #6
0
 private void button1_Click(object sender, EventArgs e)
 {
     UnitObjectStats.Stat skillLevel = _hero.Stats.Stats[18];
     UnitHelpFunctions.SaveCharacterFile(_hero, _filePath);
 }
Пример #7
0
        public CharacterItems(UnitObject unitObject, FileManager fileManager)
            : base(unitObject, fileManager)
        {
            _itemTable = fileManager.GetDataTable("ITEMS");
            DataRow[] itemRow = _itemTable.Select("code = " + unitObject.UnitCode);

            //DataTable colorTable = _dataSet.GetExcelTableFromStringId("ITEMQUALITY");
            //DataRow[] colorRow = colorTable.Select("code = " + _hero.unitCode);

            if (itemRow.Length > 0)
            {
                _isItem = true;

                uint bitMask = (uint)itemRow[0]["bitmask02"];
                _isQuestItem = (bitMask >> 13 & 1) == 1;

                string   maxStackSize = (string)itemRow[0]["stackSize"];
                string[] splitResult  = maxStackSize.Split(new char[] { ',' });
                if (splitResult.Length == 3)
                {
                    _maxStackSize = int.Parse(splitResult[1]);
                }
                if (_maxStackSize <= 0)
                {
                    _maxStackSize = 1;
                }

                _stackSize = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_quantity.ToString());
                if (_stackSize <= 0)
                {
                    _stackSize = 1;
                }

                _itemImagePath = CreateImagePath();

                _numberOfAugmentations = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_augmented_count.ToString());
                _numberOfUpgrades      = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_upgraded_count.ToString());

                DataTable gameGlobals = fileManager.GetDataTable("GAME_GLOBALS");
                //DataRow[] globalsRow = gameGlobals.Select("name = " + "max_item_upgrades");
                DataRow[] globalsRow = gameGlobals.Select("Index = " + 16);
                _maxNumberOfUpgrades = (int)globalsRow[0]["intValue"];

                //globalsRow = gameGlobals.Select("name = " + "max_item_augmentations");
                globalsRow          = gameGlobals.Select("Index = " + 17);
                _maxNumberOfAffixes = (int)globalsRow[0]["intValue"];
                UnitObjectStats.Stat affixes = UnitHelpFunctions.GetComplexValue(unitObject, ItemValueNames.applied_affix.ToString());
                if (affixes != null)
                {
                    _numberOfAffixes = affixes.Values.Count;
                }

                int numberOfInherentAffixes = _numberOfAffixes - _numberOfAugmentations;
                _numberOfAugmentationsLeft = _maxNumberOfAffixes - numberOfInherentAffixes;

                if (_numberOfAugmentationsLeft < 0)
                {
                    _numberOfAugmentationsLeft = 0;
                }

                _maxNumberOfAugmentations = _numberOfAugmentations + _numberOfAugmentationsLeft;
                if (_maxNumberOfAugmentations > _maxNumberOfAffixes)
                {
                    _maxNumberOfAugmentations = _maxNumberOfAffixes;
                }
            }

            _items = new List <CharacterItems>();

            foreach (UnitObject item in unitObject.Items)
            {
                CharacterItems wrapper = new CharacterItems(item, fileManager);
                _items.Add(wrapper);
            }
        }