Exemple #1
0
        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);
        }
Exemple #2
0
        public void handleActionKey(TCODKey key)
        {
            bool nextTurn = false;

            switch (key.KeyCode)
            {
            case TCODKeyCode.Escape:
            {
                if (dig)
                {
                    dig = false;
                }
                else if (inventory)
                {
                    inventory = false;
                }
                else if (Program.engine.gameStatus != GameStatus.MENU)
                {
                    Program.engine.gameStatus = GameStatus.MENU;
                }

                break;
            }
            }
            if (controls.ContainsKey(key.Character))
            {
                string control = controls[key.Character].ToLower();

                if (!inventory)
                {
                    switch (control)
                    {
                    case "use":
                    {
                        Container c = (Container)player.getComponent(typeof(Container));
                        if (c.inventory.Count > 0)
                        {
                            Pickable p = (Pickable)c.inventory[player.containerGui.selectedLineNum].getComponent(typeof(Pickable));
                            if (p != null)
                            {
                                p.use(player);
                                nextTurn = true;
                                break;
                            }

                            if (nextTurn == true)         //item has been consumed
                            {
                                break;
                            }
                        }

                        Message.WriteLine("You have no items to use");
                        break;
                    }

                    case "dig":
                    {
                        dig = true;
                        break;
                    }

                    case "open":
                    {
                        foreach (Actor a in Program.engine.actorHandler.actors)
                        {
                            double distance = Math.Sqrt(Math.Pow(owner.x - a.x, 2) + Math.Pow(owner.y - a.y, 2));
                            if (distance < 2)
                            {
                                Blocks.Door door = (Blocks.Door)a.getComponent(typeof(Blocks.Door));
                                if (door != null && !door.open)
                                {
                                    if (door.lockedLevel == 0)
                                    {
                                        door.open = true;
                                        door.update(false);
                                        nextTurn = true;
                                    }
                                    else
                                    {
                                        Message.WriteLineC(TCODColor.lightGrey, "The door is locked");
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case "close":
                    {
                        foreach (Actor a in Program.engine.actorHandler.actors)
                        {
                            double distance = Math.Sqrt(Math.Pow(owner.x - a.x, 2) + Math.Pow(owner.y - a.y, 2));
                            if (distance < 2)
                            {
                                Blocks.Door door = (Blocks.Door)a.getComponent(typeof(Blocks.Door));
                                if (door != null && door.open)
                                {
                                    door.lockedLevel = 0;
                                    door.open        = false;
                                    door.update(false);
                                    nextTurn = true;
                                }
                            }
                        }
                        break;
                    }

                    case "inventory":
                    {
                        inventory = !inventory;

                        player.containerGui.selected = inventory;
                        break;
                    }

                    case "heal":
                    {
                        Container c = (Container)player.getComponent(typeof(Container));
                        for (int i = 0; i < c.inventory.Count; i++)
                        {
                            Pickable p = (Pickable)c.inventory[i].getComponent(typeof(Pickable));
                            if (p != null)
                            {
                                if (p.activeEffects != null && p.activeEffects.Count > 0)
                                {
                                    foreach (Effect e in p.activeEffects)
                                    {
                                        if (e.GetType() == typeof(Effects.HealthEffect))
                                        {
                                            Effects.HealthEffect h = (Effects.HealthEffect)e;
                                            if (h.amount > 0)
                                            {
                                                nextTurn = true;
                                                player.getDestructible().heal(h.amount);
                                                Message.WriteLine("You used the " + c.inventory[i].name);
                                                c.remove(c.inventory[i]);
                                                break;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                        if (nextTurn == true)         //item has been consumed
                        {
                            break;
                        }
                        else
                        {
                            Message.WriteLine("You have no healing consumables to use");
                        }

                        break;
                    }

                    case "grab":
                    {
                        nextTurn = true;
                        bool found = false;
                        for (int i = 0; i < Program.engine.actorHandler.actors.Count; i++)
                        {
                            if (i < Program.engine.actorHandler.actors.Count)
                            {
                                Actor    a = Program.engine.actorHandler.actors[i];
                                Pickable c = (Pickable)a.getComponent(typeof(Pickable));

                                if (c != null && a.x == owner.x && a.y == owner.y)
                                {
                                    if (c.pick(owner))
                                    {
                                        found = true;
                                        Message.WriteLineC(TCODColor.lightGrey, "You pick up the {0}.",
                                                           a.name);

                                        if (tryWear(owner, a))
                                        {
                                            Message.WriteLineC(TCODColor.lightGrey, "You wear the {0}.",
                                                               a.name);
                                        }

                                        break;
                                    }
                                    else if (!found)
                                    {
                                        found = true;
                                        Message.WriteLineC(TCODColor.red, "Your inventory is full.");
                                    }
                                }
                            }
                        }
                        if (!found)
                        {
                            Message.WriteLineC(TCODColor.lightGrey, "There's nothing here that you can pick.");

                            break;
                        }

                        break;
                    }

                    default: break;
                    }
                }
                else if (control == "inventory")
                {
                    inventory = !inventory;
                    player.containerGui.selected = inventory;
                }
            }
            if (nextTurn)
            {
                Program.engine.gameStatus = GameStatus.NEW_TURN;
            }
        }