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; }
/// <summary> /// Put something IN a container, or SELL it to a vendor. /// </summary> /// <param name="boardchar">The container/vendor</param> /// <param name="token">The item token</param> /// <param name="chosen">The item's definition</param> /// <returns>Returns a failure message or null.</returns> /// <remarks>Sets vendorCaughtYou when you're being criminal scum.</remarks> private static string TryStore(BoardChar boardchar, Token token, InventoryItem chosen) { var inv = boardchar.Character.GetToken("items"); var con = other; if (token.HasToken("cursed")) { //Reveal the cursed item as such if we didn't already know. if (!token.GetToken("cursed").HasToken("known")) { token.GetToken("cursed").AddToken("known"); } return("It's cursed! You can't unequip it."); //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } if (token.HasToken("equipped")) { //You should probably switch over to the Inventory screen and take the thing off. return(i18n.GetString("inventory_youareusingthis")); } if (mode == ContainerMode.Vendor && token.HasToken("owner") && token.GetToken("owner").Text == vendorChar.Name.ToID()) { //We tried to sell the vendor's own crap back to them. vendorCaughtYou = true; //Handler can deal with this now. return(i18n.Format("inventory_vendorcaughtyou", vendorChar.Name.ToString()).Viewpoint(vendorChar)); } if (token.HasToken("torn")) { price = (float)Math.Ceiling(price * 0.25f); //this ain't worth shit, bruh. } if (mode == ContainerMode.Vendor && price != 0) { //Handle the transaction. var pMoney = boardchar.Character.GetToken("money"); var vMoney = vendorChar.GetToken("money"); if (vMoney.Value - price < 0) { return(i18n.Format("inventory_vendorcantaffordthis", vendorChar.Name.ToString())); } //TODO: add charisma and relationship bonuses -- I'll throw in another tenner cos you're awesome. //notice that the bonus is determined AFTER the budget check so a vendor won't bug out on that. pMoney.Value += price; vMoney.Value -= price; token.AddToken("for_sale"); } con.Tokens.Add(token); inv.Tokens.Remove(token); boardchar.ParentBoard.Redraw(); boardchar.ParentBoard.Draw(); boardchar.Character.CheckHasteSlow(); NoxicoGame.Sound.PlaySound("set://PutItem"); return(null); }
public void CheckPants(Character character, Token item) { if (!(character.HasToken("taur") || (character.HasToken("quadruped")))) { return; } if ((item.HasToken("underpants") && item.HasToken("undershirt")) || (item.HasToken("pants") && item.HasToken("shirt"))) { return; //allow bodysuits } throw new ItemException(i18n.GetString("cannot_equip_incompatible_body")); //"Your body is not made for this sort of clothing."); }
/// <summary> /// Take something OUT of a container, or BUY it from a vendor. /// </summary> /// <param name="boardchar">The container/vendor</param> /// <param name="token">The item token</param> /// <param name="chosen">The item's definition</param> /// <returns>Return a failure message or null.</returns> private static string TryRetrieve(BoardChar boardchar, Token token, InventoryItem chosen) { var inv = boardchar.Character.GetToken("items"); var con = other; if (token.HasToken("cursed")) { //Reveal the cursed item as such if we didn't already know. if (!token.GetToken("cursed").HasToken("known")) { token.GetToken("cursed").AddToken("known"); } return(mode == ContainerMode.Vendor ? "It's cursed. " + vendorChar.Name.ToString() + " can't unequip it." : "It's cursed. You shouldn't touch this."); //DO NOT TRANSLATE -- Curses will be replaced with better terms and variants such as "Slippery" or "Sticky". } if (token.HasToken("equipped")) { //If we're looting a corpse's equipment, just unequip it. /* Cannot happen if we only allow buying for_sale items * //If a vendor is wearing it though... * if (mode == ContainerMode.Vendor) * return i18n.Format("inventory_vendorusesthis", vendorChar.Name.ToString()); * else */ token.RemoveToken("equipped"); } if (mode == ContainerMode.Vendor && price != 0) { //Handle the transaction. var pMoney = boardchar.Character.GetToken("money"); var vMoney = vendorChar.GetToken("money"); //TODO: add charisma and relationship bonuses -- look good for free food, or get a friends discount. if (pMoney.Value - price < 0) { return(i18n.GetString("inventory_youcantaffordthis")); } vMoney.Value += price; pMoney.Value -= price; token.RemoveToken("for_sale"); } inv.Tokens.Add(token); con.Tokens.Remove(token); boardchar.ParentBoard.Redraw(); boardchar.ParentBoard.Draw(); boardchar.Character.CheckHasteSlow(); NoxicoGame.Sound.PlaySound("set://GetItem"); return(null); }
public 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)); } } }
public void AdjustView() { if (Item.HasToken("ascii")) { var ascii = Item.GetToken("ascii"); if (ascii.HasToken("char")) { this.Glyph = (char)ascii.GetToken("char").Value; } if (Item.HasToken("colored") && Token.HasToken("color")) { this.ForegroundColor = Color.FromName(Token.GetToken("color").Text); } else if (ascii.HasToken("fore")) { this.ForegroundColor = Color.FromName(ascii.GetToken("fore").Text); } else if (Item.ID == "book" && Token.Tokens.Count > 0) { this.ForegroundColor = Color.FromCGA(Token.GetToken("id").Text.GetHashCode() % 16); } if (ascii.HasToken("back")) { this.BackgroundColor = Color.FromName(ascii.GetToken("back").Tokens[0]); } else { this.BackgroundColor = this.ForegroundColor.Darken(); } } }
/// <summary> /// Returns a string containing a description of the passed 'ass' token size. /// </summary> /// <param name="buttToken">The 'ass' token of a character.</param> /// <returns>A string containing the description of the 'ass' token's size.</returns> public static string ButtSize(Token buttToken) { if (buttToken == null) { return("glitch"); } return(GetSizeDescription("ass/size", buttToken.HasToken("size") ? buttToken.GetToken("size").Value : 5)); }
/// <summary> /// Returns a string containing a description of the passed 'balls' token size. /// </summary> /// <param name="ballsToken">The 'balls' token of a character.</param> /// <returns>A string containing the description of the 'balls' token's size.</returns> public static string BallSize(Token ballsToken) { if (ballsToken == null) { return("glitch"); } return(GetSizeDescription("balls", ballsToken.HasToken("size") ? ballsToken.GetToken("size").Value : 1f)); }
/// <summary> /// Returns a string containing a description of the passed 'nipple' token's size. /// </summary> /// <param name="nipplesToken">The 'nipple' token of a character.</param> /// <returns>A string containing the description of the 'nipple' token's size.</returns> public static string NippleSize(Token nipplesToken) { if (nipplesToken == null) { return("glitch"); } return(GetSizeDescription("breasts/nipples", nipplesToken.HasToken("size") ? nipplesToken.GetToken("size").Value : 0.25f)); }
/// <summary> /// Returns a string describing the length of a the passed hair token in plain English. /// </summary> /// <param name="hairToken">A character's hair token.</param> /// <returns>An all lower case string describing the hair's length.</returns> public static string HairLength(Token hairToken) { if (hairToken == null) { return("glitch"); } return(GetSizeDescription("hair/length", hairToken.HasToken("length") ? hairToken.GetToken("length").Value : 0f)); }
public string GetDescription(Token token) { var canBeIdentified = !UnknownName.IsBlank(); var isIdentified = canBeIdentified ? NoxicoGame.Identifications.Contains(ID) : true; if (this.ID == "book" && token != null && token.HasToken("id") && NoxicoGame.BookTitles.ContainsKey(token.GetToken("id").Text)) { return(i18n.Format("book_description", NoxicoGame.BookTitles[token.GetToken("id").Text][0], NoxicoGame.BookTitles[token.GetToken("id").Text][1])); } var a = string.Empty; var description = isIdentified ? "description" : "unknown"; if (this.HasToken(description)) { var ret = GetToken(description).Text; var color = (token != null && token.HasToken("color")) ? Color.NameColor(token.GetToken("color").Text) : string.Empty; var reps = new Dictionary <string, string>() { { "[color]", color }, { "[, color]", ", " + color }, { "[color ]", color + " " }, { "[color, ]", color + ", " }, }; if (color.Length == 0) { foreach (var key in reps.Keys) { ret = ret.Replace(key, string.Empty); } } else { foreach (var item in reps) { ret = ret.Replace(item.Key, item.Value); } } return(ret); } else { a = Toolkit.StartsWithVowel(this.UnknownName) ? "an " : "a "; } return(i18n.Format("inventory_thisis_x", this.ToString(token))); //"This is " + this.ToString(token) + "."; }
public List <string> GetModifiers(Token token) { var info = new List <string>(); if (token != null && token.HasToken("torn")) { info.Add(i18n.GetString("sigil_torn")); } //if (HasToken("equipable")) { if (HasToken("weapon")) { var damage = Path("weapon/damage").Value; if (token != null && token.HasToken("bonus")) { damage = (float)Math.Ceiling(damage * ((token.GetToken("bonus").Value + 1) * 0.75f)); } info.Add(damage + " dmg"); if (new[] { "throwing", "small_firearm", "large_firearm", "huge_firearm" }.Contains(Path("weapon/skill").Text)) { info.Add(i18n.GetString("sigil_ranged")); } else { info.Add(i18n.GetString("sigil_melee")); } } if (HasToken("statbonus")) { foreach (var bonus in GetToken("statbonus").Tokens) { if (bonus.Name == "health") { info.Add(bonus.Value + " HP"); } else { info.Add(bonus.Value + " " + bonus.Name.Remove(3).ToUpperInvariant()); } } } } return(info); }
/// <summary> /// Returns a string describing a piece of equipment using its name, (optionally) color (if available), and (optionally) an appropriate article. /// </summary> /// <param name="knownItem">An InventoryItem from <see cref="NoxicoGame.KnownItems"/>.</param> /// <param name="token">An item token from a <see cref="Character"/>'s inventory that matches the type of item in the first parameter.</param> /// <param name="article">Adds either the definite article (if "the" is passed), the indefinite article (if "a" is passed), or no article (anything else is passed) /// to the front of the descriptive string.</param> /// <param name="withColor">If set to true, the returned string will also describe the color of the item if it has one.</param> /// <returns>A string containing the description of the item as defined by the parameters. If 'item' is null, then null is returned instead.</returns> public static string Item(InventoryItem knownItem, Token token, string article = "", bool withColor = false) { if (knownItem == null) { return(null); } var name = (token != null && token.HasToken("unidentified") && !knownItem.UnknownName.IsBlank()) ? knownItem.UnknownName : knownItem.Name; var color = (token != null && token.HasToken("color")) ? Color.NameColor(token.GetToken("color").Text) : ""; var reps = new Dictionary <string, string>() { { "[color]", color }, { "[, color]", ", " + color }, { "[color ]", color + " " }, { "[color, ]", color + ", " }, }; if (withColor && !string.IsNullOrEmpty(color)) { foreach (var i in reps) { name = name.Replace(i.Key, i.Value); } } else { foreach (var key in reps.Keys) { name = name.Replace(key, string.Empty); } } //TODO: see Mutamorph/GetMorphDeltas about scripted articles. if (article == "the") { name = knownItem.Definite + ' ' + name; } else if (article == "a") { name = knownItem.Indefinite + ' ' + name; } return(name); }
public static string BreastSize(Token breastToken, bool inCups = false) { if (breastToken == null) { return("glitch"); } var size = breastToken.HasToken("size") ? breastToken.GetToken("size").Value : 0f; return(GetSizeDescription(inCups ? "breasts/cupsize" : "breasts/size", size)); }
public static Culture FromToken(Token t) { var nc = new Culture(); nc.ID = t.Text; nc.Bodyplans = t.GetToken("bodyplans").Tokens; nc.Marriage = t.HasToken("marriage") ? t.GetToken("marriage").Value : 0.0f; nc.Monogamous = t.HasToken("monogamous") ? t.GetToken("monogamous").Value : 0.0f; nc.TownName = t.HasToken("townname") ? t.GetToken("townname").Text : null; if (t.HasToken("terms")) { nc.Terms = t.GetToken("terms").Tokens.ToDictionary(x => x.Name.Replace('_', ' '), x => x.Text); } if (t.HasToken("speechfilter")) { nc.SpeechFilter = t.GetToken("speechfilter").Text; } return(nc); }
public static void FoldCostumeVariables(Token token, string[] vars = null) { if (token == null) { return; } if (vars == null) { vars = new string[100]; } while (token.HasToken("setvar")) { var setvar = token.GetToken("setvar"); var id = (int)setvar.GetToken("id").Value; var value = setvar.GetToken("value"); vars[id] = value.Text; token.RemoveToken("setvar"); } while (token.HasToken("var")) { var getvar = token.GetToken("var"); var id = (int)getvar.Value; if (vars[id].IsBlank()) { token.RemoveToken("var"); } else { getvar.Name = vars[id]; } } if (!token.Text.IsBlank() && token.Text.Trim().StartsWith("var ")) { var id = int.Parse(token.Text.Trim().Substring(4)); token.Text = vars[id].IsBlank("<invalid token>", vars[id]); } foreach (var child in token.Tokens) { FoldCostumeVariables(child, vars); } }
public static BiomeData FromToken(Token t, int realmNum) { var n = new BiomeData(); n.Realm = (Realms)realmNum; n.Name = t.Text; var cvars = t.GetToken("rect").Text.Split(' ').Select(i => int.Parse(i)).ToArray(); n.Rect = new System.Drawing.Rectangle(cvars[0], cvars[1], cvars[2] - cvars[0], cvars[3] - cvars[1]); n.GroundTile = (int)t.GetToken("ground").Value; if (n.GroundTile == 0) { n.GroundTile = TileDefinition.Find(t.GetToken("ground").Text, true).Index; } var encounters = t.GetToken("encounters"); if (encounters == null) { n.Encounters = new string[0]; } else { n.MaxEncounters = 10; if (encounters.Value > 0) { n.MaxEncounters = (int)encounters.Value; } n.Encounters = encounters.Tokens.Select(x => x.Name).ToArray(); } var cultures = t.GetToken("cultures"); if (cultures == null) { n.Cultures = new[] { "human" } } ; else { n.Cultures = cultures.Tokens.Select(x => x.Name).Where(e => Culture.Cultures.ContainsKey(e)).ToArray(); } if (t.HasToken("music")) { n.Music = t.GetToken("music").Text; } return(n); }
public Template(Token token) { this.Name = token.Text; this.Inhabitants = token.HasToken("inhabitants") ? (int)token.GetToken("inhabitants").Value : 0; var map = token.GetToken("map").Tokens[0].Text; MapScans = map.Trim().Split('\n').Select(x => x.Trim()).ToArray(); Width = MapScans[0].Length; Height = MapScans.Length; PlotWidth = (int)Math.Ceiling(Width / 13.0); PlotHeight = (int)Math.Ceiling(Height / 16.0); AllowOutside = token.HasToken("allowOutside"); Markings = new Dictionary <char, Token>(); if (!token.HasToken("markings")) { return; } foreach (var marking in token.GetToken("markings").Tokens) { var c = marking.Name[0]; Markings.Add(c, marking); } }
public static void FoldCostumeRandoms(Token token) { if (token == null) { return; } while (token.HasToken("random")) { var rnd = token.GetToken("random"); var pick = rnd.Tokens.PickOne(); token.Tokens.Remove(rnd); foreach (var t in pick.Tokens) { token.Tokens.Add(t); } //rnd = pick; } }
public void AdjustView() { if (Token.HasToken("ascii")) { var ascii = Token.GetToken("ascii"); if (ascii.HasToken("char")) { this.Glyph = (char)ascii.GetToken("char").Value; } if (ascii.HasToken("fore")) { this.ForegroundColor = Color.FromName(ascii.GetToken("fore").Tokens[0]); } if (ascii.HasToken("back")) { this.BackgroundColor = Color.FromName(ascii.GetToken("back").Tokens[0]); } else { this.BackgroundColor = this.ForegroundColor.Darken(); } } }
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 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 * } */ }
public static InventoryItem FromToken(Token item) { var ni = new InventoryItem(); ni.ID = item.Text.Trim(); if (item.HasToken("_n")) { ni.Name = item.GetToken("_n").Text; } else { ni.Name = ni.ID.Replace('_', ' '); } if (item.HasToken("_u")) { ni.UnknownName = item.GetToken("_u").Text; } if (item.HasToken("_ia")) { ni.Indefinite = item.GetToken("_ia").Text; } else { ni.Indefinite = ni.Name.StartsWithVowel() ? i18n.GetString("an") : i18n.GetString("a"); } ni.IsProperNamed = char.IsUpper(ni.Name[0]); if (item.HasToken("_da")) { ni.Definite = item.GetToken("_da").Text; } else { ni.Definite = i18n.GetString("the"); } ni.OnUse = null; foreach (var script in item.Tokens.Where(t => t.Name == "script")) { switch (script.Text) { case "equip": ni.OnEquip = script.GetToken("#text").Text; break; case "unequip": ni.OnUnequip = script.GetToken("#text").Text; break; case "timer": ni.OnTimer = script.GetToken("#text").Text; break; default: ni.OnUse = script.GetToken("#text").Text; break; } } ni.Tokens.Clear(); ni.Tokens.AddRange(item.Tokens); ni.RemoveAll("_n"); ni.RemoveAll("_u"); ni.RemoveAll("_ia"); ni.RemoveAll("_da"); ni.RemoveAll("script"); ni.CarriedToken = new Dictionary <string, Token>(); return(ni); }
public void MergeBitmap(string fileName, string tiledefs) { var bitmap = Mix.GetBitmap(fileName); var tileset = new Token(); tileset.AddSet(Mix.GetTokenTree(tiledefs, true)); var width = Width; var height = Height; if (width > bitmap.Width) { width = bitmap.Width; } if (height > bitmap.Height) { height = bitmap.Height; } for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var color = bitmap.GetPixel(x, y); if (color.Name == "ff000000" || color.A == 0) { continue; } var key = color.Name.Substring(2).ToUpperInvariant(); if (!tileset.HasToken(key)) { continue; } var tile = tileset.GetToken(key); //Keep the original tile, but drain it. if (tile.Text == "drain") { this.Tilemap[x, y].Fluid = Fluids.Dry; continue; } this.Tilemap[x, y].Index = TileDefinition.Find(tile.Text).Index; if (tile.Text.StartsWith("doorway")) { var door = new Door() { XPosition = x, YPosition = y, ForegroundColor = this.Tilemap[x, y].Definition.Background, BackgroundColor = this.Tilemap[x, y].Definition.Background.Darken(), ID = "mergeBitmap_Door" + x + "_" + y, ParentBoard = this, Closed = tile.Text.EndsWith("Closed"), Glyph = '+' }; this.Entities.Add(door); } if (tile.HasToken("clutter")) { var nc = new Clutter() { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(nc); var properties = tile.GetToken("clutter"); foreach (var property in properties.Tokens) { switch (property.Name) { case "id": nc.ID = property.Text; break; case "name": nc.Name = property.Text; break; case "desc": nc.Description = property.Text; break; case "glyph": nc.Glyph = (int)property.Value; break; case "fg": if (property.Text.StartsWith('#')) { nc.ForegroundColor = Color.FromCSS(property.Text); } else { nc.ForegroundColor = Color.FromName(property.Text); } break; case "bg": if (property.Text.StartsWith('#')) { nc.BackgroundColor = Color.FromCSS(property.Text); } else { nc.BackgroundColor = Color.FromName(property.Text); } break; case "block": nc.Blocking = true; break; case "burns": nc.CanBurn = true; break; } } } if (tile.HasToken("unique")) { var unique = tile.GetToken("unique"); var newChar = new BoardChar(Character.GetUnique(unique.Text)) { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(newChar); newChar.AssignScripts(unique.Text); newChar.ReassignScripts(); } if (!tile.HasToken("fluid")) { this.Tilemap[x, y].Fluid = Fluids.Dry; } else { this.Tilemap[x, y].Fluid = (Fluids)Enum.Parse(typeof(Fluids), tile.GetToken("fluid").Text, true); } } } this.ResolveVariableWalls(); }
public bool Equip(Character character, Token item) { /* * if rings and character is quadruped, error out. * if required slots have covering slots * check for target slot's reachability. * if unreachable, try to temp-remove items in covering slots, recursively. * if still unreachable, error out. * if required slots are taken * try to unequip the items in those slots, recursively. * if required slots are still taken, error out; * else, mark the item as equipped. * replace each temp-removed item whose required slots are still free. */ var equip = this.GetToken("equipable"); var tempRemove = new Stack <Token>(); //var items = character.GetToken("items"); //TODO: make full quadrupeds equip weapons in their mouth instead of the hands they don't have. //This means they can carry only ONE weapon at a time, and maybe not be able to converse until unequipped. if ((equip.HasToken("hands") || equip.HasToken("ring")) && (character.HasToken("quadruped"))) { throw new ItemException(i18n.Format("cannot_equip_no_hands", this.ToString(item, true, false))); } if (equip.HasToken("hand")) { CheckHands(character, "hand"); } else if (equip.HasToken("ring")) { CheckHands(character, "ring"); } if (equip.HasToken("pants") || equip.HasToken("underpants") || equip.HasToken("shoes") || equip.HasToken("socks")) { CheckPants(character, equip); } if (character.HasToken("snaketail") && (equip.HasToken("pants") || equip.HasToken("underpants"))) { throw new ItemException(i18n.Format("cannot_equip_no_legs", this.ToString(item, true, false))); } //lol foreach (var nonLayeredSlot in new[] { "socks", "hat", "mask", "goggles", "neck" }) { if (equip.HasToken(nonLayeredSlot)) { var currentNonLayeredItem = character.GetEquippedItemBySlot(nonLayeredSlot); if (currentNonLayeredItem != null) { currentNonLayeredItem.Unequip(character); } } } foreach (var t in equip.Tokens) { if (t.Name == "underpants" && (!TempRemove(character, tempRemove, "pants") || !TempRemove(character, tempRemove, "underpants"))) { return(false); } else if (t.Name == "undershirt" && (!TempRemove(character, tempRemove, "shirt") || !TempRemove(character, tempRemove, "undershirt"))) { return(false); } else if (t.Name == "shirt" && (!TempRemove(character, tempRemove, "shirt") || !TempRemove(character, tempRemove, "jacket"))) { return(false); } else if (t.Name == "jacket" && (!TempRemove(character, tempRemove, "cloak") || !TempRemove(character, tempRemove, "jacket"))) { return(false); } else if (t.Name == "socks" && (!TempRemove(character, tempRemove, "shoes") || !TempRemove(character, tempRemove, "socks"))) { return(false); } } var succeed = true; if (!this.OnEquip.IsBlank()) { succeed = Convert.ToBoolean(RunScript(item, this.OnEquip, character, null, null)); } if (succeed) { item.AddToken("equipped"); } if (this.HasToken("timer") && !this.OnTimer.IsBlank() && !item.HasToken("timer")) { item.AddToken("timer").Value = (this.GetToken("timer").Value == 0) ? 60 : this.GetToken("timer").Value; item.GetToken("timer").Text = NoxicoGame.InGameTime.ToBinary().ToString(); } character.RecalculateStatBonuses(); character.CheckHasteSlow(); //Difficult bit: gotta re-equip tempremovals without removing the target item all over. THAT WOULD BE QUITE BAD. return(succeed); }
public string ToString(Token token, bool the = false, bool a = true) { if (ID == "book" && token != null && token.HasToken("id") && NoxicoGame.BookTitles.ContainsKey(token.GetToken("id").Text)) { return(string.Format("\"{0}\"", NoxicoGame.BookTitles[token.GetToken("id").Text][0])); } var canBeIdentified = !UnknownName.IsBlank(); var isIdentified = canBeIdentified ? NoxicoGame.Identifications.Contains(ID) : true; var name = isIdentified ? Name : UnknownName; var color = (token != null && token.HasToken("color")) ? Color.NameColor(token.GetToken("color").Text) : string.Empty; var reps = new Dictionary <string, string>() { { "[color]", color }, { "[, color]", ", " + color }, { "[color ]", color + " " }, { "[color, ]", color + ", " }, }; if (color.Length == 0) { foreach (var key in reps.Keys) { name = name.Replace(key, string.Empty); } } else { foreach (var item in reps) { name = name.Replace(item.Key, item.Value); } } if (token != null && token.HasToken("bonus")) { name = string.Format("{0} +{1}", name, token.GetToken("bonus").Value); } var proper = IsProperNamed && isIdentified; if (proper || !a) { if (the && !string.IsNullOrEmpty(Definite)) { return(Definite + ' ' + name); } return(name); } if (HasToken("charge") && token != null) { var charge = 0; var limit = "inf"; if (GetToken("charge").HasToken("limit")) { limit = Path("charge/limit").Value.ToString(); } if (token.HasToken("charge") && token.GetToken("charge").Value > 0) { charge = (int)token.GetToken("charge").Value; var collective = Path("charge/collectivename"); if (collective != null) { name = collective.Text; } } return(string.Format("{0} {1} ({2}/{3})", the ? Definite : i18n.GetArticle(name), name, charge, limit)); } if (isIdentified) { return(string.Format("{0} {1}", the ? Definite : Indefinite, name).Trim()); } return(string.Format("{0} {1}", the ? Definite : i18n.GetArticle(UnknownName), name).Trim()); }