예제 #1
0
    /// <summary>
    /// 获取行为构建器
    /// </summary>
    /// <returns>构建完成的单个行为</returns>
    public override IFormula GetFormula(FormulaParamsPacker paramsPacker)
    {
        // 验证数据正确, 如果有问题直接抛错误
        string errorMsg = null;

        if (paramsPacker == null)
        {
            errorMsg = "调用参数 paramsPacker 为空.";
        }


        if (!string.IsNullOrEmpty(errorMsg))
        {
            throw new Exception(errorMsg);
        }

        // 替换替换符数据
        ReplaceData(paramsPacker);

        // 数据本地化
        var myFormulaType = FormulaType;
        var myTargetPos   = TargetPos;
        var myUnitType    = UnitType;
        var myUnitID      = UnitID;
        var myLevel       = Level;


        IFormula result = new Formula((callback, scope) =>
        {
            var pos = GetPosByType(myTargetPos, paramsPacker, scope);
            DisplayOwner display;
            try
            {
                display = FightUnitFactory.CreateUnit(myUnitType, new CreateActorParam(pos.x, pos.z, myLevel)
                {
                    SoldierID = myUnitID * 1000 + myLevel
                });
                display.ClusterData.Begin();
                display.ClusterData.ContinueMove();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                throw;
            }

            callback();
        }, myFormulaType);

        return(result);
    }
예제 #2
0
 static int CreateUnit(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
         CreateActorParam arg1 = (CreateActorParam)ToLua.CheckObject(L, 2, typeof(CreateActorParam));
         DisplayOwner     o    = FightUnitFactory.CreateUnit(arg0, arg1);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #3
0
    /// <summary>
    /// 确认操作
    /// </summary>
    /// <param name="msgOp">被确认操作消息</param>
    /// <param name="isLocal">是否本地创建</param>
    private void ComfirmOptional(MsgOptional msgOp, bool isLocal = false)
    {
        // 下兵操作
        // 解析Params
        // TODO 模型动画相关参数不全
        var kvDic    = GetParams(msgOp.OpParams);
        var objectId = Convert.ToInt32(kvDic["ObjectId"]);
        var unitType = Convert.ToInt32(kvDic["UnitType"]);
        var uniqueId = Convert.ToInt32(kvDic["UniqueId"]);
        //var cmName = kvDic["CmName"];
        var    level           = Convert.ToInt32(kvDic["Level"]);
        string meshPackname    = null;
        string texturePackname = null;

        if (kvDic.ContainsKey("MeshPackName"))
        {
            meshPackname = kvDic["MeshPackName"];
        }
        if (kvDic.ContainsKey("TexturePackName"))
        {
            texturePackname = kvDic["TexturePackName"];
        }
        // 如果本地缓存了DisplayOwner不创建
        DisplayOwner memberDisplay = null;

        if (isLocal)
        {
            // 获取本地DisplayOwner
            memberDisplay = DisplayerManager.Single.GetElementById((ObjectID.ObjectType)unitType, objectId);
            // 设置起始位置
            memberDisplay.GameObj.transform.position = new Vector3(msgOp.OpPosX, msgOp.OpPosY, msgOp.OpPosZ);
        }
        else
        {
            // 映射类型
            if (enemyTypeList.ContainsKey(unitType))
            {
                unitType = enemyTypeList[unitType];
            }
            // 映射位置
            // 地图绝对宽度
            //var mapAbsoluteWidth = LoadMap.Single.MapWidth*LoadMap.Single.UnitWidth;
            //var setPosX = mapAbsoluteWidth - msgOp.OpPosX;
            var mapingPos = LoadMap.Single.MapItemToEnemy(new Vector3(msgOp.OpPosX, msgOp.OpPosY, msgOp.OpPosZ));
            // 创建单位
            memberDisplay = FightUnitFactory.CreateUnit(unitType, new CreateActorParam(mapingPos.x, mapingPos.z, level)
            {
                //ColorMat = true,
                //CardID = 0,
                //MeshPackName = meshPackname,
                //TexturePackName = texturePackname,
                SoldierID = uniqueId,
            });
            memberDisplay.ClusterData.Begin();
        }
        // 本地操作结束callback
        opSendCallbackDic[msgOp.OpUniqueNum]();
        // 激活单位
        memberDisplay.GameObj.SetActive(true);
        // 开始移动
        memberDisplay.RanderControl.Begin();
    }
예제 #4
0
    /// <summary>
    /// 解析建筑地图
    /// </summary>
    /// <param name="mapData">地图数据</param>
    /// <param name="packer">数据包装</param>
    public void AnalysisMap(int[][] mapData, MapDataParamsPacker packer = null)
    {
        // 获取基地位置
        for (var row = 0; row < mapData.Length; row++)
        {
            var line = mapData[row];
            for (var col = 0; col < line.Length; col++)
            {
                var cell = line[col];
                switch (cell)
                {
                case Utils.Accessibility:
                    // 无障碍
                    break;

                case Utils.Obstacle:
                {
                    // 障碍物
                    var paramObj = new CreateActorParam(col, row);
                    FightUnitFactory.CreateUnit((int)ObjectID.ObjectType.NPCObstacle, paramObj).ClusterData.Begin();
                }
                break;

                case Utils.MyBaseId:
                {
                    // 我方基地
                    var pos = Utils.NumToPosition(LoadMap.Single.transform.position, new Vector2(col, row),
                                                  ClusterManager.Single.UnitWidth, ClusterManager.Single.MapWidth,
                                                  ClusterManager.Single.MapHeight);
                    var paramObj = new CreateActorParam(pos.x, pos.z, packer.BaseLevel);
                    FightUnitFactory.CreateUnit((int)ObjectID.ObjectType.MyJiDi, paramObj).ClusterData.Begin();
                }
                break;

                case Utils.MyTurretId:
                {
                    // 我方防御塔
                    var pos = Utils.NumToPosition(LoadMap.Single.transform.position, new Vector2(col, row),
                                                  ClusterManager.Single.UnitWidth, ClusterManager.Single.MapWidth,
                                                  ClusterManager.Single.MapHeight);
                    var paramObj = new CreateActorParam(pos.x, pos.z, packer.TurretLevel);
                    FightUnitFactory.CreateUnit((int)ObjectID.ObjectType.MyTower, paramObj).ClusterData.Begin();
                }
                break;

                case Utils.EnemyBaseId:
                {
                    // 敌方基地
                    var pos = Utils.NumToPosition(LoadMap.Single.transform.position, new Vector2(col, row),
                                                  ClusterManager.Single.UnitWidth, ClusterManager.Single.MapWidth,
                                                  ClusterManager.Single.MapHeight);
                    var paramObj = new CreateActorParam(pos.x, pos.z, packer.EnemyBaseLevel);
                    FightUnitFactory.CreateUnit((int)ObjectID.ObjectType.EnemyJiDi, paramObj).ClusterData.Begin();
                }
                break;

                case Utils.EnemyTurretId:
                {
                    // 敌方防御塔
                    var pos = Utils.NumToPosition(LoadMap.Single.transform.position, new Vector2(col, row),
                                                  ClusterManager.Single.UnitWidth, ClusterManager.Single.MapWidth,
                                                  ClusterManager.Single.MapHeight);
                    var paramObj = new CreateActorParam(pos.x, pos.z, packer.TurretLevel);
                    var turret   = FightUnitFactory.CreateUnit((int)ObjectID.ObjectType.EnemyTower, paramObj);
                    turret.ClusterData.Begin();
                }
                break;
                }
            }
        }
    }