public void attack(Actor owner, Actor target) { if (target != null) { Destructible destructible = (Destructible)target.getComponent(typeof(Destructible)); if (destructible != null && !destructible.isDead()) { if (power - destructible.defense > 0) { if (owner != Program.engine.player) { if (target != Program.engine.player) { Message.WriteLineC(TCODColor.red, "The {0} attacks the {1} for {2} hit points.", owner.name, target.name, power - destructible.defense); } else { Message.WriteLineC(TCODColor.red, "The {0} attacks {1} for {2} hit points.", owner.name, target.name, power - destructible.defense); } } else { Message.WriteLineC(TCODColor.green, "You attack the {1} for {2} hit points.", owner.name, target.name, power - destructible.defense); } } else { if (owner != Program.engine.player) { Message.WriteLineC(TCODColor.red, "the {0} attacks the {1} but it has no effect!\n", owner.name, target.name); } else { Message.WriteLineC(TCODColor.green, "You attack the {1} for {2} hit points.\n", owner.name, target.name, power - destructible.defense); } } destructible.takeDamage(target, power); if (destructible.hp < 0) { destructible.hp = 0; } } else { if (owner != Program.engine.player) { Message.WriteLineC(TCODColor.red, "The {0} attacks {1} in vain.\n", owner.name, target.name); } else { Message.WriteLineC(TCODColor.green, "You attack the {1} for {2} hit points.\n", owner.name, target.name, power - destructible.defense); } } } }
public bool isDead() { Components.Destructible d = (Components.Destructible)getComponent(typeof(Components.Destructible)); if (d != null && !d.isDead()) { return(false); } return(true); }
public Actor getClosestMonster(int x, int y, float range) { Actor closest = null; float bestDistance = float.MaxValue; for (int i = 0; i < Program.engine.currentLevel.actorHandler.actors.Count; i++) { Actor actor = Program.engine.currentLevel.actorHandler.actors[i]; Components.Destructible d = actor.getDestructible(); if (actor != Program.engine.player && d != null && !d.isDead()) { float distance = actor.getDistance(x, y); if (distance < bestDistance && (distance <= range || range == 0.0f)) { bestDistance = distance; closest = actor; } } } return(closest); }
public bool moveOrAttack(Actor owner, int targetx, int targety) { if (Program.engine.map.isWall(targetx, targety)) { if (dig) { if (targetx < Program.engine.map.width - 1 && targety < Program.engine.map.height - 1 && targetx > 1 && targety > 1) { Program.engine.map.dig(targetx, targety, targetx, targety); Program.engine.map.updateFov = true; } else if (!noclip) { return(false); } } else if (!noclip) { return(false); } } else if (!noclip) { dig = false; } for (int i = 0; i < Program.engine.actorHandler.actors.Count; i++) { Actor a = Program.engine.actorHandler.actors[i]; Destructible d = (Destructible)a.getComponent(typeof(Destructible)); if (a.x == targetx && a.y == targety) { if (d != null && !d.isDead() && a.blocks) { if (player.mainToolSlot.item != null) { Components.Pickables.Wearable wearable = (Components.Pickables.Wearable)player.mainToolSlot.component; if (wearable != null && wearable.activeEffects.Count > 0) { foreach (Effect e in wearable.activeEffects) { e.applyTo(a); } } } Attacker att = (Attacker)a.getComponent(typeof(Attacker)); att.attack(owner, a); return(false); } if ((d != null && !d.isDead()) || a.getComponent(typeof(Components.Pickable)) != null) { Message.WriteLine("There's a {0} here", a.name); } Components.Blocks.Activatable activatable = (Blocks.Activatable)a.getComponent(typeof(Components.Blocks.Activatable)); if (activatable != null) { bool exit = activatable.activate(player); if (exit) { return(false); } } if (a.blocks) { if (autoOpen) { Blocks.Door door = (Blocks.Door)a.getComponent(typeof(Blocks.Door)); if (door != null && !door.open) { if (door.lockedLevel == 0) { door.open = true; Program.engine.map.updateFov = true; } else { Message.WriteLineC(TCODColor.lightGrey, "The door is locked"); } } open = false; } if (!noclip) { return(false); } } else { } } } // look for corpses player.x = targetx; player.y = targety; open = false; return(true); }