1
0
Quellcode durchsuchen

add `endActivity` in `$npc` and `$npcs`

Stephan Fuchs vor 10 Monaten
Ursprung
Commit
7de94b207a
2 geänderte Dateien mit 15 neuen und 0 gelöschten Zeilen
  1. 6 0
      sugarcube/src/npcs/_system/NPC.js
  2. 9 0
      sugarcube/src/npcs/_system/NPCsDict.js

+ 6 - 0
sugarcube/src/npcs/_system/NPC.js

@@ -137,6 +137,12 @@ class NPC{
 		return NPC.DICT.set(this._npcID,key,v);
 	}
 
+
+	endActivity(activity=undefined){
+		console.warn('endActivity',this);
+		return NPC.DICT.endActivity(this._npcID,activity);
+	}
+
 	constructor(npcId=undefined){
 		if(npcId)
 			this._npcID = npcId;

+ 9 - 0
sugarcube/src/npcs/_system/NPCsDict.js

@@ -639,6 +639,15 @@ class NPCsDict{
 		return locationInformation.activity.includes(activity);
 	}
 
+	endActivity(npcId,activity=undefined){
+		const currentLocationData = this.location(npcId);
+		if(activity && !this.atActivity(npcId,activity))
+			return;
+		const timeWhenNextActivityStarts = new Date(currentLocationData.end.getTime()+1);
+		this._updateLocation(npcId,timeWhenNextActivityStarts);
+		return this.location(npcId);
+	}
+
     location(npcId){
         let locationInformation = this.get(npcId,'location',{});