Exemple #1
0
    private bool TryDamageStump(INetObject damager, float amount, InteractionContext context)
    {
        if (this.Fallen && this.stumpHealth > 0)
        {
            this.stumpHealth = Mathf.Max(0, this.stumpHealth - amount);

            if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(StumpCleanerSkill), 1))
            {
                this.stumpHealth = 0;
            }

            if (this.stumpHealth <= 0)
            {
                if (World.GetBlock(this.Position.Round).GetType() == this.Species.BlockType)
                {
                    World.DeleteBlock(this.Position.Round);
                }
                this.stumpHealth = 0;
                this.RPC("DestroyStump");

                // Let another plant grow here
                EcoSim.PlantSim.UpRootPlant(this);
            }

            this.Save();
            this.CheckDestroy();
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #2
0
 public override InteractResult OnActLeft(InteractionContext context)
 {
     if (context.HasBlock && context.Block.Is <Minable>())
     {
         Result result = this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 1);
         if (result.Success)
         {
             if (RubbleObject.TrySpawnFromBlock(context.Block.GetType(), context.BlockPosition.Value))
             {
                 RubbleUtils.BreakBigRubble(context.BlockPosition.Value, 20 * SkillsUtil.GetSkillLevel(context.Player.User, typeof(StrongMiningSkill)));
                 context.Player.User.UserUI.OnCreateRubble.Invoke();
             }
         }
         return((InteractResult)result);
     }
     else if (context.Target is RubbleObject)
     {
         var rubble = (RubbleObject)context.Target;
         if (rubble.IsBreakable)
         {
             rubble.Breakup();
             BurnCalories(context.Player);
             return(InteractResult.Success);
         }
         else
         {
             return(InteractResult.NoOp);
         }
     }
     else
     {
         return(InteractResult.NoOp);
     }
 }
Exemple #3
0
 private bool ContextOnInterraction(InteractionContext context)
 {
     if (context.Method == InteractionMethod.Right)
     {
         if (context.SelectedItem is PickaxeItem)
         {
             if (context.HasBlock == false || context.Player.User.Inventory.Carried.IsEmpty)
             {
                 if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(MiningPickupAmountSkill), 1))
                 {
                     RubbleUtils.PickUpRubble(context.Player.User, 2 + (2 * SkillsUtil.GetSkillLevel(context.Player.User, typeof(MiningPickupRangeSkill))), (BetterMiningPlugin.ConfigStorage.GetInt("PickupRubbleBySkillLevel") * SkillsUtil.GetSkillLevel(context.Player.User, typeof(MiningPickupAmountSkill))));
                 }
             }
         }
     }
     else if (context.Method == InteractionMethod.Left)
     {
         if (context.SelectedItem is PickaxeItem && context.HasBlock && context.Block.Is <Minable>())
         {
             if (context.SelectedItem.OnActLeft(context).IsSuccess)
             {
                 RubbleUtils.BreakBigRubble(context.BlockPosition.Value, 20 * SkillsUtil.GetSkillLevel(context.Player.User, typeof(StrongMiningSkill)));
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #4
0
 public bool TryApplyDamage(INetObject damager, float amount, InteractionContext context)
 {
     // if the tree is really young, just outright uproot and destroy it.
     if (this.GrowthPercent < saplingGrowthPercent)
     {
         EcoSim.PlantSim.UpRootPlant(this);
         this.Destroy();
         return(false);
     }
     else if (context.Parameters == null)
     {
         return(this.TryDamageUnfelledTree(damager, amount, context));
     }
     else if (context.Parameters.ContainsKey("stump"))
     {
         return(this.TryDamageStump(damager, amount, context));
     }
     else if (context.Parameters.ContainsKey("branch"))
     {
         return(this.TryDamageBranch(damager, amount, context));
     }
     else if (context.Parameters.ContainsKey("slice"))
     {
         // trying to slice the tree
         // if there are still branches, damage them instead
         for (int branchID = 0; branchID < this.branches.Length; branchID++)
         {
             var branch = this.branches[branchID];
             if (this.TryDamageBranch(branch, branchID, amount))
             {
                 return(true);
             }
         }
         if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(ExpertLumbererSkill), 1))
         {
             bool test = false;
             for (int i = 1; i < 20; i++)
             {
                 if (this.TrySliceTrunk((Player)damager, 0.05f * (float)i))
                 {
                     test = true;
                 }
             }
             return(test);
         }
         else
         {
             return(this.TrySliceTrunk(context.Player, context.Parameters["slice"]));
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
        public override InteractResult OnActRight(InteractionContext context)
        {
            User user = context.Player.User;

            if (context.HasBlock == false || user.Inventory.Carried.IsEmpty)
            {
                if (SkillsUtil.HasSkillLevel(user, typeof(MiningPickupAmountSkill), 1))
                {
                    RubbleUtils.PickUpRubble(user, 2 + (2 * SkillsUtil.GetSkillLevel(user, typeof(MiningPickupRangeSkill))), (4 * SkillsUtil.GetSkillLevel(user, typeof(MiningPickupAmountSkill))));
                    return(InteractResult.Success);
                }
            }
            return(InteractResult.NoOp);
        }
 private bool ContextOnInterraction(InteractionContext context)
 {
     if (context.Method == InteractionMethod.Left)
     {
         if (context.SelectedItem is AxeItem)
         {
             if (context.HasBlock && context.Authed())
             {
                 var block = World.GetBlock(context.BlockPosition.Value);
                 if (block.Is <TreeDebris>())
                 {
                     foreach (Vector3i pos in WorldUtils.GetTopBlockPositionAroundPoint <TreeDebrisBlock>(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(WoodPulpCleanerSkill))))
                     {
                         if (context.Player.User.Inventory.TryAddItems <WoodPulpItem>(5))
                         {
                             World.DeleteBlock(pos);
                         }
                     }
                 }
             }
             if (context.HasTarget && context.Target is TreeEntity)
             {
                 TreeEntity tree = context.Target as TreeEntity;
                 if (context.Parameters != null && context.Parameters.ContainsKey("stump"))
                 {
                     if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(StumpCleanerSkill), 1))
                     {
                         tree.TryApplyDamage(context.Player, 500, context);
                     }
                 }
                 if (context.Parameters != null && context.Parameters.ContainsKey("slice"))
                 {
                     if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(ExpertLumbererSkill), 1))
                     {
                         TreeBranch[] branches = typeof(Tree).GetField("branches", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(tree) as TreeBranch[];
                         if (!branches.Where(branch => branch != null).Select(branch => branch.Health).Where(health => health != 0).Any())
                         {
                             for (int i = 1; i < 20; i++)
                             {
                                 typeof(TreeEntity).GetMethod("TrySliceTrunk", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(tree, new object[] { context.Player, 0.05f * (float)i });
                             }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
 private bool ContextOnInterraction(InteractionContext context)
 {
     if (context.Method == InteractionMethod.Right)
     {
         if (context.SelectedItem is ScytheItem && context.HasBlock)
         {
             if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(ScythePickupRangeSkill), 1))
             {
                 PlantUtils.GetReapableBlockAroundPoint(context, context.BlockPosition.Value, SkillsUtil.GetSkillLevel(context.Player.User, typeof(ScythePickupRangeSkill)));
             }
         }
         else if (context.SelectedItem is HoeItem && context.HasBlock)
         {
             if (SkillsUtil.HasSkillLevel(context.Player.User, typeof(HoePickupRangeSkill), 1))
             {
                 PlantUtils.GetPlantBlockAroundPoint(context, context.BlockPosition.Value, SkillsUtil.GetSkillLevel(context.Player.User, typeof(HoePickupRangeSkill)));
             }
         }
     }
     return(false);
 }
Exemple #8
0
 public override InteractResult OnActLeft(InteractionContext context)
 {
     if (context.HasBlock)
     {
         var block = World.GetBlock(context.BlockPosition.Value);
         if (block.Is <TreeDebris>())
         {
             InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
             changes.AddItems <WoodPulpItem>(5);
             TreeUtils.GetPulpAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(WoodPulpCleanerSkill)));
             return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
         }
         else
         {
             return(InteractResult.NoOp);
         }
     }
     else
     {
         return(base.OnActLeft(context));
     }
 }
Exemple #9
0
        public override InteractResult OnActRight(InteractionContext context)
        {
            if (context.HasBlock)
            {
                var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value);
                var block = World.GetBlock(context.BlockPosition.Value);
                if (plant != null && plant is IHarvestable)

                {
                    if (block is CornBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <CornItem>((4) + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <CornSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }



                    else if (block is TomatoesBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <TomatoItem>(4 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <TomatoSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }


                    else if (block is FireweedBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <FireweedShootsItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(TundraTravellerSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }


                    else if (block is WheatBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)

                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <WheatItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <WheatSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }


                    else if (block is BeansBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <BeansItem>(6 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }


                    else if (block is HuckleberryBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <HuckleberriesItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill)));
                            changes.AddItems <HuckleberrySeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                    else if (block is BeetsBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <BeetItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <BeetSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                    else if (block is RiceBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <RiceItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                    else if (block is KelpBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <KelpItem>(1);
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                    else if (block is PricklyPearBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <PricklyPearFruitItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <PricklyPearSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                    else if (block is FernBlock)
                    {
                        Result result = (plant as IHarvestable).TryHarvest(context.Player, true);
                        if (result.Success)
                        {
                            InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                            changes.AddItems <FiddleheadsItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            changes.AddItems <FernSporeItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill)));
                            PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill)));
                            return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes));
                        }
                        else
                        {
                            return(InteractResult.NoOp);
                        }
                    }
                }
                return(InteractResult.NoOp);
            }
            return(InteractResult.NoOp);
        }
Exemple #10
0
 public override void Tick()
 {
     base.Tick();
     if (this.crafting.BottleNecked == false && this.Parent.Operating && crafting.CurrentWorkOrder != null)
     {
         breakChance += JDElectricalPlugin.Conf.Get <float>("BrokenChanceOverTime") * WorldObjectManager.TickDeltaTime * speedTime;
         if (time + (60f / speedTime) < WorldObjectManager.TickStartTime)
         {
             time = (float)WorldObjectManager.TickStartTime;
             float reduction = 1f - (JDElectricalPlugin.Conf.Get <float>("CarefulSkillEfficencyPercentPerLevel") / 100f * SkillsUtil.GetSkillLevel(crafting.CurrentWorkOrder.Owner.User, typeof(CarefulWorkerSkill)));
             if (RandomUtil.Range(0.0f, 1.0f) < breakChance * reduction)
             {
                 Break();
             }
             UpdateStatus();
         }
     }
 }