Beispiel #1
0
    /** 添加单位 */
    public Unit addUnit(UnitData data)
    {
        //预处理
        //服务器驱动场景启用
        if (_config.instanceType != SceneInstanceType.ClientDriveSinglePlayerBattle)
        {
            //是自己的M单位
            if (data.identity is MUnitIdentityData && data.identity.playerID == GameC.player.role.playerID)
            {
                MUnitUseLogic useLogic = GameC.player.character.getMUnitUseLogic(data.getMUnitIdentity().mIndex);

                if (useLogic == null)
                {
                    Ctrl.throwError("不能找不到主单位的使用逻辑", data.getMUnitIdentity().mIndex);
                }

                //取主角的数据逻辑
                UnitFightDataLogic dataLogic = useLogic.getFightLogic();

                //先清空
                dataLogic.clear();
                //再重设数据
                dataLogic.setData(data.fight, data.avatar);

                data.fightDataLogic = dataLogic;
            }
        }


        //

        Unit unit = toAddUnit(data);

        if (unit != null)
        {
            toActiveUnit(unit);

            UnitSimpleData sData = _bindVisionUnits.get(data.instanceID);

            if (sData != null)
            {
                unit.makeSimpleUnitData(sData);
            }
        }

        return(unit);
    }
Beispiel #2
0
    private Unit toAddUnit(UnitData data)
    {
        if (data.instanceID <= 0)
        {
            Ctrl.throwError("单位流水ID未赋值", data.identity.type);
            return(null);
        }

        if (ShineSetting.openCheck)
        {
            if (_units.contains(data.instanceID))
            {
                Ctrl.throwError("单位已存在");
                return(null);
            }
        }

        bool canFight = BaseC.constlist.unit_canFight(data.identity.type) && !isSimple();

        if (canFight)
        {
            //没绑数据逻辑
            if (data.fightDataLogic == null)
            {
                UnitFightDataLogic dataLogic = GameC.pool.createUnitFightDataLogic();
                //主控标记
                dataLogic.isSelfControl = data.getFightIdentity().controlPlayerID == GameC.player.role.playerID;

                dataLogic.setData(data.fight, data.avatar);
                data.fightDataLogic = dataLogic;
            }
        }

        Unit unit = toCreateUnitByData(data);

        //双绑
        unit.setUnitData(data);
        unit.setScene(this);

        if (canFight)
        {
            data.fightDataLogic.setUnit(unit);
        }

        _units.put(data.instanceID, unit);

        //战斗单位
        if (canFight)
        {
            _fightUnits.put(data.instanceID, unit);
        }

        //是角色
        if (unit.isCharacter())
        {
            CharacterIdentityData iData = (CharacterIdentityData)data.identity;

            if (_config.instanceType == SceneInstanceType.FiniteBattleWithFrameSync)
            {
                _charactersByIndex.put(iData.syncIndex, unit);
            }

            _characters.put(iData.playerID, unit);
        }

        return(unit);
    }