/**
  * Constructs new <tt>SM_NPC_INFO </tt> packet
  *
  * @param npc visible npc.
  * @param player
  */
 public SM_NPC_INFO(Npc npc, Player player) {
   this.npc = npc;
   npcTemplate = npc.getObjectTemplate();
   if (npcTemplate.getNpcType() == NpcType.NEUTRAL
       || npcTemplate.getNpcType() == NpcType.ARTIFACT) {
     if (player.isAggroIconTo(npc.getTribe())) npcTypeId = NpcType.NEUTRAL.getId();
     else npcTypeId = NpcType.NON_ATTACKABLE.getId();
   } else {
     npcTypeId =
         (player.isAggroIconTo(npc.getTribe())
             ? NpcType.AGGRESSIVE.getId()
             : npcTemplate.getNpcType().getId());
   }
   npcId = npc.getNpcId();
 }
Example #2
0
 /**
  * On touch remove top touched npc and create a death effect on the touched spot. Trigger
  * GameState.END if the last Demon or Human was killed
  *
  * @param touchX
  * @param touchY
  * @return enum value that shows if some game element was actually touched or not
  */
 public TouchedElement onTouchEvent(float touchX, float touchY) {
   TouchedElement result = TouchedElement.NONE;
   if (mGameState == GameState.RUNNING) {
     Npc touchedNpc = mNpcContainer.removeTopTouchedNpc(touchX, touchY);
     if (touchedNpc != null) {
       boolean isDemon = touchedNpc.getNpcType().isEnemy();
       updateScore(touchedNpc);
       // Create a new death effect at the location of the killed npc
       mDeathEffectContainer.createDeathEffect(
           touchedNpc.getCenterX(), touchedNpc.getCenterY(), isDemon);
       if (isDemon) {
         result = TouchedElement.DEMON;
       } else {
         result = TouchedElement.HUMAN;
       }
     }
     checkForGameEnd();
   }
   return result;
 }
  /** Parse npcsJSON array and create the amount of npcs needed into npcsEntities */
  public void createNpcs() {
    try {
      /*
       * For each entry in Npcs JSON Array
       */
      for (int i = 0; i < npcsJSON.length(); i++) {
        int npcID = npcsJSON.getJSONObject(i).getInt("npcID");
        int amount = npcsJSON.getJSONObject(i).getInt("count");

        // This has int npcID, String name, Ship ship,  int averageDamage, int shieldAbsorb
        Npc npcTemplate = GameManager.getNpc(npcID);

        // If something went wrong because the npc doesn't exists in the templates
        if (npcTemplate != null) {
          for (int j = 0; j < amount; j++) {

            // Because all the npcs will have negative ID's
            int entityID = -(mapCharacterEntities.size() + 1);

            Npc createdNpc =
                new Npc(
                    entityID,
                    npcID,
                    npcTemplate.getName(),
                    npcTemplate.getShip(),
                    new Point(0, 0), // TODO add random spawn
                    mapID,
                    npcTemplate.getShip().getShipHealth(),
                    npcTemplate.getActualNanohull(),
                    npcTemplate.getAverageDamage(),
                    npcTemplate.getShieldAbsorb());
            // adds the npc to the map
            addEntity(createdNpc);
          }
        }
      }
    } catch (JSONException e) {
      Console.error(
          "Something went wrong reading the Npcs JSONArray in Spacemap.createNpcs()",
          e.getMessage());
    }
  }
Example #4
0
 public void handleNpc(final Npc npc, final Player player) throws Exception {
   if (player.getDemonSlayerStatus() == 6) { // Quest Complete
     player.informOfNpcMessage(
         new ChatMessage(
             npc,
             "Well done brave adventurer. You surely showed Delrith who is boss around here!",
             player));
     return;
   }
   if (player.getDemonSlayerStatus() == 5) { // Got the silverlight
     player.informOfNpcMessage(
         new ChatMessage(npc, "Please go slay Delrith with the silverlight!", player));
     return;
   }
   if (player.getDemonSlayerStatus() == 4) {
     player.informOfNpcMessage(
         new ChatMessage(
             npc,
             "Perhaps you should get all the keys to Sir Prysin as soon as possible!",
             player));
     return;
   }
   if (player.getDemonSlayerStatus() == 0) {
     player.informOfNpcMessage(
         new ChatMessage(
             npc, "Go speak with the gypsy. She looks like she's in trouble!", player));
     return;
   }
   if (player.getDemonSlayerStatus() == 1) {
     player.informOfNpcMessage(
         new ChatMessage(
             npc, "I heard Delrith is around town. Go find and inform Sir Prysin!", player));
     return;
   }
   if (player.getDemonSlayerStatus() == 3) {
     player.informOfNpcMessage(
         new ChatMessage(
             npc, "Take the keys back to Sir Prysin to recieve the silverlight sword!", player));
     return;
   }
   if (player.getDemonSlayerStatus() == 2) {
     player.informOfNpcMessage(new ChatMessage(npc, "How can I help you?", player));
     world
         .getDelayedEventHandler()
         .add(
             new ShortEvent(player) {
               public void action() {
                 String[] option =
                     new String[] {
                       "What are you doing up here?",
                       "I am looking for the silverlight key",
                       "You can't help me"
                     };
                 player.setMenuHandler(
                     new MenuHandler(option) {
                       public void handleReply(final int option, final String reply) {
                         if (player.isBusy()) {
                           return;
                         }
                         player.informOfChatMessage(new ChatMessage(player, reply, npc));
                         player.setBusy(true);
                         world
                             .getDelayedEventHandler()
                             .add(
                                 new ShortEvent(player) {
                                   public void action() {
                                     player.setBusy(false);
                                     if (option == 2) { // Nothing
                                       player.informOfNpcMessage(
                                           new ChatMessage(
                                               npc,
                                               "Then go away! I need to keep the guards in order!",
                                               player));
                                       return;
                                     }
                                     if (option == 0) { // What are you doing up here
                                       player.informOfNpcMessage(
                                           new ChatMessage(
                                               npc,
                                               "I am training these guards and keeping them in top shape!",
                                               player));
                                       return;
                                     }
                                     if (option == 1) { // Looking for the key
                                       player.informOfNpcMessage(
                                           new ChatMessage(
                                               npc,
                                               "Ah, yes. Sir Prysin informed of you would be coming to see me",
                                               player));
                                       world
                                           .getDelayedEventHandler()
                                           .add(
                                               new ShortEvent(player) {
                                                 public void action() {
                                                   player.informOfNpcMessage(
                                                       new ChatMessage(
                                                           npc,
                                                           "The Delrith is no push over, I hope you know what you are getting into",
                                                           player));
                                                   world
                                                       .getDelayedEventHandler()
                                                       .add(
                                                           new ShortEvent(player) {
                                                             public void action() {
                                                               player.informOfChatMessage(
                                                                   new ChatMessage(
                                                                       player,
                                                                       "Let me worry about defeating the Delrith. You stick to coaching the guards!",
                                                                       npc));
                                                               world
                                                                   .getDelayedEventHandler()
                                                                   .add(
                                                                       new ShortEvent(player) {
                                                                         public void action() {
                                                                           player
                                                                               .informOfNpcMessage(
                                                                                   new ChatMessage(
                                                                                       npc,
                                                                                       "Ok soldier! Here's the key!",
                                                                                       player));
                                                                           player
                                                                               .getInventory()
                                                                               .add(
                                                                                   new InvItem(
                                                                                       26, 1));
                                                                           player
                                                                               .getActionSender()
                                                                               .sendInventory();
                                                                           player
                                                                               .setDemonSlayerStatus(
                                                                                   3);
                                                                           npc.unblock();
                                                                         }
                                                                       });
                                                             }
                                                           });
                                                 }
                                               });
                                     }
                                   }
                                 });
                       }
                     });
                 owner.getActionSender().sendMenu(option);
               }
             });
     npc.blockedBy(player);
   }
 }
Example #5
0
 /**
  * Calculates the game score, based on the type of the killed Npc
  *
  * @param isDemon
  */
 private void updateScore(Npc touchedNpc) {
   mScore += touchedNpc.getScore();
   updateScoreView();
 }
Example #6
0
  public void handleAction(QuestAction action, Object[] args, final Player player) {
    int stage = player.getQuestStage(this);

    if (stage == -1) // Quest hasn't been started
    {
      if (action == action.TALKED_NPC) {
        if (!(args[0] instanceof Npc)) return;

        final Npc npc = (Npc) args[0];

        if (npc.getID() != FRED_ID) return;

        player.setBusy(true);
        npc.blockedBy(player);

        sendChat("Hi there, traveller. Care to make some money?", npc, player);

        addSingleEvent(
            new SingleEvent(player, 2000) {
              public void action() {
                player.setBusy(false);
                player.setMenuHandler(
                    new MenuHandler(FIRST_MENU) {
                      public void handleReply(final int option, final String reply) {
                        player.setBusy(true);
                        switch (option) {
                          case 1:
                            player.setBusy(false);
                            npc.unblock();
                            sendChat("No thanks, I'm good.", player, npc);
                            break;
                          case 0:
                            sendChat("Sure, what do I need to do?", player, npc);
                            addSingleEvent(
                                new SingleEvent(player, 2000) {
                                  public void action() {
                                    sendChat(
                                        "If you collect 20 balls of wool for me, I'll pay you 500 coins.",
                                        npc,
                                        player);
                                    addSingleEvent(
                                        new SingleEvent(player, 2000) {
                                          public void action() {
                                            sendChat(
                                                "Maybe I'll teach you a thing or two about crafting, too.",
                                                npc,
                                                player);
                                            addSingleEvent(
                                                new SingleEvent(player, 2000) {
                                                  public void action() {
                                                    sendChat(
                                                        "I'm afraid you'll have to find your own shears, but the sheep are outside.",
                                                        npc,
                                                        player);
                                                    addSingleEvent(
                                                        new SingleEvent(player, 2000) {
                                                          public void action() {
                                                            player.setBusy(false);
                                                            player.setMenuHandler(
                                                                new MenuHandler(SECOND_MENU) {
                                                                  public void handleReply(
                                                                      final int option,
                                                                      final String reply) {
                                                                    player.setBusy(true);
                                                                    switch (option) {
                                                                      case 1:
                                                                        sendChat(
                                                                            "I'd be happy to help.",
                                                                            player,
                                                                            npc);
                                                                        addSingleEvent(
                                                                            new SingleEvent(
                                                                                player, 2000) {
                                                                              public void action() {
                                                                                sendChat(
                                                                                    "Great! Come back and see me when you're done.",
                                                                                    npc,
                                                                                    player);
                                                                                addSingleEvent(
                                                                                    new SingleEvent(
                                                                                        player,
                                                                                        2000) {
                                                                                      public void
                                                                                          action() {
                                                                                        player
                                                                                            .setQuestStage(
                                                                                                getUniqueID(),
                                                                                                1);
                                                                                        player
                                                                                            .setBusy(
                                                                                                false);
                                                                                        npc
                                                                                            .unblock();
                                                                                      }
                                                                                    });
                                                                              }
                                                                            });
                                                                        break;
                                                                      case 0:
                                                                        sendChat(
                                                                            "Sorry, I don't like the sound of that.",
                                                                            player,
                                                                            npc);
                                                                        addSingleEvent(
                                                                            new SingleEvent(
                                                                                player, 2000) {
                                                                              public void action() {
                                                                                sendChat(
                                                                                    "Suit yourself. Come and see me if you change your mind.",
                                                                                    npc,
                                                                                    player);
                                                                                player.setBusy(
                                                                                    false);
                                                                                npc.unblock();
                                                                              }
                                                                            });
                                                                        break;
                                                                      default:
                                                                        player.setBusy(false);
                                                                        npc.unblock();
                                                                        break;
                                                                    }
                                                                  }
                                                                });
                                                            owner
                                                                .getActionSender()
                                                                .sendMenu(SECOND_MENU);
                                                          }
                                                        });
                                                  }
                                                });
                                          }
                                        });
                                  }
                                });
                            break;
                          default:
                            player.setBusy(false);
                            npc.unblock();
                            break;
                        }
                      }
                    });
                owner.getActionSender().sendMenu(FIRST_MENU);
              }
            });
      } else return;
    } else if (stage == 1) {
      if (action == action.TALKED_NPC) {
        if (!(args[0] instanceof Npc)) return;

        final Npc npc = (Npc) args[0];

        if (npc.getID() != FRED_ID) return;

        player.setBusy(true);
        npc.blockedBy(player);
        sendChat("Ahh, you've returned! Do you have my wool?", npc, player);

        addSingleEvent(
            new SingleEvent(player, 2000) {
              public void action() {
                player.setBusy(false);
                player.setMenuHandler(
                    new MenuHandler(new String[] {"I'm afraid not.", "Yes, I do."}) {
                      public void handleReply(final int option, final String reply) {
                        player.setBusy(true);
                        sendChat(reply, player, npc);

                        if (option == 0) {
                          addSingleEvent(
                              new SingleEvent(player, 2000) {
                                public void action() {
                                  sendChat(
                                      "Well, come and see me when you do. The offer still stands",
                                      npc,
                                      player);
                                  player.setBusy(false);
                                  npc.unblock();
                                }
                              });
                        } else if (option == 1) {
                          addSingleEvent(
                              new SingleEvent(player, 2000) {
                                public void action() {
                                  // check items
                                  if (player.getInventory().hasItemId(ITEM_WOOL)
                                      && player.getInventory().countId(ITEM_WOOL) >= 20) {
                                    finishQuest(player, npc);
                                  } else {
                                    sendChat(
                                        "Um, no you don't. Get back to me when you do. The reward still stands!",
                                        npc,
                                        player);
                                    player.setBusy(false);
                                    npc.unblock();
                                  }
                                }
                              });
                        }
                      }
                    });

                owner.getActionSender().sendMenu(new String[] {"I'm afraid not.", "Yes, I do."});
              }
            });
      }
    } else if (stage == 0) {
      if (action == action.TALKED_NPC) {
        if (!(args[0] instanceof Npc)) return;

        final Npc npc = (Npc) args[0];

        if (npc.getID() != FRED_ID) return;

        player.setBusy(true);
        npc.blockedBy(player);
        sendChat("Hello " + player.getUsername() + "!", npc, player);
        player.setBusy(false);
        npc.unblock();
      }
    }
  }