public void giveItems(int itemId, long count, Element element, int power) { Player player = getPlayer(); if (player == null) { return; } if (count <= 0) { count = 1; } // Get template of item ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId); if (template == null) { return; } for (int i = 0; i < count; i++) { ItemInstance item = ItemFunctions.createItem(itemId); if (element != Element.NONE) { item.setAttributeElement(element, power); } // Add items to player's inventory player.getInventory().addItem(item); } player.sendPacket(SystemMessage2.obtainItems(template.getItemId(), count, 0)); player.sendChanges(); }
/** * Destroy element used by quest when quest is exited * * @param repeatable * @return QuestState */ public QuestState exitCurrentQuest(boolean repeatable) { Player player = getPlayer(); if (player == null) { return this; } removePlayerOnKillListener(); // Clean drops for (int itemId : _quest.getItems()) { // Get [item from] / [presence of the item in] the inventory of the player ItemInstance item = player.getInventory().getItemByItemId(itemId); if ((item == null) || (itemId == 57)) { continue; } long count = item.getCount(); // If player has the item in inventory, destroy it (if not gold) player.getInventory().destroyItemByItemId(itemId, count); player.getWarehouse().destroyItemByItemId(itemId, count); // TODO [G1ta0] analyze this } // If quest is repeatable, delete quest from list of quest of the player and from database // (quest CAN be created again => repeatable) if (repeatable) { player.removeQuestState(_quest.getName()); Quest.deleteQuestInDb(this); _vars.clear(); } else { // Otherwise, delete variables for quest and update database (quest CANNOT be created // again => not repeatable) for (String var : _vars.keySet()) { if (var != null) { unset(var); } } setState(Quest.COMPLETED); Quest.updateQuestInDb(this); // FIXME: оно вроде не нужно? } if (isCompleted()) { // WorldStatisticsManager.getInstance().updateStat(player, CategoryType.QUESTS_COMPLETED,0, // 1); } player.sendPacket(new QuestList(player)); return this; }
public long getSumQuestItemsCount(int... itemIds) { Player player = getPlayer(); if (player == null) { return 0; } long count = 0; for (int itemId : itemIds) { count += player.getInventory().getCountOf(itemId); } return count; }
public boolean checkQuestItemsCount(int... itemIds) { Player player = getPlayer(); if (player == null) { return false; } for (int itemId : itemIds) { if (player.getInventory().getCountOf(itemId) <= 0) { return false; } } return true; }
/** * Удаляет указанные предметы из инвентаря игрока, и обновляет инвентарь * * @param itemId : id удаляемого предмета * @param count : число удаляемых предметов<br> * Если count передать -1, то будут удалены все указанные предметы. * @return Количество удаленных предметов */ public long takeItems(int itemId, long count) { Player player = getPlayer(); if (player == null) { return 0; } // Get object item from player's inventory list ItemInstance item = player.getInventory().getItemByItemId(itemId); if (item == null) { return 0; } // Tests on count value in order not to have negative value if ((count < 0) || (count > item.getCount())) { count = item.getCount(); } // Destroy the quantity of items wanted player.getInventory().destroyItemByItemId(itemId, count); // Send message of destruction to client player.sendPacket(SystemMessage2.removeItems(itemId, count)); return count; }
public String getDeathmatchScoreboardMessage( GameObject victim, GameObject killer, boolean inIntermission ) { int xOffset, statHeader, statCaps, headerIndex; String s; Team otherTeam; otherTeam = ( this == TEAM1 ? TEAM2 : TEAM1 ); xOffset = ( this == TEAM1 ? 0 : 160 ); statHeader = ( this == TEAM1 ? STAT_CTF_TEAM1_HEADER : STAT_CTF_TEAM2_HEADER ); headerIndex = ( this == TEAM1 ? Engine.getImageIndex("ctfsb1") : Engine.getImageIndex("ctfsb2") ); statCaps = ( this == TEAM1 ? STAT_CTF_TEAM1_CAPS : STAT_CTF_TEAM2_CAPS ); // display our teamheader victim.fEntity.setPlayerStat( statHeader, (short)headerIndex ); /* // if during intermission, we must blink our header if we're the winning team (or tie) if ( inIntermission && ((int)Game.getGameTime()%2 == 0 ) ) // blink every second { if ( this.getCaptures() > otherTeam.getCaptures() ) victim.fEntity.setPlayerStat( statHeader, (short)0 ); // Capture tie, check total frags else if ( this.getScore() >= otherTeam.getScore() ) victim.fEntity.setPlayerStat( statHeader, (short)0 ); } */ s = "if " + statHeader + " xv " + (8+xOffset) + " yv 8 pic " + statHeader + " endif " + "xv " + (40+xOffset) + " yv 28 string \"" + getScore() + "/" + fCaptures + "\" " + "xv " + (98+xOffset) + " yv 12 num 2 " + statCaps + " "; // TODO: sort players by score Player[] players = getPlayers(); /* int begin = 0; int i = begin; while ( i < players.length-1 ) { if ( players[i].getScore() < players[i+1].getScore() ) { Player dummy = players[i]; players[i] = players[i+1]; players[i+1] = dummy; } if ( i == players.length-2 ) i = ++begin; } */ for ( int i=0; i<8 && i<players.length; i++ ) { Player p = players[i]; int ping = Math.min( p.fEntity.getPlayerPing(), 999 ); s += "ctf " + xOffset + " " + (42+i*8) + " " + p.fEntity.getPlayerNum() + " " + p.getScore() + " " + ping + " "; GenericFlag flag = (GenericFlag)p.getInventory( "flag" ); if ( flag != null ) // flag IS other teams flag... { s += "xv " + (56+xOffset) + " picn " + flag.getSmallIconName() + " "; } } if ( players.length > 8 ) { s += "xv " + (8+xOffset) + " yv " + (42+8*8) + " string \"...and " + (players.length-8) + " more\" "; } return s; }
static boolean goblinChase(Player player) { String playerInput = ""; System.out.println("As you enter the room a goblin jumps out of the darkness and runs at you."); System.out.println("You feel the urge to either fight or run."); for (int i = 5; i > 0; i--) { Scanner input = new Scanner(System.in); playerInput = input.next(); switch (playerInput.toLowerCase()) { case "north": player.moveTo(player.getLocation().north()); break; case "south": player.moveTo(player.getLocation().south()); break; case "east": player.moveTo(player.getLocation().east()); break; case "west": player.moveTo(player.getLocation().west()); break; case "look": player.look(); break; case "drop": player.drop(input.next()); break; case "pickup": player.pickup(input.next()); break; case "inventory": player.inventory(); break; case "quit": return false; case "xyzzy": if (player.getLocation().getName().equals("Room 5")) { System.out.println( "A red portal opens in front of you, and you walk into it without thinking. \n You are still inside the cave. You see a chest in the center of the room."); player.moveTo(player.getLocation().xyzzy()); } else { System.out.println("Nothing happens."); } break; case "help": printInstructions(); break; case "use": switch (input.next()) { case "man": if (player.getLocation().getName().equals("Room 1")) { player.use(); } case "well": if (player.getLocation().getName().equals("Room 7")) { player.use(); } case "skeleton": if (player.getLocation().getName().equals("Room 2")) { player.use(); } case "writing": if (player.getLocation().getName().equals("Room 8")) { player.use(); } case "ears": if (player.getLocation().getName().equals("Room 3")) { player.use(); } case "chest": if (player.getLocation().getName().equals("Room 6")) { player.use(); } } case "fight": if (player.getInventory().contains("sword")) { System.out.println("You decide to turn and fight."); System.out.println( "You pull out the sword you picked up earlier, the only weapon you have."); System.out.println( "As the goblin charges, you stand your ground and take a fighting stance."); System.out.println( "You plunge your sword into the goblin's chest with one decisive thrust."); System.out.println( "The goblin falls to the ground in front of you as you pull out the bloody sword."); System.out.println("You examine the body. The goblin is dead."); player.getLocation().drop("goblin"); return true; } else { if (player.getLocation().getName().equals("Room 7")) { System.out.println("You decide to turn and fight."); System.out.println("As the goblin charges, you swing at him with all of your might."); System.out.println("The goblin is knocked back slightly and trips over a rock."); System.out.println( "The goblin falls into the well situated in the center of the room."); System.out.println("As he falls you hear him screech, and eventually a loud THUNK!"); System.out.println( "You approach the well and look inside it, but you can't see anything, even with the lamp."); return true; } else { if (1 == 1) { System.out.println("The goblin grabs you and tears your arm off."); System.out.println( "Wounded, you slowly bleed out as you watch the goblin eat your severed arm."); return false; } } } break; default: System.out.println("What?"); } switch (i) { case 5: System.out.println( "The goblin seems dazed by the light of the lantern and trips over a rock."); break; case 4: System.out.println("The goblin gets up and persues you."); break; case 3: System.out.println( "You try to escape the goblin's pursuit, but he is slowly getting closer."); ; break; case 2: System.out.println("The goblin has nearly caught up to you."); break; case 1: System.out.println("The goblin is right behind you, there is no hope for escape."); break; } } System.out.println("The goblin grabs you and tears your arm off."); System.out.println( "Wounded, you slowly bleed out as you watch the goblin eat your severed arm."); return false; }
/** * Return the quantity of one sort of item hold by the player * * @param itemId : ID of the item wanted to be count * @return int */ public long getQuestItemsCount(int itemId) { Player player = getPlayer(); return player == null ? 0 : player.getInventory().getCountOf(itemId); }
public boolean hasQuestItems(int itemId) { return _player.getInventory().getItemByItemId(itemId) != null; }