Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Village = ((inPage)this.Master).CurrentVillage;
        ISession session = (ISession)Context.Items["NHibernateSession"];
        if (this.Village[BuildingType.Smithy] > 0)
            this.pConstructed.Visible = true;
        else
        {
            this.pNotConstruct.Visible = true;
            return;
        }
        IList<Research> researches = this.Village.Researches;

        this.AttackPrice = Research.GetPrice(ResearchType.Attack, this.Village.VillageResearchMethods.MaxAttackLevel + 1, this.Village[BuildingType.Smithy]);
        this.DefensePrice = Research.GetPrice(ResearchType.Defense, this.Village.VillageResearchMethods.MaxDefenseLevel + 1, this.Village[BuildingType.Smithy]);
        this.SpeedPrice = Research.GetPrice(ResearchType.Speed, this.Village.VillageResearchMethods.MaxSpeedLevel + 1, this.Village[BuildingType.Smithy]);

        if (this.Village.VillageResearchMethods.CanResearch(ResearchType.Attack, this.Village.VillageResearchMethods.MaxAttackLevel + 1))
            this.panelUpgradeAttack.Visible = true;
        else
            this.cannotUpgradeAttack.Visible = true;
        if (this.Village.VillageResearchMethods.CanResearch(ResearchType.Defense, this.Village.VillageResearchMethods.MaxDefenseLevel + 1))
            this.panelUpgradeDefense.Visible = true;
        else
            this.cannotUpgradeDefense.Visible = true;
        if (this.Village.VillageResearchMethods.CanResearch(ResearchType.Speed, this.Village.VillageResearchMethods.MaxSpeedLevel + 1))
            this.panelUpgradeSpeed.Visible = true;
        else
            this.cannotUpgradeSpeed.Visible = true;

        if (researches.Count > 0)
        {
            this.rptResearches.DataSource = researches;
            this.rptResearches.DataBind();
        }
    }
        protected static void CalculateResearchPrice()
        {

            int baseAttackTime = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.time").Value;
            int baseAttackWood = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.wood").Value;
            int baseAttackClay = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.clay").Value;
            int baseAttackIron = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.iron").Value;

            int baseDefenseTime = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.time").Value;
            int baseDefenseWood = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.wood").Value;
            int baseDefenseClay = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.clay").Value;
            int baseDefenseIron = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.iron").Value;

            int baseSpeedTime = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.time").Value;
            int baseSpeedWood = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.wood").Value;
            int baseSpeedClay = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.clay").Value;
            int baseSpeedIron = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.iron").Value;


            ResearchPrice attackResearchPrice = new ResearchPrice("Attack cấp 1 smithy 1",
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.time").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.wood").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.clay").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Attack.iron").Value,
                                                                        1);
            ResearchPrice defenseResearchPrice = new ResearchPrice("Defense cấp 1 smithy 1",
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.time").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.wood").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.clay").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Defense.iron").Value, 
                                                                        1);
            ResearchPrice speedResearchPrice = new ResearchPrice("Speed cấp 1 smithy 1",
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.time").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.wood").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.clay").Value,
                                                                        (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Speed.iron").Value, 
                                                                        1);
            
            int maxResearchLevel = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Common.max_level").Value;
            int maxSmithyLevel = (int)Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Building.Smithy.max_level").Value;
            double percentResourceIncrease = Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Common.percent_resource_increase").Value;
            double percentTimeIncrease = Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Common.percent_time_increase").Value;
            double percentTimeDecrease = Configuration.TribalWarsConfiguration.GetNumericConfigurationItem("Research.Common.percent_time_decrease").Value;
            int attackType = (int)ResearchType.Attack, defenseType = (int)ResearchType.Defense, speedType = (int)ResearchType.Speed, key = 0, tmp = 0;
            
            Research.ResearchPrices.Clear();

            for (int researchLevel = 1; researchLevel < maxResearchLevel; researchLevel++)
            {
                if (researchLevel > 1)
                {
                    baseAttackTime += (int)(baseAttackTime * percentTimeIncrease);
                    baseAttackWood += (int)(baseAttackWood * percentResourceIncrease);
                    baseAttackClay += (int)(baseAttackClay * percentResourceIncrease);
                    baseAttackIron += (int)(baseAttackIron * percentResourceIncrease);

                    baseDefenseTime += (int)(baseDefenseTime * percentTimeIncrease);
                    baseDefenseWood += (int)(baseDefenseWood * percentResourceIncrease);
                    baseDefenseClay += (int)(baseDefenseClay * percentResourceIncrease);
                    baseDefenseIron += (int)(baseDefenseIron * percentResourceIncrease);

                    baseSpeedTime += (int)(baseSpeedTime * percentTimeIncrease);
                    baseSpeedWood += (int)(baseSpeedWood * percentResourceIncrease);
                    baseSpeedClay += (int)(baseSpeedClay * percentResourceIncrease);
                    baseSpeedIron += (int)(baseSpeedIron * percentResourceIncrease);
                }

                int speedTime = baseSpeedTime, attackTime = baseAttackTime, defenseTime = baseDefenseTime;
                for (int smithy = 1; smithy < maxSmithyLevel; smithy++)
                {
                    speedTime -= (int)(speedTime * percentTimeDecrease);
                    attackTime -= (int)(attackTime * percentTimeDecrease);
                    defenseTime -= (int)(defenseTime * percentTimeDecrease);
                    attackResearchPrice = new ResearchPrice(string.Format("Attack cấp {0} smithy {1}", researchLevel, smithy), attackTime, baseAttackWood, baseDefenseClay, baseDefenseIron, researchLevel);
                    defenseResearchPrice = new ResearchPrice(string.Format("Defense cấp {0} smithy {1}", researchLevel, smithy), defenseTime, baseDefenseWood, baseDefenseClay, baseDefenseIron, researchLevel);
                    speedResearchPrice = new ResearchPrice(string.Format("Speed cấp {0} smithy {1}", researchLevel, smithy), speedTime, baseSpeedWood, baseSpeedClay, baseSpeedIron, researchLevel);
                    tmp = (researchLevel * 1000) + (smithy * 1000000);
                    key = attackType + tmp;
                    Research.ResearchPrices.Add(key, attackResearchPrice);
                    key = defenseType + tmp;
                    Research.ResearchPrices.Add(key, defenseResearchPrice);
                    key = speedType + tmp;
                    Research.ResearchPrices.Add(key, speedResearchPrice);
                }
            }
        }