Example #1
0
    /// <summary>
    /// 以目标选择的对象(而不是资源ID)作为参数, 外界可以通过直接构造该对象, 而非从数据表读取, 从而调用该方法.
    /// </summary>
    public static ErrorCode SelectTargetAndAddSkillEffect(
        AttackerAttr attackerAttr,
        Vector3 centerPosition,
        float direction,
        TargetSelectionTableItem targetSelectionRes,
        uint skillEffectResID,
        SkillUtilities.FilterTarget filter = null
        )
    {
        ArrayList targets = SkillUtilities.SelectTargets(attackerAttr,
                                                         centerPosition, direction, targetSelectionRes);

        if (filter != null)
        {
            SkillUtilities.FilterTargetsBy(targets, filter, null);
        }

        foreach (BattleUnit t in targets)
        {
            // 设置效果的起始点.
            attackerAttr.SetEffectStartLocation(centerPosition,
                                                Utility.Vector3ToRadian(t.GetPosition() - attackerAttr.EffectStartPosition, direction)
                                                );

            ErrorHandler.Parse(
                AddSkillEffectByResource(attackerAttr, t, skillEffectResID),
                "failed to add skill effect with SelectTargetAndAddSkillEffect"
                );
        }

        return(ErrorCode.Succeeded);
    }
Example #2
0
    public override void Explode()
    {
        ErrorHandler.Parse(
            SkillDetails.CreateCreationAround(mBullet.FirerAttr, mBullet.CreationOnArrive, mBullet.GetPosition(), mBullet.GetDirection()),
            "failed to create creature on bullet arrived"
            );

        // 爆炸特效, 仅在子弹到达终点时播放, 即, 子弹没有命中足够的人.
        if (mBullet.CurrentHittedCount < mBullet.MaxHitCount)
        {
            SkillClientBehaviour.AddSceneEffect(mBullet.ExplodeEffect, mBullet.GetPosition(), mBullet.GetDirection());
        }

        // 用碰撞来模拟爆炸, 从而使得技能效果的方向沿着子弹的飞行方向.
        if (mBullet.TargetSelectionOnArrive != uint.MaxValue && mBullet.SkillEffectOnArrive != uint.MaxValue)
        {
            TargetSelectionTableItem targetSel = DataManager.TargetSelectionTable[mBullet.TargetSelectionOnArrive] as TargetSelectionTableItem;

            ArrayList targets = SkillUtilities.SelectTargets(mBullet.FirerAttr, mBullet.GetPosition(), mBullet.GetDirection(), targetSel);

            AttackerAttr other = mBullet.FirerAttr;
            other.SetEffectStartLocation(mBullet.GetPosition(), mBullet.GetDirection());

            foreach (BattleUnit t in targets)
            {
                SkillDetails.AddSkillEffectByResource(other, t, mBullet.SkillEffectOnArrive);
            }
        }
    }
    protected override ErrorCode doStart(ActionInitParam param)
    {
        ErrorCode err = base.doStart(param);

        if (err != ErrorCode.Succeeded)
        {
            return(err);
        }

        ActionDisplacementInitParam displacementInit = param as ActionDisplacementInitParam;

        mDisplacementResource = displacementInit.displacementResource;

        if (mDisplacementResource.leagueSelectionOnExecute != LeagueSelection.None &&
            mDisplacementResource.skillEffect2OthersOnExecute != uint.MaxValue)
        {
            mTargetSelectionOnExecute = new TargetSelectionTableItem()
            {
                resID          = -1,
                desc           = "displacement hit",
                leagueSel      = mDisplacementResource.leagueSelectionOnExecute,
                maxTargetCount = uint.MaxValue,
                shape          = ShapeType.ShapeType_Rect,
                RectLength     = mDisplacementResource.radiusOnCollide * 2
            }
        }
        ;

        return(ErrorCode.Succeeded);
    }
Example #4
0
    private bool checkTargetSelection()
    {
        DataType myName = DataType.DATA_SKILL_TARGET_SELECTION;

        IDictionaryEnumerator itr = DataManager.TargetSelectionTable.GetEnumerator();

        while (itr.MoveNext())
        {
            TargetSelectionTableItem item = itr.Value as TargetSelectionTableItem;
            if (!checkParam(item.maxTargetCount != 0, myName, item.resID, "最大目标个数", "最大目标个数不可为0"))
            {
                return(false);
            }

            if (!checkParam(item.leagueSel < LeagueSelection.Count, myName, item.resID, "敌我识别"))
            {
                return(false);
            }
        }
//      foreach (int key in DataManager.TargetSelectionTable.Keys)
//      {
//          TargetSelectionTableItem item = DataManager.TargetSelectionTable[key] as TargetSelectionTableItem;
//          if (!checkParam(item.maxTargetCount != 0, myName, key, "最大目标个数", "最大目标个数不可为0"))
//              return false;
//
//          if (!checkParam(item.leagueSel < LeagueSelection.Count, myName, key, "敌我识别"))
//              return false;
//
//      }

        return(true);
    }
Example #5
0
    public override bool Init(ObjectInitParam param)
    {
        if (!base.Init(param))
        {
            return(false);
        }

        mBulletParam = (BulletInitParam)param;

        if ((mBulletResource = DataManager.BulletTable[mBulletParam.resID] as BulletTableItem) == null)
        {
            SkillUtilities.ResourceNotFound("bullet", mBulletParam.resID);
            return(false);
        }

        mCreateDelay = mBulletParam.createDelay;

        mFirerAttr = mBulletParam.firerAttr;

        FlySpeed = mBulletResource.flySpeed;

        StartPosition  = mBulletParam.startPosition;
        TargetPosition = mBulletParam.targetPosition;

        Vector3 dir3d = TargetPosition - StartPosition;

        dir3d.y = 0;

        if (dir3d == Vector3.zero)
        {
            // 起始点与终点位置重叠, 取开火者当前朝向.
            BattleUnit firer       = mFirerAttr.CheckedAttackerObject();
            float      alternative = (firer != null) ? firer.GetDirection() : mFirerAttr.AttackerDirection;
            dir3d = Utility.RadianToVector3(alternative);
        }

        FlyDirection = Quaternion.LookRotation(dir3d);
        SetRotation(FlyDirection);

        AccelerateDelay = mBulletResource.accelerateDelay;

        mFlyTargetSelection = new TargetSelectionTableItem()
        {
            resID     = -1,
            desc      = "bullet hit",
            leagueSel = mBulletResource.leagueSelection,
            //maxTargetCount = mBulletResource.flyThroughCount - (uint)mHitted.Count,
            shape      = ShapeType.ShapeType_Rect,
            RectLength = mBulletResource.radiusOnCollide * 2
        };

        SetPosition(StartPosition);

        return(true);
    }
Example #6
0
    /// <summary>
    /// 从graphCenter, 沿dirRadian方向, 通过targetSel选择目标, 并给选择到的目标添加skillEffectID标识的技能效果.
    /// </summary>
    /// <returns>命中目标个数</returns>
    private uint collideAt(Vector3 graphCenter, float dirRadian, TargetSelectionTableItem targetSel, uint skillEffectID)
    {
        ArrayList targets = SkillUtilities.SelectTargets(mFirerAttr, graphCenter, dirRadian, targetSel);

        SkillUtilities.FilterTargetsBy(targets, checkHitObject);

        AttackerAttr other = mFirerAttr;

        other.SetEffectStartLocation(graphCenter, dirRadian);

        foreach (BattleUnit t in targets)
        {
            SkillDetails.AddSkillEffectByResource(other, t, skillEffectID);
        }

        return((uint)targets.Count);
    }
Example #7
0
    /// <summary>
    /// 选择目标, 并添加效果.
    /// </summary>
    /// <param name="attackerAttr">攻击者属性</param>
    /// <param name="centerPosition">在该位置进行目标选择</param>
    /// <param name= "direction">在中心位置时的朝向(如果形状是圆, 那么该参数没有作用)</param>
    /// <param name="targetSelection">目标选择参数</param>
    /// <param name="skillCommonResID">最初技能ID</param>
    /// <param name="skillEffectResID">为选择到的目标添加效果</param>
    /// <returns>对多少人添加了效果</returns>
    /// <remarks>
    /// 通过该方法产生的技能效果, 起始点和起始位置的方向会改变为技能选择中心点以及该点处的方向,
    /// 对之后的位移发起位置, 特效方向等产生影响.
    /// </remarks>
    public static ErrorCode SelectTargetAndAddSkillEffect(
        AttackerAttr attackerAttr,
        Vector3 centerPosition,
        float direction,
        uint targetSelection,
        uint skillEffectResID,
        SkillUtilities.FilterTarget filter = null
        )
    {
        if (targetSelection == uint.MaxValue && skillEffectResID == uint.MaxValue)
        {
            return(ErrorCode.Succeeded);
        }

        TargetSelectionTableItem targetSelectionRes = DataManager.TargetSelectionTable[targetSelection] as TargetSelectionTableItem;

        if (targetSelectionRes == null)
        {
            SkillUtilities.ResourceNotFound("targetselection", targetSelection);
            return(ErrorCode.ConfigError);
        }

        return(SelectTargetAndAddSkillEffect(attackerAttr, centerPosition, direction, targetSelectionRes, skillEffectResID, filter));
    }
Example #8
0
    /// <summary>
    /// 根据目标选择参数, 以centerPosition为中心选择目标.
    /// </summary>
    /// <param name="attackerAttr">攻击者的数据</param>
    /// <param name="centerPosition">选择的中心点</param>
    /// <param name="attackerDirection">攻击者的方向(对于矩形, 扇形时用到)</param>
    /// <param name="res">目标选择的资源</param>
    /// <returns>目标集合, 不会为null.</returns>
    public static ArrayList SelectTargets(AttackerAttr attackerAttr, Vector3 centerPosition, float attackerDirection, TargetSelectionTableItem targetSelRes)
    {
        BaseScene scn = SceneManager.Instance.GetCurScene();

        if (scn == null)
        {
            return(null);
        }

        SceneShapeRect selRect = null;
        ArrayList      result  = null;
        SceneShape     shape   = null;

        switch (targetSelRes.shape)
        {        // 假设目标最大半径为5.0f米
        case ShapeType.ShapeType_Round:
        {
            float radius = targetSelRes.CircleRadius * 2.0f + 5.0f;
            selRect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), radius, radius);
            shape   = new SceneShapeRound(new Vector2(centerPosition.x, centerPosition.z), targetSelRes.CircleRadius);
        }
        break;

        case ShapeType.ShapeType_Rect:
        {
            float radius = targetSelRes.RectLength + targetSelRes.RectWidth + 5.0f;
            selRect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), radius, radius);
            SceneShapeRect rect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), targetSelRes.RectLength, targetSelRes.RectWidth);
            shape = SceneShapeUtilities.rotate(rect, new Vector2(centerPosition.x, centerPosition.z), attackerDirection * Mathf.Rad2Deg);
        }
        break;

        case ShapeType.ShapeType_Invalid:
            break;

        default:
            ResourceInvalidParam("targetselection", (uint)targetSelRes.resID, "形状");
            break;
        }

        if (shape != null && selRect != null)
        {
            ArrayList lst = scn.SearchObject(selRect, ObjectType.OBJ_SEARCH_BATTLEUNIT);
            if (lst != null && lst.Count > 0)
            {
                result = new ArrayList();
                for (int i = 0; i < lst.Count; i++)
                {
                    ObjectBase obj = lst[i] as ObjectBase;
                    if (obj == null)
                    {
                        continue;
                    }

                    if (shape.intersect(obj.GetShape()))
                    {
                        result.Add(obj);
                    }
                }
            }
        }

        if (result == null)
        {
            result = new ArrayList();
        }

        // 根据阵营筛选.
        FilterTargetsBy(result, filterTargetsByLeague, attackerAttr, targetSelRes.leagueSel);

        // 最多只能选择maxTargetCount个单位.
        RandomSampling(result, targetSelRes.maxTargetCount);

        return(result);
    }