Beispiel #1
0
        public static new DroppedItem LoadFromFile(BinaryReader stream)
        {
            Toolkit.ExpectFromFile(stream, "DROP", "dropped item entity");
            var e = Entity.LoadFromFile(stream);

            //Handle broken references (warhammer > war_hammer)
            var id     = stream.ReadString();
            var exists = NoxicoGame.KnownItems.Any(ki => ki.ID == id);

            if (!exists)
            {
                var attempt = NoxicoGame.KnownItems.FirstOrDefault(ki => ki.ID.Replace("_", string.Empty) == id);
                if (attempt != null)
                {
                    id = attempt.ID;
                }
                else
                {
                    id = NoxicoGame.KnownItems[0].ID;                     //Fallback.
                }
            }

            var newItem = new DroppedItem(id)
            {
                ID              = e.ID,
                Glyph           = e.Glyph,
                ForegroundColor = e.ForegroundColor,
                BackgroundColor = e.BackgroundColor,
                XPosition       = e.XPosition,
                YPosition       = e.YPosition,
            };

            newItem.Token = Token.LoadFromFile(stream);
            return(newItem);
        }
Beispiel #2
0
        public void Drop(BoardChar boardChar, Token item)
        {
            //Find a spot to drop the item
            int lives = 1000, x = 0, y = 0;

            while (lives > 0)
            {
                x = boardChar.XPosition + Random.Next(-1, 2);
                y = boardChar.YPosition + Random.Next(-1, 2);
                if (!boardChar.ParentBoard.IsSolid(y, x) && !boardChar.ParentBoard.IsBurning(y, x))
                {
                    break;
                }
                lives--;
            }
            var tile = boardChar.ParentBoard.Tilemap[x, y];

            if (tile.Fluid != Fluids.Dry || tile.Definition.Cliff)
            {
                NoxicoGame.AddMessage(i18n.Format(tile.Definition.Cliff ? "x_dropped_y_inthedepths" : ("x_dropped_y_inthe_" + tile.Fluid.ToString().ToLowerInvariant()), this.ToString(item, true, false)).Viewpoint(boardChar.Character));
            }
            if (lives == 0)
            {
                boardChar.Character.GetToken("items").Tokens.Remove(item);
                boardChar.Character.CheckHasteSlow();
                return;
            }
            var droppedItem = new DroppedItem(this, item)
            {
                XPosition   = x,
                YPosition   = y,
                ParentBoard = boardChar.ParentBoard,
            };

            droppedItem.AdjustView();
            droppedItem.ParentBoard.EntitiesToAdd.Add(droppedItem);
            boardChar.Character.GetToken("items").Tokens.Remove(item);
            boardChar.Character.CheckHasteSlow();
        }
Beispiel #3
0
        public override void Update()
        {
            //base.Update();
            if (NoxicoGame.Mode != UserMode.Walkabout)
            {
                return;
            }

            //START
            if (NoxicoGame.IsKeyDown(KeyBinding.Pause) || Vista.Triggers == XInputButtons.Start)
            {
                NoxicoGame.ClearKeys();
                Pause.Open();
                return;
            }

            var increase = 200 + (int)Character.GetStat("speed");

            if (Character.HasToken("haste"))
            {
                increase *= 2;
            }
            else if (Character.HasToken("slow"))
            {
                increase /= 2;
            }
            Energy += increase;
            if (Energy < 5000)
            {
                var wasNight = Toolkit.IsNight();

                NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddMilliseconds(increase);

                if (wasNight && !Toolkit.IsNight())
                {
                    ParentBoard.UpdateLightmap(this, true);
                    ParentBoard.Redraw();
                }
                EndTurn();
                return;
            }
            else
            {
                if (!NoxicoGame.PlayerReady)
                {
                    NoxicoGame.AgeMessages();
                }
                NoxicoGame.PlayerReady = true;
                Energy = 5000;
            }

            CheckForTimedItems();
            CheckForCopiers();
            if (Character.UpdateSex())
            {
                return;
            }

            var sleeping = Character.Path("sleeping");

            if (sleeping != null)
            {
                Character.Heal(2);
                sleeping.Value--;
                if (sleeping.Value <= 0)
                {
                    Character.RemoveToken("sleeping");
                    Character.RemoveToken("helpless");
                    NoxicoGame.AddMessage(i18n.GetString("yougetup"));
                }
                NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddMinutes(5);
                EndTurn();
                return;                 //07-04-13 no more sleepwalking
            }

            var helpless = Character.HasToken("helpless");

            if (helpless)
            {
                if (Random.NextDouble() < 0.05)
                {
                    Character.Heal(2);
                    NoxicoGame.AddMessage(i18n.GetString("yougetup"));
                    Character.RemoveToken("helpless");
                    helpless = false;
                }
            }
            var flying = Character.HasToken("flying");

#if DEBUG
            if (NoxicoGame.KeyMap[Keys.Z])
            {
                NoxicoGame.ClearKeys();
                NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddMinutes(30);
            }
#endif
            //Pause menu moved up so you can pause while <5000.

            //RIGHT
            if ((NoxicoGame.IsKeyDown(KeyBinding.Travel) || Vista.Triggers == XInputButtons.RightShoulder))
            {
                NoxicoGame.ClearKeys();
                if (!this.ParentBoard.AllowTravel)
                {
                    if (this.ParentBoard.BoardType == BoardType.Dungeon)
                    {
                        NoxicoGame.AddMessage(i18n.GetString("travel_notfromdungeon"));
                    }
                    else
                    {
                        NoxicoGame.AddMessage(i18n.GetString("travel_notfromwilds"));
                    }
                    return;
                }
                Travel.Open();
                return;
            }

            //LEFT
            if (NoxicoGame.IsKeyDown(KeyBinding.Rest) || Vista.Triggers == XInputButtons.LeftShoulder)
            {
                NoxicoGame.ClearKeys();
                Energy -= 1000;
                EndTurn();
                return;
            }

            //GREEN
            if (NoxicoGame.IsKeyDown(KeyBinding.Interact) || Vista.Triggers == XInputButtons.A)
            {
                NoxicoGame.ClearKeys();
                //NoxicoGame.Messages.Add("[Aim message]");
                NoxicoGame.Mode = UserMode.Aiming;
                NoxicoGame.Cursor.ParentBoard = this.ParentBoard;
                NoxicoGame.Cursor.XPosition   = this.XPosition;
                NoxicoGame.Cursor.YPosition   = this.YPosition;
                NoxicoGame.Cursor.PopulateTabstops();
                NoxicoGame.Cursor.Point();
                if (Character.HasToken("tutorial") && !Character.GetToken("tutorial").HasToken("interactmode"))
                {
                    Character.GetToken("tutorial").AddToken("dointeractmode");
                    NoxicoGame.CheckForTutorialStuff();
                }
                return;
            }

            //BLUE
            if (NoxicoGame.IsKeyDown(KeyBinding.Items) || Vista.Triggers == XInputButtons.X)
            {
                NoxicoGame.ClearKeys();
                NoxicoGame.Mode      = UserMode.Subscreen;
                NoxicoGame.Subscreen = Inventory.Handler;
                Subscreens.FirstDraw = true;
                return;
            }

            //YELLOW
            if ((NoxicoGame.IsKeyDown(KeyBinding.Fly) || Vista.Triggers == XInputButtons.Y) && !helpless)
            {
                NoxicoGame.ClearKeys();
                if (Character.HasToken("flying"))
                {
                    LandFromFlight();
                }
                else
                {
                    if (Character.HasToken("wings"))
                    {
                        if (Character.GetToken("wings").HasToken("small"))
                        {
                            NoxicoGame.AddMessage(i18n.GetString("wingsaretoosmall"));
                            return;
                        }
                        var tile = ParentBoard.Tilemap[XPosition, YPosition];
                        if (tile.Definition.Ceiling)
                        {
                            if (Character.GetStat("mind") < 10 ||
                                (Character.GetStat("mind") < 20 && Random.NextDouble() < 0.5))
                            {
                                Hurt(2, "death_crackedagainstceiling", null, false);
                                NoxicoGame.AddMessage(i18n.GetString("hittheceiling"));
                            }
                            else
                            {
                                NoxicoGame.AddMessage(i18n.GetString("cantflyinside"));
                            }
                            return;
                        }
                        //Take off
                        Character.AddToken("flying").Value = 100;
                        NoxicoGame.AddMessage(i18n.GetString("youfly"));
                        return;
                    }
                    NoxicoGame.AddMessage(i18n.GetString("flyneedswings"));
                }
                return;
            }

            //RED
            if ((NoxicoGame.IsKeyDown(KeyBinding.Activate) || Vista.Triggers == XInputButtons.B) && !helpless && !flying)
            {
                NoxicoGame.ClearKeys();

                if (OnWarp())
                {
                    CheckWarps();
                }

                var container = ParentBoard.Entities.OfType <Container>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition);
                if (container != null)
                {
                    NoxicoGame.ClearKeys();
                    ContainerMan.Setup(container);
                    return;
                }

                //Find dropped items
                var itemsHere = DroppedItem.GetItemsAt(ParentBoard, XPosition, YPosition);
                if (itemsHere.Count == 1)
                {
                    var drop = itemsHere[0];
                    if (drop != null)
                    {
                        drop.Take(this.Character, ParentBoard);
                        NoxicoGame.Me.Player.Energy -= 1000;
                        NoxicoGame.AddMessage(i18n.Format("youpickup_x", drop.Item.ToString(drop.Token, true)));
                        NoxicoGame.Sound.PlaySound("set://GetItem");
                        ParentBoard.Redraw();
                        return;
                    }
                }
                else if (itemsHere.Count > 1)
                {
                    DroppedItem.PickItemsFrom(itemsHere);
                    return;
                }

                //Find bed
                //var bed = ParentBoard.Entities.OfType<Clutter>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition && c.Glyph == 0x147);
                var bed = ParentBoard.Entities.OfType <Clutter>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition && c.DBRole == "bed");
                if (bed != null)
                {
                    var prompt  = "It's " + NoxicoGame.InGameTime.ToShortTimeString() + ", " + NoxicoGame.InGameTime.ToLongDateString() + ". Sleep for how long?";
                    var options = new Dictionary <object, string>();
                    foreach (var interval in new[] { 1, 2, 4, 8, 12 })
                    {
                        options[interval] = Toolkit.Count(interval).Titlecase() + (interval == 1 ? " hour" : " hours");
                    }
                    options[-1] = "Cancel";
                    MessageBox.List(prompt, options, () =>
                    {
                        if ((int)MessageBox.Answer != -1)
                        {
                            Character.AddToken("helpless");
                            Character.AddToken("sleeping").Value = (int)MessageBox.Answer * 12;
                        }
                    }, true, true, i18n.GetString("Bed"));
                }
                return;
            }

#if DEBUG
            if (NoxicoGame.KeyMap[Keys.F3])
            {
                NoxicoGame.ClearKeys();
                ParentBoard.DumpToHtml(string.Empty);
                NoxicoGame.AddMessage("Board dumped.");
                return;
            }
#endif
            if (helpless)
            {
                EndTurn();
                return;
            }

            if (!AutoTravelling)
            {
                if (NoxicoGame.IsKeyDown(KeyBinding.Left) || Vista.DPad == XInputButtons.Left)
                {
                    this.Move(Direction.West);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.Right) || Vista.DPad == XInputButtons.Right)
                {
                    this.Move(Direction.East);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.Up) || Vista.DPad == XInputButtons.Up)
                {
                    this.Move(Direction.North);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.Down) || Vista.DPad == XInputButtons.Down)
                {
                    this.Move(Direction.South);
                }
                //And now, attempting to fire a long range weapon in a cardinal.
                else if (NoxicoGame.IsKeyDown(KeyBinding.ShootLeft))
                {
                    this.QuickFire(Direction.West);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.ShootRight))
                {
                    this.QuickFire(Direction.East);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.ShootUp))
                {
                    this.QuickFire(Direction.North);
                }
                else if (NoxicoGame.IsKeyDown(KeyBinding.ShootDown))
                {
                    this.QuickFire(Direction.South);
                }
            }
            else
            {
                if (NoxicoGame.IsKeyDown(KeyBinding.Left) || NoxicoGame.IsKeyDown(KeyBinding.Right) || NoxicoGame.IsKeyDown(KeyBinding.Up) || NoxicoGame.IsKeyDown(KeyBinding.Down))                //(NoxicoGame.KeyMap[(int)Keys.Left] || NoxicoGame.KeyMap[(int)Keys.Right] || NoxicoGame.KeyMap[(int)Keys.Up] || NoxicoGame.KeyMap[(int)Keys.Down])
                {
                    AutoTravelling = false;
                    return;
                }
                var x   = XPosition;
                var y   = YPosition;
                var dir = Direction.North;
                if (AutoTravelMap.RollDown(y, x, ref dir))
                {
                    Move(dir);
                }
                else
                {
                    AutoTravelling = false;
                    if ((int)AutoTravelLeave > -1)
                    {
                        this.Move(AutoTravelLeave);
                    }
                }
            }
        }