Пример #1
0
    bool CastValues(ECast Type, ECastMode Mode, int Value, float CastTime)
    {
        if (AnimatorComponent)
        {
            this.CastTime = CastTime;
            CastMode      = Mode;
            string Trigger = "Cast";
            switch (Type)
            {
            case ECast.Aoe:         Trigger += ("AOE" + Value); break;

            case ECast.Buff:        Trigger += ("Buff" + Value); break;

            case ECast.Summon:      Trigger += ("Summon" + Value); break;

            default: break;
            }
            Trigger += "Trigger";
            AnimatorComponent.SetTrigger(Trigger);
            AnimatorComponent.SetInteger("Weapon", (int)EWeapon.Armed);
            AnimatorComponent.SetInteger("LeftWeapon", 0);
            AnimatorComponent.SetInteger("RightWeapon", 0);
            return(true);
        }
        return(false);
    }
Пример #2
0
        public static bool TypeCompatible(VariableType dest, VariableType src, bool coerce = false)
        {
            if (dest is DynamicArrayType destArr && src is DynamicArrayType srcArr)
            {
                return(TypeCompatible(destArr.ElementType, srcArr.ElementType));
            }

            if (dest is ClassType destClassType && src is ClassType srcClassType)
            {
                return(destClassType.ClassLimiter == srcClassType.ClassLimiter || ((Class)srcClassType.ClassLimiter).SameAsOrSubClassOf(destClassType.ClassLimiter.Name));
            }

            if (dest.PropertyType == EPropertyType.Byte && src.PropertyType == EPropertyType.Byte)
            {
                return(true);
            }

            if (dest is DelegateType destDel && src is DelegateType srcDel)
            {
                return(true);
                // this seems like how it ought to be done, but there is bioware code that would have only compiled if all delegates are considered the same type
                // maybe log a warning here instead of an error?
                //return destDel.DefaultFunction.SignatureEquals(srcDel.DefaultFunction);
            }

            if (dest is Class destClass)
            {
                if (src is Class srcClass)
                {
                    bool sameAsOrSubClassOf = srcClass.SameAsOrSubClassOf(destClass.Name);
                    if (srcClass.IsInterface)
                    {
                        return(sameAsOrSubClassOf || destClass.Implements(srcClass));
                    }
                    return(sameAsOrSubClassOf
                           //this seems super wrong obviously. A sane type system would require an explicit downcast.
                           //But to make this work with existing bioware code, it's this, or write a control-flow analyzer that implicitly downcasts based on typecheck conditional gates
                           //I have chosen the lazy path
                           || destClass.SameAsOrSubClassOf(srcClass.Name));
                }

                if (destClass.Name.CaseInsensitiveEquals("Object") && src is ClassType)
                {
                    return(true);
                }
            }

            if (dest.Name.CaseInsensitiveEquals(src?.Name))
            {
                return(true);
            }
            ECast cast = CastHelper.GetConversion(dest, src);

            if (coerce)
            {
                return(cast != ECast.Max);
            }
            return(cast.Has(ECast.AutoConvert));
        }
Пример #3
0
        public static int ConversionCost(FunctionParameter dest, VariableType src)
        {
            if (dest.VarType == src)
            {
                return(0); //exact match
            }

            if (src?.PropertyType == EPropertyType.Vector && dest.VarType?.PropertyType == EPropertyType.Vector ||
                src?.PropertyType == EPropertyType.Rotator && dest.VarType?.PropertyType == EPropertyType.Rotator)
            {
                return(0);
            }
            if (dest.VarType is Class c && (src is null || src is ClassType && !c.IsInterface))
            {
                return(0);
            }
            if (dest.VarType is DelegateType && src is null)
            {
                return(0);
            }
            if (dest.IsOut)
            {
                return(int.MaxValue);
            }
            if (INTERFACE.CaseInsensitiveEquals(dest.VarType?.Name) && src is Class cls && cls.SameAsOrSubClassOf(INTERFACE))
            {
                return(1); //Interface subclass
            }
            if (!INTERFACE.CaseInsensitiveEquals(dest.VarType?.Name) && dest.VarType is Class && src is Class)
            {
                return(2);
            }
            ECast conversion = GetConversion(dest.VarType, src);

            //if it has 'coerce', any valid conversion is acceptable, otherwise only autoconversions are acceptable
            if (dest.Flags.Has(UnrealFlags.EPropertyFlags.CoerceParm) ? conversion != ECast.Max : conversion.Has(ECast.AutoConvert))
            {
                if (conversion.Has(ECast.Truncate))
                {
                    return(104); //lossy conversion
                }

                if (dest.VarType == SymbolTable.FloatType && (src == SymbolTable.IntType || src?.PropertyType == EPropertyType.Byte))
                {
                    return(103); //int to float conversion
                }

                return(101); //lossless conversion
            }

            return(int.MaxValue);
        }
Пример #4
0
    public void Cast(string InputName, ECast Type, ECastMode Mode, int Value, float CastTime)
    {
        switch (CastMode)
        {
        case  ECastMode.Default:
            if (Input.GetButtonDown(InputName))
            {
                IsCast = true;
                CastValues(Type, Mode, Value, CastTime);
            }
            break;

        case ECastMode.Channeling:
            if (Input.GetButtonDown(InputName))
            {
                IsCast = CastValues(Type, Mode, Value, CastTime);
            }

            if (Input.GetButtonUp(InputName))
            {
                AnimatorComponent.SetTrigger("CastEndTrigger");
                IsCast = false;
            }
            break;

        case ECastMode.Toggle:
            this.CastTime = -1;
            if (IsCast)
            {
                if (Input.GetButtonDown(InputName))
                {
                    IsCast = false;
                    AnimatorComponent.SetTrigger("CastEndTrigger");
                }
            }
            else
            {
                if (Input.GetButtonDown(InputName))
                {
                    IsCast = true;
                    CastValues(Type, Mode, Value, CastTime);
                }
            }
            break;

        case ECastMode.Instant:
            if (Input.GetButtonDown(InputName))
            {
                IsCast = true;
                CastValues(Type, Mode, Value, CastTime);
            }
            break;

        case ECastMode.Strike:
            if (Input.GetButtonDown(InputName))
            {
                CastMeter = Mathf.Clamp(CastMeter + CastAdd, 0, CastCap);
            }

            if (CastMeter >= CastCap)
            {
                IsCast    = true;
                CastMeter = 0;
                CastValues(Type, Mode, Value, CastTime);
                Invoke("OnCastInvoke", CastCapTime);
            }
            break;
        }
    }
Пример #5
0
 public static ECast PureCastType(ECast castType) => castType & ~(ECast.AutoConvert | ECast.Truncate);
Пример #6
0
 public PrimitiveCast(ECast cast, VariableType castType, Expression expr, SourcePosition start, SourcePosition end) : base(castType, expr, start, end)
 {
     Cast = cast;
 }
Пример #7
0
 protected void WriteCast(ECast castToken) => WriteByte((byte)castToken);