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:
Oskar Wiksten
2013-08-24 14:08:05 +02:00
parent d6583a4e33
commit 0212dd6bbc
6 changed files with 50 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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());
}
}
}

View File

@@ -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;

View File

@@ -8,6 +8,7 @@ public final class Reward {
,actorCondition
,alignmentChange
,giveItem
,createTimer
}
public final RewardType rewardType;