public override void effect(ISession session) { ICriteria criteria = session.CreateCriteria(typeof(Stationed)); criteria.Add(Expression.Eq("AtVillage", this.To)); criteria.Add(Expression.Eq("FromVillage", this.From)); IList<Stationed> lstStations = criteria.List<Stationed>(); if (lstStations.Count == 0) { Stationed newStation = new Stationed(); newStation.FromVillage = this.From; newStation.AtVillage = this.To; newStation.Spear = this.Spear; newStation.Sword = this.Sword; newStation.Axe = this.Axe; newStation.Scout = this.Scout; newStation.Light = this.Light; newStation.Heavy = this.Heavy; newStation.Ram = this.Ram; newStation.Catapult = this.Catapult; newStation.Noble = this.Noble; session.Save(newStation); } else { Stationed station = lstStations[0]; station.Spear += this.Spear; station.Sword += this.Sword; station.Axe += this.Axe; station.Scout += this.Scout; station.Light += this.Light; station.Heavy += this.Heavy; station.Ram += this.Ram; station.Catapult += this.Catapult; station.Noble += this.Noble; session.Save(station); return; } SupportReport supportReport = new SupportReport(); supportReport.Owner = this.To.Owner; supportReport.Time = this.LandingTime; supportReport.Title = this.From.Owner + " gửi quân hỗ trợ " + this.To.Name + "(" + this.To.X.ToString("0:000") + "|" + this.To.Y.ToString("0:000") + ")"; session.Save(supportReport); supportReport.Owner = this.From.Owner; session.Save(supportReport); }
public override MovingCommand Effect(ISession session) { //ICriteria criteria = session.CreateCriteria(typeof(Station)); //criteria.Add(Expression.Eq("AtVillage", this.ToVillage)); //criteria.Add(Expression.Eq("FromVillage", this.FromVillage)); //IList<Station> lstStations = criteria.List<Station>(); Station station = (from s in this.ToVillage.StationsAtMe where s.FromVillage == this.FromVillage select s).SingleOrDefault<Station>(); bool newStation = (station == null); if (newStation) { station = new Station(); station.FromVillage = this.FromVillage; station.AtVillage = this.ToVillage; station.Spear = this.Spear; station.Sword = this.Sword; station.Axe = this.Axe; station.Scout = this.Scout; station.LightCavalry = this.LightCavalry; station.HeavyCavalry = this.HeavyCavalry; station.Ram = this.Ram; station.Catapult = this.Catapult; station.Noble = this.Noble; this.ToVillage.VillageTroopData.SpearInVillage += this.Spear; this.ToVillage.VillageTroopData.SwordInVillage += this.Sword; this.ToVillage.VillageTroopData.AxeInVillage+= this.Axe; this.ToVillage.VillageTroopData.LightCavalryInVillage += this.LightCavalry; this.ToVillage.VillageTroopData.HeavyCavalryInVillage += this.HeavyCavalry; this.ToVillage.VillageTroopData.ScoutInVillage += this.Scout; this.ToVillage.VillageTroopData.RamInVillage += this.Ram; this.ToVillage.VillageTroopData.CatapultInVillage += this.Catapult; this.ToVillage.VillageTroopData.NobleInVillage += this.Noble; this.ToVillage.StationsAtMe.Add(station); this.FromVillage.StationsFromMe.Add(station); session.Save(station); } else { station.Spear += this.Spear; station.Sword += this.Sword; station.Axe += this.Axe; station.Scout += this.Scout; station.LightCavalry += this.LightCavalry; station.HeavyCavalry += this.HeavyCavalry; station.Ram += this.Ram; station.Catapult += this.Catapult; station.Noble += this.Noble; this.ToVillage.VillageTroopData.SpearInVillage += this.Spear; this.ToVillage.VillageTroopData.SwordInVillage += this.Sword; this.ToVillage.VillageTroopData.AxeInVillage += this.Axe; this.ToVillage.VillageTroopData.LightCavalryInVillage += this.LightCavalry; this.ToVillage.VillageTroopData.HeavyCavalryInVillage += this.HeavyCavalry; this.ToVillage.VillageTroopData.ScoutInVillage += this.Scout; this.ToVillage.VillageTroopData.RamInVillage += this.Ram; this.ToVillage.VillageTroopData.CatapultInVillage += this.Catapult; this.ToVillage.VillageTroopData.NobleInVillage += this.Noble; session.Update(station); } SupportReport supportReport = new SupportReport(); supportReport.Owner = this.ToVillage.Player; supportReport.Time = this.LandingTime; supportReport.Title = this.FromVillage.Player + " gửi quân hỗ trợ " + this.ToVillage.Name + "(" + this.ToVillage.X.ToString("000") + "|" + this.ToVillage.Y.ToString("000") + ")"; supportReport.FromVillage = this.FromVillage; supportReport.ToVillage = this.ToVillage; supportReport.Spear = this.Spear; supportReport.Sword = this.Sword; supportReport.Axe = this.Axe; supportReport.Scout = this.Scout; supportReport.LightCavalry = this.LightCavalry; supportReport.HeavyCavalry = this.HeavyCavalry; supportReport.Ram = this.Ram; supportReport.Catapult = this.Catapult; supportReport.Noble = this.Noble; supportReport.FromPlayer = this.FromVillage.Player; supportReport.ToPlayer = this.ToVillage.Player; session.Save(supportReport); supportReport.Owner = this.FromVillage.Player; session.Save(supportReport); session.Delete(this); this.ToVillage.MovingCommandsToMe.Remove(this); this.FromVillage.MovingCommandsFromMe.Remove(this); session.Delete(this); session.Update(this.ToVillage); session.Update(this.FromVillage); return null; }