Skip to content

Commit

Permalink
Made things equippable via interaction, weapons used in combat
Browse files Browse the repository at this point in the history
  • Loading branch information
nenofite committed Oct 15, 2012
1 parent c04a866 commit dae8dbf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
4 changes: 3 additions & 1 deletion wyld/core/ent.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module wyld.core.ent;
import wyld.core.common;
import wyld.core.menu;
import wyld.core.world;
import wyld.ent;
import wyld.main;


Expand Down Expand Up @@ -99,7 +100,8 @@ abstract class Ent {

bool stick, bigStick, sharp, bigSharp, tie;

int damage;
int damage, accuracy;
Attack.Type damageType;

// TODO finish transferring tags
}
Expand Down
37 changes: 36 additions & 1 deletion wyld/ent.d
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ abstract class StatEnt : DynamicEnt {
class Player : StatEnt {
Interaction[] interactions;
Recipe[] recipes;
Ent equipped;

this(Coord coord) {
Tags tags;
Expand All @@ -117,6 +118,7 @@ class Player : StatEnt {

interactions = [
new PickUp(),
new Equip(),
cast(Interaction) new Drink()
];

Expand Down Expand Up @@ -147,7 +149,11 @@ class Player : StatEnt {
if (ent.coord == newCoord) {
StatEnt statEnt = cast(StatEnt)ent;
if (statEnt !is null) {
update = (new Punch(this, statEnt)).update();
if (equipped !is null) {
update = (new WeaponAttack(this, statEnt)).update();
} else {
update = (new Punch(this, statEnt)).update();
}
return;
}
}
Expand Down Expand Up @@ -180,6 +186,31 @@ class Player : StatEnt {
return new SimpleCoordMessage(msg, from.coord);
}
}

static class WeaponAttack : Attack {
Player from;
Ent weapon;

this(Player from, StatEnt to) {
this.from = from;
weapon = from.equipped;
assert(weapon !is null);
this.to = to;
type = weapon.tags.damageType;
damage = weapon.tags.damage;
accuracy = weapon.tags.accuracy;
}

Update update() {
int time = Time.fromSeconds(weapon.tags.weight / 10);
return Attack.update(time);
}

Message message() {
string msg = "You use " ~ weapon.name ~ " on " ~ to.name ~ ".";
return new SimpleCoordMessage(msg, from.coord);
}
}
}


Expand Down Expand Up @@ -602,6 +633,8 @@ class Spear : Ent {
tags.weight = weight;
tags.bigStick = true;
tags.damage = 10;
tags.accuracy = 6;
tags.damageType = Attack.Type.Sharp;

super("spear", Sym('/', Color.Blue), tags, coord);
}
Expand Down Expand Up @@ -638,6 +671,8 @@ class Stick : Ent {
tags.weight = 15;
tags.bigStick = true;
tags.damage = 8;
tags.accuracy = 4;
tags.damageType = Attack.Type.Blunt;

super("wooden stick", Sym('/', Color.Yellow), tags, coord);
}
Expand Down
28 changes: 28 additions & 0 deletions wyld/interactions.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,31 @@ class PickUp : Interaction.Single {
};
}
}

class Equip : Interaction.Single {
this() {
super('E', "Equip");
}

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

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

static class EquipUpdate : Update {
Ent ent;

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

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

0 comments on commit dae8dbf

Please sign in to comment.