public ViewModelFarmPlantTooltip(IStaticWorldObject objectPlant, PlantPublicState publicState)
        {
            this.objectPlant = objectPlant;
            this.protoPlant  = (IProtoObjectPlant)objectPlant.ProtoStaticWorldObject;
            this.publicState = publicState;

            this.HarvestsCountMax = this.protoPlant.NumberOfHarvests;

            publicState.ClientSubscribe(
                _ => _.HasHarvest,
                _ => this.RefreshDataFromServer(),
                this);

            publicState.ClientSubscribe(
                _ => _.IsWatered,
                isWatered =>
            {
                if (isWatered)
                {
                    this.wateringEndsTime = double.MaxValue;
                    this.UpdateDisplayedTimeNoTimer();
                }

                this.UpdateWatered();
                this.RefreshDataFromServer();
            },
                this);

            this.RefreshDataFromServer();
            this.UpdateWatered();
        }
Example #2
0
        public static bool ServerIsWateringRequired(
            IWorldObject objectPlant,
            ICharacter character,
            IProtoItem protoItem,
            IProtoObjectPlant protoPlant,
            double proposedWateringDuration)
        {
            var plantPrivateState = objectPlant.GetPrivateState <PlantPrivateState>();

            if (plantPrivateState.ServerTimeWateringEnds >= double.MaxValue ||
                (proposedWateringDuration < double.MaxValue &&
                 (plantPrivateState.ServerTimeWateringEnds
                  >= Server.Game.FrameTime + proposedWateringDuration - 60)))
            {
                // the plant is already watered enough
                Instance.CallClient(character, _ => _.ClientRemote_CannotWaterAlreadyWatered(protoItem));
                return(false);
            }

            if (!protoPlant.ServerCanBeWatered((IStaticWorldObject)objectPlant))
            {
                // no need to water the plant
                Instance.CallClient(character, _ => _.ClientRemote_CannotWaterLastHarvestOrRotten(protoItem));
                return(false);
            }

            return(true);
        }
Example #3
0
 public ProtoObjectPlantViewModel([NotNull] IProtoObjectPlant plant) : base(plant)
 {
 }