Example #1
0
        /// <summary>
        /// 确认是否可以在指定地块开始这个活动
        /// </summary>
        /// <param name="place">地块对象</param>
        /// <returns>是否可以开展这个活动</returns>
        public override sealed bool CanStartAt( GamePlayer player, PlaceBase place )
        {
            var instance = place as Place;

              if ( instance == null )
            return false; ;

              return Constraint.IsSatisfy( player, place );
        }
Example #2
0
 /// <summary>
 /// 获取可以进行的操作列表
 /// </summary>
 /// <returns>可以进行的操作列表</returns>
 public abstract ActionDescriptor[] GetActions( GamePlayer player );
Example #3
0
        /// <summary>
        /// 获取指定玩家所有单位
        /// </summary>
        /// <param name="player">玩家对象</param>
        /// <returns></returns>
        public Unit[] GetUnits( GamePlayer player )
        {
            lock ( _unitSync )
              {

            HashSet<Unit> units;

            if ( _playerUnits.TryGetValue( player.Guid, out units ) )
            {
              var invalids = units.Where( item => item.Owner != player.Guid ).ToArray();//检查单位是否还属于这个玩家。
              foreach ( var item in invalids )
            units.Remove( item );

              return units.ToArray();
            }
            else
              return new Unit[0];

              }
        }
Example #4
0
        /// <summary>
        /// 尝试在指定地块开始这个活动 
        /// </summary>
        /// <param name="place">要开始活动的地方</param>
        /// <returns>正在进行的活动</returns>
        public override PlaceActing TryStartAt( GamePlayer player, PlaceBase place )
        {
            if ( player == null )
            throw new ArgumentNullException( "player" );

              if ( place == null )
            throw new ArgumentNullException( "place" );

              string errorMessage;
              if ( Constraint.IsSatisfy( player, place, out errorMessage ) == false )
            throw new InvalidOperationException( errorMessage );

              var instance = place as Place;
              if ( instance == null )
            return null;

              return TryStartAt( player, instance );
        }
Example #5
0
        /// <summary>
        /// 尝试在指定地块开始这个活动 
        /// </summary>
        /// <param name="place">要开始活动的地方</param>
        /// <returns>正在进行的活动</returns>
        protected virtual PlaceActing TryStartAt( GamePlayer player, Place place )
        {
            lock ( place )
              {
            if ( place.Acting != null )
              throw new InvalidOperationException( "土地上已经存在一个正在进行的活动" );

            if ( Requirement.TryInvest( place ) == false )
              return null;
              }

              return PlaceActing.StartAt( player, place, this );
        }
Example #6
0
 /// <summary>
 /// 尝试对指定地块进行投入来进行这个活动
 /// </summary>
 /// <param name="place">进行活动的地块</param>
 /// <returns>是否成功</returns>
 public abstract PlaceActing TryStartAt( GamePlayer player, PlaceBase place );
Example #7
0
        /// <summary>
        /// 在指定地块开始这个活动
        /// </summary>
        /// <param name="place">要开始活动的地块</param>
        internal static PlaceActing StartAt( GamePlayer player, Place place, ActionDescriptorBase action )
        {
            if ( place == null )
            throw new ArgumentNullException( "place" );

              var acting = new PlaceActing
              {
            StartOn = DateTime.UtcNow,
            ActionDescriptor = action,
            PlayerID = player.Guid,
            Place = place,
              };

              place.SetActing( acting );
              return acting;
        }
Example #8
0
        /// <summary>
        /// 检查指定地块当前是否满足限制。
        /// </summary>
        /// <param name="player">当前操作的玩家</param>
        /// <param name="place">要检查的地块</param>
        /// <returns>若不满足限制,返回原因,若满足限制,则返回null</returns>
        protected virtual string Check( GamePlayer player, Place place )
        {
            if ( player == null )
            throw new ArgumentNullException( "player" );

              if ( place == null )
            throw new ArgumentNullException( "place" );

              if ( InTerritory && place.Owner == player.Guid )
            return "只能在自己的领土上上开展该活动";

              if ( TerrainType != null )
              {
            if ( place.Terrain == null || TerrainType.IsAssignableFrom( place.Terrain.GetType() ) == false )
              return "地形不满足活动需求";
              }

              if ( TerrainDescriptors.Any() )
              {
            if ( place.Terrain == null || TerrainDescriptors.Contains( place.Terrain.Descriptor.Guid ) == false )
              return "地形不满足活动需求";
              }

              if ( BuildingType != null )
              {
            if ( place.Terrain == null || BuildingType.IsAssignableFrom( place.Building.GetType() ) == false )
              return "地形不满足活动需求";
              }

              if ( BuildingDescriptors.Any() )
              {
            if ( place.Terrain == null || BuildingDescriptors.Contains( place.Building.Descriptor.Guid ) == false )
              return "地形不满足活动需求";
              }

              if ( UnitType != null )
              {
            if ( place.GetUnits().All( unit => UnitType.IsAssignableFrom( unit.GetType() ) == false ) )
              return "单位不满足活动需求";
              }

              if ( UnitDescriptors.Any() )
              {
            if ( place.GetUnits().All( unit => UnitDescriptors.Contains( unit.Descriptor.Guid ) == false ) )
              return "单位不满足活动需求";
              }

              return null;
        }
Example #9
0
 /// <summary>
 /// 确认是否可以在指定地块开展活动
 /// </summary>
 /// <param name="place">要开展活动的地块</param>
 /// <returns>是否可以开展活动</returns>
 public abstract bool CanStartAt( GamePlayer player, PlaceBase place );
Example #10
0
        /// <summary>
        /// 检查指定地块当前是否满足限制。
        /// </summary>
        /// <param name="player">当前操作的玩家</param>
        /// <param name="place">要检查的地块</param>
        /// <returns>若不满足限制,返回原因,若满足限制,则返回null</returns>
        protected virtual string Check( GamePlayer player, PlaceBase place )
        {
            var placeInstance = place as Place;
              if ( placeInstance != null )
            return Check( player, placeInstance );

              else
            return null;//默认允许通过
        }
Example #11
0
 /// <summary>
 /// 检查指定地块当前是否满足限制。
 /// </summary>
 /// <param name="player">当前操作的玩家</param>
 /// <param name="place">要检查的地块</param>
 /// <param name="errorMessage">错误信息</param>
 /// <returns>是否满足限制</returns>
 public virtual bool IsSatisfy( GamePlayer player, PlaceBase place, out string errorMessage )
 {
     errorMessage = Check( player, place );
       return errorMessage == null;
 }
Example #12
0
 /// <summary>
 /// 检查指定地块当前是否满足限制。
 /// </summary>
 /// <param name="player">当前操作的玩家</param>
 /// <param name="place">要检查的地块</param>
 /// <returns>是否满足限制</returns>
 public virtual bool IsSatisfy( GamePlayer player, PlaceBase place )
 {
     return Check( player, place ) == null;
 }
Example #13
0
 /// <summary>
 /// 尝试对指定地块进行投入来进行这个活动
 /// </summary>
 /// <param name="place">进行活动的地块</param>
 /// <returns>是否成功</returns>
 public abstract PlaceActing TryStartAt(GamePlayer player, PlaceBase place);
Example #14
0
 /// <summary>
 /// 确认是否可以在指定地块开展活动
 /// </summary>
 /// <param name="place">要开展活动的地块</param>
 /// <returns>是否可以开展活动</returns>
 public abstract bool CanStartAt(GamePlayer player, PlaceBase place);