Stendhal NPC Coding: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Kymara
No edit summary
imported>Kymara
Define NPC with Java: indentation and brackets to line up with previous half defined
Line 64: Line 64:


<source lang="java">
<source lang="java">
private void buildNPC(final StendhalRPZone zone, final Map<String, String> attributes) {
private void buildNPC(final StendhalRPZone zone, final Map<String, String> attributes) {
final SpeakerNPC npc = new SpeakerNPC("Mr Healer") {
final SpeakerNPC npc = new SpeakerNPC("Mr Healer") {
protected void createPath() {
protected void createPath() {
List<Node> nodes=new LinkedList<Node>();
List<Node> nodes=new LinkedList<Node>();
nodes.add(new Path.Node(9,5));
nodes.add(new Path.Node(9,5));
nodes.add(new Path.Node(14,5));
nodes.add(new Path.Node(14,5));
setPath(nodes,true);
setPath(nodes,true);
}
}


protected void createDialog() {
protected void createDialog() {
// Lets the NPC reply with "Hallo" when a player greets him. But we could have set one inside the ()
// Lets the NPC reply with "Hallo" when a player greets him. But we could have set one inside the ()
addGreeting();
addGreeting();
// Lets the NPC reply when a player says "job"
// Lets the NPC reply when a player says "job"
addJob("I have healing abilities and I heal wounded players. I also sell #potions and antidotes.");
addJob("I have healing abilities and I heal wounded players. I also sell #potions and antidotes.");
// Lets the NPC reply when a player asks for help
// Lets the NPC reply when a player asks for help
addHelp("Ask me to #heal you and I will help you or ask me #offer and I will show my shop's stuff.");
addHelp("Ask me to #heal you and I will help you or ask me #offer and I will show my shop's stuff.");
// Makes the NPC sell potions and antidote
// Makes the NPC sell potions and antidote
addSeller(new SellerBehaviour(shops.get("healing")));
addSeller(new SellerBehaviour(shops.get("healing")));
// Lets the NPC heal players for free
// Lets the NPC heal players for free
addHealer(0);
addHealer(0);
// respond about a special trigger word
// respond about a special trigger word
addReply("potions","Please ask for my #offer."):
addReply("potions","Please ask for my #offer."):
// use standard goodbye, but you can also set one inside the ()
// use standard goodbye, but you can also set one inside the ()
addGoodbye();
addGoodbye();
}
}
});
});


zone.assignRPObjectID(npc);
zone.assignRPObjectID(npc);
// This determines how the NPC will look like. welcomernpc.png is a picture in data/sprites/npc/
// This determines how the NPC will look like. welcomernpc.png is a picture in data/sprites/npc/
npc.setEntityClass("welcomernpc");
npc.setEntityClass("welcomernpc");
// Set the initial position to be the first node on the Path you defined above.
// Set the initial position to be the first node on the Path you defined above.
npc.setPosition(9, 5);
npc.setPosition(9, 5);
npc.initHP(100);
npc.initHP(100);


zone.add(npc);
zone.add(npc);
}
}
</source>
</source>