Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
fixes ChildrenOfUr/cou-issues#2039 (indefinite buffs don't get remove…
Browse files Browse the repository at this point in the history
…d from the db)
  • Loading branch information
RobertBlackhart committed Nov 21, 2016
1 parent b110922 commit e695781
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CAT422
Submodule CAT422 updated 7691 files
10 changes: 6 additions & 4 deletions lib/buffs/playerbuff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ class PlayerBuff extends Buff {
_updateTimer?.cancel();

// Save the current status to the database
await _write();
if (write) {
await _write();
}
}

Future remove() async {
await stopUpdating(write: false);
remaining = new Duration(milliseconds: 0);
await _write();
await _write(remove: true);
cache.remove(this);
}

Expand All @@ -108,7 +110,7 @@ class PlayerBuff extends Buff {
}));
}

Future<bool> _write() async {
Future<bool> _write({remove: false}) async {
PostgreSql dbConn = await dbManager.getConnection();
try {
// Get existing data
Expand All @@ -118,7 +120,7 @@ class PlayerBuff extends Buff {

// Modify
buffsData[id] = remaining.inSeconds;
if (!indefinite && remaining.inSeconds <= 0) {
if ((!indefinite || remove) && remaining.inSeconds <= 0) {
buffsData.remove(id);
}
String newJson = JSON.encode(buffsData);
Expand Down
8 changes: 4 additions & 4 deletions lib/entities/npcs/rube.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class Rube extends NPC with MetabolicsChange {

static Future<bool> maybeSpawn(String tsid, String username) async {
// 1% chance of spawn when the minute is the number of players online
// TODO: remove nextBool() call (it's for testing)
if (rand.nextBool() || rand.nextInt(100) == 0 && new DateTime.now().minute == PlayerUpdateHandler.users.length.clamp(0, 59)) {
if (rand.nextInt(100) == 0 && new DateTime.now().minute == PlayerUpdateHandler.users.length.clamp(0, 59)) {
Identifier target = PlayerUpdateHandler.users[username];
if (target == null) {
return false;
Expand Down Expand Up @@ -169,9 +168,10 @@ class Rube extends NPC with MetabolicsChange {
}
} else {
// Walk toward the player
facingRight = (target?.currentX ?? 0 > this.x);
num distFromTarget = this.x - (target?.currentX ?? 0);
facingRight = distFromTarget < 0;

if ((target?.currentX ?? 0 - this.x).abs() > 100) {
if (distFromTarget.abs() > 100) {
setState('walk');
speed = FOLLOW_SPEED;
} else {
Expand Down

0 comments on commit e695781

Please sign in to comment.