示例#1
0
    /// <summary>
    /// 当服务器没返回机器人属性时,默认从怪物配置表中读取出跟玩家等级相符合的默认属性
    /// </summary>
    /// <param name="playerLevel"></param>
    public void ResetRobotAttribute(int playerLevel)
    {
        Logger.LogDetail("{0} 's attribute change to id: {1} -level: {2} from config_monster_Attribute", gameObject.name, ROBOT_ATTRIBUTE_ID, playerLevel);

        MonsterAttriubuteInfo attribute = ConfigManager.Get <MonsterAttriubuteInfo>(ROBOT_ATTRIBUTE_ID);

        for (int i = 0, length = attribute.monsterAttriubutes.Length; i < length; i++)
        {
            if (level == attribute.monsterAttriubutes[i].level)
            {
                UpdateAttribute(playerLevel, attribute.monsterAttriubutes[i]);
                break;
            }
        }
    }
示例#2
0
    public static MonsterCreature CreateMonster(int monsterID, int group, int level, Vector3_ pos, Vector3 rot, StageInfo stage = null, string name = "", string uiName = "", bool needHealthBar = true)
    {
        var info = ConfigManager.Get <MonsterInfo>(monsterID);

        if (info == null)
        {
            Logger.LogError("MonsterCreature::Create: Create monster failed, could not find monster [{0}]", monsterID);
            return(null);
        }

        var rootNode = new GameObject().transform;

        if (!CreateMorphNodes(info.models, rootNode))
        {
            Logger.LogError("MonsterCreature::Create: Create monster [{0}:{1}] failed, main model [{2}] not loaded", monsterID, info.name, CreatureInfo.GetMorphModelName(info.models, 0));
            return(null);
        }

        rootNode.position    = pos;
        rootNode.eulerAngles = rot;

        var c = Create <MonsterCreature>(string.IsNullOrEmpty(name) ? info.name : name, rootNode.gameObject);

        c.isCombat = true;
        c.InitPosition(pos);

        if (info.npcId > 0)
        {
            var npc = moduleNpc.GetTargetNpc(info.npcId);
            if (npc != null)
            {
                CharacterEquip.ChangeNpcFashion(c, npc.mode);
            }
            else
            {
                Logger.LogError($"monster表里monsterID = {info.npcId} 配置的NpcID错误,没有ID = {info.npcId}的Npc");
            }
        }

        //如果配置有属性修正,则直接使用玩家的等级作为参考模板
        int targetLevel = (stage != null && stage.levelCorrection) ? modulePlayer.roleInfo.level : level;

        double aggr  = stage != null ? 1.0 + stage.aggressiveCorrection : 1.0;
        double defen = stage != null ? 1.0 + stage.defensiveCorrection : 1.0;

        bool isSuccess = false;
        MonsterAttriubuteInfo attribute = ConfigManager.Get <MonsterAttriubuteInfo>(info.AttributeConfigId);

        if (!attribute)
        {
            var attList = ConfigManager.GetAll <MonsterAttriubuteInfo>();
            attribute = attList.GetValue(0);
            Logger.LogError("Could not find MonsterAttriubuteInfo with monsterId {0} AttributeConfigId [{1}] we will use attri with id {2} to replace", monsterID, info.AttributeConfigId, attribute ? attribute.ID : -1);
        }

        if (attribute)
        {
            for (int i = 0, length = attribute.monsterAttriubutes.Length; i < length; i++)
            {
                if (targetLevel == attribute.monsterAttriubutes[i].level)
                {
                    isSuccess = true;
                    c.UpdateConfig(info, attribute.monsterAttriubutes[i], aggr, defen);
                    c._SetField(CreatureFields.Level, targetLevel);                //怪物等级在怪物创建的时候去确定,初始化不赋值
                    break;
                }
            }

            //To avoid level is invalid
            if (!isSuccess)
            {
                MonsterAttriubuteInfo.MonsterAttriubute attri = attribute.monsterAttriubutes[attribute.monsterAttriubutes.Length - 1];
                int maxLevel = attri.level;
                c.UpdateConfig(info, attri, aggr, defen);
                c._SetField(CreatureFields.Level, maxLevel);                //怪物等级在怪物创建的时候去确定,初始化不赋值
                Logger.LogError("怪物等级修正非法!player.level = {0} ,monster max level = {1} ", modulePlayer.roleInfo.level, maxLevel);
            }
        }

        c.isPlayer  = false;
        c.isMonster = true;
        c.isRobot   = false;
        c.roleProto = 0;

        c.uiName = string.IsNullOrEmpty(uiName) ? info ? info.name : c.name : uiName;
        //怪物属性记录
        c.monsterInfo          = info;
        c.monsterId            = monsterID;
        c.monsterGroup         = group;
        c.creatureCamp         = group >= -1 ? CreatureCamp.MonsterCamp : group == -2 ? CreatureCamp.PlayerCamp : group == -3 ? CreatureCamp.NeutralCamp : CreatureCamp.None;
        c.monsterLevel         = level;
        c.isBoss               = false;
        c.isSendDeathCondition = false;
        c.teamIndex            = GetMonsterRoomIndex();

        c.obstacleMask       = info.iobstacleMask;
        c.ignoreObstacleMask = info.iignoreObstacleMask;

        c.gameObject.name = Util.Format("{0}-> id:{1} group:{2} tIdx:{3}", info.name, info.ID, group, c.Identify);

        c.OnCreate();

        c.hpVisiableCount = needHealthBar ? 1 : 0;

        return(c);
    }