-
-
Notifications
You must be signed in to change notification settings - Fork 9
Adding a new Enemy
I chose to call "agressive NPCs": Enemies
In this article we're going to create one. BUT, do you remeber what I mentioned in the previous article?
"
You'll notice it extends NpcBase and constructs it by passing some arguments, you can inspect the code to see what each one of them mean, but the most important are the first 3:
- The tile it refers to: Npcs.CityOldMale2
- If it's agressive
- It's "name". The name is important for quests, since we use this name to know which npc is involved in certain step of the quest.
"
Well, guess what, to create an enemy you basically just follow all the previous steps, but change the second argument in the NPC's constructor to true
But let's then dive a little deeper and actually create a new NPC tile this time.
As mentioned in the previous article, the files involved in the creation of any NPC are:
- ./shared/Enums.ts
- ./client/src/entities/Npcs.ts
- ./server/entities/npcs/passive
- ./server/map/npcSpawns.ts
Go to the enum "Npcs". This enum serves as an identifier for the tile used on any npc. Now let's create an enemy called "Evil Denture". Yes, the enemy consists in crazy living teeth. That's because they belonged to Lonely Man, but for some reason pop out of his mouth and became an evil living creature.
export enum Npcs {
Dog = 1,
...
...
EvilDenture
}
Now go to ./client/src/entities/Npcs.ts and append it's color matrix (created on Tiny Tools) to this object.
Attention: the key in this object must match the NPC's id and order in the Npcs enum mentioned previously
export const Npcs = {
Dog: [ ...
...
...
EvilDenture: [[0,0,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow],
[Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.White2,Color.White2],
[Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.White2,Color.White2,Color.LightOrange,Color.LightOrange],
[Color.LightYellow,Color.LightYellow,Color.White2,Color.White2,Color.LightOrange,Color.LightOrange,Color.LightOrange,Color.White2],
[Color.White2,Color.White2,Color.LightOrange,Color.LightOrange,Color.LightOrange,Color.White2,Color.White2,Color.LightYellow],
[Color.White2,Color.White2,Color.White2,Color.White2,Color.White2,Color.LightYellow,Color.LightYellow,Color.LightYellow],
[Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,Color.LightYellow,0,0],
[0,0,0,0,0,0,0,0],],
} as any
Now let's create a new file on the server, at ./server/entities/npcs.
evilDenture.ts:
import { Npcs } from '../../Enums.ts'
import NpcBase from './npcBase.ts'
import Coffee from '../items/consumable/coffee.ts'
export default class EvilDenture extends NpcBase {
constructor() {
super(Npcs.EvilDenture, true, 'evildenture', 0, 0, 0, 1, 10000, 0.25, 6, 36, null, [new Coffee(0.4)], null)
}
}
Did you notice the second argument? true
. There's another important argument for agressive NPCs, it's 7th. There you pass the NPC level, in this case, Evil Denture is level 1. From the level, the game already calculates its stats (atk, def, xp given). You can also set some bonus stats at the 4th (bonus health), 5th (bonus atk) and 6th arguments (bonus def).
The last thing is telling where we want this NPC to be in Tiny Land. Let's go to ./server/map/npcSpawns.ts and, to the NpcSpawns
object let's put Evil Denture right above OurRoom, in Plains27:
...
...
Plains27: [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,new EvilDenture(),0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],
...
...
Notice I removed all witches and rats from there so they don't get in the way.
Now if we run yarn start
on the client and deno run --allow-net --allow-read --allow-env main.ts
on the server, and go to Plains27:
Can't believe I'm actually fighting teeth.
Okay, now we have our very own enemie, but have you noticed it drops "coffee"? How about we make it drop something more interesting?