Exemplo n.º 1
0
    public static string[] FindLinkableFunctions(SpellNode mc, bool findVoid = false)
    {
        System.Reflection.MethodInfo[] methods = mc.GetType().GetMethods();
        List <string> linkableFunctions        = new List <string>();

        foreach (MethodInfo mi in methods)
        {
            if (mi.GetParameters().Length == 0)
            {
                if (!findVoid)
                {
                    if (mi.ReturnType.ToString() != typeof(void).ToString())
                    {
                        // MonoBehaviour.print(mi.Name + ": Has no parameters with a return type of " + mi.ReturnType);
                        linkableFunctions.Add(mi.Name);
                    }
                }
                else
                {
                    if (mi.ReturnType.ToString() == typeof(void).ToString())
                    {
                        // MonoBehaviour.print(mi.Name + ": Has no parameters with a return type of " + mi.ReturnType);
                        linkableFunctions.Add(mi.Name);
                    }
                }
            }
        }
        return(linkableFunctions.ToArray());
    }
Exemplo n.º 2
0
    public static string[] FindPropertiesToLinkTo(string sinkPropName, SpellNode sinkMC, SpellNode sourceMC)
    {
        string linkTypeStr = sinkMC.GetType().GetField(sinkPropName).FieldType.ToString().Split('[')[1].Split(']')[0];

        if (linkTypeStr.Contains("UnityEngine"))
        {
            // MonoBehaviour.print("Assembly Name: " + typeof(GameObject).AssemblyQualifiedName );
            string AssemblyName = typeof(GameObject).AssemblyQualifiedName;
            linkTypeStr = linkTypeStr + AssemblyName.Substring(AssemblyName.IndexOf(","));
        }
        // MonoBehaviour.print("This is the type of the string: " + Type.GetType(typeof(GameObject).AssemblyQualifiedName));
        MonoBehaviour.print(sourceMC.GetType());
        System.Reflection.MethodInfo[] methods = sourceMC.GetType().GetMethods();
        List <string> linkFields = new List <string>();

        foreach (MethodInfo mi in methods)
        {
            if (mi.GetParameters().Length == 0)
            {
                if (mi.ReturnType.ToString() == Type.GetType(linkTypeStr).ToString())
                {
                    // MonoBehaviour.print(mi.Name + ": Has no parameters with a return type of " + mi.ReturnType);
                    linkFields.Add(mi.Name);
                }
            }
        }
        return(linkFields.ToArray());
    }
    public void AddNode(SpellNode node)
    {
        node.spellParent = this;
        nodes.Add(node);
        MagicCircle mc = (MagicCircle)node.GetComponent <MagicCircle>();

        if (mc != null)
        {
            if (baseNode == null)
            {
                baseNode = mc;
            }
            if (initialMagicCircle == null && mc.GetMcType() == MagicCircleType.Element)
            {
                initialMagicCircle = (ElementMagicCircle)mc;
            }

            if (previousMagicCircle != null && autoLinkTransition)
            {
                MagicCircleTransitionLinks link = (MagicCircleTransitionLinks)AddLink(LinkTypes.Transition);
                link.source      = previousMagicCircle;
                link.destination = mc;
                updateLinksList.Add(link);
            }
            previousMagicCircle = mc;
        }
    }
Exemplo n.º 4
0
    public static string[] FindLinkablePropertyToLinkTo(string functionName, SpellNode sourceMc, SpellNode sinkMc)
    {
        MethodInfo mi = sourceMc.GetType().GetMethod(functionName);

        System.Reflection.FieldInfo[] fields = sinkMc.GetType().GetFields();
        List <string> linkFields             = new List <string>();

        foreach (FieldInfo fi in fields)
        {
            if (fi.FieldType.ToString().Contains("LinkableData"))
            {
                string linkTypeStr = fi.FieldType.ToString().Split('[')[1].Split(']')[0];
                if (linkTypeStr.Contains("UnityEngine"))
                {
                    // MonoBehaviour.print("Assembly Name: " + typeof(GameObject).AssemblyQualifiedName );
                    string AssemblyName = typeof(GameObject).AssemblyQualifiedName;
                    linkTypeStr = linkTypeStr + AssemblyName.Substring(AssemblyName.IndexOf(","));
                }
                if (Type.GetType(linkTypeStr).ToString() == mi.ReturnType.ToString())
                {
                    // MonoBehaviour.print( fi.Name + ": is a field of type " + fi.FieldType );
                    linkFields.Add(fi.Name);
                }
            }
        }
        return(linkFields.ToArray());
        // return mc.GetType();
    }
    public void OnSwapSourceDestination()
    {
        SpellNode tempSource = selectedLink.linkedLink.source;

        selectedLink.linkedLink.SetSource(selectedLink.linkedLink.destination);
        selectedLink.linkedLink.SetDestination(tempSource);
        UpdateLinkText();
    }
 public void UpdateSelectedSpellNode(SpellNode sn)
 {
     if (selectedSpellNode != sn)
     {
         selectedSpellNode = sn;
     }
     UpdateDetailsPanel((int)selectedSpellNode.GetMcType());
 }
	/// <summary>
	/// Initializes a new instance of the <see cref="ElementNode"/> class.
	/// </summary>
	/// <param name="element">Element.</param>
	protected ElementNode(Element element){
		if (element != null) {
			_nodes = new Dictionary<Element, SpellNode> ();
			foreach (var elem in Element.GetElements()) {
				if (element._id <= elem._id) {
					_nodes [elem] = new SpellNode (null);
				}
			}
		}
	}
 public void DeselectAll()
 {
     if (selectionMode == SelectionMode.TransitionLink || selectionMode == SelectionMode.DataLink)
     {
         selectedLink.deleteOnNoSource = true;
     }
     selectedSpellNode = null;
     selectedLink      = null;
     selectionMode     = SelectionMode.None;
 }
Exemplo n.º 9
0
    /*public ISpellCast CreateFromCode(GameObject weapon,ISpellCode code) {
     *  switch (code.getID())
     *  {
     *      case "SPELLProjectile":
     *         // return weapon.AddComponent<SPELLProjectile>().SpellProjectileInit("Projectiles/bullet", 10f, 10f);
     *      case "SPELLConsoleBanger":
     *          return new SPELLConsoleBanger();
     *      default:
     *          return new SPELLConsoleBanger();
     *  }
     * }*/

    public void CastSpell(SpellNode spellNode, GameEntity target, GameObject caster)
    {
        switch (spellNode.GetType().ToString())
        {
        case "SNProjectile":
            break;

        default:
            break;
        }
    }
    public void CreateSpellNode(int mct)
    {
        if (currentSpell == null)
        {
            CreateSpell();
        }

        selectedSpellNode = currentSpell.AddNode((MagicCircleType)mct);
        CreateUISpellNode(selectedSpellNode);
        UpdateDetailsPanel(mct);
    }
Exemplo n.º 11
0
 public SNProjectile(float projSpeed, float projSize, Sprite projSprite,
                     SpellNode timeoutSpell = null, float timeoutTime = 0,
                     SpellNode contactSpell = null,
                     SpellNode trailSpell   = null, float trailDelay = 0) : base(timeoutSpell, timeoutTime)
 {
     this.projSpeed    = projSpeed;
     this.projSize     = projSize;
     this.projSprite   = projSprite;
     this.contactSpell = contactSpell;
     this.trailSpell   = trailSpell;
     this.trailDelay   = trailDelay;
 }
Exemplo n.º 12
0
    public static string[] FindAllLinkableProperty(SpellNode mc)
    {
        System.Reflection.FieldInfo[] fields = mc.GetType().GetFields();
        List <string> linkFields             = new List <string>();

        foreach (FieldInfo fi in fields)
        {
            if (fi.FieldType.ToString().Contains("LinkableData"))
            {
                // MonoBehaviour.print( fi.Name + ": is a field of type " + fi.FieldType );
                linkFields.Add(fi.Name);
            }
        }
        return(linkFields.ToArray());
    }
    public override void SetDestination(SpellNode newDestination)
    {
        if (newDestination != oldDestination)
        {
            selectedLinkableProperty  = null;
            linkedActivatableFunction = null;

            if (newDestination != null)
            {
                availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(newDestination));
                activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(newDestination, true));
                oldDestination = newDestination;
                destination    = newDestination;
            }
        }
    }
    public override void SetSource(SpellNode newSource)
    {
        if (newSource != oldSource)
        {
            selectedProperty          = null;
            boolLinkedFunction        = null;
            linkedActivatableFunction = null;

            if (newSource != null)
            {
                availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(newSource));
                oldSource           = newSource;
                source = newSource;
            }
        }
    }
Exemplo n.º 15
0
    public static void LinkField(string sinkPropName, SpellNode sinkMC, string sourcePropName, SpellNode sourceMC)
    {
        FieldInfo  fi = sinkMC.GetType().GetField(sinkPropName);
        MethodInfo mi = sourceMC.GetType().GetMethod(sourcePropName);
        // Debug.Log( "Linking " + mi.Name + " from " + sourceMC.GetType().ToString() + " to "+ fi.Name + " from " + sinkMC.GetType().ToString() );
        MethodInfo setLinkedValueMethod  = fi.FieldType.GetMethod("SetLinkedValue");
        object     convertedLinkedMethod = Convert.ChangeType(Delegate.CreateDelegate(setLinkedValueMethod.GetParameters()[0].ParameterType, sourceMC, mi, true), setLinkedValueMethod.GetParameters()[0].ParameterType);

        object[] myParams = new object[1];
        myParams[0] = convertedLinkedMethod;
        // MonoBehaviour.print(setLinkedValueMethod.GetGenericArguments()[0].ToString());
        setLinkedValueMethod.Invoke(fi.GetValue(sinkMC), myParams);
        // MonoBehaviour.print( setLinkedValueMethod.Name + " with return type " + setLinkedValueMethod.ReturnType + " and parameter " + setLinkedValueMethod.GetParameters()[0].ParameterType );
        // MonoBehaviour.print("convertedLinkedMethod" + convertedLinkedMethod.GetType() );
        // fi.GetType().GetMethod("SetLinkedValue").Invoke(fi.GetValue(sinkMC), myParams );
    }
    public void CreateUISpellNode(SpellNode sn)
    {
        GameObject obj = (GameObject)Instantiate(uiSpellNodePrefab, UiBoard);

        obj.transform.position = rcm.GetRightClickedPoint();
        obj.name = "UI" + sn.GetMcType().ToString() + "SpellNode";
        UISpellNode usn = (UISpellNode)obj.GetComponent <UISpellNode>();

        if (usn != null)
        {
            usn.linkedSpellNode = sn;
            usn.SetUIMenu(this);
            uiSpellNodeList.Add(usn);
            selectedUISN = usn;
        }
    }
    public void UpdateSourceAndDestination()
    {
        oldSource      = source;
        oldDestination = destination;

        if (source != null)
        {
            availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(source));
        }

        if (destination != null)
        {
            availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(destination));
            activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(destination, true));
        }
    }
    public void DestroyNode(SpellNode node)
    {
        RemoveNode(node);
        MagicCircle mc = (MagicCircle)node;

        if (mc != null)
        {
            mc.Deactivate();
            // for( int i = 0; i < links.Count; i++ )
            // {
            //     if( links[i].destination == node || links[i].source == node )
            //     {
            //         DestroyLink(links[i]);
            //     }
            // }
        }
        Destroy(node);
    }
Exemplo n.º 19
0
 public virtual void SetDestination(SpellNode newDestination)
 {
     destination = newDestination;
 }
Exemplo n.º 20
0
 public virtual void SetSource(SpellNode newSource)
 {
     source = newSource;
 }
 public void RemoveNode(SpellNode node)
 {
     nodes.Remove(node);
 }
Exemplo n.º 22
0
 protected SpellNode(SpellNode timeoutSpell, float timeoutTime)
 {
     this.timeoutSpell = timeoutSpell;
     this.timeoutTime  = timeoutTime;
 }
Exemplo n.º 23
0
	/// <summary>
	/// Sets the self spell.
	/// </summary>
	/// <param name="selfSpell">Self spell.</param>
	/// <param name="elements">Elements.</param>
	public void SetSelfSpell(ref SelfSpell selfSpell, Queue<Element> elements){
		if (elements.Count == 0)
			return;

        Element element = elements.Dequeue ();
        Logger.Trace(element._name);


        if (!_nodes.ContainsKey (element))
			return;

		if (_nodes [element]._nodes == null) {
			_nodes [element]= new SpellNode(element);
		}

		_nodes [element].SetSelfSpell (ref selfSpell,elements);
		
	}
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // if left click is pressed...
            if (selectionMode == SelectionMode.None)
            {
                // Checking if a spell node in the game world is clicked.  This is
                // to allow the user to drag the spell node around in user space
                Vector3    mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Collider2D obj        = Physics2D.OverlapPoint((Vector2)mousePoint);
                if (obj != null)
                {
                    SpellNode sn = obj.GetComponent <SpellNode>();
                    if (sn != null)
                    {
                        // drag = true;
                        selectionMode = SelectionMode.Drag;
                        dragableObj   = sn.gameObject;
                        offset        = (Vector2)(sn.transform.position - mousePoint);
                        selectedSpace = SelectionSpace.World;
                        UpdateSelectedSpellNode(sn);
                    }
                }
            }
            else if (selectionMode == SelectionMode.TransitionLink)
            {
            }
        }
        if (selectedSpellNode == null && selectedLink == null)
        {
            UpdateDetailsPanel(0);
        }
        // if( Input.GetMouseButtonDown(2) )
        // {
        //     if( selectedMagicCircle != null )
        //     {
        //         Vector3 mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //         Collider2D obj =  Physics2D.OverlapPoint( (Vector2) mousePoint );
        //         if( obj != null )
        //         {
        //             MagicCircle mc = obj.GetComponent<MagicCircle>();
        //             if( mc != null && selectedMagicCircle != mc)
        //             {
        //                 linkableSourceMagicCircle = mc;
        //                 print( linkablePropertiesSink.captionText.text );
        //                 string[] linkableMethods = LinkableFinder.FindPropertiesToLinkTo( linkablePropertiesSink.captionText.text, selectedMagicCircle, linkableSourceMagicCircle );
        //
        //                 linkablePropertiesSource.options.Clear();
        //                 for(int i = 0; i < linkableMethods.Length; i++ )
        //                 {
        //                     linkablePropertiesSource.options.Add( new Dropdown.OptionData( linkableMethods[i] ) );
        //                 }
        //                 linkablePropertiesSource.RefreshShownValue();
        //             }
        //         }
        //     }
        // }

        // Unselect something when you right click
        if (Input.GetMouseButtonDown(1) && (selectedLink == null || (selectedLink != null && !selectedLink.isClicked)))
        {
            DeselectAll();
        }

        // Stop dragging when you release the mouse
        if (Input.GetMouseButtonUp(0))
        {
            if (selectionMode == SelectionMode.Drag)
            {
                // drag = false;
                selectionMode = SelectionMode.None;
            }
        }

        // Drag selected item
        if (selectionMode == SelectionMode.Drag)
        {
            Vector3 mousePoint;
            if (selectedSpace == SelectionSpace.World)
            {
                mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            }
            else
            {
                mousePoint = Input.mousePosition;
            }
            dragableObj.transform.position = new Vector3(mousePoint.x, mousePoint.y, dragableObj.transform.position.z) + (Vector3)offset;
        }
        else if (selectionMode == SelectionMode.TransitionLink || selectionMode == SelectionMode.DataLink)
        {
            selectedLink.SetPoint(selectedLink.points.Count - 1, Input.mousePosition);
        }
    }
Exemplo n.º 25
0
		/// <summary>
		/// Sets the target spell.
		/// </summary>
		/// <param name="targetSpell">Target spell.</param>
		/// <param name="elements">Elements.</param>
		new public void SetTargetSpell(ref TargetSpell targetSpell, Queue<Element> elements){
			if (elements.Count == 0)
            {
                _targetSpell = targetSpell;
                return;
            }
				

            Element element = elements.Dequeue ();
            Logger.Trace(element._name);

            if (!_nodes.ContainsKey (element))
				return;

			if (_nodes [element]._nodes == null) {
				_nodes [element]= new SpellNode(element);
			}

			_nodes [element].SetTargetSpell (ref targetSpell, elements);
		}
    void Update()
    {
        if (source != oldSource)
        {
            selectedProperty          = null;
            boolLinkedFunction        = null;
            linkedActivatableFunction = null;

            if (source != null)
            {
                availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(source));
                oldSource           = source;
            }
        }

        if (destination != oldDestination)
        {
            selectedLinkableProperty  = null;
            linkedActivatableFunction = null;

            if (destination != null)
            {
                availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(destination));
                activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(destination, true));
                oldDestination = destination;
            }
        }


        if (link)
        {
            link = false;
            if (source != null && destination != null)
            {
                if (previousLinkedProperty != null && previousLinkedProperty != selectedLinkableProperty)
                {
                    ResetProperty(previousLinkedProperty);
                }
                if (selectedProperty != null)
                {
                    // Link properties
                    if (selectedLinkableProperty != null)
                    {
                        Type[] conversionTypes = GetConversion();
                        if (conversionTypes[0] != null)
                        {
                            PickConversionTypes(conversionTypes[0], conversionTypes[1]);
                        }
                        else
                        {
                            Debug.LogWarning("Failed to match one value with the destination or source");
                        }
                    }
                    // Link bool to activator function
                    if (selectedActivatableFunction != null)
                    {
                        LinkActivatorFunction();
                    }
                }
            }
        }

        DrawLink();
    }
Exemplo n.º 27
0
    public void OnCreateMC()
    {
        if (spell == null)
        {
            CreateSpell();
        }
        if (rootMagicCircle == null || !rootMagicCircle.Contains((int)mcType))
        {
            if (mcType == MagicCircleType.None)
            {
                rootMagicCircle = null;
            }
            OnEmissionRateChanged(value1Slider.value);
            Transform pos = rootMagicCircle == null ? defaultMagicCircle.transform : rootMagicCircle.transform;
            // GameObject newObj = Instantiate( defaultMagicCircle, pos ) as GameObject;
            // newObj.name = mcType.ToString() + " Magic Circle";
            SpellNode newNode = spell.AddNode(mcType);
            newNode.name = mcType.ToString() + " Magic Circle";
            MagicCircle newMc;
            switch (mcType)
            {
            case MagicCircleType.Element:
                ElementMagicCircle tempMC = newNode as ElementMagicCircle;
                // tempMC.SetMcType( mcType );
                tempMC.SetElement((ElementType)subType);
                tempMC.emissionRate.SetDefaultValue(emissionRate);
                newMc = tempMC as MagicCircle;
                break;

            case MagicCircleType.Form:
                FormMagicCircle tempFormMC = newNode as FormMagicCircle;
                // tempMC.SetMcType( mcType );
                // tempMC.SetElement( (ElementType) subType );
                tempFormMC.SetForm((FormType)subType);
                tempFormMC.sizeMultiplier.SetDefaultValue(sizeMultiplier);
                newMc = tempFormMC as MagicCircle;
                break;

            case MagicCircleType.Movement:
                MovementMagicCircle tempMovementMC = newNode as MovementMagicCircle;
                // tempMC.SetMcType( mcType );
                // tempMC.SetElement( (ElementType) subType );
                tempMovementMC.SetMovement((MovementType)subType);
                tempMovementMC.force.SetDefaultValue(force);
                newMc = tempMovementMC as MagicCircle;
                break;

            default:
                newMc = newNode as MagicCircle;
                newMc.SetMcType(mcType);
                break;
            }
            if (rootMagicCircle == null)
            {
                rootMagicCircle = newMc;
            }
            else
            {
                // rootMagicCircle.AddMagicCircle( newMc );
            }
            selectedMagicCircle = newMc;
        }
    }