Example #1
0
    public void Spread(bool buffer = false)
    {
        GrowingPlant parentPlant = this.gameObject.GetComponent <GrowingPlant>();

        occupiedBlock = parentPlant.getOBlock();
        occupiedBlock.GetComponent <BoxCollider2D>().enabled = false;
        Block bUp    = checkCollision(Vector2.up, (gm.BlockHeight / 1.99f) + gm.BorderHeight);
        Block bRight = checkCollision(Vector2.right, (gm.BlockWidth / 1.99f) + gm.BorderWidth);
        Block bDown  = checkCollision(Vector2.down, (gm.BlockHeight / 1.99f) + gm.BorderHeight);
        Block bLeft  = checkCollision(Vector2.left, (gm.BlockWidth / 1.99f) + gm.BorderWidth);

        if (bUp != null)
        {
            bUp.Place(oPool.ID, false, parentPlant.uniqueID, buffer);
            bUp.content = true;
        }
        if (bRight != null)
        {
            bRight.Place(oPool.ID, false, parentPlant.uniqueID, buffer);
            bRight.content = true;
        }
        if (bDown != null)
        {
            bDown.Place(oPool.ID, false, parentPlant.uniqueID, buffer);
            bDown.content = true;
        }
        if (bLeft != null)
        {
            bLeft.Place(oPool.ID, false, parentPlant.uniqueID, buffer);
            bLeft.content = true;
        }
        occupiedBlock.GetComponent <BoxCollider2D>().enabled = true;
    }
Example #2
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            int growingPlantID = target.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                user.SendMessage("Water jugs can only target growing plants.");
                return;
            }
            GrowingPlant growingPlant = _db.GrowingPlants.Single(x => x.GrowingPlantID == growingPlantID);

            if (growingPlant.WaterStatus <= 0)
            {
                user.SendMessage("That plant doesn't need to be watered at this time.");
                return;
            }

            if (item.Charges <= 0)
            {
                user.SendMessage("There's no water in that jug!");
                return;
            }

            PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == user.GlobalID);

            // Farmers get a 5% chance to not expend a charge.
            if (pcEntity.BackgroundID != (int)BackgroundType.Farmer || _random.Random(100) + 1 > 5)
            {
                item.Charges--;
            }

            int remainingTicks = growingPlant.RemainingTicks;

            if (growingPlant.WaterStatus > 1)
            {
                remainingTicks = remainingTicks / 2;
            }

            growingPlant.WaterStatus    = 0;
            growingPlant.RemainingTicks = remainingTicks;
            _db.SaveChanges();

            user.SendMessage("You water the plant.");

            PCSkill pcSkill = _skill.GetPCSkill((NWPlayer)user, SkillType.Farming);

            if (pcSkill == null)
            {
                return;
            }

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(100, growingPlant.Plant.Level, pcSkill.Rank);

            _skill.GiveSkillXP((NWPlayer)user, SkillType.Farming, xp);
        }
Example #3
0
 public static void Postfix(GrowingPlant __instance, ref float __result)
 {
     if (Config.FARMING_VERY_SLOW.Equals(DeathRun.config.farmingChallenge))
     {
         __result *= 6;
     }
     else if (Config.FARMING_SLOW.Equals(DeathRun.config.farmingChallenge))
     {
         __result *= 3;
     }
 }
        public void RemoveGrowingPlant(NWPlaceable plant)
        {
            int growingPlantID = plant.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                return;
            }

            GrowingPlant growingPlant = _db.GrowingPlants.Single(x => x.GrowingPlantID == growingPlantID);

            growingPlant.IsActive = false;
            _db.SaveChanges();
        }
Example #5
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            string growingPlantID = target.GetLocalString("GROWING_PLANT_ID");

            if (string.IsNullOrWhiteSpace(growingPlantID))
            {
                user.SendMessage("Water jugs can only target growing plants.");
                return;
            }
            GrowingPlant growingPlant = DataService.Single <GrowingPlant>(x => x.ID == new Guid(growingPlantID));
            var          plant        = DataService.Get <Plant>(growingPlant.PlantID);

            if (growingPlant.WaterStatus <= 0)
            {
                user.SendMessage("That plant doesn't need to be watered at this time.");
                return;
            }

            if (item.Charges <= 0)
            {
                user.SendMessage("There's no water in that jug!");
                return;
            }

            int remainingTicks = growingPlant.RemainingTicks;

            if (growingPlant.WaterStatus > 1)
            {
                remainingTicks = remainingTicks / 2;
            }

            growingPlant.WaterStatus    = 0;
            growingPlant.RemainingTicks = remainingTicks;
            DataService.SubmitDataChange(growingPlant, DatabaseActionType.Update);

            user.SendMessage("You water the plant.");

            int rank = SkillService.GetPCSkillRank((NWPlayer)user, SkillType.Farming);

            int xp = (int)SkillService.CalculateRegisteredSkillLevelAdjustedXP(100, plant.Level, rank);

            SkillService.GiveSkillXP((NWPlayer)user, SkillType.Farming, xp);
        }
        public void HarvestPlant(NWPlayer player, NWItem shovel, NWPlaceable plant)
        {
            int growingPlantID = plant.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                return;
            }

            int charges = shovel.Charges;

            if (charges <= 0)
            {
                player.SendMessage("Your shovel is broken.");
                return;
            }

            GrowingPlant growingPlant = _db.GrowingPlants.Single(x => x.GrowingPlantID == growingPlantID);
            Plant        plantEntity  = growingPlant.Plant;

            if (string.IsNullOrWhiteSpace(plantEntity.SeedResref))
            {
                player.SendMessage("That plant cannot be harvested.");
                return;
            }

            PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == player.GlobalID);

            // Farmers get a 5% chance to not expend a charge.
            if (pcEntity.BackgroundID != (int)BackgroundType.Farmer || _random.Random(100) + 1 > 5)
            {
                shovel.ReduceCharges();
            }

            growingPlant.IsActive = false;
            _db.SaveChanges();

            _.CreateItemOnObject(plantEntity.SeedResref, player.Object);
            plant.Destroy();

            player.FloatingText("You harvest the plant.");
        }
Example #7
0
 private void OnEnable()
 {
     if (plantIDs == null)
     {
         plantIDs = new List <int>();
     }
     if (plant == null)
     {
         if (GetComponent <GrowingPlant>() != null)
         {
             plant = GetComponent <GrowingPlant>();
         }
         if (GetComponent <SpriteRenderer>() != null)
         {
             plantSprite = GetComponent <SpriteRenderer>();
         }
     }
     UpdateHandler.UpdateOccurred += UpdateStatus;
     //ItemDragHandler.OnClicked += UpdateStatus;
 }
Example #8
0
        public static void RemoveGrowingPlant(NWPlaceable plant)
        {
            string growingPlantID   = plant.GetLocalString("GROWING_PLANT_ID");
            Guid?  growingPlantGuid = null;

            if (!string.IsNullOrWhiteSpace(growingPlantID))
            {
                growingPlantGuid = new Guid(growingPlantID);
            }

            if (growingPlantGuid == null)
            {
                return;
            }

            GrowingPlant growingPlant = DataService.Single <GrowingPlant>(x => x.ID == growingPlantGuid);

            growingPlant.IsActive = false;
            DataService.SubmitDataChange(growingPlant, DatabaseActionType.Update);
        }
        public override void process(GameObject item, ItemData itemData)
        {
            PlantableItemData plantableData = itemData as PlantableItemData;

            if (plantableData == null)
            {
                // nothing to do; false alarm
                return;
            }
            Plantable plant = item.GetComponent <Plantable>();

            if (plant == null)
            {
                Log.Error($"FixPlantGrowth: Item for Plantable {plantableData.ItemId} is not a Plantable!");
                return;
            }

            GrowingPlant grower = GetGrowingPlant(plant);

            if (grower == null)
            {
                Log.Error($"FixPlantGrowth: Could not find GrowingPlant for Plantable {plantableData.ItemId}!");
                return;
            }


            // time in seconds
            double elapsedGrowthTime = (DayNightCycle.main.timePassedAsDouble - plantableData.PlantedGameTime);

            if (elapsedGrowthTime > grower.growthDuration)
            {
                // should be ready
                Log.Debug($"FixPlantGrowth: Finishing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds");
                grower.SetProgress(1.0f);
            }
            else
            {
                Log.Debug($"FixPlantGrowth: Growing {item.name} {plantableData.ItemId} that has grown for {elapsedGrowthTime} seconds");
                grower.SetProgress(Convert.ToSingle(elapsedGrowthTime / grower.growthDuration));
            }
        }
Example #10
0
        public static void HarvestPlant(NWPlayer player, NWItem shovel, NWPlaceable plant)
        {
            string growingPlantID   = plant.GetLocalString("GROWING_PLANT_ID");
            Guid?  growingPlantGuid = null;

            if (!string.IsNullOrWhiteSpace(growingPlantID))
            {
                growingPlantGuid = new Guid(growingPlantID);
            }

            if (growingPlantGuid == null)
            {
                return;
            }

            int charges = shovel.Charges;

            if (charges <= 0)
            {
                player.SendMessage("Your shovel is broken.");
                return;
            }

            GrowingPlant growingPlant = DataService.Single <GrowingPlant>(x => x.ID == growingPlantGuid);
            Plant        plantEntity  = DataService.Get <Plant>(growingPlant.PlantID);

            if (string.IsNullOrWhiteSpace(plantEntity.SeedResref))
            {
                player.SendMessage("That plant cannot be harvested.");
                return;
            }

            growingPlant.IsActive = false;
            DataService.SubmitDataChange(growingPlant, DatabaseActionType.Update);

            _.CreateItemOnObject(plantEntity.SeedResref, player.Object);
            plant.Destroy();

            player.FloatingText("You harvest the plant.");
        }
        public static void Postfix(GrowingPlant __instance, Transform tr, float progress)
        {
            if (Math.Abs(progress - 1f) > 0.01f || tr == __instance.growingTransform ||
                __instance.seed?.currentPlanter?.transform is null || __instance.seed?.currentPlanter?.transform?.localScale.y >= 0 || tr?.localScale.y < 0)
            {
                return;
            }

            var localScale = tr.localScale;

            localScale    = new Vector3(localScale.x, localScale.y * -1, localScale.z);
            tr.localScale = localScale;

            if (__instance.passYbounds != null)
            {
                __instance.passYbounds.UpdateWavingScale(tr.localScale);
            }
            else if (__instance.wavingScaler != null)
            {
                __instance.wavingScaler.UpdateWavingScale(tr.localScale);
            }
        }
Example #12
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        // If the player experiences a huge force from above, this kills them.
        Rigidbody2D rb = collision.gameObject.GetComponent <Rigidbody2D>();

        if (rb && -rb.velocity.y * rb.mass >= crushThreshold)
        {
            GetComponent <AudioSource>().clip = crushSound;
            Die();
        }

        Interactable interactable = collision.GetComponent <Interactable>();

        // Show interactable object indicator
        if (interactable != null)
        {
            indicator.SetActive(true);
            interactableScript = interactable;
        }

        plantScript = collision.GetComponent <GrowingPlant>();
    }
Example #13
0
    public static void AddSpreadingPlant(GrowingPlant plant, int UniqueID)
    {
        for (int l = listSpreadingTotal.Count - 1; l >= 0; l--)
        {
            if (listSpreadingTotal[l].Count == 0)
            {
                listSpreadingTotal[l].Add(plant);
                listSpreading[l].Add(plant);
                return;
            }
            else if (listSpreadingTotal[l][0].uniqueID == UniqueID)
            {
                listSpreadingTotal[l].Add(plant);
                listSpreading[l].Add(plant);
                return;
            }
        }

        listSpreadingTotal.Add(new List <GrowingPlant>());
        listSpreadingTotal[listSpreadingTotal.Count - 1].Add(plant);
        listSpreading.Add(new List <GrowingPlant>());
        listSpreading[listSpreading.Count - 1].Add(plant);
    }
Example #14
0
    /**
     * Identifies objects that are in the light
     */
    void CheckHit(RaycastHit2D hit)
    {
        Transform target = hit.transform;

        if (hitsChecked.Contains(target.gameObject))
        {
            return;                                          //don't check the same object twice in one frame
        }
        if (isActiveAndEnabled)
        {
            hitsChecked.Add(target.gameObject);
            visibleTargets.Add(target);

            //IMPORTANT: Put code here to get objects to do something when in the light
            Mirror mirror = target.GetComponent <Mirror>();
            if (mirror && mirror.gameObject != this.gameObject) //prevents mirrors from keeping themselves active
            {
                mirror.Activate(this);                          //turns mirror light on
            }
            GrowingPlant vine = target.GetComponent <GrowingPlant>();
            if (vine)
            {
                vine.Grow();
            }

            ShadowPlayerObject shadowPlayer = target.GetComponent <ShadowPlayerObject>();
            if (shadowPlayer)
            {
                shadowPlayer.Die(); //game over
            }
            PlayerController player = target.GetComponent <PlayerController>();
            if (player && player.lightOrShadow == PlayerController.PlayerType.Shadow)
            {
                player.Die(); //game over
            }
        }
    }
 private void Start()
 {
     parentPlant = GetComponentInParent <GrowingPlant>();
     theSR       = GetComponent <SpriteRenderer>();
     startColor  = theSR.color;
 }