Exemplo n.º 1
0
        public static void LoadFromSql(Armor armor, int id)
        {
            if (null == armor)
                throw new NullReferenceException();

            string query = string.Format(@"SELECT [items].* from [items] WHERE [items].[id] = {0}", id);

            DataTable dataTable = Database.Instance.Query(query);

            if (0 == dataTable.Rows.Count)
                throw new IndexOutOfRangeException();

            DataRow dataRow = dataTable.Rows[0];

            armor.Durability = (float) dataRow["durability"];
            armor.Slots = (EquipmentSlot) dataRow["slot_id"];

            var effectsTableId = (int) dataRow["effects_table_id"];

            if (0 != effectsTableId)
            {
                EffectsTableHelper.LoadFromSql(armor.Effects, effectsTableId);
            }

            var modifiersTableId = (int) dataRow["modifiers_table_id"];

            if (0 != modifiersTableId)
            {
                ModifiersTableHelper.LoadFromSql(armor.Modifiers, modifiersTableId);
            }

            var reqTableId = (int) dataRow["reqs_table_id"];

            if (0 != reqTableId)
            {
                RequirementsTableHelper.LoadFromSql(armor.Requirements, reqTableId);
            }
        }
Exemplo n.º 2
0
        private static bool CheckRequirements(Actor actor, Armor equipment)
        {
            bool equippable = false;

            if (actor == null || equipment == null)
                return false;

            foreach (Requirement requirement in equipment.Requirements)
            {
                switch (requirement.Type)
                {
                    case RequirementType.Ability:
                        equippable = actor.CurrentAbilities.ContainsKey(requirement.Id);
                        break;
                    case RequirementType.AbilityLevel:
                        equippable = actor.CurrentAbilities.ContainsKey(requirement.Id) &&
                                     actor.CurrentAbilities[requirement.Id].Level >= requirement.Value;
                        break;
                    case RequirementType.Class:
                        equippable = actor.Classes.Any(descriptor => descriptor.Id == requirement.Id);
                        break;
                    case RequirementType.ClassLevel:
                        equippable = actor.Classes.Any(descriptor => descriptor.Level >= requirement.Value);
                        break;
                    case RequirementType.Race:
                        equippable = actor.Race.Id == requirement.Id;
                        break;
                    case RequirementType.RaceLevel:
                        equippable = actor.Race.Level >= requirement.Value;
                        break;
                    case RequirementType.Skill:
                        equippable = actor.CurrentSkills.ContainsKey(requirement.Id);

                        break;
                    case RequirementType.SkillLevel:
                        equippable = actor.CurrentSkills.ContainsKey(requirement.Id) &&
                                     actor.CurrentSkills[requirement.Id].Level >= requirement.Value;
                        break;
                    case RequirementType.Stat:
                        equippable = actor.EffectiveStats[(StatType) requirement.Id] >= requirement.Value;
                        break;
                }

                if (!equippable)
                {
                    Logger.Debug("Equipment {0} did not satisify all requirements to equip.", equipment.Id);
                    break;
                }
            }

            return equippable;
        }
Exemplo n.º 3
0
        private static bool CheckSlot(EquipmentSlot slot, Armor equipment)
        {
            if (null == equipment)
                return false;

            switch (slot)
            {
                case EquipmentSlot.EarLeft:
                case EquipmentSlot.EarRight:
                    if (equipment.Slots.HasFlag(EquipmentSlot.Ears))
                        return true;
                    break;
                case EquipmentSlot.FingerLeft:
                case EquipmentSlot.FingerRight:
                    if (equipment.Slots.HasFlag(EquipmentSlot.Fingers))
                        return true;
                    break;
                case EquipmentSlot.Primary:
                    if (equipment.Slots.HasFlag(EquipmentSlot.TwoHand) || equipment.Slots.HasFlag(EquipmentSlot.Primary))
                        return true;
                    break;
                case EquipmentSlot.WristLeft:
                case EquipmentSlot.WristRight:
                    if (equipment.Slots.HasFlag(EquipmentSlot.Wrists))
                        return true;
                    break;
                default:
                    if (equipment.Slots.HasFlag(slot))
                        return true;
                    break;
            }

            Logger.Debug("Equipment {0} cannot be equipped in slot {1}", equipment.Id, slot);

            return false;
        }
Exemplo n.º 4
0
 public static bool CanEquip(Actor actor, EquipmentSlot slot, Armor equipment)
 {
     return CheckRequirements(actor, equipment) && CheckSlot(slot, equipment);
 }