示例#1
0
 private static bool canMine(Player p, Rock rock, Rock rock2)
 {
     if (rock == null || p == null || !Server.getGlobalObjects().originalObjectExists(rock.getRockId(), rock.getRockLocation()))
     {
         return(false);
     }
     if (rock.getRockIndex() != 0)
     {
         if (!p.getLocation().withinDistance(rock.getRockLocation(), 2))
         {
             return(false);
         }
     }
     else
     {
         // is rune ess rock
         if (!p.getLocation().inArea(rock.getRockLocation().getX() - 1, rock.getRockLocation().getY() - 1, rock.getRockLocation().getX() + 5, rock.getRockLocation().getY() + 5))
         {
             return(false);
         }
     }
     if (rock2 != null)
     {
         if (!rock.Equals(rock2))
         {
             return(false);
         }
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.MINING) < rock.getLevel())
     {
         p.getPackets().sendMessage("You need a Mining level of " + rock.getLevel() + " to mine that rock.");
         return(false);
     }
     if (!hasPickaxe(p))
     {
         p.getPackets().sendMessage("You need a pickaxe to mine a rock!");
         return(false);
     }
     if (p.getInventory().findFreeSlot() == -1)
     {
         p.getPackets().sendChatboxInterface(210);
         p.getPackets().modifyText("Your inventory is too full to carry any ore.", 210, 1);
         return(false);
     }
     return(true);
 }
示例#2
0
        public static void mineRock(Player p, ushort rockId, Location rockLocation, int i, bool newMine)
        {
            if (!newMine && p.getTemporaryAttribute("miningRock") == null)
            {
                return;
            }
            if (newMine)
            {
                if (!Server.getGlobalObjects().objectExists(rockId, rockLocation))
                {
                    //misc.WriteError(p.getUsername() + " tried to mine a non existing rock!");
                    //return;
                }
                Rock newRock = new Rock(i, rockId, rockLocation, ORES[i], ROCK_LEVEL[i], NAME[i], ROCK_XP[i]);
                p.setTemporaryAttribute("miningRock", newRock);
            }
            Rock rockToMine = (Rock)p.getTemporaryAttribute("miningRock");
            bool essRock    = rockToMine.getRockIndex() == 0;

            if (!canMine(p, rockToMine, null))
            {
                resetMining(p);
                return;
            }
            if (newMine)
            {
                string s = essRock ? "You begin to mine Essence.." : "You swing your pick at the rock..";
                p.getPackets().sendMessage(s);
            }
            p.getPackets().closeInterfaces();
            p.setLastAnimation(new Animation(getPickaxeAnimation(p)));
            p.setFaceLocation(rockLocation);
            int   delay         = getMineTime(p, rockToMine.getRockIndex());
            Event mineRockEvent = new Event(delay);

            mineRockEvent.setAction(() => {
                mineRockEvent.stop();                 // Stop the event no matter what
                if (p.getTemporaryAttribute("miningRock") == null)
                {
                    return;
                }
                Rock rock = (Rock)p.getTemporaryAttribute("miningRock");
                if (!canMine(p, rockToMine, rock))
                {
                    return;
                }
                if (!essRock)
                {
                    Server.getGlobalObjects().lowerHealth(rock.getRockId(), rock.getRockLocation());
                    if (!Server.getGlobalObjects().originalObjectExists(rock.getRockId(), rock.getRockLocation()))
                    {
                        resetMining(p);
                        stopAllOtherMiners(p, rock);
                        p.setLastAnimation(new Animation(65535));
                        mineRockEvent.stop();
                    }
                }
                bool addGem = (!essRock && misc.random(getGemChance(p)) == 0) ? true : false;
                if (p.getInventory().addItem(addGem ? randomGem() : rock.getOre()))
                {
                    p.getSkills().addXp(Skills.SKILL.MINING, rock.getXp());
                    if (addGem)
                    {
                        p.getPackets().sendMessage("You manage to mine a sparkling gem!");
                    }
                    else
                    {
                        if (!essRock)
                        {
                            p.getPackets().sendMessage("You manage to mine some " + rock.getName() + ".");
                        }
                    }
                }
                if (rock.isContinueMine())
                {
                    mineRock(p, rock.getRockId(), rock.getRockLocation(), rock.getRockIndex(), false);
                }
            });
            Server.registerEvent(mineRockEvent);
            if (delay >= 9000 && !rockToMine.isContinueMine())
            {
                Event mineMoreRockEvent = new Event(9000);
                mineMoreRockEvent.setAction(() => {
                    mineMoreRockEvent.stop();
                    Rock rock = (Rock)p.getTemporaryAttribute("miningRock");
                    if (!canMine(p, rockToMine, rock))
                    {
                        return;
                    }
                    p.setFaceLocation(rock.getRockLocation());
                    p.setLastAnimation(new Animation(getPickaxeAnimation(p)));
                });
                Server.registerEvent(mineMoreRockEvent);
            }
        }
 private static bool canMine(Player p, Rock rock, Rock rock2)
 {
     if (rock == null || p == null || !Server.getGlobalObjects().originalObjectExists(rock.getRockId(), rock.getRockLocation())) {
         return false;
     }
     if (rock.getRockIndex() != 0) {
         if (!p.getLocation().withinDistance(rock.getRockLocation(), 2)) {
             return false;
         }
     } else {
         // is rune ess rock
         if (!p.getLocation().inArea(rock.getRockLocation().getX()-1, rock.getRockLocation().getY()-1, rock.getRockLocation().getX()+5, rock.getRockLocation().getY()+5)) {
             return false;
         }
     }
     if (rock2 != null) {
         if (!rock.Equals(rock2)) {
             return false;
         }
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.MINING) < rock.getLevel()) {
         p.getPackets().sendMessage("You need a Mining level of " + rock.getLevel() + " to mine that rock.");
         return false;
     }
     if (!hasPickaxe(p)) {
         p.getPackets().sendMessage("You need a pickaxe to mine a rock!");
         return false;
     }
     if (p.getInventory().findFreeSlot() == -1) {
         p.getPackets().sendChatboxInterface(210);
         p.getPackets().modifyText("Your inventory is too full to carry any ore.", 210, 1);
         return false;
     }
     return true;
 }