示例#1
0
    public static RobotCreature Create(CreatureInfo info, Vector3_ pos, Vector3 rot, string name = "", string uiName = "")
    {
        if (info == null)
        {
            Logger.LogError("RobotCreature::Create: Create robot failed, invalid config");
            return(null);
        }

        var rootNode = new GameObject().transform;

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

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

        // Protect invalid weapon config
        if (info.weaponID < 1)
        {
            info.weaponID     = 1;
            info.weaponItemID = 1101;
        }

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

        c.InitPosition(pos);
        c.isPlayer     = false;
        c.isMonster    = false;
        c.isRobot      = true;
        c.isCombat     = true;
        c.creatureCamp = CreatureCamp.MonsterCamp;  // 机器人默认必须是怪物的阵营
        c.uiName       = string.IsNullOrEmpty(uiName) ? c.name : uiName;

        c.isDead        = false;
        c.realDead      = false;
        c.useSpringBone = true;
        c.teamIndex     = MonsterCreature.GetMonsterRoomIndex();

        c.UpdateConfig(info);
        c.OnCreate(info.buffs);

        return(c);
    }
示例#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);
    }
示例#3
0
    public static PetCreature Create(Creature parent, PetInfo info, Vector3_ pos, Vector3 rot, bool player = false, string name = "", string uiName = "", bool combat = true, bool useSpringBone = true)
    {
        if (info == null)
        {
            Logger.LogError("PetCreature::Create: Create pet failed, invalid config info");
            return(null);
        }

        var petInfo = info.BuildCreatureInfo();

        if (petInfo == null)
        {
            Logger.LogError("PetCreature::Create Create pet [{0}] failed, invalid config info", info.ID);
            return(null);
        }

        var rootNode = new GameObject().transform;

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

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

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

        c.InitPosition(pos);
        c.petInfo        = info;
        c.ParentCreature = parent;
        c.isPlayer       = player;
        c.isMonster      = false;
        c.isCombat       = combat;
        c.isRobot        = false;
        c.creatureCamp   = parent ? parent.creatureCamp : CreatureCamp.PlayerCamp;
        c.uiName         = string.IsNullOrEmpty(uiName) ? c.name : uiName;
        c.isDead         = false;
        c.realDead       = false;
        c.useSpringBone  = useSpringBone;

        c.UpdateConfig(petInfo);

        c.behaviour.UpdateAllColliderState(false);
        c.behaviour.attackCollider.enabled = true;
        c.teamIndex = MonsterCreature.GetMonsterRoomIndex();

        c.Buffs = info.GetBuff(info.AdditiveLevel);
        c.OnCreate(info.GetInitBuff());


        c.avatar = info.UpGradeInfo.icon;
        c.skills.Clear();
        var skill = info.GetSkill();

        if (skill != null)
        {
            c.skills.Add(skill.state, PetSkillData.Create(skill));
        }
        return(c);
    }