private void RunUpdate() { if (this.IsDead()) { return; } this.RefreshLightExposure(); float single = this.Happiness(); this.realAge += this.thinkDeltaTime; this.stageAge = this.stageAge + this.growDeltaTime * Mathf.Max(single, 0f); this.growthAge = this.growthAge + this.growDeltaTime * Mathf.Max(single, 0f); this.growthAge = Mathf.Clamp(this.growthAge, 0f, this.plantProperty.waterConsumptionLifetime * 60f); base.health = base.health + single * this.currentStage.health * this.growDeltaTime; if (base.health <= 0f) { this.Die(null); return; } if (this.stageAge > this.currentStage.lifeLength * 60f) { if (this.state == PlantProperties.State.Dying) { this.Die(null); return; } if (this.currentStage.nextState <= this.state) { this.seasons++; } if (this.seasons < this.plantProperty.maxSeasons) { this.BecomeState(this.currentStage.nextState, true); } else { this.BecomeState(PlantProperties.State.Dying, true); } } if (!this.PlacedInPlanter() || this.consumedWater >= this.plantProperty.lifetimeWaterConsumption || this.state >= PlantProperties.State.Fruiting) { this.water = this.plantProperty.maxHeldWater; } else { float single1 = this.thinkDeltaTime / (this.plantProperty.waterConsumptionLifetime * 60f) * (float)this.plantProperty.lifetimeWaterConsumption; int num = Mathf.CeilToInt(Mathf.Min((float)this.water, single1)); this.water -= num; this.consumedWater += num; PlanterBox parentEntity = base.GetParentEntity() as PlanterBox; if (parentEntity && parentEntity.soilSaturationFraction > 0f) { int num1 = this.plantProperty.maxHeldWater - this.water; int num2 = parentEntity.UseWater(Mathf.Min(Mathf.CeilToInt(single1 * 10f), num1)); this.water += num2; } } this.water = Mathf.Clamp(this.water, 0, this.plantProperty.maxHeldWater); base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
void GeneratePlanterBox(int numberOfTiles) { // Create seperate platform for them int plantIndex; if (gameManager.ShouldCreateNextPlantBox(out plantIndex)) { var level = currentLevel + Random.Range(3, 4); var xPos = Random.Range(0, numberOfTiles) + generatorManager.LastBlockX; GameObject nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos, level - 1, 0); nextBlock.SetActive(true); var newBox = PlanterBox.GetPlanterObject(plantingBox); newBox.SetIndex(plantIndex); newBox.transform.position = new Vector3(xPos + 1, level, 0); newBox.gameObject.SetActive(true); nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos + 2, level - 1, 0); nextBlock.SetActive(true); nextBlock = RunnerObject.GetRunnerObject(block.gameObject); nextBlock.transform.position = new Vector3(xPos + 1, level - 1, 0); nextBlock.SetActive(true); } }
public override void OnParentChanging(BaseEntity oldParent, BaseEntity newParent) { base.OnParentChanging(oldParent, newParent); planter = newParent as PlanterBox; if (!Rust.Application.isLoadingSave && planter != null) { planter.FertilizeGrowables(); } CalculateQualities(true); }
public static PlanterBox GetPlanterObject(PlanterBox source) { PlanterBox result = null; if (!Pool.TryGet(ref result)) { result = Instantiate(source); } return(result); }
public PlanterBox GetPlanter() { if (planter == null) { BaseEntity baseEntity = GetParentEntity(); if (baseEntity != null) { planter = baseEntity as PlanterBox; } } return(planter); }
public void RefreshGrowables() { List <GrowableEntity> obj = Facepunch.Pool.GetList <GrowableEntity>(); Vis.Entities(base.transform.position + new Vector3(0f, 0f - ConVar.Server.ceilingLightHeightOffset, 0f), ConVar.Server.ceilingLightGrowableRange, obj, 512); List <PlanterBox> obj2 = Facepunch.Pool.GetList <PlanterBox>(); foreach (GrowableEntity item in obj) { if (item.isServer) { PlanterBox planter = item.GetPlanter(); if (planter != null && !obj2.Contains(planter)) { obj2.Add(planter); planter.ForceLightUpdate(); } item.CalculateQualities(false, true); item.SendNetworkUpdate(); } } Facepunch.Pool.FreeList(ref obj2); Facepunch.Pool.FreeList(ref obj); }
public void ForceUpdateGrowablesInRange() { List <GrowableEntity> obj = Facepunch.Pool.GetList <GrowableEntity>(); Vis.Entities(base.transform.position, Server.artificialTemperatureGrowableRange, obj, 512); List <PlanterBox> obj2 = Facepunch.Pool.GetList <PlanterBox>(); foreach (GrowableEntity item in obj) { if (item.isServer) { PlanterBox planter = item.GetPlanter(); if (planter != null && !obj2.Contains(planter)) { obj2.Add(planter); planter.ForceTemperatureUpdate(); } item.CalculateQualities(false, false, true); item.SendNetworkUpdate(); } } Facepunch.Pool.FreeList(ref obj2); Facepunch.Pool.FreeList(ref obj); }
private static GeneWeighting GetDominantGeneWeighting(GrowableEntity crossBreedingGrowable, List <GrowableEntity> neighbours, int slot) { PlanterBox planter = crossBreedingGrowable.GetPlanter(); if (planter == null) { dominant.Weighting = -1f; return(dominant); } for (int i = 0; i < neighbourWeights.Length; i++) { neighbourWeights[i].Weighting = 0f; neighbourWeights[i].GeneType = (GeneType)i; } dominant.Weighting = 0f; foreach (GrowableEntity neighbour in neighbours) { if (!neighbour.isServer) { continue; } PlanterBox planter2 = neighbour.GetPlanter(); if (!(planter2 == null) && !(planter2 != planter) && !(neighbour == crossBreedingGrowable) && neighbour.prefabID == crossBreedingGrowable.prefabID && !neighbour.IsDead()) { GeneType type = neighbour.Genes.Genes[slot].Type; float crossBreedingWeight = neighbour.Properties.Genes.Weights[(int)type].CrossBreedingWeight; float num = (neighbourWeights[(int)type].Weighting += crossBreedingWeight); if (num > dominant.Weighting) { dominant.Weighting = num; dominant.GeneType = type; } } } return(dominant); }
private void RunUpdate() { if (this.IsDead()) { return; } this.RefreshLightExposure(); float num1 = this.Happiness(); this.realAge += this.thinkDeltaTime; this.stageAge += this.growDeltaTime * Mathf.Max(num1, 0.0f); this.growthAge += this.growDeltaTime * Mathf.Max(num1, 0.0f); this.growthAge = Mathf.Clamp(this.growthAge, 0.0f, this.plantProperty.waterConsumptionLifetime * 60f); this.health += num1 * this.currentStage.health * this.growDeltaTime; if ((double)this.health <= 0.0) { this.Die((HitInfo)null); } else { if ((double)this.stageAge > (double)this.currentStage.lifeLength * 60.0) { if (this.state == PlantProperties.State.Dying) { this.Die((HitInfo)null); return; } if (this.currentStage.nextState <= this.state) { ++this.seasons; } if (this.seasons >= this.plantProperty.maxSeasons) { this.BecomeState(PlantProperties.State.Dying, true); } else { this.BecomeState(this.currentStage.nextState, true); } } if (this.PlacedInPlanter() && this.consumedWater < this.plantProperty.lifetimeWaterConsumption && this.state < PlantProperties.State.Fruiting) { float num2 = this.thinkDeltaTime / (this.plantProperty.waterConsumptionLifetime * 60f) * (float)this.plantProperty.lifetimeWaterConsumption; int num3 = Mathf.CeilToInt(Mathf.Min((float)this.water, num2)); this.water -= num3; this.consumedWater += num3; PlanterBox parentEntity = this.GetParentEntity() as PlanterBox; if (Object.op_Implicit((Object)parentEntity) && (double)parentEntity.soilSaturationFraction > 0.0) { int num4 = this.plantProperty.maxHeldWater - this.water; this.water += parentEntity.UseWater(Mathf.Min(Mathf.CeilToInt(num2 * 10f), num4)); } } else { this.water = this.plantProperty.maxHeldWater; } this.water = Mathf.Clamp(this.water, 0, this.plantProperty.maxHeldWater); this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } }
public void drawInMenu(PlanterBox p, SpriteBatch b, Vector2 screenPosition, Color toTint, float rotation, float scale, float layerDepth) { b.Draw(this.spriteSheet.texture, new Vector2(screenPosition.X, screenPosition.Y - (Game1.tileSize / 2)), new Rectangle?(getSourceRect(this.rowInSpriteSheet)), Color.White, 0f, new Vector2((float)(p.defaultSourceRect.Width / 2), (float)(p.defaultSourceRect.Height / 2)), 1f * (2) * scale, SpriteEffects.None, layerDepth); }
public void drawWhenPlanterBoxHeld(PlanterBox p, SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) { spriteBatch.Draw(this.spriteSheet.texture, Game1.GlobalToLocal(Game1.viewport, new Vector2(Game1.player.GetBoundingBox().Center.X - Game1.tileSize / 2, (Game1.player.GetBoundingBox().Center.Y - Game1.tileSize * 4 / 3) - (Game1.tileSize * 2))), this.getSourceRect(this.rowInSpriteSheet), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(p.boundingBox.Bottom + 1) / 10000f); }
public void SetPlant(PlanterBox box, Plant plant) { this.plant = plant; this.box = box; }