A class used to manage items laying on the floor of a room.
Inheritance: Tile
Exemple #1
0
 /// <summary>
 /// Method to drop the full inventory of the connected player to the tile he stands on.
 /// </summary>
 public void DropItems()
 {
     while (actor.inventory.Count > 0)
     {
         ItemTile temp = new ItemTile(_parent, actor.inventory[0]);
         actor.inventory[0].tile = temp;
         ((FloorTile)_parent).Add(temp);
         actor.inventory.RemoveAt(0);
     }
 }
Exemple #2
0
        /// <summary>
        /// Load a map from a file
        /// </summary>
        /// <param name="filename">The filename to read from</param>
        /// <param name="player">The starting position on the loaded map</param>
        public void ReadXML(XmlReader xmlr, Backend.Coords targetCoords = null, bool resetPlayer = false)
        {
            List<Player> players = new List<Player>();

            // Move all players to the new map
            if (_actors.Count > 0)
            {
                for (int i = 0; i < _actors.Count; ++i)
                {
                    if (_actors[i].tile != null)
                        _actors[i].tile.enabled = false;
                    if (_actors[i] is Player)
                    {
                        players.Add(_actors[i] as Player);
                        players[players.Count - 1].tile = null;
                        break;
                    }
                }
            }
            ClearActors();

            _tiles.Clear();
            _updateTiles.Clear();
            xmlr.MoveToContent();//xml
            _width = int.Parse(xmlr.GetAttribute("width"));
            _height = int.Parse(xmlr.GetAttribute("height"));
            if (xmlr.GetAttribute("name") != null) _name = xmlr.GetAttribute("name");
            if (xmlr.GetAttribute("level") != null) _level = int.Parse(xmlr.GetAttribute("level"));
            if (xmlr.GetAttribute("dungeon") != null) _dungeonname = xmlr.GetAttribute("dungeon");
            if (xmlr.GetAttribute("floor") != null) _floorFile = xmlr.GetAttribute("floor");
            if (xmlr.GetAttribute("wall") != null) _wallFile = xmlr.GetAttribute("wall");
            if (xmlr.GetAttribute("id") != null) _id = Int32.Parse(xmlr.GetAttribute("id"));

            if (xmlr.GetAttribute("light") != null) _light = int.Parse(xmlr.GetAttribute("light"));
            if (xmlr.GetAttribute("music") != null) _music = xmlr.GetAttribute("music");

            xmlr.ReadStartElement("GameMap");//GameMap

            for (int row = 0; row < _height; ++row)
            {
                _tiles.Add(new List<FloorTile>());
                for (int col = 0; col < _width; ++col)
                {
                    _tiles[row].Add(new FloorTile(this, new Backend.Coords(col, row)));
                }
            }

            while ((xmlr.NodeType != XmlNodeType.EndElement) && (xmlr.NodeType != XmlNodeType.None))
            { // Add Tiles and overlay-Tiles
                switch (xmlr.Name)
                {
                    case "Tile":
                        FloorTile tile = _tiles[Int32.Parse(xmlr.GetAttribute("CoordY"))][Int32.Parse(xmlr.GetAttribute("CoordX"))];
                        if (xmlr.GetAttribute("visited") != null)
                        {
                            tile.visible = Boolean.Parse(xmlr.GetAttribute("visited"));
                        }
                        if (!xmlr.IsEmptyElement)
                        {
                            xmlr.Read();

                            while ((xmlr.NodeType != XmlNodeType.EndElement))
                            {
                                switch (xmlr.Name)
                                {
                                    case "WallTile":
                                        WallTile wall = new WallTile(this);
                                        if (xmlr.GetAttribute("Enabled") != null) wall.enabled = Boolean.Parse(xmlr.GetAttribute("Enabled"));
                                        if (xmlr.GetAttribute("Health") != null) wall.health = Int32.Parse(xmlr.GetAttribute("Health"));
                                        if (xmlr.GetAttribute("Type") != null) wall.type = (WallType)Enum.Parse(typeof(WallType), xmlr.GetAttribute("Type").ToString());

                                        if (xmlr.GetAttribute("Illusion") != null) wall.illusion = Boolean.Parse(xmlr.GetAttribute("Illusion"));
                                        if (xmlr.GetAttribute("Illusionvisible") != null) wall.illusionVisible = Boolean.Parse(xmlr.GetAttribute("Illusionvisible"));
                                        tile.Add(wall);
                                        break;
                                    case "ProjectileTile":
                                        {
                                            uint id = 0;
                                            if (xmlr.GetAttribute("id", _id.ToString()) != null) id = UInt32.Parse(xmlr.GetAttribute("id"));
                                            Direction dir = Direction.Up;
                                            if (xmlr.GetAttribute("direction", _id.ToString()) != null) dir = (Direction)Enum.Parse(typeof(Direction), xmlr.GetAttribute("direction").ToString());
                                            ProjectileTile projectile = new ProjectileTile(tile, dir, id);
                                        }
                                        break;
                                    case "ItemTile":
                                        Item item = new Item();
                                        xmlr.Read();
                                        item.Load(xmlr);
                                        ItemTile itemTile = new ItemTile(tile, item);
                                        item.tile = itemTile;
                                        tile.Add(itemTile);
                                        xmlr.Read(); // End Item
                                        break;

                                    case "TargetTile":
                                        tile.Add(new TargetTile(tile));
                                        break;

                                    case "TrapTile":
                                        TrapTile trap = new TrapTile(this, Int32.Parse(xmlr.GetAttribute("damage")));
                                        if (xmlr.GetAttribute("penetrate") != null) trap.penetrate = Int32.Parse(xmlr.GetAttribute("penetrate"));

                                        if (xmlr.GetAttribute("evade") != null) trap.evade = Int32.Parse(xmlr.GetAttribute("evade"));

                                        if (xmlr.GetAttribute("changing") != null)
                                        {
                                            trap.type = trap.type | TrapType.Changing;
                                        }
                                        if (xmlr.GetAttribute("hidden") != null)
                                        {
                                            trap.type = trap.type | TrapType.Hidden;
                                        }
                                        if (xmlr.GetAttribute("onlyonce") != null)
                                        {
                                            trap.type = trap.type | TrapType.OnlyOnce;
                                        }
                                        if (xmlr.GetAttribute("broken") != null)
                                        {
                                            trap.status = TrapState.Destroyed;
                                        }
                                        if (xmlr.GetAttribute("disabled") != null)
                                        {
                                            trap.status = TrapState.Disabled;
                                        }
                                        if (xmlr.GetAttribute("invisible") != null)
                                        {
                                            trap.status = TrapState.NoDisplay;
                                        }
                                        tile.Add(trap);
                                        _updateTiles.Add(tile.coords);
                                        break;
                                    case "ReservedTile":
                                        ReservedTile reserved = new ReservedTile(tile);

                                        if (xmlr.GetAttribute("Enabled") != null)
                                        { reserved.enabled = Boolean.Parse(xmlr.GetAttribute("Enabled")); }

                                        if (xmlr.GetAttribute("CanEnter") != null)
                                        { reserved.canEnter = Boolean.Parse(xmlr.GetAttribute("CanEnter")); }
                                        if (xmlr.GetAttribute("Filename") != null)
                                        { reserved.filename = xmlr.GetAttribute("Filename"); }
                                        if (xmlr.GetAttribute("Index") != null)
                                        { reserved.index = Int32.Parse(xmlr.GetAttribute("Index")); }

                                        tile.Add(reserved);

                                        break;

                                    case "DoorTile":
                                        DoorTile door = new DoorTile(tile);
                                        if (xmlr.GetAttribute("open") != null)
                                        { door.open = Boolean.Parse(xmlr.GetAttribute("open")); }

                                        if (xmlr.GetAttribute("key") != null)
                                        { door.key = int.Parse(xmlr.GetAttribute("key")); }
                                        tile.Add(door);
                                        break;

                                    case "TeleportTile":

                                        TeleportTile transporter = new TeleportTile(tile, xmlr.GetAttribute("nextRoom"), new Backend.Coords(Int32.Parse(xmlr.GetAttribute("nextX")), Int32.Parse(xmlr.GetAttribute("nextY"))));
                                        if (xmlr.GetAttribute("hidden") != null)
                                        { transporter.hidden = Boolean.Parse(xmlr.GetAttribute("hidden")); }
                                        if (xmlr.GetAttribute("enabled") != null)
                                        { transporter.enabled = Boolean.Parse(xmlr.GetAttribute("enabled")); }
                                        if (xmlr.GetAttribute("teleport") != null)
                                        { transporter.teleport = Boolean.Parse(xmlr.GetAttribute("teleport")); }
                                        if (xmlr.GetAttribute("down") != null)
                                        { transporter.down = Boolean.Parse(xmlr.GetAttribute("down")); }

                                        tile.Add(transporter);
                                        break;

                                    case "TriggerTile":
                                        Backend.Coords target = new Backend.Coords(-1, -1);
                                        if (xmlr.GetAttribute("affectX") != null) target.x = Int32.Parse(xmlr.GetAttribute("affectX"));

                                        if (xmlr.GetAttribute("affectY") != null) target.y = Int32.Parse(xmlr.GetAttribute("affectY"));

                                        TriggerTile trigger = new TriggerTile(tile, target);

                                        if (xmlr.GetAttribute("explanation") != null) { trigger.explanationEnabled = xmlr.GetAttribute("explanation"); };
                                        if (xmlr.GetAttribute("explanationdisabled") != null) { trigger.explanationDisabled = xmlr.GetAttribute("explanationdisabled"); };
                                        if (xmlr.GetAttribute("enabled") != null) { trigger.enabled = Boolean.Parse(xmlr.GetAttribute("enabled")); };
                                        if (xmlr.GetAttribute("repeat") != null) { trigger.repeat = Int32.Parse(xmlr.GetAttribute("repeat")); };

                                        if (xmlr.GetAttribute("alwaysShowDisabled") != null) { trigger.alwaysShowDisabled = Boolean.Parse(xmlr.GetAttribute("alwaysShowDisabled")); };
                                        if (xmlr.GetAttribute("alwaysShowEnabled") != null) { trigger.alwaysShowEnabled = Boolean.Parse(xmlr.GetAttribute("alwaysShowEnabled")); };

                                        if (xmlr.GetAttribute("tileimage") != null) { trigger.tileimage = xmlr.GetAttribute("tileimage"); };
                                        if (xmlr.GetAttribute("reactToEnemies") != null) { trigger.reactToEnemies = Boolean.Parse(xmlr.GetAttribute("reactToEnemies")); };
                                        if (xmlr.GetAttribute("reactToObjects") != null) { trigger.reactToObjects = Boolean.Parse(xmlr.GetAttribute("reactToObjects")); };
                                        if (xmlr.GetAttribute("reactToItem") != null)
                                        {
                                            trigger.reactToItem = Int32.Parse(xmlr.GetAttribute("reactToItem"));
                                        }
                                        tile.Add(trigger);
                                        break;
                                    case "CheckpointTile":
                                        int bonusLifes = 0;
                                        bool visited = false;

                                        if (xmlr.GetAttribute("bonuslife") != null)
                                            bonusLifes = Convert.ToInt32(xmlr.GetAttribute("bonuslife"));
                                        if (xmlr.GetAttribute("visited") != null)
                                            visited = Convert.ToBoolean(xmlr.GetAttribute("visited"));
                                        tile.Add(new CheckpointTile(tile, visited, bonusLifes));
                                        break;

                                    case "ActorTile":
                                        Actor actor;
                                        xmlr.Read();
                                        switch (xmlr.Name)
                                        {
                                            case "Enemy":
                                                actor = new Enemy();
                                                actor.Load(xmlr);
                                                break;
                                            case "Player":
                                                actor = new Player();
                                                actor.Load(xmlr);
                                                break;
                                            default:
                                                actor = new NPC();
                                                actor.Load(xmlr);
                                                break;
                                        }
                                        while (actor.id > _actors.Count - 1)
                                        {
                                            _actors.Add(new NPC());
                                            _actors[_actors.Count - 1].id = _actors.Count - 1;
                                        }

                                        if (!(actor is Player))
                                        {
                                            ActorTile tile2 = new ActorTile(tile, actor);
                                            tile2.enabled = (actor.health > 0);
                                            actor.tile = tile2;
                                            tile.Add(tile2);
                                            _actors[actor.id] = actor;
                                            _updateTiles.Add(tile.coords);
                                        }
                                        else
                                        {
                                            if (players.Count > 0)
                                            {
                                                bool found = false;
                                                for (int i = 0; i < players.Count; ++i)
                                                {
                                                    if (players[i].GUID == actor.GUID)
                                                    {
                                                        if (!resetPlayer)
                                                            actor.copyFrom(players[i]);
                                                        players.RemoveAt(i);
                                                        found = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            if (targetCoords == null)
                                            {
                                                targetCoords = tile.coords;
                                            }
                                            if (!resetPlayer)
                                            {

                                                ActorTile actortile = new ActorTile(this[targetCoords], actor);
                                                actor.tile = actortile;
                                                actortile.enabled = (actor.health > 0);
                                                actortile.parent = this[targetCoords];
                                                this[targetCoords].Add(actortile);
                                                _actors[actor.id] = actor;
                                                _updateTiles.Add(targetCoords);
                                                Uncover(actors[actor.id].tile.coords, actors[actor.id].viewRange);
                                            }
                                            else
                                            {
                                                ActorTile actortile = new ActorTile(tile, actor);
                                                actor.tile = actortile;
                                                actortile.enabled = (actor.health > 0);
                                                actortile.parent = tile;
                                                tile.Add(actortile);
                                                _actors[actor.id] = actor;
                                                _updateTiles.Add(tile.coords);
                                                Uncover(actors[actor.id].tile.coords, actors[actor.id].viewRange);
                                            }

                                        }

                                        break;
                                }
                                xmlr.Read();
                            }
                            xmlr.ReadEndElement();
                        }
                        else
                        {
                            xmlr.Read();
                        }
                        break;
                }
            }

            if (targetCoords == null)
            {
                targetCoords = new Coords(1, 1);
            }

            while (players.Count > 0)
            {
                ActorTile actortile = new ActorTile(this[targetCoords], players[0]);
                actortile.enabled = (players[0].health > 0);
                actortile.parent = this[targetCoords];
                this[targetCoords].Add(actortile);
                players[0].tile = actortile;
                _updateTiles.Add(targetCoords);
                bool found = false;
                foreach (Actor a in _actors)
                {
                    if ((a.GUID == players[0].GUID) && (players[0].GUID != ""))
                    {
                        found = true;
                        a.copyFrom(players[0]);
                        a.tile = actortile;
                        break;
                    }
                }
                if (!found)
                {
                    foreach (Actor a in _actors)
                    {
                        if ((a is Player) && (a.GUID == ""))
                        {
                            found = true;
                            a.copyFrom(players[0]);
                            a.GUID = players[0].GUID;
                            a.tile = actortile;
                            break;
                        }
                    }
                }
                if (!found)
                {
                    players[0].id = _actors.Count;
                    _actors.Add(players[0]);
                }

                players.RemoveAt(0);
            }
            foreach (Actor a in _actors)
            {
                if (a.tile == null)
                {
                    ActorTile actortile = new ActorTile(this[targetCoords], a);
                    actortile.enabled = (a.health > 0);
                    actortile.parent = this[targetCoords];
                    this[targetCoords].Add(actortile);
                    a.tile = actortile;
                    a.online = false;
                    _updateTiles.Add(targetCoords);
                }
            }
        }
Exemple #3
0
        /// /// <summary>
        /// Handle events from UIElements and/or backend objects
        /// </summary>
        ///  <param name="DownStream"></param>
        /// <param name="eventID">The ID of the event</param>
        /// <param name="data">The parameters needed for that event</param>
        public override void HandleEvent(bool DownStream, Events eventID, params object[] data)
        {
            switch (eventID)
            {
                // Client: Player used item/ability
                // Map: NPC / Monster used item/ability
                case Backend.Events.ActivateAbility:
                    {
                        Actor actor = (Actor)data[0];
                        int id = (int)data[1];

                        // Use Item from inventory
                        if (id < 0)
                        {
                            actor.Items(-id).UseItem();
                            // 2 Events:
                            // 1. Item entfernen bzw. ausrüsten
                            _parent.HandleEvent(false, Backend.Events.ActivateAbility, actor.id, id);
                            // 2. Statistiken anpassen
                            _parent.HandleEvent(false, Events.ChangeStats, actor.id, actor); // Update data on client

                        }
                        else
                        {
                            actor.mana -= actor.abilities[id - 1].cost;
                            actor.abilities[id - 1].currentCool = actor.abilities[id - 1].cooldown * 7;
                            switch (actor.abilities[id - 1].element)
                            {
                                case AbilityElement.Charm:
                                    _parent.HandleEvent(false, Events.FireProjectile, actor.id, AbilityElement.Charm);
                                    break;
                                case AbilityElement.Fire:
                                    _parent.HandleEvent(false, Events.FireProjectile, actor.id, AbilityElement.Fire);
                                    break;
                                case AbilityElement.Health:
                                    actor.health = Math.Min(actor.maxHealth, actor.health + actor.abilities[id - 1].intensity);
                                    break;
                                case AbilityElement.HealthReg:
                                    actor.health = Math.Min(actor.maxHealth, actor.health + actor.abilities[id - 1].intensity);
                                    break;
                                case AbilityElement.Ice:
                                    _parent.HandleEvent(false, Events.FireProjectile, actor.id, AbilityElement.Ice);
                                    break;
                                case AbilityElement.ManaReg:
                                    break;
                                case AbilityElement.Scare:
                                    _parent.HandleEvent(false, Events.FireProjectile, actor.id, AbilityElement.Scare);
                                    break;
                                case AbilityElement.Stun:
                                    _parent.HandleEvent(false, Events.FireProjectile, actor.id, AbilityElement.Stun);
                                    break;
                            }
                            _parent.HandleEvent(false, Events.ChangeStats, actor.id, actor); // Update data on client
                            _parent.HandleEvent(false, Backend.Events.ActivateAbility, actor.id, id);

                        }
                    }
                    break;

                // Client: Animation finished playing => Re-Enable Actor, continue game
                case Backend.Events.FinishedAnimation:
                    int FinishedID = (int)data[0];
                    if (_map.actors.Count >= FinishedID)
                    {
                        Activity FinishedActivity = (Activity)data[1];
                        switch (FinishedActivity)
                        {
                            case Activity.Die:
                                if (_map.actors[FinishedID] is Enemy)
                                {
                                    if (_map.actors[FinishedID].tile.enabled)
                                    {
                                        ((ActorTile)_map.actors[FinishedID].tile).enabled = false;
                                        ((ActorTile)_map.actors[FinishedID].tile).DropItems();
                                        if (_map.actors[FinishedID].gold > 0)
                                        {
                                            ItemTile tile = new ItemTile(((FloorTile)(_map.actors[FinishedID].tile.parent)));
                                            Backend.Item item = new Backend.Item(tile, Backend.ItemType.Gold, "", null, _map.actors[FinishedID].gold);
                                            item.value = _map.actors[FinishedID].gold;
                                            tile.item = item;
                                            ((FloorTile)(_map.actors[FinishedID].tile.parent)).Add(tile);
                                        }
                                        _parent.HandleEvent(false, Events.SetItemTiles, _map.actors[FinishedID].tile, ((FloorTile)(_map.actors[FinishedID].tile.parent)).itemTiles);
                                    }
                                }
                                else
                                {
                                    _parent.HandleEvent(false, Events.KillActor, FinishedID, _map.actors[FinishedID].tile.coords, 0, 0);
                                }

                                break;
                            default:
                                _map.actors[FinishedID].locked = false;
                                break;
                        }
                    }
                    break;

                case Backend.Events.TrapActivate:
                    {
                        Backend.Coords coords = (Coords)data[0];
                        if ((_map[coords].trap.status == TrapState.On) && (((_map[coords].hasEnemy) || (_map[coords].hasPlayer)) && (!_map[coords].firstActor.isDead)))
                        {
                            _TrapDamage(coords);
                        }
                        _parent.HandleEvent(false, Events.TrapActivate, coords, _map[coords].trap.status);

                    }
                    break;

                case Backend.Events.EndGame:
                    map.Save("savedroom" + map.id + ".xml");
                    File.WriteAllText("save\\auto\\GameData", "room" + map.id.ToString() + ".xml");
                    break;

                case Backend.Events.TileEntered:
                    {
                        int id = (int)data[0];
                        if (id < _map.actors.Count)
                        {
                            _map.actors[id].locked = false;

                            Direction dir = (Direction)data[1];
                            Backend.Coords target = _map.actors[id].tile.coords;

                            // Pickup any items
                            while (_map[target.x, target.y].hasTreasure)
                            {
                                _parent.HandleEvent(false, Events.PlaySound, SoundFX.Pickup); //SoundEffect pick items
                                _parent.HandleEvent(false, Events.ShowMessage, ((_map.actors[id] is Player) ? "You found " : _map.actors[id].name + " found ") + _map[target.x, target.y].firstItem.item.name + " .");
                                if (_map.actors[id] is Player)
                                    _parent.HandleEvent(false, Events.ActorText, _map[target].firstActor.id, target, "Found " + _map[target.x, target.y].firstItem.item.name, Color.DarkGreen);
                                _map[target.x, target.y].firstItem.item.Pickup(_map.actors[id]);
                                _map[target.x, target.y].Remove(_map[target.x, target.y].firstItem);
                            }

                            // Apply trap damage
                            if (((_map[target.x, target.y].hasTrap) && _map[target.x, target.y].trap.status == TrapState.On) && !(_map.actors[id] is NPC))
                            {
                                _TrapDamage(target);
                            }

                            if (_map.actors[id] is Player)
                            {

                                //Checkpoint - save by entering
                                if ((_map[target.x, target.y].hasCheckpoint) && (!_map[target.x, target.y].checkpoint.visited))
                                {
                                    _parent.HandleEvent(false, Events.PlaySound, SoundFX.Checkpoint);//SoundEffect checkpoint
                                    _map[target.x, target.y].checkpoint.visited = true;
                                    _map.actors[id].health = _map.actors[id].maxHealth;
                                    _map.actors[id].mana = _map.actors[id].maxMana;
                                    if (_map.actors[id].lives == -1)
                                        _map.actors[id].lives = 3;
                                    if (_map[target.x, target.y].checkpoint.bonuslife > 0)
                                        _map.actors[id].lives += (int)_map[target.x, target.y].checkpoint.bonuslife;
                                    _map.actors[id].lastCheckpoint = _map.id;
                                    _map.actors[id].checkPointCoords = new Coords(target.x, target.y);
                                    _map.Save("savedroom" + _map.id + ".xml");
                                    _parent.HandleEvent(false, Events.ActorText, _map[target].firstActor.id, target, "Checkpoint", Color.DarkOliveGreen);
                                    Regex regex = new Regex(@"\d+");

                                    _parent.HandleEvent(false, Events.ShowMessage, "Checkpoint reached (" + _map.actors[id].lives.ToString() + " lives remaining)");
                                    _parent.HandleEvent(false, Events.Checkpoint, id);
                                }

                                // Trigger floor switches
                                if (_map[_map.actors[id].tile.coords.x, _map.actors[id].tile.coords.y].hasTarget)
                                {
                                    _parent.HandleEvent(false, Backend.Events.AnimateActor, id, Activity.Talk);
                                    //_mainmap2.HandleEvent(true, Backend.Events.AnimateActor, id, Activity.Talk);

                                    _parent.HandleEvent(false, Events.GameOver, true);
                                }

                                // Apply teleporter (move to next room)
                                if (_map[target.x, target.y].hasTeleport)
                                {
                                    HandleEvent(true, Backend.Events.ChangeMap, ((TeleportTile)_map[target.x, target.y].teleportTile).nextRoom, ((TeleportTile)_map[target.x, target.y].teleportTile).nextPlayerPos);

                                }
                            }

                        }
                    }
                    // Allow to choose next turn
                    break;

                case Backend.Events.Attack:
                    {
                        int id = (int)data[0];
                        Direction dir = (Direction)data[1];
                        Backend.Coords target = Map.DirectionTile(_map.actors[id].tile.coords, dir);
                        if (_map.CanMove(_map.actors[id].tile.coords, dir))
                        {
                            _parent.HandleEvent(false, Backend.Events.Attack, id, dir);
                            _CombatDamage(id, _map[target.x, target.y].firstActor.id);
                        }
                    }
                    break;

                case Backend.Events.ExplodeProjectile:
                    {
                        _map[((ProjectileTile)data[0]).coords].Remove((ProjectileTile)data[0]);
                        if (data[2] != null)
                        {
                            Actor actor = data[2] as Actor;
                            int damage = 20 - actor.armor + (5 - _random.Next(10));
                            if (damage > 0)
                            {
                                actor.health -= damage;
                                if (actor is Player)
                                {
                                    _parent.HandleEvent(false, Events.FloatText, actor.tile.coords, damage.ToString(), Color.DarkRed);
                                    _parent.HandleEvent(false, Events.DamageActor, actor.id, actor.tile.coords, actor.health, damage);
                                }
                            }
                        }
                        _parent.HandleEvent(false, eventID, data);
                    }
                    break;

                case Backend.Events.MoveProjectile:
                    if (data[0] == null)
                    {
                        _parent.HandleEvent(false, Backend.Events.AddProjectile, ((FloorTile)data[1]).coords, (Direction)data[2], new ProjectileTile((FloorTile)data[1], (Direction)data[2]));
                    }
                    else
                    {
                        _parent.HandleEvent(false, Backend.Events.MoveProjectile, ((ProjectileTile)data[0]).id, (Coords)data[1]);
                    }
                    break;

                case Backend.Events.FinishedProjectileMove:
                    ((ProjectileTile)data[0]).NextTile(true);
                    break;

                case Backend.Events.Shop:
                    _parent.HandleEvent(false, Events.Shop, (Actor)data[1], (Actor)data[0]);
                    break;

                case Backend.Events.Dialog:
                    Player player = ((Player)data[1]); //player
                    string texttodisplay = "";
                    int queststodo = 0;
                    if (player.quests.Length <= 0)
                    {
                        texttodisplay += "Welcome, hero. I offer you this quest:\n\n";
                        // Quest nq = new Quest(Quest.QuestType.CollectItems, "Find, buy or steal a new item!", 100, null, player.inventory.Count + 1);
                        // player.AddQuest(nq);
                        //  texttodisplay += nq.text;
                    }
                    else
                    {
                        int exp = player.exp;
                        player.UpdateQuests(); //update quests and get reward
                        foreach (Quest q in player.quests)
                        {
                            texttodisplay += q.text; /*
                            if (q.Completed)
                                texttodisplay = "You successfully performed my quest. I grant you " + q.xp.ToString() + " experience points.";
                            else
                            {
                                texttodisplay = "I am still waiting for you to perform my quest:\n\n" + q.text;
                                queststodo++;
                            } */
                        }
                        if (player.exp - exp > 0)
                            _parent.HandleEvent(false, Events.ActorText, player.id, player.tile.coords, "+" + (player.exp - exp).ToString() + " Exp", Color.Gold); // Update data on client

                        while (player.exp > player.expNeeded)
                        {
                            player.LevelUp();
                            _parent.HandleEvent(false, Events.ChangeStats, player.id, player); // Update data on client
                        }
                    }
                    GenericDialog(((Actor)data[1]).id, ((Actor)data[0]).id, texttodisplay);
                    break;

                case Backend.Events.MoveActor:
                    {
                        if ((data.Length > 1) && (_map.actors.Count >= (int)data[0]) && (!_map.actors[(int)data[0]].locked))
                        {
                            int id = (int)data[0];
                            _map.actors[id].locked = true;
                            Direction dir = (Direction)data[1];
                            Backend.Coords target = Map.DirectionTile(_map.actors[id].tile.coords, dir);
                            _map.actors[id].direction = dir;

                            if (((FloorTile)_map.actors[id].tile.parent).hasTrap)
                            {
                                if (((FloorTile)_map.actors[id].tile.parent).trap.status == TrapState.Disabled)
                                    ((FloorTile)_map.actors[id].tile.parent).trap.status = TrapState.NoDisplay;
                                _parent.HandleEvent(false, Backend.Events.ChangeTrapState, _map.actors[id].tile.coords.x, _map.actors[id].tile.coords.y, TrapState.NoDisplay);
                            }

                            Actor a = _map[target.x, target.y].firstActor;
                            if ((a is NPC) && (_map.actors[id] is Player))
                            {
                                (a as NPC).Interact(_map.actors[id]);
                            }
                            if ((a is Enemy || a is Player) &&
                                !(_map.actors[id] is NPC) //  NPCs do not attack
                                && (a.id != id) // Do not attack yourself
                                && (!a.isDead) // Do not attack dead opponents
                                && !((a is Player) && (!a.online)) // Do not attack offline players
                                && !((a is Player) && (_map.actors[id] is Player)) // No Player vs Player
                                )
                            {
                                HandleEvent(true, Backend.Events.Attack, id, dir);
                            }
                            else
                            {
                                if ((_map[target].hasDoor) && (_map.actors[id] is Player) && (!_map[target].door.open))
                                {
                                    if (_map.actors[id].HasKey(_map.level))
                                    {
                                        _map[target].door.open = true;
                                        _parent.HandleEvent(false, Events.ShowMessage, "You open the door using the key you fought for.");
                                    }
                                    else
                                    {
                                        _parent.HandleEvent(false, Events.ShowMessage, "The door is locked.\n It is likely a strong creature guards the key.");
                                    }
                                }
                                if (_map.CanMove(_map.actors[id].tile.coords, dir))
                                {
                                    Coords old = new Coords(_map.actors[id].tile.coords.x, _map.actors[id].tile.coords.y);
                                    _map.MoveActor(_map.actors[id], dir);
                                    _parent.HandleEvent(false, Backend.Events.MoveActor, id, dir, _map.actors[id].moveIndex, _map.actors[id].tile.coords, old);
                                }
                                else
                                {
                                    _parent.HandleEvent(false, Backend.Events.RejectMove, id, dir, _map.actors[id].moveIndex, _map.actors[id].tile.coords, _map.actors[id].tile.coords);
                                    _map.actors[id].locked = false;
                                }
                            }
                        }
                    }
                    break;

                case Backend.Events.Initialize:
                    ReassignPlayer();
                    break;

                case Backend.Events.Pause:
                    _paused = true;
                    _parent.HandleEvent(true, Backend.Events.Pause);
                    break;

                case Backend.Events.ContinueGame:
                    if (!DownStream)
                        _parent.HandleEvent(true, Backend.Events.ContinueGame, true);
                    _paused = false;
                    break;

                case Backend.Events.LoadFromCheckPoint:
                    HandleEvent(false, Backend.Events.Pause);
                    map.Save("room" + map.id + ".xml");
                    Coords targetCoords = map.actors[(int)data[0]].checkPointCoords;
                    map.actors[(int)data[0]].lives--;
                    map.actors[(int)data[0]].health = map.actors[(int)data[0]].maxHealth;

                    if (map.id != map.actors[(int)data[0]].lastCheckpoint)
                    {
                        ChangeMap("room" + map.actors[(int)data[0]].lastCheckpoint.ToString() + ".xml", targetCoords);
                        map.Save("room" + map.id + ".xml");
                    }
                    else
                        map.PositionActor(map.actors[(int)data[0]], targetCoords);
                    HandleEvent(false, Backend.Events.Initialize, true);
                    break;

                case Backend.Events.ChangeMap: // Load another map
                    HandleEvent(false, Backend.Events.Pause);
                    ChangeMap((string)data[0], (Coords)data[1]);
                    ReassignPlayer();
                    break;

                case Backend.Events.NewMap:
                    HandleEvent(false, Backend.Events.Pause);
                    _map.ClearActors();
                    GenerateMaps();
                    map.Load("room1.xml", null, true);
                    HandleEvent(false, Backend.Events.ContinueGame, true);
                    break;
                case Backend.Events.ResetGame:
                    _DeleteSavedRooms();
                    _map.ClearActors();
                    _map.Load("room1.xml", null, true);
                    HandleEvent(false, Events.Initialize, true);
                    break;
            }
        }
Exemple #4
0
 /// <summary>
 /// Method to drop an item from an actor to the ground.
 /// Deletes the item from the inventory and creats an itemtile to place the item on the ground
 /// </summary>
 /// <param name="tile">The tile on which the itemtile with the item will be added.</param>
 public void Drop(FloorTile tile)
 {
     if (_owner != null)
         _owner.inventory.Remove(this);
     _owner = null;
     _tile = new ItemTile(tile, this);
     tile.Add(_tile);
 }
Exemple #5
0
        /// <summary>
        /// Noch ein Konstruktor mit anderen Initial-Parametern.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="parent"></param>
        /// <param name="itemtype"></param>
        /// <param name="name"></param>
        /// <param name="icon"></param>
        /// <param name="value"></param>
        /// <param name="level"></param>
        public Item(ItemTile parent, ItemType itemtype, string name = "", ImageData icon = null, int value = 0, int level = 1)
            : this()
        {
            _level = level;
            _tile = parent;
            _value = value;
            _itemType = itemtype;

            if (name != "")
            {
                _name = name;
            }
            else
            {
                GenerateName();
            }
            if (icon == null) GenerateIcon();
        }
Exemple #6
0
 /// <summary>
 /// Method called when an actor picks up an item from the ground.
 /// Replaces the old owner and deletes the itemtile from the map
 /// </summary>
 /// <param name="actor">The actor which gains the item</param>
 public void Pickup(Actor actor)
 {
     if (_owner != null)
     {
         _owner.inventory.Remove(this);
     }
     _owner = actor;
     int temp = 0;
     if (_itemType != Backend.ItemType.Gold)
     {
         for (int i = 0; i < actor.inventory.Count; ++i)
         {
             temp = Math.Max(id, actor.inventory[i].id);
         }
         _id = temp + 1;
         actor.AddItem(this);
     }
     else
     {
         actor.gold += _value;
     }
     _tile = null;
 }
Exemple #7
0
        /// <summary>
        /// Method to place some random items in a room.
        /// </summary>
        /// <param name="amount">5 by default.</param>
        public void AddItems(int amount = -1)
        {
            if (amount < 0) amount = 5;
            for (int i = 0; i < amount; ++i)
            {
                int count = 0;
                Path pos = new Path(2 + r.Next(_width / 2 - 2) * 2, 2 + r.Next(_height / 2 - 2) * 2);
                while ((pos.x > 0) &&
                    (_tiles[pos.y][pos.x].overlay.Count != 0))
                {
                    count += 1;
                    pos.x += 2;
                    if (pos.x > _width - 2)
                    {
                        pos.x = 2;
                        pos.y += 2;
                    };
                    if (pos.y > _height - 2)
                    {
                        pos.y = 2;
                        pos.x = 2;
                    }

                    if (count >= _width * _height)
                    {
                        pos.x = -1;
                        pos.y = -1;
                    }
                }

                if ((pos.x >= 0) && (pos.x < _width) && (pos.y < _height) && (pos.y >= 0))
                {
                    Item item = new Item(r, 0, _level);
                    ItemTile itemTile = new ItemTile(_tiles[pos.y][pos.x], item);
                    item.tile = itemTile;
                    _tiles[pos.y][pos.x].Add(itemTile);
                }
            }
        }