protected void Page_Load(object sender, EventArgs e)
    {
        ISession session = (ISession)Context.Items[Constant.NHibernateSessionSign];

        int heroId = 0;
        if (!int.TryParse(Request["hero"], out heroId))
        {
            this.pHeroNotFound.Visible = true;
            this.pHeroDetais.Visible = false;
            return;
        }

        this.Hero = session.Get<Hero>(heroId);
        if (this.Hero == null || this.Hero.Owner.ID != (int)Session[Constant.NormalUserSessionSign])
        {
            this.pHeroNotFound.Visible = true;
            this.pHeroDetais.Visible = false;
            return;
        }

        this.pHeroDetais.Visible = true;
        this.pHeroNotFound.Visible = false;

        this.aDeleteAvatar.Visible = this.Hero.Avatar;
        this.txtName.Text = this.Hero.Name;
        this.txtPersonalText.Text = this.Hero.Biography;
    }
Beispiel #2
0
        public override MovingCommand Cancel(ISession session)
        {
            Return returnTroop = new Return();
            returnTroop.Spear = this.Spear;
            returnTroop.Sword = this.Sword;
            returnTroop.Axe = this.Axe;
            returnTroop.Scout = this.Scout;
            returnTroop.LightCavalry = this.LightCavalry;
            returnTroop.HeavyCavalry = this.HeavyCavalry;
            returnTroop.Ram = this.Ram;
            returnTroop.Catapult = this.Catapult;
            returnTroop.Noble = this.Noble;

            returnTroop.StartingTime = returnTroop.LandingTime = DateTime.Now;
            returnTroop.LandingTime += (DateTime.Now - this.StartingTime);

            this.FromVillage.MovingCommandsFromMe.Remove(this);
            this.FromVillage.MovingCommandsToMe.Add(returnTroop);
            this.ToVillage.MovingCommandsToMe.Remove(this);
            this.ToVillage.MovingCommandsFromMe.Add(returnTroop);
            if (this.Hero != null)
            {
                this.Hero.InMovingCommand = returnTroop;
                returnTroop.Hero = this.Hero;
                session.Update(this.Hero);
                this.Hero = null;
            }

            session.Delete(this);
            session.Save(returnTroop);
            session.Update(this.ToVillage);
            session.Update(this.FromVillage);

            return returnTroop;
        }
        public virtual Attack CreateAttack(ISession session,
                                    int x,
                                    int y,
                                    int spear,
                                    int sword,
                                    int axe,
                                    int scout,
                                    int light,
                                    int heavy,
                                    int ram,
                                    int catapult,
                                    Hero hero,
                                    BuildingType building)
        {
            if (x == this.Village.X && y == this.Village.Y)
                throw new Exception("Nhập toạ độ");

            if ((spear + sword + axe + scout + light + heavy + ram + catapult) == 0)
                throw new Exception("Nhập một loại quân");

            if ((spear > this.Village.VillageTroopData.Spear) ||
            (sword > this.Village.VillageTroopData.Sword) ||
            (axe > this.Village.VillageTroopData.Axe) ||
            (scout > this.Village.VillageTroopData.Scout) ||
            (light > this.Village.VillageTroopData.LightCavalry) ||
            (heavy > this.Village.VillageTroopData.HeavyCavalry) ||
            (ram > this.Village.VillageTroopData.Ram) ||
            (catapult > this.Village.VillageTroopData.Catapult))
                throw new Exception("Không đủ quân");

            Village toVillage = Village.GetVillageByCoordinate(x, y, session);
            if (toVillage == null)
                throw new Exception("Toạ độ không tồn tại");

            if (hero != null)
            {
                if ((from h in this.Village.Heroes
                     where h == hero
                     select h).Count<Hero>() == 0)
                    throw new TribalWarsException("Không tồn tại hero trong thành phố");
                else if (this.Village.MainHero == hero)
                    throw new TribalWarsException("Không thể đưa chủ thành đi tấn công");
            }

            Attack attack = new Attack();
            attack.ToVillage = toVillage;
            attack.FromVillage = this.Village;

            TroopType type = TroopType.Spear;
            if (scout > 0)
                type = TroopType.Scout;
            if (light > 0)
                type = TroopType.Light;
            if (heavy > 0)
                type = TroopType.Heavy;
            if (spear > 0)
                type = TroopType.Spear;
            if (axe > 0)
                type = TroopType.Axe;
            if (sword > 0)
                type = TroopType.Sword;
            if (ram > 0)
                type = TroopType.Ram;
            if (catapult > 0)
                type = TroopType.Catapult;
            attack.Hero = hero;

            attack.Building = building;
            attack.Spear = spear;
            attack.Sword = sword;
            attack.Axe = axe;
            attack.Scout = scout;
            attack.LightCavalry = light;
            attack.HeavyCavalry = heavy;
            attack.Ram = ram;
            attack.Catapult = catapult;
            attack.StartingTime = DateTime.Now;
            attack.LandingTime = Map.LandingTime(type, attack.FromVillage.X, attack.FromVillage.Y, attack.ToVillage.X, attack.ToVillage.Y, attack.StartingTime, Research.SpeedValuesDictionary[this.Village[ResearchType.Speed]]);
            return attack;
        }
        public Hero CreateHero(string name, HeroType type, ISession session)
        {
            Random r = new Random();
            try
            {

                Price price = Recruit.GetPrice(TroopType.Nobleman, 1);
                int heroCount = this.Village.Player.Heroes.Count + 1;
                

                int clay = price.Clay * heroCount, wood = price.Wood * heroCount, iron = price.Iron * heroCount;
                this.Village[ResourcesType.Wood] -= wood;
                this.Village[ResourcesType.Clay] -= clay;
                this.Village[ResourcesType.Iron] -= iron;

                if (this.Village[ResourcesType.Wood] < wood || this.Village[ResourcesType.Clay] < clay || this.Village[ResourcesType.Iron] < iron)
                    throw new TribalWarsException("Không đủ tài nguyên");

                if ((this.Village.Population + price.Population) > this.Village.MaxPopulation)
                    throw new TribalWarsException("Không đủ farm xây dựng hero");

                if (this.Village[BuildingType.Academy] < heroCount)
                    throw new TribalWarsException("Số hero không được vượt quá công trình academy");

                Hero hero = new Hero();
                hero.Type = type;
                hero.Name = name;
                hero.Biography = "";
                hero.Avatar = false;
                switch (type)
                {
                    case HeroType.Intelligent:
                        hero.Intelligent = 15 + r.Next(10);
                        hero.Attack = 10 + r.Next(10);
                        hero.Defense = 10 + r.Next(10);
                        break;
                    case HeroType.Attack:
                        hero.Attack = 15 + r.Next(10);
                        hero.Intelligent = 10 + r.Next(10);
                        hero.Defense = 10 + r.Next(10);
                        break;
                    case HeroType.Defense:
                        hero.Defense = 15 + r.Next(10);
                        hero.Attack = 10 + r.Next(10);
                        hero.Intelligent = 10 + r.Next(10);
                        break;
                    default:
                        break;
                }

                

                this.Village.Heroes.Add(hero);
                this.Village.Player.Heroes.Add(hero);
                
                hero.InVillage = this.Village;
                hero.Owner = this.Village.Player;
                hero.IsRecruiting = true;
                hero.IsDead = true;

                RecruitHero recruit = new RecruitHero();
                recruit.IsResurrection = false;
                recruit.Hero = hero;
                recruit.Owner = this.Village.Player;
                recruit.StartingTime = DateTime.Now;
                recruit.FinishTime = recruit.StartingTime.AddMilliseconds(Recruit.GetPrice(TroopType.Nobleman, this.Village[BuildingType.Academy]).BuildTime);

                
                session.Save(hero);
                session.Save(recruit);
                session.Update(this.Village);
                session.Update(this.Village.Player);

                return hero;
            }
            catch (TribalWarsException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                ServicesList.LogService.LogException(ex);
                throw ex;
            }
        }