public static void LookAt(BoardChar target) { var pa = target; var chr = ((BoardChar)pa).Character; Plain(chr.LookAt(pa), chr.GetKnownName(true), false, true); //Fix: disabled wrapping to prevent Look At from looking like shit with new wrapper. }
private static void TryDrop(BoardChar boardchar, Token token, InventoryItem chosen) { //Subscreens.PreviousScreen.Push(NoxicoGame.Subscreen); itemList.Enabled = false; if (token.HasToken("equipped")) { try { chosen.Unequip(boardchar.Character); } catch (ItemException x) { MessageBox.Notice(x.Message.Viewpoint(boardchar.Character)); } } if (!token.HasToken("equipped")) { NoxicoGame.AddMessage(i18n.Format("dropped_x", chosen.ToString(token, true, true))); NoxicoGame.Sound.PlaySound("set://PutItem"); chosen.Drop(boardchar, token); NoxicoGame.Me.CurrentBoard.Update(); //NoxicoGame.Me.CurrentBoard.Draw(); NoxicoGame.Subscreen = Inventory.Handler; Subscreens.Redraw = true; } itemList.Enabled = true; }
public override bool MeleeAttack(BoardChar target) { var killedThem = base.MeleeAttack(target); if (!killedThem && !target.Character.HasToken("helpless")) { target.Character.AddToken("justmeleed"); target.MeleeAttack(this); } return(killedThem); }
/// <summary> /// Put something IN a container, or SELL it to a vendor. /// </summary> /// <param name="boardchar">The container/vendor</param> /// <param name="token">The item token</param> /// <param name="chosen">The item's definition</param> /// <returns>Returns a failure message or null.</returns> /// <remarks>Sets vendorCaughtYou when you're being criminal scum.</remarks> private static string TryStore(BoardChar boardchar, Token token, InventoryItem chosen) { var inv = boardchar.Character.GetToken("items"); var con = other; if (token.HasToken("cursed")) { //Reveal the cursed item as such if we didn't already know. if (!token.GetToken("cursed").HasToken("known")) { token.GetToken("cursed").AddToken("known"); } return("It's cursed! You can't unequip it."); //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } if (token.HasToken("equipped")) { //You should probably switch over to the Inventory screen and take the thing off. return(i18n.GetString("inventory_youareusingthis")); } if (mode == ContainerMode.Vendor && token.HasToken("owner") && token.GetToken("owner").Text == vendorChar.Name.ToID()) { //We tried to sell the vendor's own crap back to them. vendorCaughtYou = true; //Handler can deal with this now. return(i18n.Format("inventory_vendorcaughtyou", vendorChar.Name.ToString()).Viewpoint(vendorChar)); } if (token.HasToken("torn")) { price = (float)Math.Ceiling(price * 0.25f); //this ain't worth shit, bruh. } if (mode == ContainerMode.Vendor && price != 0) { //Handle the transaction. var pMoney = boardchar.Character.GetToken("money"); var vMoney = vendorChar.GetToken("money"); if (vMoney.Value - price < 0) { return(i18n.Format("inventory_vendorcantaffordthis", vendorChar.Name.ToString())); } //TODO: add charisma and relationship bonuses -- I'll throw in another tenner cos you're awesome. //notice that the bonus is determined AFTER the budget check so a vendor won't bug out on that. pMoney.Value += price; vMoney.Value -= price; token.AddToken("for_sale"); } con.Tokens.Add(token); inv.Tokens.Remove(token); boardchar.ParentBoard.Redraw(); boardchar.ParentBoard.Draw(); boardchar.Character.CheckHasteSlow(); NoxicoGame.Sound.PlaySound("set://PutItem"); return(null); }
/// <summary> /// Take something OUT of a container, or BUY it from a vendor. /// </summary> /// <param name="boardchar">The container/vendor</param> /// <param name="token">The item token</param> /// <param name="chosen">The item's definition</param> /// <returns>Return a failure message or null.</returns> private static string TryRetrieve(BoardChar boardchar, Token token, InventoryItem chosen) { var inv = boardchar.Character.GetToken("items"); var con = other; if (token.HasToken("cursed")) { //Reveal the cursed item as such if we didn't already know. if (!token.GetToken("cursed").HasToken("known")) { token.GetToken("cursed").AddToken("known"); } return(mode == ContainerMode.Vendor ? "It's cursed. " + vendorChar.Name.ToString() + " can't unequip it." : "It's cursed. You shouldn't touch this."); //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } if (token.HasToken("equipped")) { //If we're looting a corpse's equipment, just unequip it. /* Cannot happen if we only allow buying for_sale items * //If a vendor is wearing it though... * if (mode == ContainerMode.Vendor) * return i18n.Format("inventory_vendorusesthis", vendorChar.Name.ToString()); * else */ token.RemoveToken("equipped"); } if (mode == ContainerMode.Vendor && price != 0) { //Handle the transaction. var pMoney = boardchar.Character.GetToken("money"); var vMoney = vendorChar.GetToken("money"); //TODO: add charisma and relationship bonuses -- look good for free food, or get a friends discount. if (pMoney.Value - price < 0) { return(i18n.GetString("inventory_youcantaffordthis")); } vMoney.Value += price; pMoney.Value -= price; token.RemoveToken("for_sale"); } inv.Tokens.Add(token); con.Tokens.Remove(token); boardchar.ParentBoard.Redraw(); boardchar.ParentBoard.Draw(); boardchar.Character.CheckHasteSlow(); NoxicoGame.Sound.PlaySound("set://GetItem"); return(null); }
public static new Player LoadFromFile(BinaryReader stream) { Toolkit.ExpectFromFile(stream, "PLAY", "player entity"); var e = BoardChar.LoadFromFile(stream); var newChar = new Player() { ID = e.ID, Glyph = e.Glyph, ForegroundColor = e.ForegroundColor, BackgroundColor = e.BackgroundColor, XPosition = e.XPosition, YPosition = e.YPosition, Blocking = e.Blocking, Character = e.Character, }; newChar.PlayingTime = new TimeSpan(stream.ReadInt64()); return(newChar); }
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(); }
public override void Update() { base.Update(); NoxicoGame.ContextMessage = i18n.GetString("context_interactmode"); if (this.ParentBoard == null) { NoxicoGame.Mode = UserMode.Walkabout; return; } //this.ParentBoard.Draw(true); if (NoxicoGame.IsKeyDown(KeyBinding.Interact) || NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { NoxicoGame.Mode = UserMode.Walkabout; NoxicoGame.ClearKeys(); NoxicoGame.ContextMessage = string.Empty; Hide(); return; } if (NoxicoGame.IsKeyDown(KeyBinding.TabFocus) || Vista.Triggers == XInputButtons.RightShoulder) { NoxicoGame.ClearKeys(); Tabstop++; if (Tabstop >= Tabstops.Count) { Tabstop = 0; } XPosition = Tabstops[Tabstop].X; YPosition = Tabstops[Tabstop].Y; Point(); } if (NoxicoGame.IsKeyDown(KeyBinding.Accept) || Vista.Triggers == XInputButtons.A) { Subscreens.PreviousScreen.Clear(); NoxicoGame.ClearKeys(); var player = NoxicoGame.Me.Player; #if DEBUG if (PointingAt == null) { ActionList.Show("Debug?", this.XPosition - NoxicoGame.CameraX, this.YPosition - NoxicoGame.CameraY, new Dictionary <object, string>() { { "teleport", "Teleport" }, { "spawn", "Spawn character" }, }, () => { Hide(); if (ActionList.Answer is int && (int)ActionList.Answer == -1) { NoxicoGame.Mode = UserMode.Walkabout; Hide(); return; } switch (ActionList.Answer as string) { case "teleport": player.XPosition = this.XPosition; player.YPosition = this.YPosition; ParentBoard.AimCamera(); ParentBoard.Redraw(); NoxicoGame.Mode = UserMode.Aiming; Point(); return; case "spawn": var spawnOptions = new Dictionary <object, string>(); foreach (var bp in Character.Bodyplans) { spawnOptions[bp.Text] = bp.Text; } var uniques = Mix.GetTokenTree("uniques.tml", true); foreach (var bp in uniques) { spawnOptions['!' + bp.Text] = bp.Text; } ActionList.Show("Debug?", this.XPosition - NoxicoGame.CameraX, this.YPosition - NoxicoGame.CameraY, spawnOptions, () => { if (ActionList.Answer is int && (int)ActionList.Answer == -1) { NoxicoGame.Mode = UserMode.Aiming; Point(); return; } Character newChar = null; if (ActionList.Answer is string && ((string)ActionList.Answer).StartsWith('!')) { newChar = Character.GetUnique(((string)ActionList.Answer).Substring(1)); } else { newChar = Character.Generate((string)ActionList.Answer, Gender.RollDice); } var newBoardChar = new BoardChar(newChar) { XPosition = this.XPosition, YPosition = this.YPosition, ParentBoard = this.ParentBoard }; newBoardChar.AdjustView(); ParentBoard.EntitiesToAdd.Add(newBoardChar); ParentBoard.Redraw(); NoxicoGame.Mode = UserMode.Walkabout; Hide(); return; } ); break; } } ); } #endif if (PointingAt != null) { LastTarget = PointingAt; var distance = player.DistanceFrom(PointingAt); var canSee = player.CanSee(PointingAt); var options = new Dictionary <object, string>(); var description = "something"; options["look"] = i18n.GetString("action_lookatit"); if (PointingAt is Player) { description = i18n.Format("action_descyou", player.Character.Name); options["look"] = i18n.GetString("action_lookatyou"); if (player.Character.GetStat("excitement") >= 30) { options["f**k"] = i18n.GetString("action_masturbate"); } if (player.Character.HasToken("copier") && player.Character.GetToken("copier").Value == 1) { if (player.Character.Path("copier/backup") != null || player.Character.Path("copier/full") == null) { options["revert"] = i18n.GetString("action_revert"); } } } else if (PointingAt is DroppedItem) { var drop = PointingAt as DroppedItem; var item = drop.Item; var token = drop.Token; description = item.ToString(token); if (distance <= 1) { options["take"] = i18n.GetString("action_pickup"); } } else if (PointingAt is Container) { var container = PointingAt as Container; description = container.Name ?? "container"; } else if (PointingAt is Clutter) { var clutter = PointingAt as Clutter; description = clutter.Name ?? "something"; if (clutter.ID == "craftstation") { options["craft"] = i18n.GetString("action_craft"); } } else if (PointingAt is BoardChar) { var boardChar = PointingAt as BoardChar; description = boardChar.Character.GetKnownName(true); options["look"] = i18n.Format("action_lookathim", boardChar.Character.HimHerIt(true)); if (canSee && distance <= 2 && !boardChar.Character.HasToken("beast") && !boardChar.Character.HasToken("sleeping")) { options["talk"] = i18n.Format("action_talktohim", boardChar.Character.HimHerIt(true)); if (boardChar.Character.Path("role/vendor") != null && boardChar.Character.Path("role/vendor/class").Text != "carpenter") { options["trade"] = i18n.Format("action_trade", boardChar.Character.HimHerIt(true)); } } if (canSee && player.Character.GetStat("excitement") >= 30 && distance <= 1) { var mayFuck = boardChar.Character.HasToken("willing"); var willRape = boardChar.Character.HasToken("helpless"); if (!IniFile.GetValue("misc", "allowrape", false) && willRape) { mayFuck = false; } //but DO allow it if they're helpless but willing if (boardChar.Character.HasToken("willing") && willRape) { mayFuck = true; willRape = false; } if (boardChar.Character.HasToken("beast")) { mayFuck = false; } if (mayFuck) { options["f**k"] = i18n.Format(willRape ? "action_rapehim" : "action_fuckhim", boardChar.Character.HimHerIt(true)); } } if (canSee && !boardChar.Character.HasToken("beast") && player.Character.HasToken("copier") && player.Character.Path("copier/timeout") == null) { //if (player.Character.UpdateCopier()) if (player.Character.HasToken("fullCopy") || player.Character.HasToken("sexCopy")) { options["copy"] = i18n.Format("action_copyhim", boardChar.Character.HimHerIt(true)); } } if (canSee && player.Character.CanShoot() != null && player.ParentBoard.HasToken("combat")) { options["shoot"] = i18n.Format("action_shoothim", boardChar.Character.HimHerIt(true)); } } #if DEBUG if (PointingAt is BoardChar) { options["mutate"] = "(debug) Random mutate"; } if (PointingAt is BoardChar) { options["turbomutate"] = "(debug) Apply LOTS of mutations!"; } #endif ActionList.Show(description, PointingAt.XPosition - NoxicoGame.CameraX, PointingAt.YPosition - NoxicoGame.CameraY, options, () => { Hide(); if (ActionList.Answer is int && (int)ActionList.Answer == -1) { //NoxicoGame.Messages.Add("[Aim message]"); NoxicoGame.Mode = UserMode.Aiming; Point(); return; } switch (ActionList.Answer as string) { case "look": if (PointingAt is DroppedItem) { var drop = PointingAt as DroppedItem; var item = drop.Item; var token = drop.Token; var text = (item.HasToken("description") && !token.HasToken("unidentified") ? item.GetToken("description").Text : i18n.Format("thisis_x", item.ToString(token))).Trim(); MessageBox.Notice(text, true); } else if (PointingAt is Clutter && !((Clutter)PointingAt).Description.IsBlank()) { MessageBox.Notice(((Clutter)PointingAt).Description.Trim(), true, ((Clutter)PointingAt).Name ?? "something"); } else if (PointingAt is Container) { MessageBox.Notice(((Container)PointingAt).Description.Trim(), true, ((Container)PointingAt).Name ?? "container"); } else if (PointingAt is BoardChar) { if (((BoardChar)PointingAt).Character.HasToken("beast")) { MessageBox.Notice(((BoardChar)PointingAt).Character.LookAt(PointingAt), true, ((BoardChar)PointingAt).Character.GetKnownName(true)); } else { TextScroller.LookAt((BoardChar)PointingAt); } } break; case "talk": if (PointingAt is Player) { //if (Culture.CheckSummoningDay()) return; if (player.Character.Path("mind").Value >= 10) { MessageBox.Notice(i18n.GetString("talkingotyourself"), true); } else { MessageBox.Notice(i18n.GetString("talkingtoyourself_nutso"), true); } } else if (PointingAt is BoardChar) { var boardChar = PointingAt as BoardChar; if (boardChar.Character.HasToken("hostile") && !boardChar.Character.HasToken("helpless")) { MessageBox.Notice(i18n.Format("nothingtosay", boardChar.Character.GetKnownName(false, false, true, true)), true); } else { SceneSystem.Engage(player.Character, boardChar.Character); } } break; case "trade": ContainerMan.Setup(((BoardChar)PointingAt).Character); break; case "f**k": if (PointingAt is BoardChar) { SexManager.Engage(player.Character, ((BoardChar)PointingAt).Character); } break; case "shoot": player.AimShot(PointingAt); break; case "copy": player.Character.Copy(((BoardChar)PointingAt).Character); player.AdjustView(); //NoxicoGame.AddMessage(i18n.Format((player.Character.Path("copier/full") == null) ? "youimitate_x" : "become_x", ((BoardChar)PointingAt).Character.GetKnownName(false, false, true))); NoxicoGame.AddMessage(i18n.Format(player.Character.HasToken("fullCopy") ? "x_becomes_y" : "x_imitates_y").Viewpoint(player.Character, ((BoardChar)PointingAt).Character)); player.Energy -= 2000; break; case "revert": player.Character.Copy(null); player.AdjustView(); NoxicoGame.AddMessage(i18n.GetString((player.Character.HasToken("fullCopy")) ? "youmelt" : "yourevert")); player.Energy -= 1000; break; case "take": if (PointingAt is DroppedItem) { var drop = PointingAt as DroppedItem; var item = drop.Item; var token = drop.Token; drop.Take(player.Character, ParentBoard); player.Energy -= 1000; NoxicoGame.AddMessage(i18n.Format("youpickup_x", item.ToString(token, true)), drop.ForegroundColor); NoxicoGame.Sound.PlaySound("set://GetItem"); ParentBoard.Redraw(); } break; case "craft": Crafting.Open(player.Character); break; #if DEBUG case "edit": TokenCarrier tc = null; if (PointingAt is DroppedItem) { tc = ((DroppedItem)PointingAt).Token; } else if (PointingAt is BoardChar) { tc = ((BoardChar)PointingAt).Character; } NoxicoGame.HostForm.Write("TOKEN EDIT ENGAGED. Waiting for editor process to exit.", Color.Black, Color.White, 0, 0); NoxicoGame.HostForm.Draw(); ((MainForm)NoxicoGame.HostForm).timer.Enabled = false; var dump = "-- WARNING! Many things may cause strange behavior or crashes. WATCH YOUR F*****G STEP.\r\n" + tc.DumpTokens(tc.Tokens, 0); var temp = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString() + ".txt"); File.WriteAllText(temp, dump); var process = System.Diagnostics.Process.Start(temp); process.WaitForExit(); var newDump = File.ReadAllText(temp); File.Delete(temp); ((MainForm)NoxicoGame.HostForm).timer.Enabled = true; ParentBoard.Redraw(); if (newDump == dump) { break; } tc.Tokenize(newDump); ((BoardChar)PointingAt).AdjustView(); ((BoardChar)PointingAt).Character.RecalculateStatBonuses(); ((BoardChar)PointingAt).Character.CheckHasteSlow(); break; case "mutate": var result = ((BoardChar)PointingAt).Character.Mutate(1, 30); NoxicoGame.AddMessage(result); break; case "turbomutate": result = ((BoardChar)PointingAt).Character.Mutate(2500, 30); NoxicoGame.AddMessage(result); break; #endif default: MessageBox.Notice("Unknown action handler \"" + ActionList.Answer.ToString() + "\".", true); break; } } ); // true, true); return; } else { /* * var tSD = this.ParentBoard.GetDescription(YPosition, XPosition); * if (!string.IsNullOrWhiteSpace(tSD)) * { * PointingAt = null; * MessageBox.ScriptPauseHandler = () => * { * NoxicoGame.Mode = UserMode.Aiming; * Point(); * }; * MessageBox.Notice(tSD, true); * return; * } */ } } #if DEBUG if (NoxicoGame.KeyMap[Keys.D]) { NoxicoGame.ClearKeys(); if (PointingAt != null && PointingAt is BoardChar) { ((BoardChar)PointingAt).Character.CreateInfoDump(); NoxicoGame.AddMessage("Info for " + ((BoardChar)PointingAt).Character.GetKnownName(true, true, true) + " dumped.", Color.Red); } } #endif 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); } }
public virtual void ToTilemap(ref Tile[,] map) { var woodFloor = Color.FromArgb(86, 63, 44); var caveFloor = Color.FromArgb(65, 66, 87); var wall = Color.FromArgb(20, 15, 12); var water = BiomeData.Biomes[BiomeData.ByName(biome.Realm == Realms.Nox ? "Water" : "KoolAid")]; allowCaveFloor = false; Clutter.ParentBoardHack = Board; var doorCount = 0; var safeZones = new List <Rectangle>(); for (var row = 0; row < plotRows; row++) { for (var col = 0; col < plotCols; col++) { if (plots[col, row].BaseID == null) { //Can clutter this up! if (includeClutter && Random.Flip()) { Board.AddClutter(col * plotWidth, row * plotHeight, (col * plotWidth) + plotWidth, (row * plotHeight) + plotHeight + row); } else { safeZones.Add(new Rectangle() { Left = col * plotWidth, Top = row * plotHeight, Right = (col * plotWidth) + plotWidth, Bottom = (row * plotHeight) + plotHeight + row }); } continue; } if (plots[col, row].BaseID == "<spillover>") { continue; } var building = plots[col, row]; var template = building.Template; var sX = (col * plotWidth) + building.XShift; var sY = (row * plotHeight) + building.YShift; for (var y = 0; y < template.Height; y++) { for (var x = 0; x < template.Width; x++) { var tc = template.MapScans[y][x]; var def = string.Empty; var fluid = Fluids.Dry; var addDoor = true; if (tc == '/') { addDoor = false; tc = '\\'; } switch (tc) { case '\'': continue; case ',': def = "pathWay"; // FIXME: kind of ugly but does the job break; case '.': def = "woodFloor"; break; case '+': //Exit -- can't be seen, coaxes walls into shape. def = "doorwayClosed"; if (addDoor) { doorCount++; var door = new Door() { XPosition = sX + x, YPosition = sY + y, ForegroundColor = woodFloor, BackgroundColor = woodFloor.Darken(), ID = building.BaseID + "_Door" + doorCount, ParentBoard = Board, Closed = true, Glyph = '+' }; Board.Entities.Add(door); } break; case '=': def = "outerWoodWall"; break; case '-': def = "innerWoodWall"; break; case '#': def = allowCaveFloor ? "stoneFloor" : "woodFloor"; break; default: if (template.Markings.ContainsKey(tc)) { #region Custom markings var m = template.Markings[tc]; if (m.Text == "block") { throw new Exception("Got a BLOCK-type marking in a building template."); } if (m.Text != "tile" && m.Text != "floor" && m.Text != "water") { //Keep a floor here. The entity fills in the blank. def = "woodFloor"; var tileDef = TileDefinition.Find(def, false); map[sX + x, sY + y].Index = tileDef.Index; //var owner = m.Owner == 0 ? null : building.Inhabitants[m.Owner - 1]; var owner = (Character)null; if (m.HasToken("owner")) { owner = building.Inhabitants[(int)m.GetToken("owner").Value - 1]; } if (m.Text == "bed") { var newBed = new Clutter() { XPosition = sX + x, YPosition = sY + y, Name = "Bed", ID = "Bed_" + (owner == null ? Board.Entities.Count.ToString() : owner.Name.ToID()), Description = owner == null?i18n.GetString("freebed") : i18n.Format("someonesbed", owner.Name.ToString(true)), ParentBoard = Board, }; Clutter.ResetToKnown(newBed); Board.Entities.Add(newBed); } if (m.Text == "container") { //var type = c == '\x14B' ? "cabinet" : c == '\x14A' ? "chest" : "container"; var type = "chest"; if (m.HasToken("wardrobe")) { type = "wardrobe"; } var contents = DungeonGenerator.GetRandomLoot("container", type, new Dictionary <string, string>() { { "gender", owner.PreferredGender.ToString().ToLowerInvariant() }, { "biome", BiomeData.Biomes[DungeonGenerator.DungeonGeneratorBiome].Name.ToLowerInvariant() }, }); if (owner != null) { foreach (var content in contents) { content.AddToken("owner", 0, owner.ID); } } var newContainer = new Container(type, contents) //owner == null ? type.Titlecase() : owner.Name.ToString(true) + "'s " + type, contents) { XPosition = sX + x, YPosition = sY + y, ID = "Container_" + type + "_" + (owner == null ? Board.Entities.Count.ToString() : owner.Name.ToID()), ParentBoard = Board, }; Clutter.ResetToKnown(newContainer); Board.Entities.Add(newContainer); } else if (m.Text == "clutter") { if (m.HasToken("id")) { var newClutter = new Clutter() { XPosition = sX + x, YPosition = sY + y, ParentBoard = Board, ID = m.GetToken("id").Text, Name = string.Empty, }; Clutter.ResetToKnown(newClutter); Board.Entities.Add(newClutter); } else { var newClutter = new Clutter() { Glyph = (char)m.GetToken("char").Value, //m.Params.Last()[0], XPosition = sX + x, YPosition = sY + y, ForegroundColor = Color.Black, BackgroundColor = tileDef.Background, ParentBoard = Board, Name = m.GetToken("name").Text, //Name, Description = m.HasToken("description") ? m.GetToken("description").Text : string.Empty, Blocking = m.HasToken("blocking"), }; Board.Entities.Add(newClutter); } } } else if (m.Text == "water") { fluid = Fluids.Water; } else { def = TileDefinition.Find((int)m.GetToken("index").Value).Name; } #endregion } break; } map[sX + x, sY + y].Index = TileDefinition.Find(def).Index; map[sX + x, sY + y].Fluid = fluid; } } for (var i = 0; i < building.Inhabitants.Count; i++) { var inhabitant = building.Inhabitants[i]; //Find each inhabitant's bed so we can give them a starting place. //Alternatively, place them anywhere there's a ' ' within their sector. var bc = new BoardChar(inhabitant); //var bedID = building.BaseID + "_Bed_" + inhabitant.Name.FirstName; //var bed = Board.Entities.OfType<Clutter>().FirstOrDefault(b => b.ID == bedID); //if (bed != null) //{ // bc.XPosition = bed.XPosition; // bc.YPosition = bed.YPosition; //} //else { //var okay = false; var x = 0; var y = 0; var lives = 100; while (lives > 0) { lives--; x = (col * plotWidth) + Random.Next(plotWidth); y = (row * plotHeight) + Random.Next(plotHeight); if (!map[x, y].Definition.Wall && (!template.AllowOutside && map[x, y].Definition.Ceiling) && Board.Entities.FirstOrDefault(e => e.XPosition == x && e.YPosition == y) == null) { break; } } bc.XPosition = x; bc.YPosition = y; } bc.Character.AddToken("sectorlock"); bc.ParentBoard = Board; bc.AdjustView(); bc.Sector = string.Format("s{0}x{1}", row, col); Board.Entities.Add(bc); } } } Board.ResolveVariableWalls(); if (safeZones.Count > 0 && includeWater) { Board.AddWater(safeZones); } }
public void MergeBitmap(string fileName, string tiledefs) { var bitmap = Mix.GetBitmap(fileName); var tileset = new Token(); tileset.AddSet(Mix.GetTokenTree(tiledefs, true)); var width = Width; var height = Height; if (width > bitmap.Width) { width = bitmap.Width; } if (height > bitmap.Height) { height = bitmap.Height; } for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var color = bitmap.GetPixel(x, y); if (color.Name == "ff000000" || color.A == 0) { continue; } var key = color.Name.Substring(2).ToUpperInvariant(); if (!tileset.HasToken(key)) { continue; } var tile = tileset.GetToken(key); //Keep the original tile, but drain it. if (tile.Text == "drain") { this.Tilemap[x, y].Fluid = Fluids.Dry; continue; } this.Tilemap[x, y].Index = TileDefinition.Find(tile.Text).Index; if (tile.Text.StartsWith("doorway")) { var door = new Door() { XPosition = x, YPosition = y, ForegroundColor = this.Tilemap[x, y].Definition.Background, BackgroundColor = this.Tilemap[x, y].Definition.Background.Darken(), ID = "mergeBitmap_Door" + x + "_" + y, ParentBoard = this, Closed = tile.Text.EndsWith("Closed"), Glyph = '+' }; this.Entities.Add(door); } if (tile.HasToken("clutter")) { var nc = new Clutter() { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(nc); var properties = tile.GetToken("clutter"); foreach (var property in properties.Tokens) { switch (property.Name) { case "id": nc.ID = property.Text; break; case "name": nc.Name = property.Text; break; case "desc": nc.Description = property.Text; break; case "glyph": nc.Glyph = (int)property.Value; break; case "fg": if (property.Text.StartsWith('#')) { nc.ForegroundColor = Color.FromCSS(property.Text); } else { nc.ForegroundColor = Color.FromName(property.Text); } break; case "bg": if (property.Text.StartsWith('#')) { nc.BackgroundColor = Color.FromCSS(property.Text); } else { nc.BackgroundColor = Color.FromName(property.Text); } break; case "block": nc.Blocking = true; break; case "burns": nc.CanBurn = true; break; } } } if (tile.HasToken("unique")) { var unique = tile.GetToken("unique"); var newChar = new BoardChar(Character.GetUnique(unique.Text)) { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(newChar); newChar.AssignScripts(unique.Text); newChar.ReassignScripts(); } if (!tile.HasToken("fluid")) { this.Tilemap[x, y].Fluid = Fluids.Dry; } else { this.Tilemap[x, y].Fluid = (Fluids)Enum.Parse(typeof(Fluids), tile.GetToken("fluid").Text, true); } } } this.ResolveVariableWalls(); }
public object RunScript(Token item, string script, Character character, BoardChar boardchar, Action <string> running) { var env = Lua.Environment; env.user = character; env.thisItem = this; env.thisToken = item; env.Consume = new Action <string>(x => this.Consume(character, item) /* character.GetToken("items").Tokens.Remove(item) */); env.print = new Action <string, bool>((x, y) => { var paused = true; MessageBox.ScriptPauseHandler = () => { paused = false; }; MessageBox.Notice((y ? x : x.Viewpoint(character)), true); while (paused) { NoxicoGame.Me.Update(); System.Windows.Forms.Application.DoEvents(); } }); env.ReportSet = new Action <List <string> >(x => { foreach (var result in x) { if (!result.IsBlank() && result[0] != '\uE2FC') { NoxicoGame.AddMessage(result.Viewpoint(character)); } } }); env.Identify = new Action <string>(x => { if (character.GetStat("mind") < 10) { //Dumb characters can't identify as well. if (Random.NextDouble() < 0.5) { return; } } //Random potion identification /* * if (this.HasToken("randomized")) * { * var rid = (int)this.GetToken("randomized").Value; * if (this.Path("equipable/ring") != null && rid < 128) * rid += 128; * var rdesc = NoxicoGame.Me.Potions[rid]; * if (rdesc[0] != '!') * { * //Still unidentified. Let's rock. * rdesc = '!' + rdesc; * NoxicoGame.Me.Potions[rid] = rdesc; * this.UnknownName = null; * } * //Random potions and rings are un-unidentified by taking away their UnknownName, but we clear the unidentified state anyway. * //item.RemoveToken("unidentified"; * //runningDesc += "You have identified this as " + this.ToString(item, true) + "."; * //return; * } */ //Regular item identification if (!this.UnknownName.IsBlank() && !NoxicoGame.Identifications.Contains(this.ID)) { NoxicoGame.Identifications.Add(this.ID); if (running != null) { running(i18n.Format("inventory_identify_as_x", this.ToString(item, true))); } } }); //var ret = env.DoChunk(script, "lol.lua"); return(Lua.Run(script, env)); }