Ejemplo n.º 1
0
 public async Task<IActionResult> Delete(int id)
 {
     var gradeTemplate = new GradeTemplate { ID = id };
     _context.Remove(gradeTemplate);
     await _context.SaveChangesAsync();
     return NoContent();
 }
Ejemplo n.º 2
0
 public GradeIndexModel(Grade grade, GradeTemplate gradeTemplate)
 {
     ID        = grade.ID;
     Name      = gradeTemplate.Name;
     Points    = grade.Points;
     TimeTaken = grade.TimeTaken;
     MaxPoints = gradeTemplate.MaxPoints;
     Addendum  = grade.Addendum;
 }
        private GradeEnchantResult RollRegrade(GradeTemplate gradeTemplate, Item item, bool isLucky, bool useCharm, ItemGradeEnchantingSupport charmInfo)
        {
            var successRoll      = Rand.Next(0, 10000);
            var breakRoll        = Rand.Next(0, 10000);
            var downgradeRoll    = Rand.Next(0, 10000);
            var greatSuccessRoll = Rand.Next(0, 10000);

            // TODO : Refactor
            var successChance      = useCharm ? GetCharmChance(gradeTemplate.EnchantSuccessRatio, charmInfo.AddSuccessRatio, charmInfo.AddSuccessMul) : gradeTemplate.EnchantSuccessRatio;
            var greatSuccessChance = useCharm ? GetCharmChance(gradeTemplate.EnchantGreatSuccessRatio, charmInfo.AddGreatSuccessRatio, charmInfo.AddGreatSuccessMul) : gradeTemplate.EnchantGreatSuccessRatio;
            var breakChance        = useCharm ? GetCharmChance(gradeTemplate.EnchantBreakRatio, charmInfo.AddBreakRatio, charmInfo.AddBreakMul) : gradeTemplate.EnchantBreakRatio;
            var downgradeChance    = useCharm ? GetCharmChance(gradeTemplate.EnchantDowngradeRatio, charmInfo.AddDowngradeRatio, charmInfo.AddDowngradeMul) : gradeTemplate.EnchantDowngradeRatio;

            if (successRoll < successChance)
            {
                if (isLucky && greatSuccessRoll < greatSuccessChance)
                {
                    // TODO : Refactor
                    var increase = useCharm ? 2 + charmInfo.AddGreatSuccessGrade : 2;
                    item.Grade = (byte)GetNextGrade(gradeTemplate, increase).Grade;
                    return(GradeEnchantResult.GreatSuccess);
                }
                else
                {
                    item.Grade = (byte)GetNextGrade(gradeTemplate, 1).Grade;
                    return(GradeEnchantResult.Success);
                }
            }
            else
            {
                if (breakRoll < breakChance)
                {
                    return(GradeEnchantResult.Break);
                }
                else
                {
                    if (downgradeRoll < downgradeChance)
                    {
                        var newGrade = (byte)Rand.Next(gradeTemplate.EnchantDowngradeMin, gradeTemplate.EnchantDowngradeMax);
                        if (newGrade < 0)
                        {
                            return(GradeEnchantResult.Fail);
                        }

                        item.Grade = newGrade;
                        return(GradeEnchantResult.Downgrade);
                    }
                    else
                    {
                        return(GradeEnchantResult.Fail);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void AddNewPotentialTemplateToSimulatorScenarios(GradeTemplate gradeTemplate)
        {
            var scenarioGradesTemplates = new List<ScenarioGradesTemplates>();

            foreach (Scenario scenario in Context.Scenarios.Where(x => x.SimulatorID == gradeTemplate.SimulatorID).ToList())
            {
                scenarioGradesTemplates.Add(new ScenarioGradesTemplates(scenario.ID, gradeTemplate.ID));
            }
            Context.AddRange(scenarioGradesTemplates);
            Context.SaveChanges();
        }
Ejemplo n.º 5
0
 public void UpdateScenariosMaxGradeSumOnTemplateChange(GradeTemplate gradeTemplate)
 {
     Context.Entry(gradeTemplate).Reference(x => x.Simulator).Load();
     var simulator = Context.Entry(gradeTemplate).Entity.Simulator;
     if (simulator.Scenarios != null)
     {
         var scenariosToEdit = simulator.Scenarios.ToList();
         foreach (Scenario scenario in scenariosToEdit)
         {
             UpdateScenarioMaxGradeSum(scenario.ID);
         }
     }
 }
        private int GoldCost(GradeTemplate gradeTemplate, Item item, int ItemType)
        {
            int cost = 0;

            uint slotTypeId = 0;

            switch (ItemType)
            {
            case 1:
                WeaponTemplate weaponTemplate = (WeaponTemplate)item.Template;
                _log.Info(weaponTemplate.HoldableTemplate.SlotTypeId);
                slotTypeId = weaponTemplate.HoldableTemplate.SlotTypeId;
                break;

            case 2:
                ArmorTemplate armorTemplate = (ArmorTemplate)item.Template;
                _log.Info(armorTemplate.SlotTemplate.SlotTypeId);
                slotTypeId = armorTemplate.SlotTemplate.SlotTypeId;
                break;

            case 24:
                AccessoryTemplate accessoryTemplate = (AccessoryTemplate)item.Template;
                _log.Info(accessoryTemplate.SlotTemplate.SlotTypeId);
                slotTypeId = accessoryTemplate.SlotTemplate.SlotTypeId;
                break;
            }

            if (slotTypeId == 0)
            {
                return(-1);
            }
            EquipSlotEnchantingCost enchantingCost = ItemManager.Instance.GetEquipSlotEnchantingCost(slotTypeId);

            int item_grade = gradeTemplate.EnchantCost;
            int item_level = item.Template.Level;
            int equip_slot_enchant_cost = enchantingCost.Cost;

            Dictionary <string, double> parameters = new Dictionary <string, double>();

            parameters.Add("item_grade", item_grade);
            parameters.Add("item_level", item_level);
            parameters.Add("equip_slot_enchant_cost", equip_slot_enchant_cost);
            Formula formula = FormulaManager.Instance.GetFormula(22);

            cost = (int)formula.Evaluate(parameters);

            return(cost);
        }
Ejemplo n.º 7
0
        public void Load()
        {
            _grades             = new Dictionary <int, GradeTemplate>();
            _holdables          = new Dictionary <uint, Holdable>();
            _wearables          = new Dictionary <uint, Wearable>();
            _wearableKinds      = new Dictionary <uint, WearableKind>();
            _wearableSlots      = new Dictionary <uint, WearableSlot>();
            _modifiers          = new Dictionary <uint, AttributeModifiers>();
            _templates          = new Dictionary <uint, ItemTemplate>();
            _enchantingCosts    = new Dictionary <uint, EquipSlotEnchantingCost>();
            _gradesOrdered      = new Dictionary <int, GradeTemplate>();
            _enchantingSupports = new Dictionary <uint, ItemGradeEnchantingSupport>();
            _config             = new ItemConfig();
            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_configs";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            if (!reader.Read())
                            {
                                return;
                            }
                            _config.DurabilityDecrementChance  = reader.GetFloat("durability_decrement_chance");
                            _config.DurabilityRepairCostFactor = reader.GetFloat("durability_repair_cost_factor");
                            _config.DurabilityConst            = reader.GetFloat("durability_const");
                            _config.HoldableDurabilityConst    = reader.GetFloat("holdable_durability_const");
                            _config.WearableDurabilityConst    = reader.GetFloat("wearable_durability_const");
                            _config.DeathDurabilityLossRatio   = reader.GetInt32("death_durability_loss_ratio");
                            _config.ItemStatConst     = reader.GetInt32("item_stat_const");
                            _config.HoldableStatConst = reader.GetInt32("holdable_stat_const");
                            _config.WearableStatConst = reader.GetInt32("wearable_stat_const");
                            _config.StatValueConst    = reader.GetInt32("stat_value_const");
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_grades";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new GradeTemplate();
                                template.Grade                    = reader.GetInt32("id");
                                template.GradeOrder               = reader.GetInt32("grade_order");
                                template.HoldableDps              = reader.GetFloat("var_holdable_dps");
                                template.HoldableArmor            = reader.GetFloat("var_holdable_armor");
                                template.HoldableMagicDps         = reader.GetFloat("var_holdable_magic_dps");
                                template.WearableArmor            = reader.GetFloat("var_wearable_armor");
                                template.WearableMagicResistance  = reader.GetFloat("var_wearable_magic_resistance");
                                template.Durability               = reader.GetFloat("durability_value");
                                template.UpgradeRatio             = reader.GetInt32("upgrade_ratio");
                                template.StatMultiplier           = reader.GetInt32("stat_multiplier");
                                template.RefundMultiplier         = reader.GetInt32("refund_multiplier");
                                template.EnchantSuccessRatio      = reader.GetInt32("grade_enchant_success_ratio");
                                template.EnchantGreatSuccessRatio = reader.GetInt32("grade_enchant_great_success_ratio");
                                template.EnchantBreakRatio        = reader.GetInt32("grade_enchant_break_ratio");
                                template.EnchantDowngradeRatio    = reader.GetInt32("grade_enchant_downgrade_ratio");
                                template.EnchantCost              = reader.GetInt32("grade_enchant_cost");
                                template.HoldableHealDps          = reader.GetFloat("var_holdable_heal_dps");
                                template.EnchantDowngradeMin      = reader.GetInt32("grade_enchant_downgrade_min");
                                template.EnchantDowngradeMax      = reader.GetInt32("grade_enchant_downgrade_max");
                                template.CurrencyId               = reader.GetInt32("currency_id");
                                _grades.Add(template.Grade, template);
                                _gradesOrdered.Add(template.GradeOrder, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM holdables";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new Holdable
                                {
                                    Id     = reader.GetUInt32("id"),
                                    KindId = reader.GetUInt32("kind_id"),
                                    Speed  = reader.GetInt32("speed"),
                                    ExtraDamagePierceFactor = reader.GetInt32("extra_damage_pierce_factor"),
                                    ExtraDamageSlashFactor  = reader.GetInt32("extra_damage_slash_factor"),
                                    ExtraDamageBluntFactor  = reader.GetInt32("extra_damage_blunt_factor"),
                                    MaxRange         = reader.GetInt32("max_range"),
                                    Angle            = reader.GetInt32("angle"),
                                    EnchantedDps1000 = reader.GetInt32("enchanted_dps1000"),
                                    SlotTypeId       = reader.GetUInt32("slot_type_id"),
                                    DamageScale      = reader.GetInt32("damage_scale"),
                                    FormulaDps       = new Formula(reader.GetString("formula_dps")),
                                    FormulaMDps      = new Formula(reader.GetString("formula_mdps")),
                                    FormulaArmor     = new Formula(reader.GetString("formula_armor")),
                                    MinRange         = reader.GetInt32("min_range"),
                                    SheathePriority  = reader.GetInt32("sheathe_priority"),
                                    DurabilityRatio  = reader.GetFloat("durability_ratio"),
                                    RenewCategory    = reader.GetInt32("renew_category"),
                                    ItemProcId       = reader.GetInt32("item_proc_id"),
                                    StatMultiplier   = reader.GetInt32("stat_multiplier")
                                };

                                _holdables.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearables";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new Wearable
                                {
                                    TypeId            = reader.GetUInt32("armor_type_id"),
                                    SlotTypeId        = reader.GetUInt32("slot_type_id"),
                                    ArmorBp           = reader.GetInt32("armor_bp"),
                                    MagicResistanceBp = reader.GetInt32("magic_resistance_bp")
                                };
                                _wearables.Add(template.TypeId * 128 + template.SlotTypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearable_kinds";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new WearableKind
                                {
                                    TypeId               = reader.GetUInt32("armor_type_id"),
                                    ArmorRatio           = reader.GetInt32("armor_ratio"),
                                    MagicResistanceRatio = reader.GetInt32("magic_resistance_ratio"),
                                    FullBufId            = reader.GetUInt32("full_buff_id"),
                                    HalfBufId            = reader.GetUInt32("half_buff_id"),
                                    ExtraDamagePierce    = reader.GetInt32("extra_damage_pierce"),
                                    ExtraDamageSlash     = reader.GetInt32("extra_damage_slash"),
                                    ExtraDamageBlunt     = reader.GetInt32("extra_damage_blunt"),
                                    DurabilityRatio      = reader.GetFloat("durability_ratio")
                                };
                                _wearableKinds.Add(template.TypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearable_slots";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new WearableSlot
                                {
                                    SlotTypeId = reader.GetUInt32("slot_type_id"),
                                    Coverage   = reader.GetInt32("coverage")
                                };
                                _wearableSlots.Add(template.SlotTypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM equip_item_attr_modifiers";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new AttributeModifiers
                                {
                                    Id        = reader.GetUInt32("id"), // TODO ... alias
                                    StrWeight = reader.GetInt32("str_weight"),
                                    DexWeight = reader.GetInt32("dex_weight"),
                                    StaWeight = reader.GetInt32("sta_weight"),
                                    IntWeight = reader.GetInt32("int_weight"),
                                    SpiWeight = reader.GetInt32("spi_weight")
                                };
                                _modifiers.Add(template.Id, template);
                            }
                        }
                }

                _log.Info("Loading items...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_armors";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var slotTypeId = reader.GetUInt32("slot_type_id");
                                var typeId     = reader.GetUInt32("type_id");

                                var template = new ArmorTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    WearableTemplate     = _wearables[typeId * 128 + slotTypeId],
                                    KindTemplate         = _wearableKinds[typeId],
                                    SlotTemplate         = _wearableSlots[slotTypeId],
                                    BaseEnchantable      = reader.GetBoolean("base_enchantable", true),
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    BaseEquipment        = reader.GetBoolean("base_equipment", true),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_weapons";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var holdableId = reader.GetUInt32("holdable_id");
                                var template   = new WeaponTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    BaseEnchantable      = reader.GetBoolean("base_enchantable"),
                                    HoldableTemplate     = _holdables[holdableId],
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    BaseEquipment        = reader.GetBoolean("base_equipment", true),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_accessories";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var slotTypeId = reader.GetUInt32("slot_type_id");
                                var typeId     = reader.GetUInt32("type_id");

                                var template = new AccessoryTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    WearableTemplate     = _wearables[typeId * 128 + slotTypeId],
                                    KindTemplate         = _wearableKinds[typeId],
                                    SlotTemplate         = _wearableSlots[slotTypeId],
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_summon_mates";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new SummonMateTemplate
                                {
                                    Id    = reader.GetUInt32("item_id"),
                                    NpcId = reader.GetUInt32("npc_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_summon_slaves";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new SummonSlaveTemplate
                                {
                                    Id      = reader.GetUInt32("item_id"),
                                    SlaveId = reader.GetUInt32("slave_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_body_parts";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                if (reader.IsDBNull("item_id"))
                                {
                                    continue;
                                }
                                var template = new BodyPartTemplate
                                {
                                    Id             = reader.GetUInt32("item_id"),
                                    ModelId        = reader.GetUInt32("model_id"),
                                    NpcOnly        = reader.GetBoolean("npc_only", true),
                                    BeautyShopOnly = reader.GetBoolean("beautyshop_only", true)
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_enchanting_gems";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new RuneTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    EquipSlotGroupId = reader.GetUInt32("equip_slot_group_id", 0),
                                    EquipLevel       = reader.GetByte("equip_level", 0),
                                    ItemGradeId      = reader.GetByte("item_grade_id", 0)
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_backpacks";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new BackpackTemplate
                                {
                                    Id                      = reader.GetUInt32("item_id"),
                                    AssetId                 = reader.GetUInt32("asset_id"),
                                    BackpackType            = (BackpackType)reader.GetUInt32("backpack_type_id"),
                                    DeclareSiegeZoneGroupId = reader.GetUInt32("declare_siege_zone_group_id"),
                                    Heavy                   = reader.GetBoolean("heavy"),
                                    Asset2Id                = reader.GetUInt32("asset2_id"),
                                    NormalSpeciality        = reader.GetBoolean("normal_specialty"),
                                    UseAsStat               = reader.GetBoolean("use_as_stat"),
                                    SkinKindId              = reader.GetUInt32("skin_kind_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM items";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var id       = reader.GetUInt32("id");
                                var template = _templates.ContainsKey(id) ? _templates[id] : new ItemTemplate();
                                template.Id                = id;
                                template.Level             = reader.GetInt32("level");
                                template.Price             = reader.GetInt32("price");
                                template.Refund            = reader.GetInt32("refund");
                                template.BindId            = reader.GetUInt32("bind_id");
                                template.PickupLimit       = reader.GetInt32("pickup_limit");
                                template.MaxCount          = reader.GetInt32("max_stack_size");
                                template.Sellable          = reader.GetBoolean("sellable", true);
                                template.UseSkillId        = reader.GetUInt32("use_skill_id");
                                template.BuffId            = reader.GetUInt32("buff_id");
                                template.Gradable          = reader.GetBoolean("gradable", true);
                                template.LootMulti         = reader.GetBoolean("loot_multi", true);
                                template.LootQuestId       = reader.GetUInt32("loot_quest_id");
                                template.HonorPrice        = reader.GetInt32("honor_price");
                                template.ExpAbsLifetime    = reader.GetInt32("exp_abs_lifetime");
                                template.ExpOnlineLifetime = reader.GetInt32("exp_online_lifetime");
                                template.ExpDate           = reader.IsDBNull("exp_online_lifetime") ? reader.GetInt32("exp_date") : 0;
                                template.LevelRequirement  = reader.GetInt32("level_requirement");
                                template.LevelLimit        = reader.GetInt32("level_limit");
                                template.FixedGrade        = reader.GetInt32("fixed_grade");
                                template.LivingPointPrice  = reader.GetInt32("living_point_price");
                                template.CharGender        = reader.GetByte("char_gender_id");
                                if (!_templates.ContainsKey(id))
                                {
                                    _templates.Add(template.Id, template);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM equip_slot_enchanting_costs";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new EquipSlotEnchantingCost();
                                template.Id         = reader.GetUInt32("id");
                                template.SlotTypeId = reader.GetUInt32("slot_type_id");
                                template.Cost       = reader.GetInt32("cost");
                                if (!_enchantingCosts.ContainsKey(template.SlotTypeId))
                                {
                                    _enchantingCosts.Add(template.SlotTypeId, template);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_grade_enchanting_supports";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new ItemGradeEnchantingSupport();
                                template.Id                   = reader.GetUInt32("id");
                                template.ItemId               = reader.GetUInt32("item_id");
                                template.RequireGradeMin      = reader.GetInt32("require_grade_min");
                                template.RequireGradeMax      = reader.GetInt32("require_grade_max");
                                template.AddSuccessRatio      = reader.GetInt32("add_success_ratio");
                                template.AddSuccessMul        = reader.GetInt32("add_success_mul");
                                template.AddGreatSuccessRatio = reader.GetInt32("add_great_success_ratio");
                                template.AddGreatSuccessMul   = reader.GetInt32("add_great_success_mul");
                                template.AddBreakRatio        = reader.GetInt32("add_break_ratio");
                                template.AddBreakMul          = reader.GetInt32("add_break_mul");
                                template.AddDowngradeRatio    = reader.GetInt32("add_downgrade_ratio");
                                template.AddDowngradeMul      = reader.GetInt32("add_downgrade_mul");
                                template.AddGreatSuccessGrade = reader.GetInt32("add_great_success_grade");

                                if (!_enchantingSupports.ContainsKey(template.ItemId))
                                {
                                    _enchantingSupports.Add(template.ItemId, template);
                                }
                            }
                        }
                }

                _log.Info("Loaded {0} items", _templates.Count);
            }
        }
 // This is required because XLGames are very smart! Instead of being logical and ordering the item_grades table, they added grade_order column...
 private GradeTemplate GetNextGrade(GradeTemplate currentGrade, int gradeChange)
 {
     return(ItemManager.Instance.GetGradeTemplateByOrder(currentGrade.GradeOrder + gradeChange));
 }
Ejemplo n.º 9
0
        public string CalculateGrade(string classroomName, string studentName, string termName)
        {
            var Grade = new GradeTemplate();

            double CalculatePercentage(GradeTemplate.Recorded component)
            {
                return(100 / component.Total * component.Score);
            }

            Classroom classroom = Login.User.userData.GetClassroom(ClassroomList.Text);
            Term      student   = classroom.Students.FirstOrDefault(s => s.Name == StudentList.Text).Terms
                                  .FirstOrDefault(t => t.Name == termName);

            #region Laboratory

            foreach (Graded item in student.Laboratory)
            {
                Grade.Laboratory.Total += item.Total;
                Grade.Laboratory.Score += item.Score;
                if (item.Score > 0)
                {
                    Grade.Lectures.Attendance.Score += 2;
                }
                Grade.Lectures.Attendance.Total += 2;
                Grade.Table.Laboratory.Add(new List <string> {
                    item.Name, $"{item.Score}/{item.Total}", "+2"
                });
            }

            Grade.Laboratory.Percentage = CalculatePercentage(Grade.Laboratory) * 0.30;

            #endregion Laboratory

            #region HandsOn

            Grade.HandsOn.Teamwork += student.HandsOn.Teamwork;
            if (student.HandsOn.Teamwork > 0)
            {
                Grade.Lectures.Attendance.Score += 2;
            }
            Grade.Lectures.Attendance.Total += 2;
            Grade.Table.HandsOn.Add(new List <string> {
                "Teamwork", $"{student.HandsOn.Teamwork:0.00}%", "+2"
            });

            Grade.HandsOn.Communication += student.HandsOn.Communication;
            if (student.HandsOn.Communication > 0)
            {
                Grade.Lectures.Attendance.Score += 2;
            }
            Grade.Lectures.Attendance.Total += 2;
            Grade.Table.HandsOn.Add(new List <string> {
                "Communication", $"{student.HandsOn.Communication:0.00}%", "+2"
            });

            Grade.HandsOn.Percentage = (Grade.HandsOn.Communication + Grade.HandsOn.Teamwork) / 2 * 0.45;

            #endregion HandsOn

            #region Lectures

            foreach (Graded item in student.Lecture.Exams)
            {
                Grade.Lectures.Exams.Total += item.Total;
                Grade.Lectures.Exams.Score += item.Score;
                if (item.Score > 0)
                {
                    Grade.Lectures.Attendance.Score += 2;
                }
                Grade.Lectures.Attendance.Total += 2;
                Grade.Table.Lectures.Add(new List <string> {
                    item.Name, $"{item.Score}/{item.Total}", "+2"
                });
            }

            Grade.Lectures.Exams.Score += Grade.Lectures.Recitation;
            if (Grade.Lectures.Exams.Score > Grade.Lectures.Exams.Total)
            {
                Grade.Lectures.Exams.Percentage = 100;
            }
            else
            {
                Grade.Lectures.Exams.Percentage = CalculatePercentage(Grade.Lectures.Exams);
            }

            Grade.Lectures.Recitation = student.Lecture.Recitation;
            Grade.Table.Lectures.Add(new List <string> {
                "Recitation", $"+{Grade.Lectures.Recitation}"
            });

            Grade.Lectures.Attendance.Percentage =
                CalculatePercentage(Grade.Lectures.Attendance);

            Grade.Lectures.Percentage =
                (Grade.Lectures.Attendance.Percentage * 0.15 + Grade.Lectures.Exams.Percentage * 0.75) * 0.25;

            #endregion Lectures

            finalGrade += (Grade.HandsOn.Percentage + Grade.Laboratory.Percentage + Grade.Lectures.Percentage) / 2;

            List <List <string> > tableList =
                Grade.Table.Lectures.Count > Grade.Table.Laboratory.Count
                    ? Grade.Table.Lectures
                    : Grade.Table.Laboratory;
            List <List <string> > lower =
                Grade.Table.Lectures.Count < Grade.Table.Laboratory.Count
                    ? Grade.Table.Lectures
                    : Grade.Table.Laboratory;

            for (var i = 0; i < lower.Count; i++)
            {
                tableList[i].AddRange(lower[i]);
            }

            for (var i = 0; i < Grade.Table.HandsOn.Count; i++)
            {
                tableList[i].AddRange(Grade.Table.HandsOn[i]);
            }

            var tableOutput = new List <string>
            {
                "|__Lectures__|___|___|__Laboratories__|___|___|__Hands-on__|___|___|",
                "|--:|:-:|:-:|--:|:--|:-:|--:|:-:|:-:|"
            };

            foreach (List <string> item in tableList)
            {
                if (item.Count < 9)
                {
                    int c = 9 - item.Count;
                    for (var i = 0; i < c; i++)
                    {
                        item.Add(" ");
                    }
                }

                tableOutput.Add($"|{string.Join("|", item)}|");
            }

            tableOutput.Add(
                $"|**Total**|{Grade.Lectures.Percentage:0.00}%| | |{Grade.Laboratory.Percentage:0.00}%| | |{Grade.HandsOn.Percentage:0.00}%| |");

            return(string.Join(Environment.NewLine, tableOutput));
        }