Ejemplo n.º 1
0
 /// <summary>
 /// 在指定的地块尝试进行投入
 /// </summary>
 /// <param name="place">要进行投入的地块</param>
 /// <returns>是否成功扣除所需物品</returns>
 public bool TryInvest( Place place )
 {
     lock ( place.SyncRoot )
       {
     return place.GetPlayer().Resources.RemoveItems( Items );
       }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 从 JSON 数据中读取
        /// </summary>
        /// <param name="place">活动所处地块</param>
        /// <param name="data">活动数据</param>
        /// <returns>活动对象</returns>
        public static PlaceActing FromData( Place place, JObject data )
        {
            if ( place == null )
            throw new ArgumentNullException( "place" );

              if ( data == null )
            return null;

              var startOn = data.Value<DateTime>( "StartOn" );
              var playerId = data.GuidValue( "PlayerID" );
              var action = GameHost.GameRules.GetDataItem<ActionDescriptorBase>( data.GuidValue( "ActionDescriptor" ) );

              if ( action == null )
            return null;

              return new PlaceActing
              {
            PlayerID = playerId,
            Place = place,
            StartOn = startOn,
            ActionDescriptor = action,
              };
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 保存游戏地块对象
 /// </summary>
 /// <param name="place"></param>
 private void Save( Place place )
 {
     var filepath = Path.Combine( placesDirectory, place.Coordinate + ".json" );
       File.WriteAllText( filepath, place.SaveAsJson() );
 }
Ejemplo n.º 4
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 );
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 获取移动到指定位置所需要的移动力
 /// </summary>
 /// <param name="place">抵达位置</param>
 /// <returns>所需移动力</returns>
 public virtual decimal MobilityRequired( Place place )
 {
     return 1;
 }