1
0
Prechádzať zdrojové kódy

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

Stephan Fuchs 10 mesiacov pred
rodič
commit
7de94b207a

+ 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',{});