Exemplo n.º 1
0
    void Start()
    {
        var granny = GameObject.Find("Granny");

        if (granny != null)
        {
            grannyCollider = granny.GetComponent<Collider2D>();
            itemUse = granny.GetComponent<ItemUse>();
        }

        var spriteRenderer = GetComponent<SpriteRenderer>();

        if (materials == null)
        {
            var effectsCount = Enum.GetNames(typeof(Effect)).Length;

            materials = new Material[effectsCount];

            materials[0] = spriteRenderer.material;

            for (int i = 1; i < effectsCount; i++)
            {
                var randomMaterial = new Material(spriteRenderer.material);

                randomMaterial.SetColor("_ColorR", Utils.RandomHueColor());
                randomMaterial.SetColor("_ColorG", Utils.RandomHueColor());
                randomMaterial.SetColor("_ColorB", Color.white);

                materials[i] = randomMaterial;
            }
        }

        spriteRenderer.material = getMaterial(PillEffect);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Fixes <see cref="ItemUse"/> so it propagates correctly through our visitor.
 /// </summary>
 /// <remarks><c>IsMemberOf</c> will be set on Array, not ItemUse itself.</remarks>
 public static void PatchItemUse(ItemUse item)
 {
     if (item.IsMemberOf != null)
     {
         item.Array.IsMemberOf = item.IsMemberOf;
         item.IsMemberOf = null;
     }
 }
    void Start()
    {
        var granny = GameObject.Find("Granny");

        if (granny != null)
        {
            grannyCollider = granny.GetComponent<Collider2D>();
            itemUse = granny.GetComponent<ItemUse>();
        }
    }
Exemplo n.º 4
0
        private static VarLikeConstructUse /*!*/ CreateFcnArrayDereference(Position pos, VarLikeConstructUse /*!*/ varUse, List <Expression> arrayKeysExpression)
        {
            if (arrayKeysExpression != null && arrayKeysExpression.Count > 0)
            {
                // wrap fcnCall into ItemUse
                foreach (var keyExpr in arrayKeysExpression)
                {
                    varUse = new ItemUse(pos, varUse, keyExpr, true);
                }
            }

            return(varUse);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Check if the AST node is an input channel according to the active policy.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private ChannelLabel FindInputLabel(ItemUse node)
        {
            var varUse = node.Array as DirectVarUse;

            //var arrayKey = node.Index as StringLiteral;

            if (varUse != null)
            {
                return(_policy.Input.FirstOrDefault(channel => channel.Name.Equals(varUse.VarName.Value)));
            }

            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets value indicating whether the expression is in form of <c>$GLOBALS[...]</c>.
        /// </summary>
        public static bool IsGlobalVar(ItemUse itemUse)
        {
            if (itemUse != null &&
                itemUse.IsMemberOf == null && (itemUse.Array as VarLikeConstructUse)?.IsMemberOf == null &&
                itemUse.Array is DirectVarUse)
            {
                // $GLOBALS[...]
                var dvar = (DirectVarUse)itemUse.Array;
                return(dvar.VarName.Value == VariableName.GlobalsName);
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fixes <see cref="ItemUse"/> so it propagates correctly through our visitor.
        /// </summary>
        /// <remarks><c>IsMemberOf</c> will be set on Array, not ItemUse itself.</remarks>
        public static void PatchItemUse(ItemUse item)
        {
            if (item.IsMemberOf != null)
            {
                var varlike = item.Array as VarLikeConstructUse;

                Debug.Assert(varlike != null);
                Debug.Assert(varlike.IsMemberOf == null);

                // fix this ast weirdness:
                varlike.IsMemberOf = item.IsMemberOf;
                item.IsMemberOf    = null;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Visits elements like $_GET["xyz"]. These elements can be input channels if they meet the policy requirements.
        /// </summary>
        /// <param name="node"></param>
        public override void VisitItemUse(ItemUse node)
        {
            var inputLabel = FindInputLabel(node);

            if (inputLabel != null)
            {
                var channel = new Channel()
                {
                    Id = _uniqueId, Label = inputLabel, Location = new PhpSourceLocation(node.Span)
                };
                InputChannels.Add(channel);
                _uniqueId++;
            }
            base.VisitItemUse(node);
        }
Exemplo n.º 9
0
 public static int GetItemUses(SqliteDataReader reader)
 {
     while (reader.Read())
     {
         ItemUse item = new ItemUse();
         item.EventID = reader.GetInt32(0);
         item.SessionID = reader.GetInt32(1);
         item.item = (ItemType)reader.GetInt32(2);
         float? timeUsed = reader.GetValue(2) as float?;
         if (timeUsed.HasValue)
             item.TimeUsed = timeUsed.Value;
         ItemsUsed.Add(item);
     }
     return 0;
 }
Exemplo n.º 10
0
        private void item(string name, int level, object appearance,
                          string equipSlot = null, ItemUse use             = null,
                          Attack attack    = null, RangedAttack tossAttack = null,
                          int armor        = 0, int price = 0,
                          bool treasure    = false)
        {
            // If the appearance isn"t an actual glyph, it should be a color function
            // that will be applied to the current glyph.
            Glyph localGlyph = null;

            if (!(appearance is Glyph) && appearance is string)
            {
                var gylphForColor = appearance as string;
                localGlyph      = _glyph;
                localGlyph.Fore = gylphForColor;
            }
            else
            {
                localGlyph = appearance as Glyph;
            }

            var categories = new List <string>();

            if (_category != null)
            {
                categories = _category.Split('/').ToList();
            }

            if (equipSlot == null)
            {
                equipSlot = _equipSlot;
            }

            if (tossAttack == null && _tossDamage != null)
            {
                tossAttack = new RangedAttack(new Noun($"the {name.ToLower()}"), "hits",
                                              (double)_tossDamage, _tossElement, _tossRange.HasValue ? _tossRange.Value : 0);
            }

            var newItemType = new ItemType(name, localGlyph, level, _sortIndex++,
                                           categories, equipSlot, use, attack, tossAttack, _breakage, armor, price,
                                           treasure);

            ItemTypes.Add(name, newItemType);
        }
Exemplo n.º 11
0
        private VariableUse CreateStaticFieldUse(Position position, TypeRef /*!*/ typeRef, CompoundVarUse /*!*/ field)
        {
            DirectVarUse   dvu;
            IndirectVarUse ivu;

            if ((dvu = field as DirectVarUse) != null)
            {
                return(new DirectStFldUse(position, typeRef, dvu.VarName, field.Position));
            }
            else if ((ivu = field as IndirectVarUse) != null)
            {
                return(new IndirectStFldUse(position, typeRef, ivu.VarNameEx));
            }
            else
            {
                ItemUse iu = (ItemUse)field;
                iu.Array = CreateStaticFieldUse(iu.Array.Position, typeRef, (CompoundVarUse)iu.Array);
                return(iu);
            }
        }
 private void GrabObject()
 {
     if (collidingObject != null && collidingObject.GetComponent <OutlineMirrorObject> () != null)
     {
         collidingObject.GetComponent <OutlineMirrorObject> ().activeOutlines = false;
     }
     objectInHand    = collidingObject;
     collidingObject = null;
     if (objectInHand.tag != "CannotGrab")
     {
         ItemUse itemUse = objectInHand.GetComponent <ItemUse> ();
         if (itemUse != null)
         {
             AnchorObject(itemUse);
         }
         var joint = AddFixedJoint();
         joint.connectedBody = objectInHand.GetComponent <Rigidbody> ();
         objectInHand.GetComponent <Collider> ().enabled = false;
     }
 }
Exemplo n.º 13
0
 public ItemType(string name, Glyph glyph, int level, int sortIndex, List <string> categories, string equipSlot, ItemUse use, Attack attack, RangedAttack tossAttack,
                 int?breakage, int armor, int price, bool treasure, int id = 0, string description = null, string slug = null, bool stackable = false)
 {
     this.name        = name;
     this.glyph       = glyph;
     this.level       = level;
     this.sortIndex   = sortIndex;
     this.categories  = categories;
     this.equipSlot   = equipSlot;
     this.use         = use;
     this.attack      = attack;
     this.tossAttack  = tossAttack;
     this.breakage    = breakage;
     this.armor       = armor;
     this.price       = price;
     isTreasure       = treasure;
     this.id          = id;
     this.description = description;
     this.slug        = slug;
     this.stackable   = stackable;
 }
Exemplo n.º 14
0
        public override void VisitItemUse(ItemUse node)
        {
            var inputChannel = FindChannel(node, _inputChannels);

            if (inputChannel != null)
            {
                //keep track of visited channels to prevent infinite recursion
                if (!_visitedChannels.Contains(inputChannel.Id))
                {
                    _visitedChannels.Add(inputChannel.Id);
                    RewriteInputChannel(inputChannel, node);
                }
                else
                {
                    base.VisitItemUse(node);
                }
            }
            else
            {
                //not found as input channel
                base.VisitItemUse(node);
            }
        }
    private void AnchorObject(ItemUse itemUse)
    {
//		Vector3 obj_pos = objectInHand.transform.position;
//		Vector3 anchor_pos = itemUse.GetAnchorPoint ().position;
//		Vector3 difference = anchor_pos - obj_pos;
//		Vector3 target = transform.position;// - difference;
//		Quaternion rotation = transform.rotation;
//		objectInHand.transform.position = target;
//		objectInHand.transform.rotation = Quaternion.Euler (rotation.eulerAngles - itemUse.GetAnchorEulerAngles());
//


        Quaternion rotation = transform.rotation;

        objectInHand.transform.rotation = Quaternion.Euler(rotation.eulerAngles - itemUse.GetAnchorEulerAngles());

        Vector3 obj_pos      = objectInHand.transform.position;
        Vector3 anchor_pos   = itemUse.GetAnchorPoint().position;
        Vector3 target_pos   = snapPoint.position;
        Vector3 anchor_2_obj = obj_pos - anchor_pos;
        Vector3 obj_2_target = target_pos - obj_pos;

        objectInHand.transform.position = obj_pos + anchor_2_obj + obj_2_target;
    }
Exemplo n.º 16
0
 /// <summary>
 /// Automatically detects sprite in default asset bundle of mod. (item.{name}) <para />
 /// If you want to manually initialize it, use InitSprite on this item.
 /// </summary>
 /// <param name="name">Name you access the item by</param>
 /// <param name="displayName">Name you see ingame</param>
 /// <param name="description">Description you see ingame</param>
 /// <param name="category">The category this item belongs into (for example; crafting menu)</param>
 /// <param name="use">The use of the item</param>
 /// <param name="durability">The max uses, aka durability of an item</param>
 /// <param name="stackSize">The max stack size</param>
 /// <param name="subcategory">The subcategory for this item; for example, fishing</param>
 public Item(string name, string displayName, string description, ItemCategory category, ItemUse use, int durability = 1, int stackSize = 20, string subcategory = "")
 {
     this.name        = name;
     this.displayName = displayName;
     this.durability  = durability;
     this.stackSize   = stackSize;
     this.description = description;
     this.category    = category;
     this.use         = use;
     this.subcategory = subcategory;
 }
Exemplo n.º 17
0
 /// <inheritdoc />
 public override void VisitItemUse(ItemUse x)
 {
     RValueResult(x);
 }
 public async Task <IEnumerable <ItemEffect> > RetrieveItemEffects(ItemUse itemUse)
 {
     return(await RetrieveItemEffects(itemUse.ItemType, itemUse.ItemFunctionality));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Gets value indicating whether the expression is in form of <c>$GLOBALS[...]</c>.
        /// </summary>
        public static bool IsGlobalVar(ItemUse itemUse)
        {
            if (itemUse != null &&
                itemUse.IsMemberOf == null && itemUse.Array.IsMemberOf == null &&
                itemUse.Array is DirectVarUse)
            {
                // $GLOBALS[...]
                var dvar = (DirectVarUse)itemUse.Array;
                return (dvar.VarName.Value == VariableName.GlobalsName);
            }

            return false;
        }
Exemplo n.º 20
0
 /// <inheritdoc />
 public override void VisitItemUse(ItemUse x)
 {
     // Access to array: $object->array[number]
     FindUndefinedMembersUse(x);
     base.VisitItemUse(x);
 }
Exemplo n.º 21
0
 private void AddOnly(ref ItemUse itemNum, ItemType type)
 {
     itemNum.type = type;
     itemNum.num++;
 }
Exemplo n.º 22
0
 public static void RemoveUseListener(ItemUse itemUse)
 {
     m_onItemUse -= itemUse;
 }
Exemplo n.º 23
0
        /// <summary>
        /// Tries to resolve global variable name from array item use. (eg. <c>$GLOBALS["varname"]</c>).
        /// </summary>
        public static bool TryGetGlobalVarName(ItemUse itemUse, out VariableName varname)
        {
            if (IsGlobalVar(itemUse) && itemUse.Index is StringLiteral)
            {
                varname = new VariableName(((StringLiteral)itemUse.Index).Value);
                return true;
            }

            varname = default(VariableName);
            return false;
        }
Exemplo n.º 24
0
 public void ItemUse(ItemUse rpc)
 {
     itemStacks[rpc.index].Use(this);
 }
Exemplo n.º 25
0
 public static void AddUseListener(ItemUse itemUse)
 {
     m_onItemUse += itemUse;
 }
Exemplo n.º 26
0
        /// <inheritdoc />
        public override void VisitItemUse(ItemUse x)
        {
            base.VisitItemUse(x);

            vars.Add(x);
        }
Exemplo n.º 27
0
 public void ItemUse(ItemUse rpc)
 {
     itemStacks[rpc.index].Use(this);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Visit item use index (if not null) and array.
 /// </summary>
 /// <param name="x"></param>
 virtual public void VisitItemUse(ItemUse x)
 {
     VisitVarLikeConstructUse(x);
     VisitElement(x.Index);
     VisitElement(x.Array);
 }
Exemplo n.º 29
0
 internal ItemUsePoint(ItemUse itemUse, ValuePoint usedItem, ValuePoint index)
 {
     ItemUse  = itemUse;
     UsedItem = usedItem;
     Index    = index;
 }
Exemplo n.º 30
0
 public Record(int _id, string _name, ItemType _type, ItemUse _use)
     : base(_id, _name, _type, _use)
 {
 }
Exemplo n.º 31
0
 protected abstract void DoAction(Entity entity, Item item, ItemUse use);