Exemple #1
0
        /// <summary>
        /// 检查活动是否已经完成,若已经完成则获取相应的收益
        /// </summary>
        /// <param name="acting">正在进行的活动</param>
        /// <returns>活动是否已经完成</returns>
        public override bool TryComplete(PlaceActing acting, DateTime now)
        {
            var completedOn = acting.StartOn + Requirement.Time;

            if (completedOn > now)
            {
                return(false);
            }

            var place  = acting.Place;
            var player = acting.GetPlayer();


            if (Returns.Items != null && player != null)
            {
                player.Resources.AddItems(Returns.Items);
            }

            if (Returns.Building != null)
            {
                place.SetBuilding(Returns.Building.Guid);
            }


            place.CheckPoint = completedOn;

            if (player != null)
            {
                var message = new GameMessageEntry(completedOn, string.Format("通过不懈的努力,在位置 {0} 的活动 {1} 已经完成 {2}", place.Coordinate.ToRelative(player), Name, Returns.DescriptiveMessage));
                GameHost.MessageService.AddMessage(player.Guid, message);
            }
            return(true);
        }
Exemple #2
0
        internal void SetActing(PlaceActing acting)
        {
            if (Acting != null && acting != null)
            {
                throw new InvalidOperationException();
            }

            Acting = acting;
            SaveActing();
        }
Exemple #3
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));
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// 初始化 Place 对象
        /// </summary>
        protected override void Initialize()
        {
            {
                var items = ItemListJsonConverter.FromJson((JObject)DataObject.Resources);
                Resources = new ItemCollection(items, collection =>
                {
                    DataObject.Resources = ItemListJsonConverter.ToJson(collection);
                });
            }


            Acting = PlaceActing.FromData(this, (JObject)DataObject.Acting);


            Terrain       = InitializeImmovableInstance <Terrain>((JsonDataObject)DataObject.Terrain);
            TraficNetwork = InitializeImmovableInstance <TraficNetwork>((JsonDataObject)DataObject.TraficNetwork);
            Building      = InitializeImmovableInstance <Building>((JsonDataObject)DataObject.Building);



            base.Initialize();
        }
Exemple #6
0
        /// <summary>
        /// 检查活动是否已经完成,若已经完成则获取相应的收益
        /// </summary>
        /// <param name="acting">正在进行的活动</param>
        /// <returns>活动是否已经完成</returns>
        public override bool TryComplete( PlaceActing acting, DateTime now )
        {
            var completedOn = acting.StartOn + Requirement.Time;

              if ( completedOn > now )
            return false;

              var place = acting.Place;
              var player = acting.GetPlayer();

              if ( Returns.Items != null && player != null )
            player.Resources.AddItems( Returns.Items );

              if ( Returns.Building != null )
            place.SetBuilding( Returns.Building.Guid );

              place.CheckPoint = completedOn;

              if ( player != null )
              {
            var message = new GameMessageEntry( completedOn, string.Format( "通过不懈的努力,在位置 {0} 的活动 {1} 已经完成 {2}", place.Coordinate.ToRelative( player ), Name, Returns.DescriptiveMessage ) );
            GameHost.MessageService.AddMessage( player.Guid, message );
              }
              return true;
        }
Exemple #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;
        }
 /// <summary>
 /// 检查活动是否已经完成
 /// </summary>
 /// <param name="acting">正在进行的活动对象</param>
 /// <returns>是否已经完成</returns>
 public abstract bool TryComplete( PlaceActing acting, DateTime now );
 /// <summary>
 /// 检查活动是否已经完成
 /// </summary>
 /// <param name="acting">正在进行的活动对象</param>
 /// <returns>是否已经完成</returns>
 public abstract bool TryComplete(PlaceActing acting, DateTime now);