Exemplo n.º 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);
        }
    }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
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);
 }