/// <summary> /// Generic Subscreen handler. /// </summary> public static void Handler() { if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; NoxicoGame.DrawMessages(); NoxicoGame.DrawStatus(); UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || NoxicoGame.IsKeyDown(KeyBinding.Accept) || Vista.Triggers == XInputButtons.A || Vista.Triggers == XInputButtons.B) { //If we pressed Back/Esc or [B], pick the out-of-band -1 sentinel option. if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { option = -1; } Enter(null, null); ActionList.Answer = option == -1 ? -1 : options.ElementAt(option).Key; onChoice(); //Let the caller handle things. NoxicoGame.ClearKeys(); } else { UIManager.CheckKeys(); } }
public void LandFromFlight(bool forced = false) { NoxicoGame.AddMessage(i18n.GetString("youland")); Character.RemoveToken("flying"); //add swim capability? var tile = ParentBoard.Tilemap[XPosition, YPosition]; if (tile.Fluid != Fluids.Dry && !tile.Shallow && Character.IsSlime) { Hurt(9999, "death_doveinanddrowned", null, false); } else if (tile.Definition.Cliff) { Hurt(9999, "death_doveintodepths", null, false, false); } else if (tile.Definition.Fence) { //I guess I'm still a little... on the fence. /* * var tileDesc = tile.GetDescription(); * if (!tileDesc.HasValue) * tileDesc = new TileDescription() { Color = Color.Silver, Name = "obstacle" }; * NoxicoGame.AddMessage("You fall off the " + tileDesc.Value.Name + ".", tileDesc.Value.Color); * Hurt(5, "landed on " + (tileDesc.Value.Name.StartsWithVowel() ? "an" : "a") + ' ' + tileDesc.Value.Name, null, false, true); */ //YEEEEAAAAH!!!!!!!! } }
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 void Eat(Character gourmand, Token item) { if (item.HasToken("fat")) { var hwa = Random.Flip() ? "hips" : Random.Flip() ? "waist" : "ass/size"; if (gourmand.Path(hwa) == null) { return; } var change = Random.NextDouble() * 0.25; if (change > 0) { gourmand.Path(hwa).Value += (float)change; if (!gourmand.HasToken("player")) { return; } if (hwa == "ass/size") { hwa = "butt"; } NoxicoGame.AddMessage(i18n.GetString("eat_toyour" + hwa).Viewpoint(gourmand)); } } }
/// <summary> /// Sets up a Crafting subscreen for the given Character, usually the Player. /// </summary> /// <param name="carrier"></param> public static void Open(Character carrier) { Carrier = carrier; NoxicoGame.Subscreen = Handler; NoxicoGame.Mode = UserMode.Subscreen; Subscreens.FirstDraw = true; NoxicoGame.ClearKeys(); }
public bool UpdateSex() { if (!EnsureSexPartner()) { return(false); } if (HasToken("havingsex_initsex")) { var runinit = SexManager.GetResult("initsex", this, sexPartner); SexManager.Apply(runinit, this, sexPartner, new Action <string>(x => NoxicoGame.AddMessage(x))); RemoveToken("havingsex_initsex"); } var everysexturn = SexManager.GetResult("everysexturn", this, sexPartner); SexManager.Apply(everysexturn, this, sexPartner, new Action <string>(x => NoxicoGame.AddMessage(x))); if (this.GetStat("pleasure") >= 100) { var result = SexManager.GetResult("climax", this, sexPartner); if (this.HasItemEquipped("orgasm_denial_ring")) { result = SexManager.GetResult("orgasm_denial_ring", this, sexPartner); } SexManager.Apply(result, this, sexPartner, new Action <string>(x => NoxicoGame.AddMessage(x))); this.BoardChar.Energy -= (int)result.GetToken("time").Value; return(true); } var possibilities = SexManager.GetPossibilities(this, sexPartner); if (this.BoardChar is Player) { ActionList.Show(string.Empty, this.BoardChar.XPosition, this.BoardChar.YPosition, possibilities, () => { var answer = ActionList.Answer as Token; var action = (answer == null) ? "wait" : answer.Text; var result = SexManager.GetResult(action, this, sexPartner); SexManager.Apply(result, this, sexPartner, new Action <string>(x => NoxicoGame.AddMessage(x))); this.BoardChar.Energy -= (int)result.GetToken("time").Value; } ); } else { //var keys = possibilities.Keys.Select(p => p as string).ToArray(); //var choice = Toolkit.PickOne(keys); var choice = possibilities.Keys.OfType <Token>().ToList().PickWeighted().Text; var result = SexManager.GetResult(choice, this, sexPartner); SexManager.Apply(result, this, sexPartner, new Action <string>(x => NoxicoGame.AddMessage(x))); this.BoardChar.Energy -= (int)result.GetToken("time").Value; } return(true); }
public static void PickItemsFrom(List <DroppedItem> items) { var itemDict = new Dictionary <object, string>(); foreach (var item in items) { var name = item.Item.ToString(item.Token, false, false); name = name.Substring(0, 1).ToUpperInvariant() + name.Substring(1); itemDict.Add(item, name); } itemDict.Add(-2, i18n.GetString("action_pickup_all")); itemDict.Add(-1, i18n.GetString("action_pickup_cancel")); //"...nothing" ActionList.Show(i18n.GetString("action_pickup_window") /* "Pick up..." */, items[0].XPosition, items[0].YPosition, itemDict, () => { var player = NoxicoGame.Me.Player; if (ActionList.Answer is int && (int)ActionList.Answer == -1) { //Cancelled. return; } else if (ActionList.Answer is int && (int)ActionList.Answer == -2) { //All foreach (var d in items) { d.Take(player.Character, player.ParentBoard); player.Energy -= 1000; } NoxicoGame.AddMessage(i18n.Format("youpickup_all")); } else { var drop = ActionList.Answer as DroppedItem; var item = drop.Item; var token = drop.Token; drop.Take(player.Character, player.ParentBoard); player.Energy -= 1000; NoxicoGame.AddMessage(i18n.Format("youpickup_x", item.ToString(token, true))); //, drop.ForegroundColor); } NoxicoGame.Sound.PlaySound("set://GetItem"); player.ParentBoard.Redraw(); } ); }
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 void EndTurn() { var nrg = Energy; Energy = 5000; var r = Lua.Environment.EachBoardCharTurn(this, this.Character); Energy = nrg; NoxicoGame.PlayerReady = false; if (Character.HasToken("flying")) { var f = Character.GetToken("flying"); f.Value--; if (!Character.HasToken("wings") || Character.GetToken("wings").HasToken("small")) { NoxicoGame.AddMessage(i18n.GetString("losewings")); f.Value = -10; } if (f.Value <= 0) { LandFromFlight(true); } } if (ParentBoard == null) { return; } ParentBoard.Update(true); if (ParentBoard.IsBurning(YPosition, XPosition)) { Hurt(10, "death_burned", null, false, false); } //Leave EntitiesToAdd/Remove to Board.Update next passive cycle. }
private void Form1_KeyUp(object sender, KeyEventArgs e) { NoxicoGame.KeyMap[e.KeyCode] = false; NoxicoGame.KeyTrg[e.KeyCode] = true; if (numpad.ContainsKey(e.KeyCode)) { NoxicoGame.KeyMap[numpad[e.KeyCode]] = false; NoxicoGame.KeyTrg[numpad[e.KeyCode]] = true; } if (e.Modifiers == Keys.Shift) { NoxicoGame.Modifiers[0] = false; } if (e.KeyCode == (Keys)NoxicoGame.KeyBindings[KeyBinding.Screenshot]) { if (e.Modifiers == Keys.Shift) { using (var dumpFile = new StreamWriter("lol.txt", false, System.Text.Encoding.GetEncoding(437))) { for (int row = 0; row < Program.Rows; row++) { for (int col = 0; col < Program.Cols; col++) { dumpFile.Write(NoxicoGame.IngameTo437[image[col, row].Character]); } dumpFile.WriteLine(); } } using (var dumpFile = new StreamWriter("lol.html")) { dumpFile.WriteLine("<!DOCTYPE html><html><head>"); dumpFile.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; CHARSET=utf-8\" />"); dumpFile.WriteLine("</head><body>"); dumpFile.WriteLine("<table style=\"font-family: Unifont, monospace\" cellspacing=0 cellpadding=0>"); for (int row = 0; row < Program.Rows; row++) { dumpFile.Write("<tr>"); for (int col = 0; col < Program.Cols; col++) { var ch = string.Format("&#x{0:X};", (int)NoxicoGame.IngameToUnicode[image[col, row].Character]); if (ch == " ") { ch = " "; } dumpFile.Write("<td style=\"background:{1};color:{2}\">{0}</td>", ch, image[col, row].Background.ToHex(), image[col, row].Foreground.ToHex()); } dumpFile.WriteLine("</tr>"); } dumpFile.WriteLine("</table>"); dumpFile.WriteLine("</body></html>"); } return; } var shotDir = IniFile.GetValue("misc", "shotpath", "screenshots"); if (shotDir.StartsWith('$')) { shotDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + shotDir.Substring(1); } if (!Directory.Exists(shotDir)) { Directory.CreateDirectory(shotDir); } int i = 1; while (File.Exists(Path.Combine(shotDir, "screenshot" + i.ToString("000") + ".png"))) { i++; } backBuffer.Save(Path.Combine(shotDir, "screenshot" + i.ToString("000") + ".png"), ImageFormat.Png); Program.WriteLine("Screenshot saved."); } if (e.KeyValue == 191) { NoxicoGame.KeyMap[Keys.L] = false; } if (e.KeyCode == Keys.R && e.Control) { NoxicoGame.KeyMap[Keys.R] = false; for (int row = 0; row < Program.Rows; row++) { for (int col = 0; col < Program.Cols; col++) { previousImage[col, row].Character = '\uFFFE'; } } } if (e.KeyCode == Keys.A && e.Control && NoxicoGame.Mode == UserMode.Walkabout) { NoxicoGame.KeyMap[Keys.A] = false; NoxicoGame.ShowMessageLog(); } #if DEBUG if (e.KeyCode == Keys.E && e.Control && NoxicoGame.Mode == UserMode.Walkabout) { (new Editor()).LoadBoard(Noxico.CurrentBoard); } #endif }
public static void Handler() { var host = NoxicoGame.HostForm; var keys = NoxicoGame.KeyMap; var left = (Program.Cols / 2) - (72 / 2); if (Subscreens.FirstDraw) { scroll = 1; Subscreens.FirstDraw = false; window = new UIWindow(text[0]) { Left = left, Top = 1, Width = 74, Height = Program.Rows - 3 }; window.Draw(); var help = ' ' + i18n.GetString("textscroller_help") + ' '; host.Write(help, UIColors.WindowBorder, Color.Transparent, Program.Rows - 3, (Program.Cols / 2) - (help.Length() / 2)); var empty = new string(' ', 70); for (int i = 1; i < Program.Rows - 5; i++) { host.Write(empty, UIColors.RegularText, UIColors.WindowBackground, 1 + i, left + 2); } for (int i = scroll; i < text.Length && i - scroll < Program.Rows - 5; i++) { if (i < 1) { continue; } host.Write(' ' + text[i].PadEffective(70), UIColors.RegularText, UIColors.WindowBackground, 1 + i, left + 2); } Subscreens.Redraw = true; } if (Subscreens.Redraw) { NoxicoGame.HostForm.SetCell(2, left + 73, (scroll > 1) ? '\x1E' : '\xBA', (scroll > 1) ? UIColors.RegularText : UIColors.WindowBorder, UIColors.WindowBackground); NoxicoGame.HostForm.SetCell(Program.Rows - 4, left + 73, (scroll + 21 < text.Length) ? '\x1F' : '\xBA', (scroll + 21 < text.Length) ? UIColors.RegularText : UIColors.WindowBorder, UIColors.WindowBackground); Subscreens.Redraw = false; } if (keys[System.Windows.Forms.Keys.S]) { File.WriteAllText("current.txt", string.Join("\n", text).ToUnicode()); File.WriteAllText("current.html", string.Join("\n", text).ToUnicode().ToHtml()); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } if ((NoxicoGame.IsKeyDown(KeyBinding.ScrollUp) || Vista.DPad == XInputButtons.Up) && (DateTime.Now - slow).Milliseconds >= 100) { slow = DateTime.Now; scroll--; if (scroll < 1) { scroll = 1; } else { host.ScrollDown(2, Program.Rows - 4, left + 1, left + 72, UIColors.DarkBackground); var i = scroll; host.Write(new string(' ', 72), UIColors.RegularText, UIColors.WindowBackground, 2, left + 1); host.Write(text[i], UIColors.RegularText, UIColors.WindowBackground, 2, left + 2); Subscreens.Redraw = true; } } if ((NoxicoGame.IsKeyDown(KeyBinding.ScrollDown) || Vista.DPad == XInputButtons.Down) && (DateTime.Now - slow).Milliseconds >= 100) { slow = DateTime.Now; scroll++; if (scroll > text.Length - Program.Rows + 4) { scroll = text.Length - Program.Rows + 4; } else if (scroll < 1) { scroll = 1; } else { host.ScrollUp(2, Program.Rows - 4, left + 1, left + 72, UIColors.DarkBackground); var i = scroll + Program.Rows - 6; host.Write(new string(' ', 72), UIColors.RegularText, UIColors.WindowBackground, Program.Rows - 4, left + 1); if (i < text.Length) { host.Write(text[i], UIColors.RegularText, UIColors.WindowBackground, Program.Rows - 4, left + 2); } Subscreens.Redraw = true; } } }
public new void AimShot(Entity target) { //TODO: throw whatever is being held by the player at the target, according to their Throwing skill and the total distance. //If it's a gun they're holding, fire it instead, according to their Shooting skill. //MessageBox.Message("Can't shoot yet, sorry.", true); if (target is Player) { MessageBox.Notice("Don't shoot yourself in the foot!", true); return; } var weapon = Character.CanShoot(); var weap = weapon.GetToken("weapon"); var skill = weap.GetToken("skill"); if (new[] { "throwing", "small_firearm", "large_firearm", "huge_firearm" }.Contains(skill.Text)) { if (weap.HasToken("ammo")) { var ammoName = weap.GetToken("ammo").Text; var carriedAmmo = this.Character.GetToken("items").Tokens.Find(ci => ci.Name == ammoName); if (carriedAmmo == null) { return; } var knownAmmo = NoxicoGame.KnownItems.Find(ki => ki.ID == ammoName); if (knownAmmo == null) { return; } knownAmmo.Consume(Character, carriedAmmo); } else if (weapon.HasToken("charge")) { var carriedGun = this.Character.GetToken("items").Tokens.Find(ci => ci.Name == weapon.ID && ci.HasToken("equipped")); weapon.Consume(Character, carriedGun); } if (weapon != null) { FireLine(weapon.Path("effect"), target); } } else { MessageBox.Notice("Can't throw yet, sorry.", true); return; } var aimSuccess = true; //TODO: make this skill-relevant. if (aimSuccess) { if (target is BoardChar) { var hit = target as BoardChar; var damage = weap.Path("damage").Value *GetDefenseFactor(weap, hit.Character); var overallArmor = 0f; foreach (var targetArmor in hit.Character.GetToken("items").Tokens.Where(t => t.HasToken("equipped"))) { var targetArmorItem = NoxicoGame.KnownItems.FirstOrDefault(i => i.Name == targetArmor.Name); if (targetArmorItem == null) { continue; } if (!targetArmorItem.HasToken("armor")) { continue; } if (targetArmorItem.GetToken("armor").Value > overallArmor) { overallArmor = Math.Max(1.5f, targetArmorItem.GetToken("armor").Value); } } if (overallArmor != 0) { damage /= overallArmor; } NoxicoGame.AddMessage(i18n.Format("youhitxfory", hit.Character.GetKnownName(false, false, true), damage, i18n.Pluralize("point", (int)damage))); hit.Hurt(damage, "death_shot", this, false); } this.Character.IncreaseSkill(skill.Text); } NoxicoGame.Mode = UserMode.Walkabout; Energy -= 500; EndTurn(); }
public override bool Hurt(float damage, string cause, object aggressor, bool finishable = false, bool leaveCorpse = true) { if (AutoTravelling) { NoxicoGame.AddMessage(i18n.Format("autotravelstop")); AutoTravelling = false; } if (Character.HasItemEquipped("eternitybrooch")) { var brooch = Character.GetEquippedItemBySlot("neck"); //can assume the neck slot has the brooch. var today = NoxicoGame.InGameTime.DayOfYear; if (!brooch.HasToken("lastTrigger")) { brooch.AddToken("lastTrigger", today - 2); } if (Math.Abs(brooch.GetToken("lastTrigger").Value - today) >= 2 && Character.Health - damage <= 0) { brooch.GetToken("lastTrigger").Value = today; NoxicoGame.AddMessage(i18n.GetString("eternitybrooched")); Character.Health = Character.MaximumHealth; Reposition(); return(false); } } var dead = base.Hurt(damage, cause, aggressor, finishable); if (dead) { if (aggressor != null && aggressor is BoardChar) { var aggChar = ((BoardChar)aggressor).Character; var relation = Character.Path("ships/" + aggChar.ID); if (relation == null) { relation = new Token(aggChar.ID); Character.Path("ships").Tokens.Add(relation); } relation.AddToken("killer"); if (aggChar.HasToken("stolenfrom")) { var myItems = Character.GetToken("items").Tokens; var hisItems = aggChar.GetToken("items").Tokens; var stolenGoods = myItems.Where(t => t.HasToken("owner") && t.GetToken("owner").Text == aggChar.ID).ToList(); foreach (var item in stolenGoods) { hisItems.Add(item); myItems.Remove(item); } aggChar.GetToken("stolenfrom").Name = "wasstolenfrom"; aggChar.RemoveToken("hostile"); } } if (Lives == 0) { Character.AddToken("gameover"); NoxicoGame.AddMessage(i18n.GetString("gameover_title"), Color.Red); //var playerFile = Path.Combine(NoxicoGame.SavePath, NoxicoGame.WorldName, "player.bin"); //File.Delete(playerFile); var world = string.Empty; if (NoxicoGame.WorldName != "<Testing Arena>") { world = System.IO.Path.Combine(NoxicoGame.SavePath, NoxicoGame.WorldName); } NoxicoGame.Sound.PlayMusic("set://Death"); NoxicoGame.InGame = false; var c = i18n.GetString(cause + "_player"); if (c[0] == '[') { c = i18n.GetString(cause); } MessageBox.Ask( i18n.Format("youdied", c), () => { Character.CreateInfoDump(); if (NoxicoGame.WorldName != "<Testing Arena>") { Directory.Delete(world, true); } NoxicoGame.HostForm.Close(); }, () => { if (NoxicoGame.WorldName != "<Testing Arena>") { Directory.Delete(world, true); } NoxicoGame.HostForm.Close(); } ); } else { Respawn(); } } return(dead); }
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)); }
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); } } } }
/// <summary> /// Generic Subscreen handler. /// </summary> public static void Handler() { //TODO: add more things, such as a status bar and a window with the exact results. if (Subscreens.FirstDraw) { UIManager.Initialize(); Subscreens.FirstDraw = false; NoxicoGame.ClearKeys(); Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; recipes = GetPossibilities(Carrier); var h = recipes.Count < 40 ? recipes.Count : 40; if (h == 0) { h++; } recipeWindow = new UIWindow(string.Empty) { Top = 2, Left = 2, Width = 76, Height = h + 2 }; recipeList = new UIList(string.Empty, null, recipes.Select(r => r.Display)) { Top = 3, Left = 3, Width = 74, Height = h }; recipeList.Enter = (s, e) => { if (recipes.Count == 0) { return; } var i = recipeList.Index; recipes[i].Apply(); //Redetermine the possibilities and update the UI accordingly. recipes = GetPossibilities(Carrier); if (recipes.Count > 0) { recipeList.Items = recipes.Select(r => r.Display).ToList(); if (i >= recipeList.Items.Count) { i = recipeList.Items.Count - 1; } recipeList.Index = i; h = recipes.Count < 40 ? recipes.Count : 40; } else { h = 1; recipeList.Hidden = true; } recipeWindow.Height = h + 2; recipeList.Height = h; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(); UIManager.Draw(); }; UIManager.Elements.Add(recipeWindow); UIManager.Elements.Add(new UILabel(i18n.GetString("craft_nothing")) { Left = 3, Top = 3 }); UIManager.Elements.Add(recipeList); UIManager.Highlight = recipeList; UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || NoxicoGame.IsKeyDown(KeyBinding.Items) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } else { UIManager.CheckKeys(); } }
private static Bitmap backdrop; //, backWithPortrait; /// <summary> /// Don't see a Subscreen with multiple handlers often... /// </summary> public static void CharacterCreator() { if (Subscreens.FirstDraw) { //Start creating the world as we work... if (worldgen == null) //Conditional added by Mat. { worldgen = new System.Threading.Thread(NoxicoGame.Me.CreateRealm); worldgen.Start(); } //Load all bonus traits. var traits = new List <string>(); var traitHelps = new List <string>(); var traitsDoc = Mix.GetTokenTree("bonustraits.tml"); foreach (var trait in traitsDoc.Where(t => t.Name == "trait")) { traits.Add(trait.GetToken("display").Text); traitHelps.Add(trait.GetToken("description").Text); } //Define the help texts for the standard controls. controlHelps = new Dictionary <string, string>() { { "back", i18n.GetString("cchelp_back") }, { "next", i18n.GetString("cchelp_next") }, { "play", Random.NextDouble() > 0.7 ? "FRUITY ANGELS MOLEST SHARKY" : "ENGAGE RIDLEY MOTHER F****R" }, { "name", i18n.GetString("cchelp_name") }, { "species", string.Empty }, { "sex", i18n.GetString("cchelp_sex") }, { "gid", i18n.GetString("cchelp_gid") }, { "pref", i18n.GetString("cchelp_pref") }, { "tutorial", i18n.GetString("cchelp_tutorial") }, { "easy", i18n.GetString("cchelp_easy") }, { "gift", traitHelps[0] }, }; var xScale = Program.Cols / 80f; var yScale = Program.Rows / 25f; //backdrop = Mix.GetBitmap("chargen.png"); backdrop = new Bitmap(Program.Cols, Program.Rows * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb); var ccback = Mix.GetBitmap("ccback.png"); var ccpage = Mix.GetBitmap("ccpage.png"); var ccbars = Mix.GetBitmap("ccbars.png"); var pageLeft = Program.Cols - ccpage.Width - (int)(2 * yScale); var pageTop = Program.Rows - (ccpage.Height / 2); using (var gfx = Graphics.FromImage(backdrop)) { gfx.Clear(Color.Black); gfx.DrawImage(ccback, 0, 0, Program.Cols, Program.Rows * 2); gfx.DrawImage(ccpage, pageLeft, pageTop, ccpage.Width, ccpage.Height); var barsSrc = new System.Drawing.Rectangle(0, 3, ccbars.Width, 7); var barsDst = new System.Drawing.Rectangle(0, 0, Program.Cols, 7); gfx.DrawImage(ccbars, barsDst, barsSrc, GraphicsUnit.Pixel); barsSrc = new System.Drawing.Rectangle(0, 0, ccbars.Width, 5); barsDst = new System.Drawing.Rectangle(0, (Program.Rows * 2) - 5, Program.Cols, 5); gfx.DrawImage(ccbars, barsDst, barsSrc, GraphicsUnit.Pixel); } //Build the interface. var title = "\xB4 " + i18n.GetString("cc_title") + " \xC3"; var bar = new string('\xC4', 33); string[] sexoptions = { i18n.GetString("Male"), i18n.GetString("Female"), i18n.GetString("Herm"), i18n.GetString("Neuter") }; string[] prefoptions = { i18n.GetString("Male"), i18n.GetString("Female"), i18n.GetString("Either") }; var labelL = pageLeft + 5; var cntrlL = labelL + 2; var header = (pageTop / 2) + 3; var top = header + 2; var buttons = (pageTop / 2) + 20; controls = new Dictionary <string, UIElement>() { { "backdrop", new UIPNGBackground(backdrop) }, //backWithPortrait) }, { "headerline", new UILabel(bar) { Left = labelL, Top = header, Foreground = Color.Black } }, { "header", new UILabel(title) { Left = labelL + 17 - (title.Length() / 2), Top = header, Width = title.Length(), Foreground = Color.Black } }, { "back", new UIButton(i18n.GetString("cc_back"), null) { Left = labelL, Top = buttons, Width = 10, Height = 1 } }, { "next", new UIButton(i18n.GetString("cc_next"), null) { Left = labelL + 23, Top = buttons, Width = 10, Height = 1 } }, { "wait", new UILabel(i18n.GetString("cc_wait")) { Left = labelL + 23, Top = buttons, Foreground = Color.Silver } }, { "play", new UIButton(i18n.GetString("cc_play"), null) { Left = labelL + 23, Top = buttons, Width = 10, Height = 1, Hidden = true } }, { "nameLabel", new UILabel(i18n.GetString("cc_name")) { Left = labelL, Top = top, Foreground = Color.Gray } }, { "name", new UITextBox(string.Empty) { Left = cntrlL, Top = top + 1, Width = 24, Foreground = Color.Black, Background = Color.Transparent } }, { "nameRandom", new UILabel(i18n.GetString("cc_random")) { Left = cntrlL + 2, Top = top + 1, Foreground = Color.Gray } }, { "speciesLabel", new UILabel(i18n.GetString("cc_species")) { Left = labelL, Top = top + 3, Foreground = Color.Gray } }, { "species", new UISingleList() { Left = cntrlL, Top = top + 4, Width = 26, Foreground = Color.Black, Background = Color.Transparent } }, { "tutorial", new UIToggle(i18n.GetString("cc_tutorial")) { Left = labelL, Top = top + 6, Width = 24, Foreground = Color.Black, Background = Color.Transparent } }, { "easy", new UIToggle(i18n.GetString("cc_easy")) { Left = labelL, Top = top + 7, Width = 24, Foreground = Color.Black, Background = Color.Transparent } }, { "sexLabel", new UILabel(i18n.GetString("cc_sex")) { Left = labelL, Top = top, Foreground = Color.Gray } }, { "sex", new UIRadioList(sexoptions) { Left = cntrlL, Top = top + 1, Width = 24, Foreground = Color.Black, Background = Color.Transparent } }, { "gidLabel", new UILabel(i18n.GetString("cc_gid")) { Left = labelL, Top = top + 6, Foreground = Color.Gray } }, { "gid", new UISingleList(string.Empty, null, sexoptions.ToList(), 0) { Left = cntrlL, Top = top + 7, Width = 26, Foreground = Color.Black, Background = Color.Transparent } }, { "prefLabel", new UILabel(i18n.GetString("cc_pref")) { Left = labelL, Top = top + 9, Foreground = Color.Gray } }, { "pref", new UISingleList(string.Empty, null, prefoptions.ToList(), 1) { Left = cntrlL, Top = top + 10, Width = 26, Foreground = Color.Black, Background = Color.Transparent } }, { "giftLabel", new UILabel(i18n.GetString("cc_gift")) { Left = labelL, Top = top, Foreground = Color.Gray } }, { "gift", new UIList(string.Empty, null, traits) { Left = cntrlL, Top = top + 1, Width = 30, Height = 24, Foreground = Color.Black, Background = Color.Transparent } }, { "controlHelp", new UILabel(traitHelps[0]) { Left = 1, Top = 1, Width = pageLeft - 2, Height = 4, Foreground = Color.White, Darken = true } }, { "topHeader", new UILabel(i18n.GetString("cc_header")) { Left = 1, Top = 0, Foreground = Color.Silver } }, { "helpLine", new UILabel(i18n.GetString("cc_footer")) { Left = 1, Top = Program.Rows - 1, Foreground = Color.Silver } }, }; //Map the controls to pages. pages = new List <UIElement>[] { new List <UIElement>() { controls["backdrop"], controls["headerline"], controls["header"], controls["topHeader"], controls["helpLine"], controls["nameLabel"], controls["name"], controls["nameRandom"], controls["speciesLabel"], controls["species"], controls["tutorial"], controls["easy"], controls["controlHelp"], controls["next"], }, new List <UIElement>() { controls["backdrop"], controls["headerline"], controls["header"], controls["topHeader"], controls["helpLine"], controls["sexLabel"], controls["sex"], controls["gidLabel"], controls["gid"], controls["prefLabel"], controls["pref"], controls["controlHelp"], controls["back"], controls["next"], }, new List <UIElement>(), //Placeholder, filled in on-demand from PlayableRace.ColorItems. new List <UIElement>() { controls["backdrop"], controls["headerline"], controls["header"], controls["topHeader"], controls["helpLine"], controls["giftLabel"], controls["gift"], controls["controlHelp"], controls["back"], controls["wait"], controls["play"], }, }; CollectPlayables(); loadPage = new Action <int>(p => { UIManager.Elements.Clear(); UIManager.Elements.AddRange(pages[page]); UIManager.Highlight = UIManager.Elements[5]; //select whatever comes after helpLine. }); //Called when changing species. loadColors = new Action <int>(i => { var species = playables[i]; controlHelps["species"] = species.Bestiary; pages[2].Clear(); pages[2].AddRange(new[] { controls["backdrop"], controls["headerline"], controls["header"], controls["topHeader"], controls["helpLine"] }); pages[2].AddRange(species.ColorItems.Values); pages[2].AddRange(new[] { controls["controlHelp"], controls["back"], controls["next"] }); }); controls["back"].Enter = (s, e) => { page--; loadPage(page); UIManager.Draw(); }; controls["next"].Enter = (s, e) => { page++; loadPage(page); UIManager.Draw(); }; controls["play"].Enter = (s, e) => { var playerName = controls["name"].Text; var sex = ((UIRadioList)controls["sex"]).Value; var gid = ((UISingleList)controls["gid"]).Index; var pref = ((UISingleList)controls["pref"]).Index; var species = ((UISingleList)controls["species"]).Index; var tutorial = ((UIToggle)controls["tutorial"]).Checked; var easy = ((UIToggle)controls["easy"]).Checked; var bonus = ((UIList)controls["gift"]).Text; var colorMap = new Dictionary <string, string>(); foreach (var editable in playables[species].ColorItems) { if (editable.Key.StartsWith("lbl")) { continue; } var path = editable.Key; var value = ((UISingleList)editable.Value).Text; colorMap.Add(path, value); } NoxicoGame.Me.CreatePlayerCharacter(playerName.Trim(), (Gender)(sex + 1), (Gender)(gid + 1), pref, playables[species].ID, colorMap, bonus); if (tutorial) { NoxicoGame.Me.Player.Character.AddToken("tutorial"); } if (easy) { NoxicoGame.Me.Player.Character.AddToken("easymode"); } NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddYears(Random.Next(0, 10)); NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddDays(Random.Next(20, 340)); NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddHours(Random.Next(10, 54)); NoxicoGame.Me.CurrentBoard.UpdateLightmap(NoxicoGame.Me.Player, true); Subscreens.FirstDraw = true; NoxicoGame.Immediate = true; /* #if DEBUG * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("orgasm_denial_ring"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("baseballbat"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("really_kinky_panties"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("timertest"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("clit_regenring"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("gExtractor"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("strapon_ovi"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("strapon"); #if FREETESTPOTIONS * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("foxite"); // ok * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("odd_nip"); // ok * //NoxicoGame.Me.Player.Character.GetToken("items").AddToken("dogmorph"); no bodyplan * //NoxicoGame.Me.Player.Character.GetToken("items").AddToken("bunnymorph"); no bodyplan * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("chaos_potion"); // ok * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("enhanced_chaos_potion"); // ok * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("demonite_potion"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("tentacle_potion"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("cock_potion"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("corrupted_cock_potion"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("neutralizer_potion"); * NoxicoGame.Me.Player.Character.GetToken("items").AddToken("spidermorph"); #endif #endif */ NoxicoGame.AddMessage(i18n.GetString("welcometonoxico"), Color.Yellow); NoxicoGame.AddMessage(i18n.GetString("rememberhelp")); //Story(); }; ((UISingleList)controls["species"]).Items.Clear(); playables.ForEach(x => ((UISingleList)controls["species"]).Items.Add(x.Name.Titlecase())); ((UISingleList)controls["species"]).Index = 0; loadColors(0); ((UIRadioList)controls["sex"]).ItemsEnabled = playables[0].SexLocks; controls["species"].Change = (s, e) => { var speciesIndex = ((UISingleList)controls["species"]).Index; loadColors(speciesIndex); var playable = playables[speciesIndex]; controlHelps["species"] = playable.Bestiary; controls["controlHelp"].Text = playable.Bestiary.Wordwrap(controls["controlHelp"].Width); var sexList = (UIRadioList)controls["sex"]; sexList.ItemsEnabled = playable.SexLocks; if (!sexList.ItemsEnabled[sexList.Value]) { //Uh-oh. Select the first non-disabled item. for (var i = 0; i < sexList.ItemsEnabled.Length; i++) { if (sexList.ItemsEnabled[i]) { sexList.Value = i; break; } } } //redrawBackdrop(0); UIManager.Draw(); }; controls["sex"].Change = (s, e) => { //redrawBackdrop(0); UIManager.Draw(); }; controls["name"].Change = (s, e) => { controls["nameRandom"].Hidden = !controls["name"].Text.IsBlank(); UIManager.Draw(); }; controls["gift"].Change = (s, e) => { var giftIndex = ((UIList)controls["gift"]).Index; controls["controlHelp"].Text = traitHelps[giftIndex].Wordwrap(controls["controlHelp"].Width); controls["controlHelp"].Top = controls["gift"].Top + giftIndex; UIManager.Draw(); }; ((UIToggle)controls["tutorial"]).Checked = IniFile.GetValue("misc", "tutorial", true); ((UIToggle)controls["easy"]).Checked = IniFile.GetValue("misc", "easymode", false); UIManager.Initialize(); UIManager.HighlightChanged = (s, e) => { var c = controls.FirstOrDefault(x => x.Value == UIManager.Highlight); if (c.Key != null && controlHelps.ContainsKey(c.Key)) { controls["controlHelp"].Text = controlHelps[c.Key].Wordwrap(controls["controlHelp"].Width); controls["controlHelp"].Top = c.Value.Top; } else { controls["controlHelp"].Text = string.Empty; } UIManager.Draw(); }; loadPage(page); //redrawBackdrop(0); Subscreens.FirstDraw = false; Subscreens.Redraw = true; UIManager.HighlightChanged(null, null); NoxicoGame.Sound.PlayMusic("set://Character Creation", false); NoxicoGame.InGame = false; } if (Subscreens.Redraw) { UIManager.Draw(); Subscreens.Redraw = false; } if (WorldGenFinished) { WorldGenFinished = false; controls["play"].Hidden = false; UIManager.Draw(); } UIManager.CheckKeys(); }
public void Use(Character character, Token item, bool noConfirm = false) { var boardchar = NoxicoGame.Me.CurrentBoard.Entities.OfType <BoardChar>().First(x => x.Character == character); var runningDesc = string.Empty; Action <string> showDesc = new Action <string>(d => { NoxicoGame.DrawStatus(); if (d.Contains('\n')) { MessageBox.Notice(runningDesc.Viewpoint(boardchar.Character, null)); } else { NoxicoGame.AddMessage(runningDesc.Viewpoint(boardchar.Character, null)); } }); #region Books if (this.ID == "book") { TextScroller.ReadBook(item.GetToken("id").Text); return; } #endregion #region Equipment if (this.HasToken("equipable")) { if (item == null) { var items = character.GetToken("items"); item = items.Tokens.Find(x => x.Name == this.ID); } if (!item.HasToken("equipped")) { //TODO: only ask if it's the player? //Not wearing it MessageBox.Ask(runningDesc + i18n.Format("inventory_equip_x", this.ToString(item, true)), () => { try { if (this.Equip(character, item)) { runningDesc += i18n.Format("x_equiped_y", this.ToString(item, true)); } } catch (ItemException c) { runningDesc += c.Message; } if (!runningDesc.IsBlank()) { showDesc(runningDesc.Viewpoint(boardchar.Character)); } return; }, null); } else { //Wearing/wielding it if (item.HasToken("cursed") && item.GetToken("cursed").HasToken("known")) { runningDesc += item.GetToken("cursed").Text.IsBlank(i18n.Format("inventory_cursed_" + (this.HasToken("plural") ? "plural" : "singular"), this.ToString(item, true)), item.GetToken("cursed").Text); showDesc(runningDesc.Viewpoint(boardchar.Character)); return; } MessageBox.Ask(i18n.Format("inventory_unequip_x", this.ToString(item, true)), () => { try { if (this.Unequip(character)) { runningDesc += i18n.Format("x_unequiped_y", this.ToString(item, true)); } } catch (ItemException x) { runningDesc += x.Message; } if (!runningDesc.IsBlank()) { showDesc(runningDesc.Viewpoint(boardchar.Character)); } return; }, null); } return; } #endregion if (this.HasToken("ammo")) { MessageBox.Notice(i18n.GetString("thisisammo")); return; } if (this.HasToken("quest") || this.HasToken("nouse")) { if (this.HasToken("description")) { runningDesc = this.GetToken("description").Text + "\n\n"; } showDesc(runningDesc + i18n.GetString("noeffect")); return; } //Confirm use of potentially hazardous items if (!noConfirm) { var name = new StringBuilder(); if (this.IsProperNamed) { name.Append(this.Definite.IsBlank(string.Empty, this.Definite + ' ')); } else { name.Append(this.Indefinite.IsBlank(string.Empty, this.Indefinite + ' ')); } name.Append(this.Name); if (item.HasToken("unidentified") && !this.UnknownName.IsBlank()) { runningDesc = i18n.GetString("unidentified_warning"); } else { if (this.HasToken("description")) { //No need to check for "worn" or "examined" here... runningDesc = this.GetDescription(item) + "\n\n"; //this.GetToken("description").Text + "\n\n"; } runningDesc += i18n.Format("use_x_confirm", this.ToString(item, true)); } MessageBox.Ask(runningDesc, () => { this.Use(character, item, true); }, null); return; } var statBonus = this.GetToken("statbonus"); if (statBonus != null) { foreach (var bonus in statBonus.Tokens) { if (bonus.Name == "health") { character.Health += bonus.Value; if (character.Health > character.MaximumHealth) { character.Health = character.MaximumHealth; } } } } var food = this.GetToken("food"); if (food != null) { Eat(character, food); } if (!this.OnUse.IsBlank()) { RunScript(item, this.OnUse, character, boardchar, (x => runningDesc += x)); } else { this.Consume(character, item); } if (!runningDesc.IsBlank()) { showDesc(runningDesc.Viewpoint(boardchar.Character)); } }
public static void Handler() { if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; if (!FromTitle) { UIManager.Initialize(); UIManager.Elements.Clear(); } else { //Leave the title screen background UIManager.Highlight = UIManager.Elements[0]; UIManager.Elements.RemoveRange(3, UIManager.Elements.Count - 3); } window = new UIWindow(i18n.GetString("opt_title")) { Left = 0, Top = 0, Width = 80, Height = 25, }; window.Center(); var speedLabel = new UILabel(i18n.GetString("opt_speed")); speedLabel.Move(3, 2, window); speed = new UITextBox(IniFile.GetValue("misc", "speed", "15")) { Width = 4, Numeric = true }; speed.Move(1, 1, speedLabel); var fonts = Mix.GetFilesWithPattern("fonts\\*.png").Select(x => System.IO.Path.GetFileNameWithoutExtension(x)).ToArray(); var currentFont = IniFile.GetValue("misc", "font", "8x8-thin"); var currentFontIndex = 0; if (fonts.Contains(currentFont)) { for (currentFontIndex = 0; currentFontIndex < fonts.Length; currentFontIndex++) { if (fonts[currentFontIndex] == currentFont) { break; } } } var fontLabel = new UILabel(i18n.GetString("opt_font")); fontLabel.Move(0, 3, speedLabel); font = new UIList(string.Empty, null, fonts, currentFontIndex) { Width = 20, Height = 8, }; font.Move(1, 1, fontLabel); font.Enter = (s, e) => { var previousFont = font.Text; IniFile.SetValue("misc", "font", font.Text); NoxicoGame.HostForm.RestartGraphics(false); IniFile.SetValue("misc", "font", previousFont); }; font.EnsureVisible(); var screenColsLabel = new UILabel(i18n.GetString("opt_screencols")); screenColsLabel.MoveBelow(-1, 1, font); screenCols = new UITextBox(IniFile.GetValue("misc", "screencols", "80")) { Width = 4, Numeric = true }; screenCols.Move(1, 1, screenColsLabel); var screenRowsLabel = new UILabel(i18n.GetString("opt_screenrows")); screenRowsLabel.Move(-1, 1, screenCols); screenRows = new UITextBox(IniFile.GetValue("misc", "screenrows", "25")) { Width = 4, Numeric = true }; screenRows.Move(1, 1, screenRowsLabel); screenCols.Enter = screenRows.Enter = (s, e) => { var resetGraphics = false; var i = int.Parse(screenCols.Text); if (i < 80) { i = 80; } if (i > 300) { i = 300; } if (i != Program.Cols) { resetGraphics = true; } Program.Cols = i; IniFile.SetValue("misc", "screencols", i); i = int.Parse(screenRows.Text); if (i < 25) { i = 25; } if (i > 100) { i = 100; } if (i != Program.Rows) { resetGraphics = true; } Program.Rows = i; IniFile.SetValue("misc", "screenrows", i); if (resetGraphics) { NoxicoGame.HostForm.RestartGraphics(true); window.Center(); UIManager.ReMove(); } Subscreens.Redraw = true; NoxicoGame.Me.CurrentBoard.AimCamera(); NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(); }; var miscWindow = new UIWindow(i18n.GetString("opt_misc")) { Width = 50, Height = 11, }; miscWindow.MoveBeside(2, 0, speedLabel); rememberPause = new UIToggle(i18n.GetString("opt_rememberpause")) { Checked = IniFile.GetValue("misc", "rememberpause", true), Background = Color.Transparent, }; rememberPause.Move(2, 1, miscWindow); vistaSaves = new UIToggle(i18n.GetString("opt_vistasaves")) { Checked = IniFile.GetValue("misc", "vistasaves", true), Enabled = Vista.IsVista, Background = Color.Transparent, }; vistaSaves.MoveBelow(0, 1, rememberPause); xInput = new UIToggle(i18n.GetString("opt_xinput")) { Checked = IniFile.GetValue("misc", "xinput", true), Enabled = Vista.IsVista, Background = Color.Transparent, }; xInput.MoveBelow(0, 1, vistaSaves); imperial = new UIToggle(i18n.GetString("opt_imperial")) { Checked = IniFile.GetValue("misc", "imperial", false), Background = Color.Transparent, }; imperial.MoveBelow(0, 1, xInput); fourThirtySeven = new UIToggle(i18n.GetString("opt_437")) { Checked = IniFile.GetValue("misc", "437", false), Background = Color.Transparent, }; fourThirtySeven.MoveBelow(0, 1, imperial); var audioWindow = new UIWindow(i18n.GetString("opt_audio")) { Width = 30, Height = 8, }; audioWindow.MoveBelow(0, 1, miscWindow); enableAudio = new UIToggle(i18n.GetString("opt_enableaudio")) { Checked = IniFile.GetValue("audio", "enabled", true), Background = Color.Transparent, }; enableAudio.Move(2, 1, audioWindow); var musicVolumeLabel = new UILabel(i18n.GetString("opt_musicvolume")); musicVolumeLabel.MoveBelow(0, 1, enableAudio); musicVolume = new UITextBox(IniFile.GetValue("audio", "musicvolume", "100")); musicVolume.Move(1, 1, musicVolumeLabel); var soundVolumeLabel = new UILabel(i18n.GetString("opt_soundvolume")); soundVolumeLabel.Move(-1, 1, musicVolume); soundVolume = new UITextBox(IniFile.GetValue("audio", "soundvolume", "100")); soundVolume.Move(1, 1, soundVolumeLabel); saveButton = new UIButton(i18n.GetString("opt_save"), (s, e) => { var i = int.Parse(speed.Text); if (i < 1) { i = 1; } if (i > 200) { i = 200; } IniFile.SetValue("misc", "speed", i); IniFile.SetValue("misc", "font", font.Text); IniFile.SetValue("misc", "rememberpause", rememberPause.Checked); IniFile.SetValue("misc", "vistasaves", vistaSaves.Checked); IniFile.SetValue("misc", "xinput", xInput.Checked); IniFile.SetValue("misc", "imperial", imperial.Checked); IniFile.SetValue("misc", "437", fourThirtySeven.Checked); Vista.GamepadEnabled = xInput.Checked; var resetGraphics = false; i = int.Parse(screenCols.Text); if (i < 80) { i = 80; } if (i > 300) { i = 300; } if (i != Program.Cols) { resetGraphics = true; } Program.Cols = i; IniFile.SetValue("misc", "screencols", i); i = int.Parse(screenRows.Text); if (i < 25) { i = 25; } if (i > 100) { i = 100; } if (i != Program.Rows) { resetGraphics = true; } Program.Rows = i; IniFile.SetValue("misc", "screenrows", i); IniFile.SetValue("misc", "imperial", imperial.Checked); IniFile.SetValue("audio", "enabled", enableAudio.Checked); i = int.Parse(musicVolume.Text); if (i < 0) { i = 0; } if (i > 100) { i = 100; } NoxicoGame.Sound.MusicVolume = i / 100f; IniFile.SetValue("audio", "musicvolume", i); i = int.Parse(soundVolume.Text); if (i < 0) { i = 0; } if (i > 100) { i = 100; } NoxicoGame.Sound.SoundVolume = i / 100f; IniFile.SetValue("audio", "soundvolume", i); if (!enableAudio.Checked && NoxicoGame.Sound != null) { NoxicoGame.Sound.ShutDown(); } else if (enableAudio.Checked && !NoxicoGame.Sound.Enabled) { NoxicoGame.Sound = new SoundSystem(); if (NoxicoGame.Me.CurrentBoard != null) { NoxicoGame.Me.CurrentBoard.PlayMusic(); } } if (resetGraphics) { NoxicoGame.HostForm.RestartGraphics(true); } IniFile.Save(string.Empty); cancelButton.DoEnter(); }) { Width = 16 }; saveButton.MoveBeside(2, 0, audioWindow); keysButton = new UIButton(i18n.GetString("opt_keys"), (s, e) => { Controls.Open(); }) { Width = 16 }; keysButton.MoveBelow(0, 1, saveButton); openButton = new UIButton(i18n.GetString("opt_open"), (s, e) => { System.Diagnostics.Process.Start(NoxicoGame.HostForm.IniPath); }) { Width = 16 }; openButton.MoveBelow(0, 1, keysButton); cancelButton = new UIButton(i18n.GetString("opt_cancel"), (s, e) => { UIManager.Elements.Clear(); NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; if (FromTitle) { Introduction.Title(); } Subscreens.FirstDraw = true; }) { Width = 16 }; cancelButton.MoveBelow(0, 1, openButton); UIManager.Elements.Add(window); UIManager.Elements.Add(speedLabel); UIManager.Elements.Add(speed); UIManager.Elements.Add(fontLabel); UIManager.Elements.Add(font); UIManager.Elements.Add(screenColsLabel); UIManager.Elements.Add(screenCols); UIManager.Elements.Add(screenRowsLabel); UIManager.Elements.Add(screenRows); UIManager.Elements.Add(miscWindow); UIManager.Elements.Add(rememberPause); UIManager.Elements.Add(vistaSaves); UIManager.Elements.Add(xInput); UIManager.Elements.Add(imperial); UIManager.Elements.Add(fourThirtySeven); UIManager.Elements.Add(audioWindow); UIManager.Elements.Add(enableAudio); UIManager.Elements.Add(musicVolumeLabel); UIManager.Elements.Add(musicVolume); UIManager.Elements.Add(soundVolumeLabel); UIManager.Elements.Add(soundVolume); UIManager.Elements.Add(saveButton); UIManager.Elements.Add(keysButton); UIManager.Elements.Add(openButton); UIManager.Elements.Add(cancelButton); Subscreens.FirstDraw = false; Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { cancelButton.DoEnter(); } else { UIManager.CheckKeys(); } }
public static void Handler() { if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; var lines = text.Split('\n').Length; var height = lines + 1; var listHeight = 0; if (type == BoxType.List) { listHeight = options.Count; if (listHeight > Program.Rows - 9) { listHeight = Program.Rows - 9; } height += 1 + listHeight; } else if (type == BoxType.Input) { height += 2; } var top = (Program.Rows / 2) - (height / 2); if (top < 0) { top = 0; } if (UIManager.Elements == null || fromWalkaround) { UIManager.Initialize(); } if (icon != null) { icon.Left = Program.Cols - icon.Bitmap.Width; icon.Top = Program.Rows - icon.Bitmap.Height; UIManager.Elements.Add(icon); } var left = (Program.Cols / 2) - (width / 2); win = new UIWindow(type == BoxType.Question ? i18n.GetString("msgbox_question") : title) { Left = left, Top = top, Width = width + 4, Height = height }; UIManager.Elements.Add(win); lbl = new UILabel(text) { Left = left + 2, Top = top + 1, Width = width, Height = lines }; UIManager.Elements.Add(lbl); lst = null; txt = null; if (type == BoxType.List) { lst = new UIList(string.Empty, Enter, options.Values.ToList(), 0) { Left = left + 2, Top = top + lines + 1, Width = width, Height = listHeight }; lst.Change += (s, e) => { option = lst.Index; Answer = options.Keys.ToArray()[option]; }; lst.Change(null, null); UIManager.Elements.Add(lst); } else if (type == BoxType.Input) { txt = new UITextBox((string)Answer) { Left = left + 2, Top = top + lines + 1, Width = width - 1, Height = 1 }; UIManager.Elements.Add(txt); } var keys = string.Empty; if (type == BoxType.Notice || type == BoxType.Input) { keys = " \x137 "; } else if (type == BoxType.Question) { keys = " " + Toolkit.TranslateKey(KeyBinding.Accept) + "/" + Toolkit.TranslateKey(KeyBinding.Back) + " "; } else if (type == BoxType.List) { keys = " \x18/\x19 "; } key = new UILabel(keys) { Top = top + height - 1, Left = left + width - 2 - keys.Length() }; UIManager.Elements.Add(key); Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || NoxicoGame.IsKeyDown(KeyBinding.Accept) || Vista.Triggers == XInputButtons.A || Vista.Triggers == XInputButtons.B) { if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { if (type == BoxType.List) { if (!allowEscape) { return; } else { option = -1; } } else if (type == BoxType.Input) { UIManager.CheckKeys(); return; } } Enter(null, null); if (type == BoxType.Question) { if ((NoxicoGame.IsKeyDown(KeyBinding.Accept) || Vista.Triggers == XInputButtons.A) && onYes != null) { NoxicoGame.ClearKeys(); onYes(); } else if ((NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) && onNo != null) { NoxicoGame.ClearKeys(); onNo(); } } else if (type == BoxType.List) { Answer = option == -1 ? -1 : options.ElementAt(option).Key; onYes(); NoxicoGame.ClearKeys(); } else if (type == BoxType.Input) { Answer = txt.Text; onYes(); NoxicoGame.ClearKeys(); } else { type = BoxType.Notice; NoxicoGame.ClearKeys(); } if (ScriptPauseHandler != null) { ScriptPauseHandler(); ScriptPauseHandler = null; } } else { UIManager.CheckKeys(); } }
/// <summary> /// Generic Subscreen handler. /// </summary> public static void Handler() { var keys = NoxicoGame.KeyMap; var player = NoxicoGame.Me.Player; var width = (Program.Cols / 2) - 2; if (Subscreens.FirstDraw) { UIManager.Initialize(); UIManager.Elements.Clear(); //Prepare the left item list and its UIElements... var height = 1; containerTokens.Clear(); containerItems.Clear(); containerList = null; var containerTexts = new List <string>(); containerWindow = new UIWindow(title) { Left = 1, Top = 1, Width = width, Height = 2 + height }; containerList = new UIList(string.Empty, null, containerTexts) { Width = width - 2, Height = height, Index = indexLeft, Background = UIColors.WindowBackground }; containerList.Move(1, 1, containerWindow); UIManager.Elements.Add(containerWindow); var emptyMessage = mode == ContainerMode.Vendor ? i18n.Format("inventory_x_hasnothing", vendorChar.Name.ToString()) : mode == ContainerMode.Corpse ? i18n.GetString("inventory_nothingleft") : i18n.GetString("inventory_empty"); var emptyMessageC = new UILabel(emptyMessage) { Width = width - 3, Height = 1 }; emptyMessageC.Move(2, 1, containerWindow); UIManager.Elements.Add(emptyMessageC); UIManager.Elements.Add(containerList); if (other.Tokens.Count == 0) { containerList.Hidden = true; containerWindow.Height = 3; } else { //Populate the left list... foreach (var carriedItem in other.Tokens) { //Only let vendors sell things meant for sale, not their literal shirt off their back if (vendorChar != null && !carriedItem.HasToken("for_sale")) { continue; } var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name); if (find == null) { continue; } containerTokens.Add(carriedItem); containerItems.Add(find); var item = find; var itemString = item.ToString(carriedItem, false, false); if (itemString.Length > width - 5) { itemString = itemString.Disemvowel(); } itemString = itemString.PadEffective(width - 5); //Add any extra sigils. if (mode == ContainerMode.Vendor && carriedItem.HasToken("equipped")) { itemString = itemString.Remove(width - 6) + i18n.GetString("sigil_short_worn"); } if (carriedItem.Path("cursed/known") != null) { itemString = itemString.Remove(width - 6) + "C"; //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } containerTexts.Add(itemString); } height = containerItems.Count; if (height > Program.Rows - 15) { height = Program.Rows - 15; } if (indexLeft >= containerItems.Count) { indexLeft = containerItems.Count - 1; } containerList.Items.Clear(); containerList.Items.AddRange(containerTexts); containerWindow.Height = 2 + height; containerList.Height = height; } //Prepare the right item list and its UIElements... playerTokens.Clear(); playerItems.Clear(); playerList = null; var playerTexts = new List <string>(); playerWindow = new UIWindow(i18n.GetString("inventory_yours")) { Width = width, Height = 3 }; playerWindow.MoveBeside(2, 0, containerWindow); playerList = new UIList(string.Empty, null, playerTexts) { Width = width - 2, Height = 1, Index = indexRight, Background = UIColors.WindowBackground }; playerList.Move(1, 1, playerWindow); UIManager.Elements.Add(playerWindow); var playerNothing = new UILabel(i18n.GetString("inventory_youhavenothing")) { Left = width + 5, Top = 2, Width = width - 3, Height = 1 }; playerNothing.Move(2, 1, playerWindow); UIManager.Elements.Add(playerNothing); UIManager.Elements.Add(playerList); if (player.Character.GetToken("items").Tokens.Count == 0) { playerList.Hidden = true; playerWindow.Height = 3; } else { //Populate the right list... foreach (var carriedItem in player.Character.GetToken("items").Tokens) { var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name); if (find == null) { continue; } playerTokens.Add(carriedItem); playerItems.Add(find); var item = find; var itemString = item.ToString(carriedItem, false, false); if (itemString.Length > width - 5) { itemString = itemString.Disemvowel(); } itemString = itemString.PadEffective(width - 5); if (carriedItem.HasToken("equipped")) { itemString = itemString.Remove(width - 6) + i18n.GetString("sigil_short_worn"); } if (carriedItem.Path("cursed/known") != null) { itemString = itemString.Remove(width - 6) + "C"; //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } playerTexts.Add(itemString); } var height2 = playerItems.Count; if (height2 == 0) { height2 = 1; } if (height2 > Program.Rows - 15) { height2 = Program.Rows - 15; } if (indexRight >= playerItems.Count) { indexRight = playerItems.Count - 1; } if (height2 > height) { height = height2; } playerList.Items.Clear(); playerList.Items.AddRange(playerTexts); playerWindow.Height = 2 + height2; playerList.Height = height2; } //Build the bottom window. UIManager.Elements.Add(new UILabel(new string(' ', Program.Cols)) { Left = 0, Top = 0, Width = Program.Cols - 1, Height = 1, Background = UIColors.StatusBackground, Foreground = UIColors.StatusForeground }); UIManager.Elements.Add(new UILabel(i18n.GetString(mode == ContainerMode.Vendor ? "inventory_pressenter_vendor" : "inventory_pressenter_container")) { Left = 0, Top = 0, Width = Program.Cols - 1, Height = 1, Background = UIColors.StatusBackground, Foreground = UIColors.StatusForeground }); descriptionWindow = new UIWindow(string.Empty) { Left = 2, Top = Program.Rows - 10, Width = Program.Cols - 4, Height = 8, Title = UIColors.RegularText }; description = new UILabel(string.Empty) { Width = Program.Cols - 8, Height = 5 }; description.Move(2, 1, descriptionWindow); capacity = new UILabel(string.Format("{0:F2}/{1:F2}", player.Character.Carried, player.Character.Capacity)); capacity.MoveBelow(4, -1, descriptionWindow); UIManager.Elements.Add(descriptionWindow); UIManager.Elements.Add(description); UIManager.Elements.Add(capacity); //Should we be trading, replace the weight with a money indication. if (mode == ContainerMode.Vendor) { capacity.Text = i18n.Format("inventory_money", vendorChar.Name.ToString(), vendorChar.GetToken("money").Value, player.Character.GetToken("money").Value); } //FIXME: why is this check a thing? if (containerList != null) { containerList.Change = (s, e) => { if (containerList.Items.Count == 0) { return; } indexLeft = containerList.Index; //Build up the content for the description window. var t = containerTokens[containerList.Index]; var i = containerItems[containerList.Index]; descriptionWindow.Text = i.ToString(t, false, false); var desc = i.GetDescription(t); price = 0; //Reset price no matter the mode so we don't accidentally pay for free shit. if (mode == ContainerMode.Vendor && i.HasToken("price")) { price = i.GetToken("price").Value; desc += "\n" + i18n.Format("inventory_itcosts", price); } if (mode == ContainerMode.Vendor && i.HasToken("equipable") && t.HasToken("equipped")) { desc += "\n" + i18n.Format("inventory_vendorusesthis", vendorChar.Name.ToString()); } description.Text = Toolkit.Wordwrap(desc.SmartQuote(), description.Width); descriptionWindow.Draw(); description.Draw(); capacity.Draw(); }; containerList.Enter = (s, e) => { if (containerList.Items.Count == 0) { return; } //onLeft = true; var tryAttempt = TryRetrieve(player, containerTokens[containerList.Index], containerItems[containerList.Index]); if (tryAttempt.IsBlank()) { //No errors were returned by TryRetrieve, so let's do this. playerItems.Add(containerItems[containerList.Index]); playerTokens.Add(containerTokens[containerList.Index]); playerList.Items.Add(containerList.Items[containerList.Index]); containerItems.RemoveAt(containerList.Index); containerTokens.RemoveAt(containerList.Index); containerList.Items.RemoveAt(containerList.Index); //If this was the bottom-most item, adjust our selection. if (containerList.Index >= containerList.Items.Count) { containerList.Index--; } //If this was the last item, hide the list entirely and switch to the player's side. //We know that's possible -- after all, there must be at -least- one item in there now. if (containerList.Items.Count == 0) { containerList.Hidden = true; keys[NoxicoGame.KeyBindings[KeyBinding.Right]] = true; } else { containerList.Height = (containerList.Items.Count < 10) ? containerList.Items.Count : 10; } playerList.Hidden = false; //always the case. playerList.Height = (playerList.Items.Count < 10) ? playerList.Items.Count : 10; containerWindow.Height = containerList.Height + 2; playerWindow.Height = playerList.Height + 2; capacity.Text = player.Character.Carried + "/" + player.Character.Capacity; if (mode == ContainerMode.Vendor) { capacity.Text = i18n.Format("inventory_money", vendorChar.Name.ToString(), vendorChar.GetToken("money").Value, player.Character.GetToken("money").Value); } containerList.Change(s, e); NoxicoGame.DrawStatus(); UIManager.Draw(); } else { //There was some error returned by TryRetrieve, which we'll show now. MessageBox.Notice(tryAttempt); } }; } //FIXME: same with this check. if (playerList != null) { //We do basically the same thing as above in reverse. playerList.Change = (s, e) => { if (playerList.Items.Count == 0) { return; } indexRight = playerList.Index; var t = playerTokens[playerList.Index]; var i = playerItems[playerList.Index]; descriptionWindow.Text = i.ToString(t, false, false); var desc = i.GetDescription(t); price = 0; if (mode == ContainerMode.Vendor && i.HasToken("price")) { price = i.GetToken("price").Value; desc += "\n" + i18n.Format("inventory_itcosts", price); } //This is one of the few differences. if (t.Path("cursed/path") != null) { desc += "\nThis item is cursed and can't be removed."; //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } else if (i.HasToken("equipable") && t.HasToken("equipped")) { desc += "\n" + i18n.GetString("inventory_youusethis"); } description.Text = Toolkit.Wordwrap(desc.SmartQuote(), description.Width); descriptionWindow.Draw(); description.Draw(); capacity.Draw(); }; playerList.Enter = (s, e) => { if (playerList.Items.Count == 0) { return; } //onLeft = false; var tryAttempt = TryStore(player, playerTokens[playerList.Index], playerItems[playerList.Index]); if (tryAttempt.IsBlank()) { containerItems.Add(playerItems[playerList.Index]); containerTokens.Add(playerTokens[playerList.Index]); containerList.Items.Add(playerList.Items[playerList.Index]); playerItems.RemoveAt(playerList.Index); playerTokens.RemoveAt(playerList.Index); playerList.Items.RemoveAt(playerList.Index); if (playerList.Index >= playerList.Items.Count) { playerList.Index--; } if (playerList.Items.Count == 0) { playerList.Hidden = true; keys[NoxicoGame.KeyBindings[KeyBinding.Left]] = true; } else { playerList.Height = (playerList.Items.Count < 10) ? playerList.Items.Count : 10; } containerList.Hidden = false; //always the case. containerList.Height = (containerList.Items.Count < 10) ? containerList.Items.Count : 10; containerWindow.Height = containerList.Height + 2; playerWindow.Height = playerList.Height + 2; capacity.Text = player.Character.Carried + "/" + player.Character.Capacity; if (mode == ContainerMode.Vendor) { capacity.Text = i18n.Format("inventory_money", vendorChar.Name.ToString(), vendorChar.GetToken("money").Value, player.Character.GetToken("money").Value); } playerList.Change(s, e); NoxicoGame.DrawStatus(); UIManager.Draw(); } else { //This is set by TryStore. if (vendorCaughtYou) { //Immediately break out of ContainerMan and call out. NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; SceneSystem.Engage(player.Character, vendorChar, "(criminalscum)"); } else { MessageBox.Notice(tryAttempt); } } }; } UIManager.Highlight = containerList.Items.Count > 0 ? containerList : playerList; UIManager.Draw(); if (UIManager.Highlight.Change != null) { UIManager.Highlight.Change(null, null); } Subscreens.FirstDraw = false; } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } else if (NoxicoGame.IsKeyDown(KeyBinding.Left)) { NoxicoGame.ClearKeys(); if (containerList.Items.Count == 0) { return; } UIManager.Highlight = containerList ?? playerList; containerList.DrawQuick(); containerList.Change(null, null); playerList.DrawQuick(); } else if (NoxicoGame.IsKeyDown(KeyBinding.Right)) { NoxicoGame.ClearKeys(); if (playerList.Items.Count == 0) { return; } UIManager.Highlight = playerList ?? containerList; playerList.Change(null, null); containerList.DrawQuick(); playerList.DrawQuick(); } else { UIManager.CheckKeys(); } }
public static void Handler() { var host = NoxicoGame.HostForm; if (Subscreens.FirstDraw) { UIManager.Initialize(); Subscreens.FirstDraw = false; NoxicoGame.ClearKeys(); Subscreens.Redraw = true; var backdrop = new Bitmap(Program.Cols, Program.Rows * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb); var ccback = Mix.GetBitmap("travelback.png"); var ccpage = Mix.GetBitmap("ccpage.png"); var ccbars = Mix.GetBitmap("ccbars.png"); var pageTop = Program.Rows - (ccpage.Height / 2); using (var gfx = Graphics.FromImage(backdrop)) { gfx.Clear(Color.Black); gfx.DrawImage(ccback, 0, 0, Program.Cols, Program.Rows * 2); gfx.DrawImage(ccpage, 0, pageTop, ccpage.Width, ccpage.Height); var barsSrc = new System.Drawing.Rectangle(0, 3, ccbars.Width, 7); var barsDst = new System.Drawing.Rectangle(0, 0, Program.Cols, 7); gfx.DrawImage(ccbars, barsDst, barsSrc, GraphicsUnit.Pixel); barsSrc = new System.Drawing.Rectangle(0, 0, ccbars.Width, 5); barsDst = new System.Drawing.Rectangle(0, (Program.Rows * 2) - 5, Program.Cols, 5); gfx.DrawImage(ccbars, barsDst, barsSrc, GraphicsUnit.Pixel); } var list = new UIList() { Left = 4, Top = (pageTop / 2) + 4, Width = 34, Height = (ccpage.Height / 2) - 6, Background = Color.White, Foreground = Color.Black, }; UIManager.Elements.Add(new UIPNGBackground(backdrop)); UIManager.Elements.Add(new UILabel(i18n.GetString("travel_header")) { Left = 1, Top = 0, Foreground = Color.Silver }); UIManager.Elements.Add(new UILabel(i18n.GetString("travel_footer")) { Left = 1, Top = Program.Rows - 1, Foreground = Color.Silver }); UIManager.Elements.Add(new UILabel(i18n.GetString("travel_current") + "\n \x07<cCyan> " + (host.Noxico.CurrentBoard.Name ?? "Somewhere")) { Left = 44, Top = (pageTop / 2) + 4, Width = Program.Cols - 46, Foreground = Color.Teal }); UIManager.Elements.Add(list); var targets = new List <int>(); foreach (var target in NoxicoGame.TravelTargets) { targets.Add(target.Key); } targets.Sort(); list.Items.AddRange(targets.Select(x => NoxicoGame.TravelTargets[x])); list.Index = 0; //fixes crash when pressing Enter right away list.Enter = (s, e) => { var newBoard = NoxicoGame.TravelTargets.First(tn => tn.Value == list.Text).Key; if (host.Noxico.CurrentBoard.BoardNum == newBoard) { return; } NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddDays(1); while (Toolkit.IsNight()) { NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddHours(Random.Next(1, 3)); } NoxicoGame.InGameTime = NoxicoGame.InGameTime.AddMinutes(Random.Next(10, 50)); host.Noxico.Player.OpenBoard(newBoard); var hereNow = host.Noxico.Player.ParentBoard; if (hereNow.BoardType == BoardType.Dungeon) { //find the exit and place the player there //TODO: something similar for towns var dngExit = hereNow.Warps.FirstOrDefault(w => w.TargetBoard == -2); if (dngExit != null) { host.Noxico.Player.XPosition = dngExit.XPosition; host.Noxico.Player.YPosition = dngExit.YPosition; } } else { host.Noxico.Player.Reposition(); } }; if (host.Noxico.CurrentBoard.Name != null) { var thisBoard = NoxicoGame.TravelTargets.FirstOrDefault(tn => host.Noxico.CurrentBoard.Name.StartsWith(tn.Value)); if (thisBoard.Value != null) { list.Index = list.Items.FindIndex(i => thisBoard.Value.StartsWith(i)); } } } if (Subscreens.Redraw) { Subscreens.Redraw = false; UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; host.Noxico.CurrentBoard.Redraw(); host.Noxico.CurrentBoard.Draw(true); host.Noxico.CurrentBoard.AimCamera(); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } else { UIManager.CheckKeys(); } }
public MainForm() { #if !DEBUG try #endif { this.Text = "Noxico"; this.BackColor = System.Drawing.Color.Black; this.DoubleBuffered = true; this.FormBorderStyle = FormBorderStyle.FixedSingle; this.MaximizeBox = false; //it's about time, too! this.FormClosing += new FormClosingEventHandler(this.Form1_FormClosing); this.KeyDown += new KeyEventHandler(this.Form1_KeyDown); this.KeyPress += new KeyPressEventHandler(this.Form1_KeyPress); this.KeyUp += new KeyEventHandler(this.Form1_KeyUp); this.Icon = global::Noxico.Properties.Resources.app; this.ClientSize = new Size(Program.Cols * cellWidth, Program.Rows * cellHeight); this.Controls.Add(new Label() { Text = "Loading...", AutoSize = true, Font = new System.Drawing.Font("Arial", 24, FontStyle.Bold | FontStyle.Italic), ForeColor = System.Drawing.Color.White, Visible = true, Location = new System.Drawing.Point(16, 16) }); foreach (var reqDll in new[] { "Neo.Lua.dll" }) { if (!File.Exists(reqDll)) { throw new FileNotFoundException("Required DLL " + reqDll + " is missing."); } } try { Mix.Initialize("Noxico"); } catch (UnauthorizedAccessException) { if (!UacHelper.IsProcessElevated) { var proc = new System.Diagnostics.ProcessStartInfo(); proc.UseShellExecute = true; proc.WorkingDirectory = Environment.CurrentDirectory; proc.FileName = Application.ExecutablePath; proc.Verb = "runas"; try { System.Diagnostics.Process.Start(proc); } catch { } } Close(); return; } if (!Mix.FileExists("credits.txt")) { SystemMessageBox.Show(this, "Could not find game data. Please redownload the game.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } var portable = false; IniPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "noxico.ini"); if (File.Exists("portable")) { portable = true; var oldIniPath = IniPath; IniPath = "noxico.ini"; Program.CanWrite(); /* * if (!Program.CanWrite()) * { * var response = SystemMessageBox.Show(this, "Trying to start in portable mode, but from a protected location. Use non-portable mode?" + Environment.NewLine + "Selecting \"no\" may cause errors.", Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); * if (response == DialogResult.Cancel) * { * Close(); * return; * } * else if (response == DialogResult.Yes) * { * IniPath = oldIniPath; * portable = false; * } * } */ } if (!File.Exists(IniPath)) { File.WriteAllText(IniPath, Mix.GetString("noxico.ini")); } IniFile.Load(IniPath); if (portable) { IniFile.SetValue("misc", "vistasaves", false); IniFile.SetValue("misc", "savepath", "./saves"); IniFile.SetValue("misc", "shotpath", "./screenshots"); } RestartGraphics(true); fourThirtySeven = IniFile.GetValue("misc", "437", false); Noxico = new NoxicoGame(); Noxico.Initialize(this); MouseUp += new MouseEventHandler(MainForm_MouseUp); MouseWheel += new MouseEventHandler(MainForm_MouseWheel); GotFocus += (s, e) => { Vista.GamepadFocused = true; }; LostFocus += (s, e) => { Vista.GamepadFocused = false; }; Vista.GamepadEnabled = IniFile.GetValue("misc", "xinput", true); Program.WriteLine("Environment: {0} {1}", Environment.OSVersion.Platform, Environment.OSVersion); Program.WriteLine("Application: {0}", Application.ProductVersion); if (Environment.OSVersion.Platform == PlatformID.Unix) { Program.WriteLine("*** You are running on a *nix system. ***"); Program.WriteLine("Key repeat delays exaggerated."); NoxicoGame.Mono = true; Vista.GamepadEnabled = false; } this.Controls.Clear(); starting = false; Running = true; Cursor = new Point(-1, -1); cursorPens = new Pen[3, 16]; cursorPens[0, 0] = cursorPens[1, 0] = cursorPens[2, 0] = Pens.Black; for (var i = 1; i < 9; i++) { cursorPens[0, i] = cursorPens[0, 16 - i] = new Pen(Color.FromArgb((i * 16) - 1, (i * 16) - 1, 0)); cursorPens[1, i] = cursorPens[1, 16 - i] = new Pen(Color.FromArgb(0, (i * 32) - 1, 0)); cursorPens[2, i] = cursorPens[2, 16 - i] = new Pen(Color.FromArgb((i * 32) - 1, (i * 32) - 1, (i * 32) - 1)); } fpsTimer = new Timer() { Interval = 1000, Enabled = true, }; fpsTimer.Tick += (s, e) => { this.Text = "Noxico - " + NoxicoGame.Updates + " updates, " + Frames + " frames"; NoxicoGame.Updates = 0; Frames = 0; }; #if GAMELOOP while (Running) { Noxico.Update(); Application.DoEvents(); } #else FormClosing += new FormClosingEventHandler(MainForm_FormClosing); var speed = IniFile.GetValue("misc", "speed", 15); if (speed <= 0) { speed = 15; } timer = new Timer() { Interval = speed, Enabled = true, }; timer.Tick += new EventHandler(timer_Tick); #endif } #if !DEBUG catch (Exception x) { new ErrorForm(x).ShowDialog(this); SystemMessageBox.Show(this, x.ToString(), Application.ProductName, MessageBoxButtons.OK); Running = false; fatal = true; Application.ExitThread(); } #endif if (!fatal) { Noxico.SaveGame(); } }
public static void Handler() { if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; if (!Options.FromTitle) { UIManager.Initialize(); UIManager.Elements.Clear(); } else { UIManager.Highlight = UIManager.Elements[0]; UIManager.Elements.RemoveRange(3, UIManager.Elements.Count - 3); } NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); var items = Enum.GetNames(typeof(KeyBinding)); numControls = items.Length; var numShown = numControls > 17 ? 17 : numControls; var window = new UIWindow(i18n.GetString("key_Title")) { Width = 44, Height = numShown + 6 }; window.Center(); controlList = new UIList(string.Empty, null, items) { Width = 40, Height = numShown }; controlList.Move(2, 2, window); controlList.Enter = (s, e) => { waitingForKey = true; controlList.Items[controlList.Index] = i18n.GetString("key_" + Enum.GetName(typeof(KeyBinding), controlList.Index)).PadEffective(16) + "........"; controlList.DrawQuick(); }; saveButton = new UIButton(i18n.GetString("key_Save"), (s, e) => { //TODO: set values IniFile.Save("noxico.ini"); Options.Open(); }) { Width = 12 }; saveButton.MoveBelow(0, 1, controlList); resetButton = new UIButton(i18n.GetString("key_Reset"), (s, e) => { NoxicoGame.ResetKeymap(); UpdateItems(); UIManager.Highlight = controlList; UIManager.Draw(); }) { Width = 12 }; resetButton.MoveBeside(2, 0, saveButton); UpdateItems(); UIManager.Elements.Add(window); UIManager.Elements.Add(controlList); UIManager.Elements.Add(saveButton); UIManager.Elements.Add(resetButton); Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; UIManager.Draw(); } if (!waitingForKey) { UIManager.CheckKeys(); } else { var binding = (KeyBinding)controlList.Index; for (var i = 0; i < 255; i++) { if ((i >= 16 && i <= 18) || i == 91) { continue; //skip modifiers } if (NoxicoGame.KeyMap[(Keys)i]) { var theKey = (Keys)i; NoxicoGame.KeyBindings[binding] = theKey; NoxicoGame.RawBindings[binding] = theKey.ToString().ToUpperInvariant(); NoxicoGame.KeyBindingMods[binding] = NoxicoGame.Modifiers[0]; UpdateItems(); controlList.DrawQuick(); waitingForKey = false; NoxicoGame.KeyMap[(Keys)i] = false; break; } } } }
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 override void Move(Direction targetDirection, SolidityCheck check = SolidityCheck.Walker) { var lx = XPosition; var ly = YPosition; check = SolidityCheck.Walker; if (Character.IsSlime) { check = SolidityCheck.DryWalker; } if (Character.HasToken("flying")) { check = SolidityCheck.Flyer; } #region Inter-board travel var n = NoxicoGame.Me; Board otherBoard = null; if (ly == 0 && targetDirection == Direction.North && this.ParentBoard.ToNorth > -1) { otherBoard = n.GetBoard(this.ParentBoard.ToNorth); if (this.CanMove(otherBoard, lx, otherBoard.Height - 1, check) != null) { return; } this.YPosition = otherBoard.Height; OpenBoard(this.ParentBoard.ToNorth); } else if (ly == ParentBoard.Height - 1 && targetDirection == Direction.South && this.ParentBoard.ToSouth > -1) { otherBoard = n.GetBoard(this.ParentBoard.ToSouth); if (this.CanMove(otherBoard, lx, 0, check) != null) { return; } this.YPosition = -1; OpenBoard(this.ParentBoard.ToSouth); } else if (lx == 0 && targetDirection == Direction.West && this.ParentBoard.ToWest > -1) { otherBoard = n.GetBoard(this.ParentBoard.ToWest); if (this.CanMove(otherBoard, otherBoard.Width - 1, ly, check) != null) { return; } this.XPosition = otherBoard.Width; OpenBoard(this.ParentBoard.ToWest); } else if (lx == ParentBoard.Width - 1 && targetDirection == Direction.East && this.ParentBoard.ToEast > -1) { otherBoard = n.GetBoard(this.ParentBoard.ToEast); if (this.CanMove(otherBoard, 0, ly, check) != null) { return; } this.XPosition = -1; OpenBoard(this.ParentBoard.ToEast); } #endregion if (Character.HasToken("tutorial")) { Character.GetToken("tutorial").Value++; } var newX = this.XPosition; var newY = this.YPosition; Toolkit.PredictLocation(newX, newY, targetDirection, ref newX, ref newY); foreach (var entity in ParentBoard.Entities.Where(x => x.XPosition == newX && x.YPosition == newY)) { if (entity.Blocking) { NoxicoGame.ClearKeys(); if (entity is BoardChar) { var bc = (BoardChar)entity; if (bc.Character.HasToken("hostile") || (bc.Character.HasToken("teambehavior") && bc.Character.DecideTeamBehavior(Character, TeamBehaviorClass.Attacking) != TeamBehaviorAction.Nothing)) { //Strike at your foes! AutoTravelling = false; MeleeAttack(bc); EndTurn(); return; } if (!bc.OnPlayerBump.IsBlank()) { bc.RunScript(bc.OnPlayerBump); return; } //Displace! NoxicoGame.AddMessage(i18n.Format("youdisplacex", bc.Character.GetKnownName(false, false, true)), bc.GetEffectiveColor()); bc.XPosition = this.XPosition; bc.YPosition = this.YPosition; } } } base.Move(targetDirection, check); ParentBoard.AimCamera(XPosition, YPosition); EndTurn(); if (Character.HasToken("squishy") || (Character.Path("skin/type") != null && Character.Path("skin/type").Text == "slime")) { NoxicoGame.Sound.PlaySound("set://Squish"); } else { NoxicoGame.Sound.PlaySound("set://Step"); } if (lx != XPosition || ly != YPosition) { ParentBoard.UpdateLightmap(this, true); this.DijkstraMap.Hotspots[0] = new Point(XPosition, YPosition); this.DijkstraMap.Update(); } else if (AutoTravelling) { AutoTravelling = false; #if DEBUG NoxicoGame.AddMessage("* TEST: couldn't go any further. *"); #endif } NoxicoGame.ContextMessage = null; if (OnWarp()) { NoxicoGame.ContextMessage = i18n.GetString("context_warp"); } else if (ParentBoard.Entities.OfType <DroppedItem>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition) != null) { NoxicoGame.ContextMessage = i18n.GetString("context_droppeditem"); } else if (ParentBoard.Entities.OfType <Container>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition) != null) { if (ParentBoard.Entities.OfType <Container>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition).Token.HasToken("corpse")) { NoxicoGame.ContextMessage = i18n.GetString("context_corpse"); } else { NoxicoGame.ContextMessage = i18n.GetString("context_container"); } } //else if (ParentBoard.Entities.OfType<Clutter>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition && c.Glyph == 0x147) != null) else if (ParentBoard.Entities.OfType <Clutter>().FirstOrDefault(c => c.XPosition == XPosition && c.YPosition == YPosition && c.DBRole == "bed") != null) { NoxicoGame.ContextMessage = i18n.GetString("context_bed"); } if (NoxicoGame.ContextMessage != null) { NoxicoGame.ContextMessage = Toolkit.TranslateKey(KeyBinding.Activate, false, false) + " - " + NoxicoGame.ContextMessage; } }
public static void Handler() { var player = NoxicoGame.Me.Player; if (!player.Character.HasToken("items") || player.Character.GetToken("items").Tokens.Count == 0) { MessageBox.Notice(i18n.GetString("inventory_youhavenothing"), true); Subscreens.PreviousScreen.Clear(); Subscreens.FirstDraw = true; return; } if (Subscreens.FirstDraw) { UIManager.Initialize(); Subscreens.FirstDraw = false; NoxicoGame.ClearKeys(); Subscreens.Redraw = true; } if (Subscreens.Redraw) { Subscreens.Redraw = false; inventoryTokens.Clear(); inventoryItems.Clear(); var itemTexts = new List <string>(); Inventory.sigils = new List <string>(); foreach (var carriedItem in player.Character.GetToken("items").Tokens) { var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name); if (find == null) { continue; } inventoryTokens.Add(carriedItem); inventoryItems.Add(find); var item = find; var sigils = new List <string>(); var carried = carriedItem; var icon = " "; if (item.HasToken("ascii")) { var color = "Silver"; if (item.Path("ascii/fore") != null) { color = item.Path("ascii/fore").Text; } if (carriedItem.HasToken("color")) { color = carriedItem.GetToken("color").Text; } if (item.ID == "book") { var cga = new[] { "Black", "DarkBlue", "DarkGreen", "DarkCyan", "DarkRed", "Purple", "Brown", "Silver", "Gray", "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White" }; color = cga[carriedItem.GetToken("id").Text.GetHashCode() % cga.Length]; } if (color.Equals("black", StringComparison.OrdinalIgnoreCase)) { color = "Gray"; } icon = "<c" + color + ">" + (char)item.Path("ascii/char").Value; } if (item.HasToken("equipable")) { var eq = item.GetToken("equipable"); //if (item.HasToken("weapon")) // sigils.Add("weapon"); if (eq.HasToken("hat") && eq.HasToken("goggles") && eq.HasToken("mask")) { sigils.Add("fullmask"); } else { foreach (var x in new[] { "hat", "goggles", "mask" }) { if (eq.HasToken(x)) { sigils.Add(x); } } } foreach (var x in new[] { "neck", "ring" }) { if (eq.HasToken(x)) { sigils.Add(x); } } if (eq.HasToken("underpants") || eq.HasToken("undershirt")) { sigils.Add("undies"); } if (eq.HasToken("shirt") && !eq.HasToken("pants")) { sigils.Add("shirt"); } if (eq.HasToken("pants") && !eq.HasToken("shirt")) { sigils.Add("pants"); } if (eq.HasToken("shirt") && eq.HasToken("pants")) { sigils.Add("suit"); } foreach (var x in new[] { "shoes", "jacket", "cloak", "socks" }) { if (eq.HasToken(x)) { sigils.Add(x); } } if (carried.HasToken("equipped")) { sigils.Add("equipped"); } } if (carried.HasToken("unidentified")) { sigils.Add("unidentified"); } /* * if (item.HasToken("statbonus")) * { * foreach (var bonus in item.GetToken("statbonus").Tokens) * { * if (bonus.Name == "health") * sigils.Add("\uE300" + bonus.Value + "HP"); * } * } */ var info = item.GetModifiers(carriedItem); sigils.AddRange(info.Select(x => "\uE300" + x)); /* Removed -- should be replaced with less cursy words. #if DEBUG * if (carried.HasToken("cursed")) * sigils.Add(carried.GetToken("cursed").HasToken("known") ? "cursed" : carried.GetToken("cursed").HasToken("hidden") ? "(cursed)" : "cursed!"); #else * if (carried.HasToken("cursed") && !carried.GetToken("cursed").HasToken("hidden") && carried.GetToken("cursed").HasToken("known")) * sigils.Add("cursed"); #endif */ var itemString = item.ToString(carried, false, false); if (itemString.Length > 33) { itemString = itemString.Disemvowel(); } itemTexts.Add(itemString); var sigilText = new StringBuilder(); var sigilComma = string.Empty; for (var i = 0; i < sigils.Count; i++) { if (sigilText.Length < Program.Cols - 40) { sigilText.Append(sigilComma); sigilText.Append((sigils[i][0] == '\uE300') ? sigils[i].Substring(1) : i18n.GetString("sigil_" + sigils[i])); sigilComma = ", "; } else { if (i < sigils.Count) { sigilText.Append('\u0137'); } break; } } Inventory.sigils.Add(icon + "<cGray> " + sigilText.ToString()); /* Inventory.sigils.Add(icon + "<cGray> " + string.Join(", ", sigils.Select(s => * { * if (s[0] == '\uE300') * return s.Substring(1); * else * return i18n.GetString("sigil_" + s); * }))); */ } var height = inventoryItems.Count; if (height > Program.Rows - 15) { height = Program.Rows - 15; } if (selection >= inventoryItems.Count) { selection = inventoryItems.Count - 1; } if (UIManager.Elements.Count < 2) { yourWindow = new UIWindow(i18n.GetString("inventory_yours")) { Left = 1, Top = 1, Width = Program.Cols - 2, Height = 2 + height }; descriptionWindow = new UIWindow(string.Empty) { Left = 2, Top = Program.Rows - 10, Width = Program.Cols - 4, Height = 8, Title = UIColors.RegularText }; howTo = new UILabel(string.Empty) { Left = 0, Top = 0, Width = Program.Cols - 1, Height = 1, Background = UIColors.StatusBackground, Foreground = UIColors.StatusForeground }; itemDesc = new UILabel(string.Empty) { Width = Program.Cols - 8, Height = 5 }; itemDesc.Move(2, 1, descriptionWindow); itemList = new UIList(string.Empty, null, itemTexts) { Width = Program.Cols - 4, Height = height, Index = selection, Background = UIColors.WindowBackground }; itemList.Move(1, 1, yourWindow); sigilView = new UILabel(string.Empty) { Width = 60, Height = height }; sigilView.Move(33, 0, itemList); itemList.Change = (s, e) => { selection = itemList.Index; var t = inventoryTokens[itemList.Index]; var i = inventoryItems[itemList.Index]; var r = string.Empty; var d = i.GetDescription(t) + "\n\n"; var weaponData = i.GetToken("weapon"); if (weaponData != null) { if (weaponData.HasToken("skill")) { d += i18n.Format("inventory_weaponskill", weaponData.GetToken("skill").Text.Replace('_', ' ') + " "); } if (weaponData.HasToken("attacktype")) { d += i18n.Format("inventory_weapontype", i18n.GetString("attacktype_" + weaponData.GetToken("attacktype").Text)); } d += '\n'; } var mods = i.GetModifiers(t); if (mods.Count > 0) { d += i18n.Format("inventory_modifiers", mods.Join()); } d = Toolkit.Wordwrap(d.SmartQuote(), itemDesc.Width); if (i.ID == "book") { r = i18n.GetString("inventory_pressenter_book"); } else if (i.HasToken("equipable")) { if (t.HasToken("equipped")) { if (t.Path("cursed/known") != null) { r = i18n.GetString("inventory_cannotunequip"); } else { r = i18n.GetString("inventory_pressenter_unequip"); } } else { r = i18n.GetString("inventory_pressenter_equip"); } } else if (i.HasToken("quest")) { r = i18n.GetString("inventory_questitem"); } else { r = i18n.GetString("inventory_pressenter_use"); } howTo.Text = (' ' + r).PadEffective(Program.Cols); itemDesc.Text = d; descriptionWindow.Text = i.ToString(t, false, false); //howTo.Draw(); //itemDesc.Draw(); UpdateColumns(); UIManager.Draw(); }; itemList.Enter = (s, e) => { TryUse(player.Character, inventoryTokens[itemList.Index], inventoryItems[itemList.Index]); }; capacity = new UILabel(string.Format("{0:F2}/{1:F2}", player.Character.Carried, player.Character.Capacity)); capacity.MoveBelow(4, -1, descriptionWindow); UIManager.Elements.Add(new UILabel(new string(' ', Program.Cols)) { Left = 0, Top = Program.Rows - 1, Background = UIColors.StatusBackground }); UIManager.Elements.Add(yourWindow); UIManager.Elements.Add(descriptionWindow); UIManager.Elements.Add(howTo); UIManager.Elements.Add(itemList); UIManager.Elements.Add(sigilView); UIManager.Elements.Add(itemDesc); UIManager.Elements.Add(capacity); UIManager.Elements.Add(new UIButton(' ' + i18n.GetString("inventory_drop") + ' ', (s, e) => { TryDrop(player, inventoryTokens[itemList.Index], inventoryItems[itemList.Index]); }) { Left = Program.Cols - 4 - i18n.GetString("inventory_drop").Length() - 2, Top = 1 }); UIManager.Highlight = itemList; } else { yourWindow.Height = 2 + height; itemList.Items = itemTexts; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(); } itemList.Index = selection; NoxicoGame.DrawStatus(); UIManager.Draw(); } if (NoxicoGame.IsKeyDown(KeyBinding.Back) || NoxicoGame.IsKeyDown(KeyBinding.Items) || Vista.Triggers == XInputButtons.B) { NoxicoGame.ClearKeys(); NoxicoGame.Immediate = true; NoxicoGame.Me.CurrentBoard.Redraw(); NoxicoGame.Me.CurrentBoard.Draw(true); NoxicoGame.Mode = UserMode.Walkabout; Subscreens.FirstDraw = true; } //else if (NoxicoGame.IsKeyDown(KeyBinding.Drop)) //{ // TryDrop(player, inventoryTokens[itemList.Index], inventoryItems[itemList.Index]); //} else { UIManager.CheckKeys(); sigilView.Draw(); } }
public void QuickFire(Direction targetDirection) { NoxicoGame.Modifiers[0] = false; if (this.ParentBoard.BoardType == BoardType.Town && !this.ParentBoard.HasToken("combat")) { return; } var weapon = Character.CanShoot(); if (weapon == null) { return; //Don't whine about it. } var weap = weapon.GetToken("weapon"); if (weap.HasToken("ammo")) { var ammoName = weap.GetToken("ammo").Text; var carriedAmmo = this.Character.GetToken("items").Tokens.Find(ci => ci.Name == ammoName); if (carriedAmmo == null) { return; } var knownAmmo = NoxicoGame.KnownItems.Find(ki => ki.ID == ammoName); if (knownAmmo == null) { return; } knownAmmo.Consume(Character, carriedAmmo); } else if (weapon.HasToken("charge")) { var carriedGun = this.Character.GetToken("items").Tokens.Find(ci => ci.Name == weapon.ID && ci.HasToken("equipped")); weapon.Consume(Character, carriedGun); } if (weapon == null) { return; } Energy -= 500; var x = this.XPosition; var y = this.YPosition; var distance = 0; var range = (int)weapon.Path("weapon/range").Value; //var damage = (int)weapon.Path("weapon/damage").Value; var skill = weap.GetToken("skill").Text; Func <int, int, bool> gotHit = (xPos, yPos) => { if (this.ParentBoard.IsSolid(y, x, SolidityCheck.Projectile)) { FireLine(weapon.Path("effect"), x, y); return(true); } var hit = this.ParentBoard.Entities.OfType <BoardChar>().FirstOrDefault(e => e.XPosition == x && e.YPosition == y); if (hit != null) { var damage = weap.Path("damage").Value *GetDefenseFactor(weap, hit.Character); var overallArmor = 0f; foreach (var targetArmor in hit.Character.GetToken("items").Tokens.Where(t => t.HasToken("equipped"))) { var targetArmorItem = NoxicoGame.KnownItems.FirstOrDefault(i => i.Name == targetArmor.Name); if (targetArmorItem == null) { continue; } if (!targetArmorItem.HasToken("armor")) { continue; } if (targetArmorItem.GetToken("armor").Value > overallArmor) { overallArmor = Math.Max(1.5f, targetArmorItem.GetToken("armor").Value); } } if (overallArmor != 0) { damage /= overallArmor; } FireLine(weapon.Path("effect"), x, y); NoxicoGame.AddMessage(i18n.Format("youhitxfory", hit.Character.GetKnownName(false, false, true), damage, i18n.Pluralize("point", (int)Math.Ceiling(damage)))); hit.Hurt(damage, "death_shot", this, false); this.Character.IncreaseSkill(skill); return(true); } return(false); }; if (targetDirection == Direction.East) { for (x++; x < this.ParentBoard.Width && distance < range; x++, distance++) //TODO: confirm if boardspace or screenspace { if (gotHit(x, y)) { break; } } } else if (targetDirection == Direction.West) { for (x--; x >= 0 && distance < range; x--, distance++) { if (gotHit(x, y)) { break; } } } else if (targetDirection == Direction.South) { for (y++; y < this.ParentBoard.Height && distance < range; y++, distance++) //TODO: confirm if boardspace or screenspace { if (gotHit(x, y)) { break; } } } else if (targetDirection == Direction.North) { for (y--; y >= 0 && distance < range; y--, distance++) { if (gotHit(x, y)) { break; } } } }
/// <summary> /// Generic Subscreen handler. /// </summary> public static void TitleHandler() { var host = NoxicoGame.HostForm; if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; host.Clear(); var xScale = Program.Cols / 80f; var yScale = Program.Rows / 25f; var background = new Bitmap(Program.Cols, Program.Rows * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb); var logo = Mix.GetBitmap("logo.png"); var titleOptions = Mix.GetFilesWithPattern("titles\\*.png"); var chosen = Mix.GetBitmap(titleOptions.PickOne()); //Given our random backdrop and fixed logo, draw them both onto background //because we can't -just- display alpha-blended PNGs. using (var gfx = Graphics.FromImage(background)) { gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gfx.Clear(Color.Black); gfx.DrawImage(chosen, 0, 0, Program.Cols, Program.Rows * 2); gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gfx.DrawImage(logo, 0, 0, logo.Width * xScale, logo.Height * yScale); } UIManager.Initialize(); titleBack = new UIPNGBackground(background); var subtitleLeft = (int)(10 * xScale); var subtitleTop = (int)((logo.Height * yScale) / 2) + 1; var subtitle = i18n.GetString("ts_subtitle"); var pressEnter = "\xC4\xC4\xC4\xC4\xB4 " + i18n.GetString("ts_pressentertobegin") + " <cGray>\xC3\xC4\xC4\xC4\xC4"; titleCaption = new UILabel(subtitle) { Top = subtitleTop, Left = subtitleLeft + 2, Foreground = Color.Teal, Darken = true }; titlePressEnter = new UILabel(pressEnter) { Top = subtitleTop + 2, Left = subtitleLeft, Foreground = Color.Gray, Darken = true }; UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); //UIManager.Elements.Add(new UILabel("\u015c") { Top = 6, Left = 50, Foreground = Color.Gray }); UIManager.Draw(); Options.FromTitle = true; } if (NoxicoGame.IsKeyDown(KeyBinding.Accept) || Subscreens.Mouse || Vista.Triggers != 0) { if (Subscreens.Mouse) { Subscreens.UsingMouse = true; } Subscreens.Mouse = false; Subscreens.FirstDraw = true; var rawSaves = Directory.GetDirectories(NoxicoGame.SavePath); var saves = new List <string>(); //Check each possible save's version. foreach (var s in rawSaves) { var verCheck = Path.Combine(s, "version"); if (!File.Exists(verCheck)) { continue; } var version = int.Parse(File.ReadAllText(verCheck)); if (version < 20) { continue; } if (File.Exists(Path.Combine(s, "global.bin"))) { saves.Add(s); } } NoxicoGame.ClearKeys(); Subscreens.Mouse = false; //Linq up a set of options for each save game. This returns the game's names as the keys. var options = saves.ToDictionary(new Func <string, object>(s => Path.GetFileName(s)), new Func <string, string>(s => { string p; var playerFile = Path.Combine(s, "player.bin"); if (File.Exists(playerFile)) { using (var f = new BinaryReader(File.OpenRead(playerFile))) { p = Player.LoadFromFile(f).Character.Name.ToString(true); } return(i18n.Format("ts_loadgame", p, Path.GetFileName(s))); } return(i18n.Format("ts_startoverinx", Path.GetFileName(s))); })); options.Add("~", i18n.GetString("ts_startnewgame")); options.Add("~~", i18n.GetString("ts_testingarena")); options.Add("~~~", i18n.GetString("ts_options")); //Display our list of saves. MessageBox.List(saves.Count == 0 ? i18n.GetString("ts_welcometonoxico") : i18n.GetString(saves.Count == 1 ? "ts_thereisasave" : "ts_therearesaves"), options, () => { if ((string)MessageBox.Answer == "~") { //Restore our title screen backdrop, since the MessageBox subscreen purged it. UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); UIManager.Draw(); MessageBox.Input("What name would you like for your new world?", NoxicoGame.RollWorldName(), () => { NoxicoGame.WorldName = (string)MessageBox.Answer; NoxicoGame.Mode = UserMode.Subscreen; NoxicoGame.Subscreen = Introduction.CharacterCreator; NoxicoGame.Immediate = true; } ); } else if ((string)MessageBox.Answer == "~~") { NoxicoGame.WorldName = "<Testing Arena>"; var env = Lua.Environment; Lua.RunFile("testarena.lua"); var testBoard = new Board(env.TestArena.ArenaWidth, env.TestArena.ArenaHeight); var me = NoxicoGame.Me; me.Boards.Add(testBoard); me.CurrentBoard = testBoard; me.CreatePlayerCharacter(env.TestArena.Name, env.TestArena.BioGender, env.TestArena.IdentifyAs, env.TestArena.Preference, env.TestArena.Bodyplan, new Dictionary <string, string>(), env.TestArena.BonusTrait); env.BuildTestArena(testBoard); me.Player.ParentBoard = testBoard; testBoard.EntitiesToAdd.Add(me.Player); NoxicoGame.InGameTime = new DateTime(740 + Random.Next(0, 20), 6, 26, 12, 0, 0); testBoard.UpdateLightmap(null, true); testBoard.AimCamera(); testBoard.Redraw(); testBoard.Draw(); Options.FromTitle = false; Subscreens.FirstDraw = true; NoxicoGame.Immediate = true; NoxicoGame.AddMessage(i18n.GetString("welcometest"), Color.Yellow); NoxicoGame.AddMessage(i18n.GetString("rememberhelp")); NoxicoGame.Mode = UserMode.Walkabout; } else if ((string)MessageBox.Answer == "~~~") { Options.FromTitle = true; //Restore our title screen backdrop, since the MessageBox subscreen purged it. UIManager.Initialize(); UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); Options.Open(); } else { Options.FromTitle = false; NoxicoGame.WorldName = (string)MessageBox.Answer; host.Noxico.LoadGame(); NoxicoGame.Me.CurrentBoard.Draw(); Subscreens.FirstDraw = true; NoxicoGame.Immediate = true; NoxicoGame.AddMessage(i18n.GetString("welcomeback"), Color.Yellow); NoxicoGame.AddMessage(i18n.GetString("rememberhelp")); //TextScroller.LookAt(NoxicoGame.Me.Player); NoxicoGame.Mode = UserMode.Walkabout; } } ); } }
public static void Apply(Token result, Character actor, Character target, Action <string> writer) { if (!result.HasToken("effect")) { return; } var f = result.GetToken("effect"); var script = f.Tokens.Count == 1 ? f.Tokens[0].Text : f.Text; var env = Lua.Environment; env.top = actor; env.bottom = target; env.consentual = !target.HasToken("helpless"); env.nonconsentual = target.HasToken("helpless"); env.masturbating = actor == target; env.MessageR = new Action <object, Color>((x, y) => { if (x is Neo.IronLua.LuaTable) { x = ((Neo.IronLua.LuaTable)x).ArrayList.ToArray(); } while (x is object[]) { var options = (object[])x; x = options.PickOne(); if (x is Neo.IronLua.LuaTable) { x = ((Neo.IronLua.LuaTable)x).ArrayList.ToArray(); } } NoxicoGame.AddMessage(ApplyMemory(x.ToString()).Viewpoint(actor, target), y); }); env.Stop = new Action(() => { actor.RemoveAll("havingsex"); target.RemoveAll("havingsex"); }); env.Roll = new Func <object, object, bool>((x, y) => { float a, b; if (!float.TryParse(x.ToString(), out a)) { if (Character.StatNames.Contains(x.ToString().ToLowerInvariant())) { a = actor.GetStat(x.ToString()); } else { a = actor.GetSkillLevel(x.ToString()); } } if (!float.TryParse(y.ToString(), out b)) { if (Character.StatNames.Contains(x.ToString().ToLowerInvariant())) { b = actor.GetStat(x.ToString()); } else { b = target.GetSkillLevel(y.ToString()); } } return(a >= b); }); // Okay, Sparky. What I did was, I put all the error handling in Lua.cs, with a Run method. // Instead of worrying about presentation, it just uses a standard WinForms MessageBox. // After all, the game's already in a broken state by now. var msg = env.Message; env.Message = new Action <object, object>((x, y) => { if (x is Neo.IronLua.LuaTable) { x = ((Neo.IronLua.LuaTable)x).ArrayList.ToArray(); } while (x is object[]) { var options = (object[])x; x = options.PickOne(); if (x is Neo.IronLua.LuaTable) { x = ((Neo.IronLua.LuaTable)x).ArrayList.ToArray(); } } NoxicoGame.AddMessage(ApplyMemory(x.ToString()).Viewpoint(actor, target), y); }); Lua.Run(script, env); env.Message = msg; /* * try * { * // really should just compile once at startup but we're just testing the debugger trace * // anyway here's how you'd do it. * //LuaChunk chunk = env.Lua.CompileChunk(script, "lol.lua", new LuaStackTraceDebugger()); * //env.DoChunk(chunk, "lol.lua"); * env.DoChunk(script, "lol.lua"); * } * catch (Neo.IronLua.LuaParseException lpe) * { * string complain = String.Format("Exception: {0} line {1} col {2},\r\n", * lpe.Message, lpe.Line, lpe.Column); * * LuaExceptionData lex = LuaExceptionData.GetData(lpe); * foreach (LuaStackFrame lsf in lex) * { * complain += String.Format("StackTrace: {0} line {1} col {2},\r\n", * lsf.MethodName, lsf.LineNumber, lsf.ColumnNumber); * } * * var paused = true; * MessageBox.ScriptPauseHandler = () => paused = false; * MessageBox.Notice(complain); * while (paused) * { * NoxicoGame.Me.Update(); * System.Windows.Forms.Application.DoEvents(); * } * // kawa! things get REALLY BROKEN at this point but at least you got a MessageBox -- sparks * } */ }