public ShopManager() {
            if (!File.Exists(misc.getServerPath() + @"\data\shops.xml"))
            {
                misc.WriteError(@"Missing data\shops.xml");
                return;
            }
            try
            {
                //Deserialize text file to a new object.
                StreamReader objStreamReader = new StreamReader(misc.getServerPath() + @"\data\shops.xml");
                XmlSerializer serializer = new XmlSerializer(typeof(List<Shop>));

                List<Shop> listShops = (List<Shop>)serializer.Deserialize(objStreamReader);
                shops = new Dictionary<int, Shop>();
                foreach (Shop shop in listShops)
                {
                    shops.Add(shop.id, shop);
                }
            }
            catch (Exception e)
            {
                misc.WriteError((e.InnerException == null ? e.ToString() : e.InnerException.ToString()));
            }

		    //shops = (Map<Integer, Shop>) XStreamUtil.getXStream().fromXML(new FileInputStream("data/shops.xml"));
            Event updateShopAmountsEvent = new Event(60000);
            updateShopAmountsEvent.setAction(() => {
		        updateShopAmounts();
		    });
            Server.registerEvent(updateShopAmountsEvent);
		    Console.WriteLine("Loaded " + shops.Count + " shops.");
	    }
 public static void createAmmo(Player p, int sets, int type, bool bolt, bool newFletch)
 {
     Ammo item = null;
     if (newFletch || Fletching.getFletchItem(p) == null) {
         item = getAmmo(type, bolt, sets);
         Fletching.setFletchItem(p, item);
     }
     item = (Ammo) Fletching.getFletchItem(p);
     if (item == null || p == null) {
         return;
     }
     if (!canFletch(p, item)) {
         p.getPackets().closeInterfaces();
         return;
     }
     int amt = getArrowAmount(p, item);
     if (amt <= 0) {
         return;
     }
     if (p.getInventory().deleteItem(item.getItemOne(), amt) && p.getInventory().deleteItem(item.getItemTwo(), amt)) {
         p.getInventory().addItem(item.getFinishedItem(), amt);
         p.getSkills().addXp(Skills.SKILL.FLETCHING, item.getXp() * amt);
         p.getPackets().sendMessage(getMessage(item, amt));
         item.decreaseAmount();
         p.getPackets().closeInterfaces();
     }
     if (item.getAmount() >= 1) {
         Event createMoreAmmoEvent = new Event(1500);
         createMoreAmmoEvent.setAction(() => {
             createAmmo(p, -1, -1, false, false);
             createMoreAmmoEvent.stop();
         });
         Server.registerEvent(createMoreAmmoEvent);
     }
 }
	    protected void spawnMonsters() {
		    if (monstersSpawned || !gameInProgress) {
			    return;
		    }
		    monstersSpawned = true;
            Event spawnMonstersEvent = new Event(3000);
            spawnMonstersEvent.setAction(() => {
				if (!monstersSpawned || playersPlaying.Count() <= 1) {
					spawnMonstersEvent.stop();
					foreach(Npc n in Server.getNpcList()) {
						if (Location.inFightPits(n.getLocation())) {
							n.setVisible(false);
							Server.getNpcList().Remove(n);
						}
					}
					return;
				}
		    });
            Server.registerEvent(spawnMonstersEvent);

		    foreach(Player p in playersPlaying) {
			    teleportToWaitingRoom(p, false);
			    sendNPCMessage(p, "You took to long in defeating your enemies.");
		    }
		    playersPlaying.Clear();
	    }
	    private void newGlobalItem(GroundItem item) {
		    if (item == null) {
			    return;
		    }
		    item = itemExists(item);
		    if (item != null) {
			    item.setGlobal(true);
			    foreach(Player p in Server.getPlayerList()) {
				    if (p == null || (item.getDefinition().isPlayerBound() && !item.getOwner().Equals(p))) {
					    continue;
				    }
				    if (p.getLocation().withinDistance(item.getLocation(), 60)) {
					    if(item.getOwner() != null) {
						    p.getPackets().createGroundItem2(item);
					    } else {
						    p.getPackets().createGroundItem(item);
					    }
				    }
			    }
			    if (!item.getDefinition().isPlayerBound()) {
				    item.setOwner(null);
			    }
			    GroundItem i = item;
			    if (!item.isRespawn()) {
                    Event removeGlobalItemEvent = new Event(60000);
				    removeGlobalItemEvent.setAction(() => {
						clearGlobalItem(i);
						removeGlobalItemEvent.stop();
				    });
                    Server.registerEvent(removeGlobalItemEvent);
			    }
		    }
	    }
        public void processPatches()
        {
            /*
             * If something has to be removed from the ArrayList in this loop, use it.remove() not patches.remove()
             * or else we end up with a ConcurrentModificationException and it'll break out the loop :$.
             */
            Event processPatchesEvent = new Event(3000);
            processPatchesEvent.setAction(() => {

                foreach(Patch patch in patches) {
                    if (patch == null) {
                        removedPatches.Add(patch);
                    } else if (patch.isSapling()) {
                        if (Farming.growSapling(patch)) {
                            removedPatches.Add(patch);
                        }
                    } else if (!patch.patchOccupied()) {
                        if (Farming.regrowWeeds(patch)) { // true if we should remove from the list
                            removedPatches.Add(patch);
                        }
                    } else if (!patch.isFullyGrown() && patch.patchOccupied()) {
                        long currentTime = Environment.TickCount;
                        long lastUpdatedTime = patch.getLastUpdate();
                        int delay = (int) (patch.getTimeToGrow() / patch.getConfigLength());
                        //if (currentTime - lastUpdatedTime >= delay) {
                            Farming.growPatch(patch);
                        //}
                    }
                }
                patches.RemoveAll(new Predicate<Patch>(delegate(Patch x) { return removedPatches.Contains(x); }));
            });
            Server.registerEvent(processPatchesEvent);
        }
	    private void startArena() {
            Event startArenaEvent = new Event(0);
            startArenaEvent.setAction(() => {
				currentPillar = misc.random(AGILITY_ARENA_PILLARS.Length - 1);
				updateArrow();
				startArenaEvent.setTick(30000 + misc.random(30000));
		    });
            Server.registerEvent(startArenaEvent);
	    }
	    protected static void createdAnimatedArmour(Player p, int index) {
		    if (p.getTemporaryAttribute("warriorGuildAnimator") == null) {
			    return;
		    }
		    p.setLastAnimation(new Animation(827));
		    p.setTemporaryAttribute("unmovable", true);
		    for (int i = 0; i < ARMOUR_SETS[index].Length; i++) {
			    p.getInventory().deleteItem(ARMOUR_SETS[index][i]);
		    }
		    p.getPackets().sendChatboxInterface(211);
		    p.getPackets().modifyText("You place the armour onto the platform where it", 211, 1);
		    p.getPackets().modifyText("dissapears...", 211, 2);
		    int animatorIndex = (int) p.getTemporaryAttribute("warriorGuildAnimator");
            Event createAnimatedArmourEvent = new Event(1500);
            int createAnimatedArmourCounter = 0;
            Npc npc = null;
            createAnimatedArmourEvent.setAction(() => {
                if (createAnimatedArmourCounter == 0)
                {
					p.getPackets().sendChatboxInterface(211);
					p.getPackets().modifyText("The animator hums, something appears to be working.", 211, 1);
					p.getPackets().modifyText("You stand back.", 211, 2);
					createAnimatedArmourEvent.setTick(500);
                }
                else if (createAnimatedArmourCounter == 1)
                {
					p.getWalkingQueue().forceWalk(0, + 3);
					createAnimatedArmourEvent.setTick(2000);
                }
                else if (createAnimatedArmourCounter == 2)
                {
					createAnimatedArmourEvent.setTick(500);
					Location minCoords = new Location(2849, 3534, 0);
					Location maxCoords = new Location(2861, 3545, 0);
					npc = new Npc(ANIMATED_ARMOUR[index]);
					npc.setMinimumCoords(minCoords);
					npc.setMaximumCoords(maxCoords);
					npc.setLocation(new Location(ANIMATOR_LOCATIONS[animatorIndex][0], ANIMATOR_LOCATIONS[animatorIndex][1], 0));
					npc.setWalkType(WalkType.STATIC);
					npc.setForceText("I'm ALIVE!");
					npc.setLastAnimation(new Animation(4166));
					npc.setEntityFocus(p.getClientIndex());
					npc.setOwner(p);
					npc.setTarget(p);
					p.getPackets().setArrowOnEntity(1, npc.getClientIndex());
					Server.getNpcList().Add(npc);
				} else {
					p.setEntityFocus(npc.getClientIndex());
					p.getPackets().softCloseInterfaces();
					createAnimatedArmourEvent.stop();
					p.removeTemporaryAttribute("unmovable");
					npc.getFollow().setFollowing(p);
				}
                createAnimatedArmourCounter++;
		    });
            Server.registerEvent(createAnimatedArmourEvent);
	    }
	    public void enterChannel(Player p, string owner) {
		    if (p.getClan() != null) {
			    return;
		    }
		    p.getPackets().sendMessage("Attempting to join channel...:clan:");
		    if (owner.Equals(p.getLoginDetails().getUsername())) {
			    Clan newClan = new Clan(p, owner, owner);
			    addChannel(newClan);
		    }
            Event enterChannelEvent = new Event(700);
            enterChannelEvent.setAction(() => {
				enterChannelEvent.stop();
				foreach(Clan c in clans) {
					if (c != null) {
						if (c.getClanOwner().Equals(owner)) {
							if(c.getUserList().Count >= 100) {
								p.getPackets().sendMessage("The channel is full.");
								return;
							}
							if (!owner.Equals(p.getLoginDetails().getUsername())) {
								if (c.getEnterRights() != Clan.ClanRank.NO_RANK) {
									if (c.getEnterRights() == Clan.ClanRank.FRIEND) {
										if (!c.isFriendOfOwner(p) && !c.userHasRank(p.getLoginDetails().getUsername())) {
											p.getPackets().sendMessage("You do not have a high enough rank to enter this clan chat.");
											return;
										}
									} else {
										bool canEnter = true;
										foreach (KeyValuePair<string, Clan.ClanRank> u in c.getUsersWithRank()) {
											if(u.Key.Equals(p.getLoginDetails().getUsername())) {
												if (u.Value < c.getEnterRights()) {
													canEnter = false;
													break;
												}
											}
										}
										if (!canEnter) {
											p.getPackets().sendMessage("You do not have a high enough rank to enter this clan chat.");
											return;
										}
									}
								}
							}
							c.addUser(p);
							updateClan(c);
							p.getPackets().sendMessage("Now talking in channel : " + misc.formatPlayerNameForDisplay(c.getClanName() + ":clan:"));
							p.getPackets().sendMessage("To talk, start each line of chat with the / symbol. :clan:");
							return;
						}
					}
				}
				p.getPackets().sendMessage("The channel you tried to join does not exist. :clan:");
		    });
            Server.registerEvent(enterChannelEvent);
	    }
	    private static void activateObelisk(int index) {
		    if (obeliskActivated[index])
			    return;

		    Location[] obeliskLocations = getLocations(index);
		    for (int i = 0; i < 4; i++) {
			    WorldObject obj = new WorldObject(OBELISK_ID[index], ACTIVATED_ID, obeliskLocations[i], 0, 10);
			    obj.setSecondForm(true);
			    Server.getGlobalObjects().add(obj);
			    foreach(Player p in Server.getPlayerList()) {
				    p.getPackets().createObject(ACTIVATED_ID, obeliskLocations[i], 0, 10);
			    }
		    }
		    obeliskActivated[index] = true;
            Event activateObeliskEvent = new Event(4000 + (misc.random(4)) * 1000);
            activateObeliskEvent.setAction(() => {
				activateObeliskEvent.stop();
				int randomOb = index;
				while(randomOb == index) {
					// While loop so if the random one is the same one, it picks a new one
					randomOb = misc.random(OBELISK_ID.Length);
				}
				int random = randomOb;
				foreach(Player p in Server.getPlayerList()) {
					if (p != null) {
						if (p.getLocation().inArea(OBELISK_LOCATIONS[index][0] - 2, OBELISK_LOCATIONS[index][1] - 2, OBELISK_LOCATIONS[index][0] + 2, OBELISK_LOCATIONS[index][1] + 2)) {
							// TODO get the big purple graphic
							p.setLastGraphics(new Graphics(1690));
							p.setLastAnimation(new Animation(8939));
							Player p2 = p;

                            Event obeliskTeleportEvent = new Event(1200);
                            obeliskTeleportEvent.setAction(() => {
								obeliskTeleportEvent.stop();
								p2.teleport(new Location((OBELISK_LOCATIONS[random][0] - 1) + misc.random(2), (OBELISK_LOCATIONS[random][1] - 1) + misc.random(2), 0));
								
                                Event obeliskAnimationEvent = new Event(500);
                                obeliskAnimationEvent.setAction(() => {
                                    obeliskAnimationEvent.stop();
									p2.setLastAnimation(new Animation(8941));
								});
                                Server.registerEvent(obeliskAnimationEvent);
							});
                            Server.registerEvent(obeliskTeleportEvent);
						}
					}
				}

				for (int i = 0; i < 4; i++) {
					WorldObject obj = Server.getGlobalObjects().getObject(OBELISK_ID[index], obeliskLocations[i]);
					Server.getGlobalObjects().restoreObject(obj);
				}
				obeliskActivated[index] = false;
		    });
	    }
 public static void craftDragonHide(Player p, int amount, int itemIndex, int leatherType, bool newCraft)
 {
     if (newCraft) {
         itemIndex = leatherType != 0 ? itemIndex += leatherType : itemIndex;
         p.setTemporaryAttribute("craftItem", new CraftItem(leatherType, itemIndex, amount, (double) LEATHER_ITEMS[itemIndex][2], (int) LEATHER_ITEMS[itemIndex][0], (string) LEATHER_ITEMS[itemIndex][4], (int) LEATHER_ITEMS[itemIndex][1]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0) {
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     int index = item.getCraftItem();
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to craft that item.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItemAmount(TANNED_HIDE[item.getCraftType()], (int) LEATHER_ITEMS[index][3])) {
         p.getPackets().sendMessage("You need " + (int) LEATHER_ITEMS[index][3] + " dragonhide to craft that.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItem(NEEDLE)) {
         p.getPackets().sendMessage("You need a needle if you wish to craft leather.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItemAmount(THREAD, (int)LEATHER_ITEMS[index][3])) {
         p.getPackets().sendMessage("You need " + (int)LEATHER_ITEMS[index][3] + " thread to craft that.");
         Crafting.resetCrafting(p);
         return;
     }
     string s = index < 4 ? "a" : "a pair of";
     for (int j = 0; j < (int) LEATHER_ITEMS[index][3]; j++) {
         if (!p.getInventory().deleteItem(TANNED_HIDE[item.getCraftType()])) {
             return;
         }
     }
     p.getInventory().deleteItem(THREAD, (int) LEATHER_ITEMS[index][3]);
     p.getInventory().addItem(item.getFinishedItem());
     p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
     p.setLastAnimation(new Animation(1249));
     p.getPackets().sendMessage("You craft " + s + " " + item.getMessage() + ".");
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event craftMoreDragonHide = new Event(1500);
         craftMoreDragonHide.setAction(() => {
                 craftDragonHide(p, -1, -1, -1, false);
                 craftMoreDragonHide.stop();
         });
         Server.registerEvent(craftMoreDragonHide);
     }
 }
	    public static void exitCave(Player p, int objectX, int objectY) {
            AreaEvent exitCaveAreaEvent = new AreaEvent(p, objectX, objectY - 1, objectX + 2, objectY - 1);
            exitCaveAreaEvent.setAction(() => {
				p.setTemporaryAttribute("unmovable", true);
                Event teleFromCaveEvent = new Event(600);
                teleFromCaveEvent.setAction(() => {
					teleFromCaveEvent.stop();
					p.getFightCave().teleFromCave(true);
				});
                Server.registerEvent(teleFromCaveEvent);
		    });
            Server.registerCoordinateEvent(exitCaveAreaEvent);
	    }
	    public void newEntityDrop(GroundItem item) {
		    lock(items) {
			    items.Add(item);
		    }
		    if (item.getOwner() != null && !item.getOwner().isDestroyed()) {
			    item.getOwner().getPackets().createGroundItem(item);
		    }
            Event showItemDropGloballyEvent = new Event(60000); //60 seconds to show dropped item to all players.
		    showItemDropGloballyEvent.setAction(() => {
				    newGlobalItem(item);
				    showItemDropGloballyEvent.stop();
		    });
            Server.registerEvent(showItemDropGloballyEvent);
	    }
	    private void startCloseDoorEvent() {

            Event closeDoorEvent = new Event(CHANGE_CYCLE_TIME);
            closeDoorEvent.setAction(() => {
				foreach(Door door in doors) {
					if (door != null) {
						if (door.isDoorOpen() && !door.isInstantClose() && misc.random(1) == 0) {
							changeDoor(door);
						}
					}
				}
		    });
            Server.registerEvent(closeDoorEvent);
	    }
Example #14
0
 public static void craftClay(Player p, int amount, int craftType, int craftItem, bool newCraft)
 {
     if (newCraft) {
         if ((craftType != 1 && craftType != 2) || craftItem < 0 || craftItem > 4) {
             return;
         }
         int index = craftItem;
         int endItem = craftType == 1 ? 0 : 1;
         int xp = craftType == 1 ? 3 : 4;
         p.setTemporaryAttribute("craftItem", new CraftItem(craftType, craftItem, amount, (double) CLAY_ITEMS[index][xp], (int) CLAY_ITEMS[index][endItem], (string) CLAY_ITEMS[index][5], (int) CLAY_ITEMS[index][2]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0) {
         Crafting.resetCrafting(p);
         return;
     }
     int neededItem = item.getCraftType() == 1 ? CLAY : (int) CLAY_ITEMS[item.getCraftItem()][0];
     string s = item.getCraftType() == 1 ? "You mould the clay into a " + item.getMessage() : "You bake the " + item.getMessage() + " in the oven";
     string s1 = item.getCraftType() == 1 ? "You need some soft clay to mould a " + item.getMessage() : "You need a pre-made " + item.getMessage() + " to put in the oven";
     int animation = item.getCraftType() == 1 ? 883 : 899;
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to make a " + item.getMessage() + ".");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItem(neededItem)) {
         p.getPackets().sendMessage(s1 + ".");
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     if (p.getInventory().deleteItem(neededItem)) {
         if (p.getInventory().addItem(item.getFinishedItem())) {
             p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
             p.getPackets().sendMessage(s + ".");
             p.setLastAnimation(new Animation(animation));
         }
     }
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event craftMoreClayEvent = new Event(1500);
         craftMoreClayEvent.setAction(() =>
         {
             craftClay(p, -1, -1, -1, false);
             craftMoreClayEvent.stop();
         });
         Server.registerEvent(craftMoreClayEvent);
     }
 }
 public static void completePotion(Player p, int amount, bool newMix)
 {
     if (newMix && p.getTemporaryAttribute("completePotion") == null) {
         return;
     }
     if (!newMix && p.getTemporaryAttribute("herbloreItem") == null) {
         return;
     }
     if (newMix) {
         if (p.getTemporaryAttribute("completePotion") == null) {
             return;
         }
         int index = (int) p.getTemporaryAttribute("completePotion");
         p.setTemporaryAttribute("herbloreItem", new Potion(END_POTION[index], UNFINISHED[index], SECONDARY[index], POTION_LEVEL[index], POTION_XP[index], amount));
     }
     Potion item = (Potion) p.getTemporaryAttribute("herbloreItem");
     if (item == null || p == null || item.getAmount() <= 0) {
         resetAllHerbloreVariables(p);
         return;
     }
     if (!p.getInventory().hasItem(item.getSecondary()) || !p.getInventory().hasItem(item.getUnfinished())) {
         resetAllHerbloreVariables(p);
         return;
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.HERBLORE) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Herblore level of " + item.getLevel() + " to make that potion.");
         resetAllHerbloreVariables(p);
         return;
     }
     string s = ItemData.forId(item.getFinished()).getName().Replace("(3)", "");
     if (p.getInventory().deleteItem(item.getUnfinished()) && p.getInventory().deleteItem(item.getSecondary())) {
         if (p.getInventory().addItem(item.getFinished())) {
             item.decreaseAmount();
             p.setLastAnimation(new Animation(MIX_ANIMATION));
             p.getSkills().addXp(Skills.SKILL.HERBLORE, item.getXp());
             p.getPackets().sendMessage("You add the ingredient into the murky vial, you have completed the potion.");
             p.getPackets().closeInterfaces();
         }
     }
     if (item.getAmount() >= 1) {
         Event completeMorePotionsEvent = new Event(750);
         completeMorePotionsEvent.setAction(() => {
             completePotion(p, item.getAmount(), false);
             completeMorePotionsEvent.stop();
         });
         Server.registerEvent(completeMorePotionsEvent);
     }
 }
 public static void cutGem(Player p, int index, int amount, bool newCut)
 {
     index -= 50;
     if (newCut) {
         p.setTemporaryAttribute("craftItem", new CraftItem(5, index, amount, (double) GEMS[index][3], (int) GEMS[index][1], (string) GEMS[index][4], (int) GEMS[index][2]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0 || item.getCraftType() != 5) {
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     if (!p.getInventory().hasItem(CHISEL)) {
         p.getPackets().sendMessage("You cannot cut gems without a chisel.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItem((int)GEMS[item.getCraftItem()][0])) {
         if (newCut) {
             p.getPackets().sendMessage("You have no " + item.getMessage() + " to cut.");
         } else {
             p.getPackets().sendMessage("You have no more " + item.getMessage() + "'s to cut.");
         }
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to cut that gem.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getInventory().deleteItem((int)GEMS[item.getCraftItem()][0])) {
         p.getInventory().addItem(item.getFinishedItem());
         p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
         p.setLastAnimation(new Animation((int) GEMS[item.getCraftItem()][5]));
         p.getPackets().sendMessage("You cut the " + item.getMessage() + ".");
     }
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event cutMoreGemEvent = new Event(1500);
         cutMoreGemEvent.setAction(() => {
             cutGem(p, -1, -1, false);
             cutMoreGemEvent.stop();
         });
         Server.registerEvent(cutMoreGemEvent);
     }
 }
 public static void cutLog(Player p, int amount, int logType, int itemType, bool isStringing, bool newFletch)
 {
     Bow item = null;
     if (newFletch) {
         item = getBow(itemType, logType, amount, isStringing);
         Fletching.setFletchItem(p, item);
     }
     item = (Bow) Fletching.getFletchItem(p);
     if (item == null || p == null) {
         return;
     }
     bool stringing = item.isStringing();
     if (!canFletch(p, item, stringing)) {
         p.getPackets().closeInterfaces();
         return;
     }
     int animation = getAnimation(item);
     if (!stringing) {
         int amt = item.getItemType() == 2 ? ARROW_AMOUNT : 1;
         if (p.getInventory().deleteItem(LOGS[item.getLogType()])) {
             p.getInventory().addItem(item.getFinishedItem(), amt);
             p.getSkills().addXp(Skills.SKILL.FLETCHING, item.getXp());
             item.decreaseAmount();
             p.getPackets().sendMessage("You carefully cut the wood into " + MESSAGE[item.getItemType()] + ".");
             p.setLastAnimation(new Animation(animation));
         }
     } else {
         int[] bows = item.getItemType() == 0 ? UNSTRUNG_SHORTBOW : UNSTRUNG_LONGBOW;
         if (p.getInventory().deleteItem(BOWSTRING) && p.getInventory().deleteItem(bows[item.getLogType()])) {
             p.getInventory().addItem(item.getFinishedItem());
             p.getSkills().addXp(Skills.SKILL.FLETCHING, item.getXp());
             item.decreaseAmount();
             p.getPackets().sendMessage("You add a string to the bow.");
             p.setLastAnimation(new Animation(animation));
         }
     }
     p.getPackets().closeInterfaces();
     if (item.getAmount() >= 1) {
         Event cutMoreLogsEvent = new Event(1500);
         cutMoreLogsEvent.setAction(() => {
             cutLog(p, -1, -1, -1, false, false);
             cutMoreLogsEvent.stop();
         });
         Server.registerEvent(cutMoreLogsEvent);
     }
 }
	    private void startGame() {
            Event startFightCaveGameEvent = new Event(3000);
            startFightCaveGameEvent.setAction(() => {
				if (completed) {
					startFightCaveGameEvent.stop();
					return;
				}
				if (mobAmount > 0 || currentWave > 63) {
					return;
				}
				if (gamePaused && currentWave != 63) {
					startFightCaveGameEvent.stop();
					p.getPackets().forceLogout();
					return;
				}
				if (currentWave == 62) {
					startFightCaveGameEvent.setTick(8000);
					currentWave++;
					showJadMessage();
					return;
				} else if (currentWave < 62){
					currentWave++;
				}
				int[] mobs = decryptWave(currentWave);
				int amount = 0;
				for (int i = 0; i < mobs.Length; i++) {
					if (mobs[i] > 0) {
						Npc npc = new Npc(mobs[i]);
						Location minCoords = new Location(((20000 + 2363) + (200 * p.getIndex())), 25051, 0);
						Location maxCoords = new Location(((20000 + 2430) + (200 * p.getIndex())), 25123, 0);
						npc.setMinimumCoords(minCoords);
						npc.setMaximumCoords(maxCoords);
						npc.setLocation(new Location((20000 + 2387) + (200 * p.getIndex()) + misc.random(22), 20000 + 5069 + misc.random(33), 0));
						npc.setEntityFocus(p.getClientIndex());
						npc.setOwner(p);
						npc.setTarget(p);
						npc.getFollow().setFollowing(p);
						Server.getNpcList().Add(npc);
						amount++;
					}
				}
				mobAmount = (byte)amount;
		    });
            Server.registerEvent(startFightCaveGameEvent);
	    }
 public static void newSilverItem(Player p, int amount, int index, bool newCraft)
 {
     index -= 120;
     if (newCraft) {
         p.setTemporaryAttribute("craftItem", new CraftItem(3, index, amount, (double) SILVER_ITEMS[index][3], (int) SILVER_ITEMS[index][0], (string) SILVER_ITEMS[index][4], (int) SILVER_ITEMS[index][2]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0 || item.getCraftType() != 3) {
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     string s = item.getCraftItem() == 0 ? "an" : "a";
     if (!p.getInventory().hasItem((int)SILVER_ITEMS[item.getCraftItem()][1])) {
         p.getPackets().sendMessage("You need " + s + " " + item.getMessage() + " mould to make that.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItem(SILVER_BAR)) {
         p.getPackets().sendMessage("You don't have a Silver bar.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to smelt that.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getInventory().deleteItem(SILVER_BAR)) {
         p.getInventory().addItem(item.getFinishedItem());
         p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
         p.setLastAnimation(new Animation(3243));
         p.getPackets().sendMessage("You smelt the Silver bar in to " + s + " " + item.getMessage() + ".");
     }
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event makeMoreSilverItemEvent = new Event(1500);
         makeMoreSilverItemEvent.setAction(() =>
         {
             newSilverItem(p, -1, -1, false);
             makeMoreSilverItemEvent.stop();
         });
         Server.registerEvent(makeMoreSilverItemEvent);
     }
 }
        public void fireCannon()
        {
            if (firing) {
                loadCannon();
                return;
            }

            firing = true;
            int cannonTurnAnimation = 515;
            Event attemptFireCannonEvent = new Event(1000);
            attemptFireCannonEvent.setAction(() => {
                if (!firing)
                {
                    attemptFireCannonEvent.stop();
                    return;
                }
                p.getPackets().newObjectAnimation(cannonLocation, cannonTurnAnimation);
                Event fireCannonEvent = new Event(600);
                fireCannonEvent.setAction(() => {
                    if (!firing)
                    {
                        fireCannonEvent.stop();
                        return;
                    }
                    if (stopCannon && cannonTurnAnimation == 514)
                    {
                        cannonTurnAnimation = 514;
                        fireCannonEvent.stop();
                        firing = false;
                        return;
                    }
                    if (!stopCannon) {
                        if (checkHitTarget())
                            checkCannonballs();
                    }
                    if (direction++ == 7)
                        direction = 0;
                    if (++cannonTurnAnimation > 521)
                        cannonTurnAnimation = 514;
                   fireCannonEvent.stop();
                });
                Server.registerEvent(fireCannonEvent);
            });
            Server.registerEvent(attemptFireCannonEvent);
        }
Example #21
0
 public static void craftGlass(Player p, int amount, int index, bool newCraft)
 {
     if (newCraft) {
         p.setTemporaryAttribute("craftItem", new CraftItem(3, index, amount, (double) GLASS_ITEMS[index][2], (int) GLASS_ITEMS[index][0], (string) GLASS_ITEMS[index][3], (int) GLASS_ITEMS[index][1]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0 || item.getCraftType() != 3) {
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     if (!p.getInventory().hasItem(MOLTEN_GLASS)) {
         p.getPackets().sendMessage("You have no molten glass.");
         Crafting.resetCrafting(p);
         return;
     }
     if (!p.getInventory().hasItem(GLASSBLOWING_PIPE)) {
         p.getPackets().sendMessage("You need a glassblowing pipe if you wish to make a glass item.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to craft that item.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getInventory().deleteItem(MOLTEN_GLASS)) {
         p.getInventory().addItem(item.getFinishedItem());
         p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
         p.setLastAnimation(new Animation(884));
         p.getPackets().sendMessage("You blow through the pipe, shaping the molten glass into a " + item.getMessage() + ".");
     }
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event craftMoreGlassEvent = new Event(1500);
         craftMoreGlassEvent.setAction(() =>
         {
             craftGlass(p, -1, -1, false);
             craftMoreGlassEvent.stop();
         });
         Server.registerEvent(craftMoreGlassEvent);
     }
 }
        // TODO make this use an AreaEvent so itll work from a distance.
        /**
         * Will fill vials in a continuous motion from a water source.
         */
        public static bool fillingVial(Player p, Location loc)
        {
            if (!p.getInventory().hasItem(VIAL) || !p.getLocation().withinDistance(loc, 2))
            {
                return true;
            }
            if (p.getTemporaryAttribute("fillVialTimer") != null) {
                long lastFillTime = (int) p.getTemporaryAttribute("fillVialTimer");
                if (Environment.TickCount - lastFillTime < 600) {
                    return true;
                }
            }
            p.setTemporaryAttribute("fillingVials", true);
            p.setFaceLocation(loc);

            Event fillVialEvent = new Event(500);
            fillVialEvent.setAction(() => {
                int amountFilled = 0;
                string s = amountFilled == 1 ? "vial" : "vials";
                if (p.getTemporaryAttribute("fillingVials") == null || !p.getLocation().withinDistance(loc, 2) || !p.getInventory().hasItem(229)) {
                    p.setLastAnimation(new Animation(65535));
                    if (amountFilled > 0) {
                        p.getPackets().sendMessage("You fill up the " + s + " with water.");
                    }
                    fillVialEvent.stop();
                    return;
                }
                if (p.getInventory().replaceSingleItem(VIAL, VIAL_OF_WATER))
                {
                    p.setLastAnimation(new Animation(832));
                    amountFilled++;
                    p.setTemporaryAttribute("fillVialTimer", Environment.TickCount);
                } else {
                    if (amountFilled > 0) {
                        p.setLastAnimation(new Animation(65535));
                        p.getPackets().sendMessage("You fill up the " + s + " with water.");
                    }
                    fillVialEvent.stop();
                }
            });
            Server.registerEvent(fillVialEvent);
            return true;
        }
 public static void chopTendrils(Player p, int x, int y)
 {
     int var = x == 3057 ? x+2 : x-1;
     AreaEvent chopTendrilsAreaEvent = new AreaEvent(p, var, y, var, y+2);
     chopTendrilsAreaEvent.setAction(() => {
         if (!Woodcutting.hasAxe(p)) {
             p.getPackets().sendMessage("You need an axe to get past this obstacle.");
             return;
         }
         p.getWalkingQueue().resetWalkingQueue();
         p.setFaceLocation(new Location(x + 1, y, 0));
         p.setLastAnimation(new Animation(Woodcutting.getAxeAnimation(p)));
         p.setTemporaryAttribute("unmovable", true);
         Event chopTendrilsEvent = new Event(1900);
         chopTendrilsEvent.setAction(() => {
             int status = 0;
             int[] TENDRILS = {7161, 7162, 7163};
             if (status < 3) {
                 p.getPackets().createObject(TENDRILS[status], new Location(x, y, 0), x == 3057 ? 3 : 1, 10);
             }
             status++;
             if (status == 1) {
                 p.setLastAnimation(new Animation(Woodcutting.getAxeAnimation(p)));
                 chopTendrilsEvent.setTick(1300);
             }
             if (status == 3) {
                 p.getPackets().sendMessage("You clear your way through the tendrils.");
                 p.setLastAnimation(new Animation(65535));
                 chopTendrilsEvent.setTick(800);
             }
             if (status == 4) {
                 chopTendrilsEvent.stop();
                 teleportPastObstacle(p);
                 p.removeTemporaryAttribute("unmovable");
             }
         });
         Server.registerEvent(chopTendrilsEvent);
         return;
     });
     Server.registerCoordinateEvent(chopTendrilsAreaEvent);
 }
	    private void startWaitingEvent() {
            Event gameWaitingEvent = new Event(10000);
            gameWaitingEvent.setAction(() => {
				if (!gameInProgress) {
					if (playersWaiting.Count() >= 2 || (playersWaiting.Count() >= 1 && playersPlaying.Count() == 1)) {
						startGame();
						gameWaitingEvent.setTick(1000);
					}
				} else {
					if (playersPlaying.Count() <= 1) {
						gameInProgress = false;
						gameWaitingEvent.setTick(40000);
						setWinner();
					} else {
						if (Environment.TickCount - gameStartedTime >= (MAX_GAME_LENGTH * 60000)) {
							spawnMonsters();
						}
					}
				}
		    });
            Server.registerEvent(gameWaitingEvent);
	    }
	    public static void leverTeleport(Player p, int option) {
		    p.getPackets().closeInterfaces();
		    Location teleLocation = new Location(LEVER_COORDINATES[option][0], LEVER_COORDINATES[option][1], LEVER_COORDINATES[option][2]);
		    
            Event leverTeleportEvent = new Event(200);
            leverTeleportEvent.setAction(() => {
				leverTeleportEvent.stop();
				if (p.getTemporaryAttribute("teleblocked") != null) {
					p.getPackets().sendMessage("A magical force prevents you from teleporting!");
					return;
				} else if ((p.getTemporaryAttribute("teleporting") != null )) {
					return;
				}
				p.setLastAnimation(new Animation(2140));
				p.getPackets().closeInterfaces();
				p.setTemporaryAttribute("teleporting", true);
                p.getWalkingQueue().resetWalkingQueue();
				p.getPackets().clearMapFlag();
				SkillHandler.resetAllSkills(p);
                Event levelTeleportStartEvent = new Event(700);
                levelTeleportStartEvent.setAction(() => {
					levelTeleportStartEvent.stop();
					p.setLastAnimation(new Animation(8939, 0));
					p.setLastGraphics(new Graphics(1576, 0));
                    Event levelTeleportFinishEvent = new Event(1800);
                    levelTeleportFinishEvent.setAction(() => {
                        levelTeleportFinishEvent.stop();
						p.teleport(teleLocation);
						p.setLastAnimation(new Animation(8941, 0));
						p.setLastGraphics(new Graphics(1577, 0));
						Teleport.resetTeleport(p);
					});
                    Server.registerEvent(levelTeleportFinishEvent);
				});
                Server.registerEvent(levelTeleportStartEvent);
		    });
            Server.registerEvent(leverTeleportEvent);
	    }
 public static void craftSpinning(Player p, int amount, int index, bool newCraft)
 {
     if (newCraft) {
         p.setTemporaryAttribute("craftItem", new CraftItem(6, index, amount, (double) SPINNING_ITEMS[index][3], (int) SPINNING_ITEMS[index][0], (string) SPINNING_ITEMS[index][4], (int) SPINNING_ITEMS[index][2]));
     }
     CraftItem item = (CraftItem) p.getTemporaryAttribute("craftItem");
     if (item == null || p == null || item.getAmount() <= 0 || item.getCraftType() != 6) {
         Crafting.resetCrafting(p);
         return;
     }
     p.getPackets().closeInterfaces();
     int i = item.getCraftItem();
     if (!p.getInventory().hasItem((int) SPINNING_ITEMS[i][1])) {
         p.getPackets().sendMessage("You have no " + item.getMessage() + ".");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.CRAFTING) < item.getLevel()) {
         p.getPackets().sendMessage("You need a Crafting level of " + item.getLevel() + " to spin that.");
         Crafting.resetCrafting(p);
         return;
     }
     if (p.getInventory().deleteItem((int) SPINNING_ITEMS[i][1])) {
         p.getInventory().addItem(item.getFinishedItem());
         p.getSkills().addXp(Skills.SKILL.CRAFTING, item.getXp());
         p.setLastAnimation(new Animation(894));
         p.getPackets().sendMessage("You spin the " + item.getMessage() + " into a " + SPIN_FINISH[i] + ".");
     }
     item.decreaseAmount();
     if (item.getAmount() >= 1) {
         Event craftMoreSpinningEvent = new Event(750);
         craftMoreSpinningEvent.setAction(() => {
             craftSpinning(p, -1, -1, false);
             craftMoreSpinningEvent.stop();
         });
         Server.registerEvent(craftMoreSpinningEvent);
     }
 }
 public static void createXbow(Player p, int amount, int xbowType, bool isStringing, bool newFletch)
 {
     SkillItem item = null;
     if (newFletch || Fletching.getFletchItem(p) == null) {
         item = getXbow(xbowType, isStringing, amount);
         Fletching.setFletchItem(p, item);
     }
     item = (SkillItem) Fletching.getFletchItem(p);
     if (item == null || p == null) {
         return;
     }
     bool stringing = item.getItemTwo() == XBOW_STRING ? true : false;
     if (!canFletch(p, item)) {
         p.getPackets().closeInterfaces();
         return;
     }
     if (p.getInventory().deleteItem(item.getItemOne()) &&  p.getInventory().deleteItem(item.getItemTwo())) {
         p.getInventory().addItem(item.getFinishedItem());
         p.getSkills().addXp(Skills.SKILL.FLETCHING, item.getXp());
         item.decreaseAmount();
         p.getPackets().closeInterfaces();
         if (!stringing) {
             p.getPackets().sendMessage("You attach some limbs to the Crossbow.");
         } else {
             p.setLastAnimation(new Animation(6677));
             p.getPackets().sendMessage("You add a Crossbow String to the Crossbow, you have completed the " + ItemData.forId(item.getFinishedItem()).getName() + ".");
         }
     }
     if (item.getAmount() >= 1) {
         Event createMoreXBowEvent = new Event(1500);
         createMoreXBowEvent.setAction(() => {
             createXbow(p, -1, -1, false, false);
             createMoreXBowEvent.stop();
         });
         Server.registerEvent(createMoreXBowEvent);
     }
 }
 public static void burnBoil(Player p, int x, int y)
 {
     AreaEvent burnBoilAreaEvent = new AreaEvent(p, x-1, y-1, x +3, y+2);
     burnBoilAreaEvent.setAction(() => {
         if (!p.getInventory().hasItem(590)) {
             p.getPackets().sendMessage("You need a tinderbox to get past this obstacle.");
             return;
         }
         p.setFaceLocation(new Location(x + 1, y, 0));
         p.setLastAnimation(new Animation(733));
         p.setTemporaryAttribute("unmovable", true);
         Event burnBoilEvent = new Event(1900);
         burnBoilEvent.setAction(() => {
             int status = 0;
             int[] BOIL = {7165, 7166, 7167};
             if (status < 3) {
                 p.getPackets().createObject(BOIL[status], new Location(x, y, 0), x == 3060 ? 3 : 1, 10);
             }
             status++;
             if (status == 1) {
                 burnBoilEvent.setTick(1300);
             }
             if (status == 3) {
                 p.setLastAnimation(new Animation(65535));
                 burnBoilEvent.setTick(1000);
             }
             if (status == 4) {
                 burnBoilEvent.stop();
                 teleportPastObstacle(p);
                 p.removeTemporaryAttribute("unmovable");
             }
         });
         Server.registerEvent(burnBoilEvent);
         return;
     });
     Server.registerCoordinateEvent(burnBoilAreaEvent);
 }
	    private void changeObject(WorldObject worldObject) {
		    if (worldObject != null) {
			    worldObject.setSecondForm(true);
			    foreach(Player p in Server.getPlayerList()) {
				    if (p != null) {
					    if (p.getLocation().withinDistance(worldObject.getLocation(), 60)) {
						    if (!worldObject.isFire()) {
							    p.getPackets().removeObject(worldObject.getLocation(), worldObject.getFace(), worldObject.getType());
							    p.getPackets().createObject(worldObject.getSecondaryId(), worldObject.getLocation(), worldObject.getFace(), worldObject.getType());
						    } else {
							    p.getPackets().createObject(worldObject.getOriginalId(), worldObject.getLocation(), worldObject.getFace(), worldObject.getType());
						    }
					    }
				    }
			    }
			    int delay = worldObject.isFire() ? (60000 + misc.random(90000)) : worldObject.getRestoreDelay(); 
                Event restoreObjectEvent = new Event(delay);
                restoreObjectEvent.setAction(() => {
					    restoreObject(worldObject);
					    restoreObjectEvent.stop();
			    });
                Server.registerEvent(restoreObjectEvent);
		    }
	    }
	    public static void enterCave(Player p) {
            AreaEvent enterCaveAreaEvent = new AreaEvent(p, 2438, 5168, 2439, 5168);
            enterCaveAreaEvent.setAction(() => {
				/*
				 * Fight cave is 20k squares from the original place, then another (200 * playerIndex) squares west.
				 */
				Location instanceLocation = new Location((20000 + 2413) + (200 * p.getIndex()), 20000 + 5116, 0);
				p.teleport(instanceLocation);
				p.setFightCave(new FightCaveSession(p));
				
                Event caveNpcEvent = new Event(600);
                caveNpcEvent.setAction(() => {
						caveNpcEvent.stop();
						p.getPackets().sendNPCHead(2617, 242, 1);
						p.getPackets().modifyText("TzHaar-Mej-Jal", 242, 3);
						p.getPackets().modifyText("You're on your own now, JalYt.", 242, 4);
						p.getPackets().modifyText("Pepare to fight for your life!", 242, 5);
						p.getPackets().animateInterface(9827, 242, 1);
						p.getPackets().sendChatboxInterface2(242);
				});
                Server.registerEvent(caveNpcEvent);
		    });
            Server.registerCoordinateEvent(enterCaveAreaEvent);
	    }