예제 #1
0
        /// <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);
        }
예제 #2
0
 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);
     }
 }