@hytopia.com/examples 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "health": 130,
3
- "currentRegionId": "stalkhaven",
3
+ "currentRegionId": "stalkhaven-port",
4
4
  "skillExperience": [
5
5
  [
6
6
  "exploration",
@@ -131,10 +131,10 @@
131
131
  }
132
132
  ]
133
133
  },
134
- "currentRegionSpawnFacingAngle": 0,
134
+ "currentRegionSpawnFacingAngle": 180,
135
135
  "currentRegionSpawnPoint": {
136
- "x": 1,
137
- "y": 2,
138
- "z": 40
136
+ "x": -6,
137
+ "y": 8,
138
+ "z": -28
139
139
  }
140
140
  }
@@ -124,14 +124,14 @@ export default abstract class BaseWeaponItem extends BaseItem {
124
124
  attack.reach,
125
125
  );
126
126
 
127
- if (target && !(target instanceof GamePlayerEntity)) { // change this for PVP support later.
127
+ if (target) {
128
128
  const damage = this.calculateDamageWithVariance(attack.damage, attack.damageVariance);
129
129
  this.dealDamage(target, damage, attackDirection, attack.knockbackForce);
130
130
  }
131
131
  }
132
132
 
133
133
  protected dealDamage(target: Entity, damage: number, knockbackDirection: Vector3Like, knockbackForce?: number): void {
134
- if (!isDamageable(target)) {
134
+ if (!isDamageable(target) || target instanceof GamePlayerEntity) { // disabled instanceof for pvp support later.
135
135
  return;
136
136
  }
137
137
 
@@ -1,7 +1,10 @@
1
1
  import { Quaternion } from 'hytopia';
2
2
  import GameRegion from '../../GameRegion';
3
+ import Spawner from '../../systems/Spawner';
3
4
  import PortalEntity from '../../entities/PortalEntity';
5
+ import type { WanderOptions } from '../../entities/BaseEntity';
4
6
 
7
+ // NPCs
5
8
  import CapfolkVillagerEntity from '../../entities/npcs/CapfolkVillagerEntity';
6
9
  import CaptainSpornEntity from './npcs/CaptainSpornEntity';
7
10
  import CommanderMarkEntity from './npcs/CommanderMarkEntity';
@@ -28,6 +31,7 @@ export default class StalkhavenRegion extends GameRegion {
28
31
  super.setup();
29
32
 
30
33
  this._setupNPCs();
34
+ this._setupNPCSpawners();
31
35
  this._setupPortals();
32
36
  }
33
37
 
@@ -38,31 +42,38 @@ export default class StalkhavenRegion extends GameRegion {
38
42
  (new CommanderMarkEntity({ facingAngle: 180 })).spawn(this.world, { x: 3, y: 3, z: 12 });
39
43
  (new HealerMycelisEntity({ facingAngle: 180 })).spawn(this.world, { x: -13.5, y: 3, z: -30 });
40
44
  (new MerchantFinnEntity({ facingAngle: 90 })).spawn(this.world, { x: 13, y: 3, z: 26.5 });
45
+ }
41
46
 
42
- // Wandering Villagers
43
- const villagerStartPositions = [
44
- { x: -6, y: 3, z: 13 }, // town center
45
- { x: 14, y: 3, z: 4 }, // town center
46
- { x: -2, y: 3, z: -15 }, // town center
47
- { x: 23, y: 3, z: 41 }, // well
48
- { x: 26, y: 3, z: -22 }, // market
49
- { x: 15, y: 3, z: -30 }, // market
50
- ];
47
+ private _setupNPCSpawners(): void {
48
+ const wanderOptions: WanderOptions = {
49
+ idleMinMs: 5000,
50
+ idleMaxMs: 15000,
51
+ maxWanderRadius: 12,
52
+ moveOptions: {
53
+ moveCompletesWhenStuck: true,
54
+ moveStoppingDistance: 1,
55
+ }
56
+ }
51
57
 
52
- for (const position of villagerStartPositions) {
53
- const villager = new CapfolkVillagerEntity({ facingAngle: Math.random() * 360 });
54
- villager.spawn(this.world, position);
55
- villager.wander(villager.moveSpeed, {
56
- idleMinMs: 5000,
57
- idleMaxMs: 15000,
58
- maxWanderRadius: 12,
59
- moveOptions: {
60
- moveCompletesWhenStuck: true,
61
- moveStoppingDistance: 1,
58
+ const capfolkVillagerSpawner = new Spawner({
59
+ groundCheckDistance: 10,
60
+ maxSpawns: 10,
61
+ spawnables: [
62
+ { entityConstructor: CapfolkVillagerEntity, weight: 1, wanders: true, wanderOptions },
63
+ ],
64
+ spawnRegions: [
65
+ {
66
+ min: { x: -24, y: 2, z: -29 },
67
+ max: { x: 29, y: 12, z: 38 },
68
+ weight: 1,
62
69
  }
63
- });
64
- }
65
- }
70
+ ],
71
+ spawnIntervalMs: 60000,
72
+ world: this.world,
73
+ });
74
+
75
+ capfolkVillagerSpawner.start(true);
76
+ }
66
77
 
67
78
  private _setupPortals(): void {
68
79
  const chitterForestPortal = new PortalEntity({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hytopia.com/examples",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",