示例#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);
        }
示例#2
0
文件: Place.cs 项目: Ivony/HelloWorld
        internal void SetActing(PlaceActing acting)
        {
            if (Acting != null && acting != null)
            {
                throw new InvalidOperationException();
            }

            Acting = acting;
            SaveActing();
        }
示例#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));
        }
示例#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);
        }
示例#5
0
文件: Place.cs 项目: Ivony/HelloWorld
        /// <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();
        }
示例#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;
        }
示例#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;
        }
示例#8
0
 /// <summary>
 /// 检查活动是否已经完成
 /// </summary>
 /// <param name="acting">正在进行的活动对象</param>
 /// <returns>是否已经完成</returns>
 public abstract bool TryComplete( PlaceActing acting, DateTime now );
示例#9
0
 /// <summary>
 /// 检查活动是否已经完成
 /// </summary>
 /// <param name="acting">正在进行的活动对象</param>
 /// <returns>是否已经完成</returns>
 public abstract bool TryComplete(PlaceActing acting, DateTime now);