mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-02 06:51:20 +01:00
Add world timers and world time (counted in number of rounds)
* Increase world time each round. * Add script reward "createTimer" * Add script requirement "timerElapsed"
This commit is contained in:
@@ -69,6 +69,9 @@ public final class ConversationController {
|
||||
case giveItem:
|
||||
addItemReward(reward.rewardID, reward.value, result);
|
||||
break;
|
||||
case createTimer:
|
||||
world.model.worldData.createTimer(reward.rewardID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +168,8 @@ public final class ConversationController {
|
||||
return player.getSkillLevel(SkillCollection.SkillID.valueOf(requirement.requireID)) >= requirement.value;
|
||||
case killedMonster:
|
||||
return world.model.statistics.getNumberOfKillsForMonsterType(requirement.requireID) >= requirement.value;
|
||||
case timerElapsed:
|
||||
return world.model.worldData.hasTimerElapsed(requirement.requireID, requirement.value);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public final class GameRoundController implements TimedMessageTask.Callback {
|
||||
gameRoundListeners.onNewRound();
|
||||
}
|
||||
public void onNewPlayerRound() {
|
||||
world.model.worldData.tickWorldTime();
|
||||
controllers.actorStatsController.applyConditionsToPlayer(world.model.player, false);
|
||||
controllers.actorStatsController.applySkillEffectsForNewRound(world.model.player, world.model.currentMap);
|
||||
controllers.mapController.handleMapEvents(world.model.currentMap, world.model.player.position, MapObject.MapObjectEvaluationType.afterEveryRound);
|
||||
|
||||
@@ -133,6 +133,7 @@ public final class MapController {
|
||||
m.resetTemporaryData();
|
||||
}
|
||||
controllers.monsterSpawnController.spawnAll(world.model.currentMap, world.model.currentTileMap);
|
||||
world.model.worldData.tickWorldTime(20);
|
||||
controllers.gameRoundController.resetRoundTimers();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,57 @@ package com.gpl.rpg.AndorsTrail.model;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class WorldData {
|
||||
private long worldTime = 0; // Measured in number of game rounds
|
||||
private final HashMap<String, Long> timers = new HashMap<String, Long>();
|
||||
|
||||
public WorldData() {}
|
||||
|
||||
public void tickWorldTime() {
|
||||
++worldTime;
|
||||
}
|
||||
public void tickWorldTime(int ticks) {
|
||||
worldTime += ticks;
|
||||
}
|
||||
public long getWorldTime() {
|
||||
return worldTime;
|
||||
}
|
||||
|
||||
public void createTimer(String name) {
|
||||
timers.put(name, worldTime);
|
||||
}
|
||||
|
||||
public void removeTimer(String name) {
|
||||
timers.remove(name);
|
||||
}
|
||||
|
||||
public boolean hasTimerElapsed(String name, long duration) {
|
||||
Long v = timers.get(name);
|
||||
if (v == null) return false;
|
||||
return v + duration <= worldTime;
|
||||
}
|
||||
|
||||
// ====== PARCELABLE ===================================================================
|
||||
|
||||
public WorldData(DataInputStream src, int fileversion) throws IOException {
|
||||
worldTime = src.readLong();
|
||||
final int numTimers = src.readInt();
|
||||
for(int i = 0; i < numTimers; ++i) {
|
||||
final String timerName = src.readUTF();
|
||||
final long value = src.readLong();
|
||||
this.timers.put(timerName, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToParcel(DataOutputStream dest, int flags) throws IOException {
|
||||
dest.writeLong(worldTime);
|
||||
dest.writeInt(timers.size());
|
||||
for(Map.Entry<String, Long> e : timers.entrySet()) {
|
||||
dest.writeUTF(e.getKey());
|
||||
dest.writeLong(e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public final class Requirement {
|
||||
,wear // Player must be wearing item(s). Items will NOT be removed when selecting reply.
|
||||
,skillLevel // Player needs to have a specific skill equal to or above a certain level
|
||||
,killedMonster
|
||||
,timerElapsed
|
||||
}
|
||||
|
||||
public final RequirementType requireType;
|
||||
|
||||
@@ -8,6 +8,7 @@ public final class Reward {
|
||||
,actorCondition
|
||||
,alignmentChange
|
||||
,giveItem
|
||||
,createTimer
|
||||
}
|
||||
|
||||
public final RewardType rewardType;
|
||||
|
||||
Reference in New Issue
Block a user