Skip to content

Commit

Permalink
Can now unequip; made equip check if weapon is already equipped
Browse files Browse the repository at this point in the history
  • Loading branch information
nenofite committed Oct 23, 2012
1 parent 377da9b commit f320625
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions wyld/ent.d
Expand Up @@ -126,6 +126,7 @@ class Player : StatEnt {
interactions = [
new PickUp(),
new Equip(),
new Unequip(),
cast(Interaction) new Drink()
];

Expand Down
30 changes: 29 additions & 1 deletion wyld/interactions.d
Expand Up @@ -86,7 +86,7 @@ class Equip : Interaction.Single {
}

bool isApplicable(Ent ent) {
return ent.container is player && ent.tags.damage > 0;
return ent.container is player && player.equipped !is ent && ent.tags.damage > 0;
}

void apply(Ent ent) {
Expand All @@ -107,3 +107,31 @@ class Equip : Interaction.Single {
}
}
}

class Unequip : Interaction.Single {
this() {
super('R', "Unequip");
}

bool isApplicable(Ent ent) {
return player.equipped is ent;
}

void apply(Ent ent) {
player.update = new UnequipUpdate(ent);
}

static class UnequipUpdate : Update {
Ent ent;

this(Ent ent) {
super(Time.fromSeconds(ent.tags.weight / 10), [], []);
this.ent = ent;
}

void apply() {
player.equipped = null;
menu.addMessage("You unequip " ~ ent.name ~ ".");
}
}
}

0 comments on commit f320625

Please sign in to comment.