/// <summary>
    /// 禁用子弹的出现特效
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int DisableBulletAppearEffect(ILuaState luaState)
    {
        EnemySimpleBullet bullet = luaState.ToUserData(-1) as EnemySimpleBullet;

        bullet.SetAppearEffectAvailable(false);
        return(0);
    }
    /// <summary>
    /// 创建自定义的simpleBullet
    /// <para>customizedName 自定义的子弹名称</para>
    /// <para>float posX</para>
    /// <para>float posY</para>
    /// <para>args...</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedBullet(ILuaState luaState)
    {
        int               numArgs        = luaState.GetTop() - 3;
        string            customizedName = luaState.ToString(-3 - numArgs);
        float             posX           = (float)luaState.ToNumber(-2 - numArgs);
        float             posY           = (float)luaState.ToNumber(-1 - numArgs);
        EnemySimpleBullet bullet         = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet;

        bullet.SetPosition(posX, posY);
        // 设置自定义的数据
        BCCustomizedTask bc = bullet.AddOrGetComponent <BCCustomizedTask>();
        int funcRef         = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef);
        if (!luaState.IsFunction(-1))
        {
            Logger.LogError("InitFuncRef of " + customizedName + " is not point to a function");
        }
        luaState.PushLightUserData(bullet);
        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(-2 - numArgs);
        }
        luaState.Call(numArgs + 1, 0);
        luaState.PushLightUserData(bullet);
        return(1);
    }
    /// <summary>
    /// 设置子弹生成时是否播放生成特效
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetBulletAppearEffectAvailable(ILuaState luaState)
    {
        EnemySimpleBullet bullet = luaState.ToUserData(-2) as EnemySimpleBullet;
        bool isAvailable         = luaState.ToBoolean(-1);

        bullet.SetAppearEffectAvailable(isAvailable);
        return(0);
    }
Пример #4
0
    private BulletBase NewBullet(BulletType bulletID)
    {
        BulletBase         bullet = null;
        Stack <BulletBase> _stack;

        // 判断对象池中是否有该类型的对象,如果有,则取出
        if (_bulletsPool.TryGetValue(bulletID, out _stack))
        {
            if (_stack.Count > 0)
            {
                bullet = _stack.Pop();
            }
        }
        else
        {
            _stack = new Stack <BulletBase>();
            _bulletsPool.Add(bulletID, _stack);
        }
        // 如果对象池内没有该对象,则创建
        if (bullet == null)
        {
            switch (bulletID)
            {
            case BulletType.ReimuA_Sub1:
                bullet = new BulletReimuASub1();
                break;

            case BulletType.Player_Laser:
                bullet = new PlayerLaser();
                break;

            case BulletType.Player_Simple:
                bullet = new PlayerBulletSimple();
                break;

            case BulletType.Enemy_Laser:
                bullet = new EnemyLaser();
                break;

            case BulletType.Enemy_CurveLaser:
                bullet = new EnemyCurveLaser();
                break;

            case BulletType.Enemy_Simple:
                bullet = new EnemySimpleBullet();
                break;

            case BulletType.Enemy_LinearLaser:
                bullet = new EnemyLinearLaser();
                break;

            default:
                Logger.Log("Create Bullet Fail! Invalid BulledId!");
                break;
            }
        }
        return(bullet);
    }
    /// <summary>
    /// 设置子弹是否自旋
    /// <para>SimpleBullet bullet</para>
    /// <para>float omega 自旋角度,为0说明不自旋</para>
    /// <para></para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetBulletSelfRotation(ILuaState luaState)
    {
        EnemySimpleBullet bullet = luaState.ToUserData(-2) as EnemySimpleBullet;
        float             omega  = (float)luaState.ToNumber(-1);

        luaState.Pop(2);
        bullet.SetSelfRotation(omega);
        return(0);
    }
    /// <summary> 赋予子弹加速度
    /// <para>bullet</para>
    /// <para>acce</para>
    /// <para>accAngle</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int DoBulletAcceleration(ILuaState luaState)
    {
        EnemySimpleBullet bullet   = luaState.ToUserData(-3) as EnemySimpleBullet;
        float             acce     = (float)luaState.ToNumber(-2);
        float             accAngle = (float)luaState.ToNumber(-1);

        luaState.Pop(3);
        bullet.DoAcceleration(acce, accAngle);
        return(0);
    }
    /// <summary> 赋予子弹加速度
    /// <para>bullet</para>
    /// <para>acce</para>
    /// <para>accAngle</para>
    /// <para>maxVelocity  速度最大值</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int DoBulletAccelerationWithLimitation(ILuaState luaState)
    {
        EnemySimpleBullet bullet      = luaState.ToUserData(-4) as EnemySimpleBullet;
        float             acce        = (float)luaState.ToNumber(-3);
        float             accAngle    = (float)luaState.ToNumber(-2);
        float             maxVelocity = (float)luaState.ToNumber(-1);

        luaState.Pop(4);
        bullet.DoAccelerationWithLimitation(acce, accAngle, maxVelocity);
        return(0);
    }
    /// <summary>
    /// SimpleBullet延迟delay帧后经过duration帧缩放至toScale
    /// <para>SimpleBullet bullet</para>
    /// <para>float toScale</para>
    /// <para>int duration</para>
    /// <para>int delay</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int BulletDoScale(ILuaState luaState)
    {
        EnemySimpleBullet bullet  = luaState.ToUserData(-4) as EnemySimpleBullet;
        float             toScale = (float)luaState.ToNumber(-3);
        int delay    = luaState.ToInteger(-2);
        int duration = luaState.ToInteger(-1);

        luaState.Pop(4);
        bullet.DoScale(toScale, delay, duration);
        return(0);
    }
    /// <summary>
    /// <para>bullet</para>
    /// <para>radius</para>
    /// <para>curveAngle</para>
    /// <para>deltaR</para>
    /// <para>omiga</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetBulletCurvePara(ILuaState luaState)
    {
        EnemySimpleBullet bullet     = luaState.ToUserData(-5) as EnemySimpleBullet;
        float             radius     = (float)luaState.ToNumber(-4);
        float             curveAngle = (float)luaState.ToNumber(-3);
        float             deltaR     = (float)luaState.ToNumber(-2);
        float             omiga      = (float)luaState.ToNumber(-1);

        luaState.Pop(5);
        bullet.SetPolarParas(radius, curveAngle, deltaR, omiga);
        return(0);
    }
    /// <summary>
    /// 设置子弹的缩放
    /// <para>bullet</para>
    /// <para>(1)scale 缩放值</para>
    /// <para>(2)float scaleX,float scaleY</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetBulletScale(ILuaState luaState)
    {
        int top = luaState.GetTop();

        if (top == 2)
        {
            EnemySimpleBullet bullet = luaState.ToUserData(-2) as EnemySimpleBullet;
            float             scale  = (float)luaState.ToNumber(-1);
            bullet.SetScale(scale);
        }
        else
        {
            EnemySimpleBullet bullet = luaState.ToUserData(-3) as EnemySimpleBullet;
            float             scaleX = (float)luaState.ToNumber(-2);
            float             scaleY = (float)luaState.ToNumber(-1);
            bullet.SetBulletPara(BulletParaType.ScaleX, scaleX);
            bullet.SetBulletPara(BulletParaType.ScaleY, scaleY);
        }
        return(0);
    }
    /// <summary>
    /// 创建自定义的simpleBullet
    /// <para>customizedName 自定义的子弹名称</para>
    /// <para>id 默认的id</para>
    /// <para>float posX</para>
    /// <para>float posY</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateCustomizedBullet2(ILuaState luaState)
    {
        int    numArgs        = luaState.ToInteger(-1);
        string customizedName = luaState.ToString(-5 - numArgs);
        string sysId;

        if (luaState.Type(-4 - numArgs) == LuaType.LUA_TNUMBER)
        {
            sysId = luaState.ToNumber(-4 - numArgs).ToString();
        }
        else
        {
            sysId = luaState.ToString(-4 - numArgs);
        }
        float posX = (float)luaState.ToNumber(-3 - numArgs);
        float posY = (float)luaState.ToNumber(-2 - numArgs);

        luaState.Pop(1);
        EnemySimpleBullet bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet;

        bullet.SetStyleById(sysId);
        bullet.SetPosition(posX, posY);
        // 设置自定义的数据
        BCCustomizedTask bc = bullet.AddOrGetComponent <BCCustomizedTask>();
        int funcRef         = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef);
        if (!luaState.IsFunction(-1))
        {
            Logger.LogError("InitFuncRef of " + customizedName + " is not point to a function");
        }
        luaState.PushLightUserData(bullet);
        luaState.Replace(-3 - numArgs);
        luaState.Replace(-3 - numArgs);
        luaState.Call(numArgs + 1, 0);
        // 弹出剩余两个参数
        luaState.Pop(2);
        luaState.PushLightUserData(bullet);
        return(1);
    }
    /// <summary>
    /// 根据id创建SimpleBullet
    /// <para>id 配置里面的id</para>
    /// <para>float posX</para>
    /// <para>float posY</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateSimpleBulletById(ILuaState luaState)
    {
        string sysId;

        if (luaState.Type(-3) == LuaType.LUA_TNUMBER)
        {
            sysId = luaState.ToNumber(-3).ToString();
        }
        else
        {
            sysId = luaState.ToString(-3);
        }
        float posX = (float)luaState.ToNumber(-2);
        float posY = (float)luaState.ToNumber(-1);

        luaState.Pop(3);
        EnemySimpleBullet bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet;

        bullet.SetStyleById(sysId);
        bullet.SetPosition(posX, posY);
        luaState.PushLightUserData(bullet);
        return(1);
    }
    public static bool Get(object o, TValue key, out TValue res)
    {
        EnemySimpleBullet bullet = (EnemySimpleBullet)o;

        res = new TValue();
        if (key.TtIsString())
        {
            switch (key.SValue())
            {
                #region 基础变量
            case "x":
            {
                res.SetNValue(bullet.GetPosition().x);
                return(true);
            }

            case "y":
            {
                res.SetNValue(bullet.GetPosition().y);
                return(true);
            }

            case "rot":
            {
                res.SetNValue(bullet.GetRotation());
                return(true);
            }

            case "dx":
            {
                res.SetNValue(bullet.dx);
                return(true);
            }

            case "dy":
            {
                res.SetNValue(bullet.dy);
                return(true);
            }

            case "id":
            {
                res.SetNValue(int.Parse(bullet.BulletId));
                return(true);
            }

                #endregion
                #region 运动相关变量
            case "v":
            {
                res.SetNValue(bullet.Velocity);
                return(true);
            }

            case "vx":
            {
                res.SetNValue(bullet.Vx);
                return(true);
            }

            case "vy":
            {
                res.SetNValue(bullet.Vy);
                return(true);
            }

            case "vAngle":
            {
                res.SetNValue(bullet.VAngle);
                return(true);
            }

            case "maxV":
            {
                res.SetNValue(bullet.MaxVelocity);
                return(true);
            }

            case "acce":
            {
                res.SetNValue(bullet.Acce);
                return(true);
            }

            case "accAngle":
            {
                res.SetNValue(bullet.AccAngle);
                return(true);
            }

                #endregion
                #region 子弹类专属变量
            case "timer":
            {
                res.SetNValue(bullet.timeSinceCreated);
                return(true);
            }

            case "alpha":
            {
                res.SetNValue(bullet.alpha);
                return(true);
            }

            case "SetSelfRotation":
            {
                res.SetClCsValue(_funcSetSelfRotaion);
                return(true);
            }

            case "SetStyleById":
            {
                res.SetClCsValue(_funcSetStyleById);
                return(true);
            }

            case "SetResistEliminatedTypes":
            {
                res.SetClCsValue(_funcSetResistEliminatedTypes);
                return(true);
            }

            case "SetColor":
            {
                res.SetClCsValue(_funcSetColor);
                return(true);
            }

                #endregion
                #region SimpleBullet 专属变量
            case "DisableAppearEffect":
            {
                res.SetClCsValue(_funcDisableAppearEffect);
                return(true);
            }

            case "SetScale":
            {
                res.SetClCsValue(_funcSetScale);
                return(true);
            }

                #endregion
                #region 运动类专属方法 ISTGMovable
            case "SetV":
            {
                res.SetClCsValue(_funcSetV);
                return(true);
            }

            case "SetAcce":
            {
                res.SetClCsValue(_funcSetAcce);
                return(true);
            }

            case "SetStraightParas":
            {
                res.SetClCsValue(_funcSetStraightParas);
                return(true);
            }

            case "SetPolarParas":
            {
                res.SetClCsValue(_funcSetPolarParas);
                return(true);
            }

            case "MoveTo":
            {
                res.SetClCsValue(_funcMoveTo);
                return(true);
            }

            case "MoveTowards":
            {
                res.SetClCsValue(_funcMoveTowards);
                return(true);
            }

            case "SetPos":
            {
                res.SetClCsValue(_funcSetPos);
                return(true);
            }

            case "GetPos":
            {
                res.SetClCsValue(_funcGetPos);
                return(true);
            }

                #endregion
                #region IAttachable
            case "AttachTo":
            {
                res.SetClCsValue(_funcAttachTo);
                return(true);
            }

            case "SetRelativePos":
            {
                res.SetClCsValue(_funcSetRelativePos);
                return(true);
            }

                #endregion
                #region ITaskExecuter
            case "AddTask":
            {
                res.SetClCsValue(_funcAddTask);
                return(true);
            }

                #endregion
                #region Component
            case "AddColliderTrigger":
            {
                res.SetClCsValue(_funcAddColliderTrigger);
                return(true);
            }

            case "AddRebound":
            {
                res.SetClCsValue(_funcAddRebound);
                return(true);
            }

            case "ChangeProperty":
            {
                res.SetClCsValue(_funcChangeProperty);
                return(true);
            }
                #endregion
            }
        }
        res.SetSValue(string.Format("GetField from userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name));
        return(false);
    }
    public static bool Set(object o, TValue key, ref TValue value)
    {
        EnemySimpleBullet bullet = (EnemySimpleBullet)o;

        if (key.TtIsString())
        {
            switch (key.SValue())
            {
                #region 基础变量
            case "x":
            {
                Vector2 pos = bullet.GetPosition();
                pos.x = (float)value.NValue;
                bullet.SetPosition(pos);
                return(true);
            }

            case "y":
            {
                Vector2 pos = bullet.GetPosition();
                pos.y = (float)value.NValue;
                bullet.SetPosition(pos);
                return(true);
            }

            case "rot":
            {
                bullet.SetRotation((float)value.NValue);
                return(true);
            }

                #endregion
                #region 运动相关变量
            case "v":
            {
                bullet.Velocity = (float)value.NValue;
                return(true);
            }

            case "vx":
            {
                bullet.Vx = (float)value.NValue;
                return(true);
            }

            case "vy":
            {
                bullet.Vy = (float)value.NValue;
                return(true);
            }

            case "vAngle":
            {
                bullet.VAngle = (float)value.NValue;
                return(true);
            }

            case "maxV":
            {
                bullet.MaxVelocity = (float)value.NValue;
                return(true);
            }

            case "acce":
            {
                bullet.Acce = (float)value.NValue;
                return(true);
            }

            case "accAngle":
            {
                bullet.AccAngle = (float)value.NValue;
                return(true);
            }

                #endregion
                #region 子弹类专属变量
            case "orderInLayer":
            {
                bullet.SetOrderInLayer((int)value.NValue);
                return(true);
            }

            case "checkCollision":
            {
                bullet.SetDetectCollision(value.BValue());
                return(true);
            }

            case "navi":
            {
                bullet.SetRotatedByVelocity(value.BValue());
                return(true);
            }

            case "checkBorder":
            {
                bullet.SetCheckOutOfBorder(value.BValue());
                return(true);
            }

            case "alpha":
            {
                bullet.SetAlpha((float)value.NValue);
                return(true);
            }

            case "omega":
            {
                bullet.SetSelfRotation((float)value.NValue);
                return(true);
            }

            case "scale":
            {
                bullet.SetScale((float)value.NValue);
                return(true);
            }

            case "scaleX":
            {
                bullet.SetBulletPara(BulletParaType.ScaleX, (float)value.NValue);
                return(true);
            }

            case "scaleY":
            {
                bullet.SetBulletPara(BulletParaType.ScaleY, (float)value.NValue);
                return(true);
            }
                #endregion
            }
        }
        value.SetSValue(string.Format("SetField of userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name));
        return(false);
    }