Beispiel #1
0
    /// <summary>
    /// 每次普通攻击结束后思考一次是否使用技能
    /// </summary>
    public void ThinkUseSkill(object[] objs)
    {
        if (target == null || target.state == FightUnit.UnitState.Dead)
        {
            target = FightRule.GetFightTarget(self, self.isConfused ? self.parentGroup : self.parentGroup.targetGroup);
            if (target == null)
            {
                return;
            }
        }
        List <int> indexList   = new List <int>();
        uint       totalWeight = 0;
        float      randomVal   = Random.value;

        for (int i = 0; i < autoSkills.Count; i++)
        {
            ActiveSkillStruct skill = autoSkills[i];
            if (skill.isLocked)
            {
                if (skill.autoSkillCondition.unlockTime <= time)
                {
                    skill.isLocked = false;
                }
            }
            if (!skill.isLocked && skill.cd + skill.lastUseTime <= time && IsFitSkillCondition(skill))
            {
                totalWeight += skill.autoSkillCondition.weight;
                indexList.Add(i);
            }
        }
        for (int i = 0; i < indexList.Count; i++)
        {
            float val = (float)autoSkills[i].autoSkillCondition.weight / totalWeight;
            if (randomVal <= val)
            {
                selectedSkill             = autoSkills[i].autoSkill;
                autoSkills[i].lastUseTime = time;
                autoSkills[i].GetCd();
                break;
            }
            else
            {
                randomVal -= val;
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// 判断是否满足技能AI条件
    /// </summary>
    /// <param name="skillStruct"></param>
    /// <returns></returns>
    bool IsFitSkillCondition(ActiveSkillStruct skillStruct)
    {
        switch (skillStruct.condition)
        {
        case SkillCondition.None:
            return(true);

        case SkillCondition.HPLower:
            return(self.healthValue * 100 <= skillStruct.conditionVal);

        case SkillCondition.HPHigher:
            return(self.healthValue * 100 > skillStruct.conditionVal);

        case SkillCondition.FirendHPLower:
            return(self.parentGroup.WeakestUnit.healthValue <= skillStruct.conditionVal);

        default:
            return(true);
        }
    }
Beispiel #3
0
    public override void Init()
    {
        self = GetComponent <MonsterFightUnit>();
        self.OnNoramlAttackFinish += ThinkUseSkill;
        /*普通攻击初始化*/
        normalAttack        = NGUITools.AddChild <NormalAttack>(gameObject);
        normalAttack.attack = Util.GetDic <MsgAttackData, AttackData>()[normalAttackId];
        JsonData castEffectDt = JsonMapper.ToObject(Util.GetConfigString(normalAttack.attack.castEffect));

        for (int i = 0; i < castEffectDt.Count; i++)
        {
            normalAttack.castEffectIds.Add((int)castEffectDt[i]);
        }
        JsonData flyEffectDt = JsonMapper.ToObject(Util.GetConfigString(normalAttack.attack.flyEffect));

        for (int i = 0; i < flyEffectDt.Count; i++)
        {
            normalAttack.flyEffectIds.Add((int)flyEffectDt[i]);
        }
        JsonData hitEffectDt = JsonMapper.ToObject(Util.GetConfigString(normalAttack.attack.hitEffect));

        for (int i = 0; i < hitEffectDt.Count; i++)
        {
            normalAttack.hitEffectIds.Add((int)hitEffectDt[i]);
        }
        normalAttack.mineUnit = self;
        normalAttack.Init();
        /*主动技能初始化*/
        foreach (int normalSkillId in autoSkillsId)
        {
            ActiveSkill normalSkill = NGUITools.AddChild <ActiveSkill>(gameObject);
            normalSkill.normalSkill  = Util.GetDic <MsgNormalSkill, NormalSkill>()[normalSkillId];
            normalSkill.dmgEffectId  = (int)normalSkill.normalSkill.dmgEffect;
            normalSkill.castEffectId = (int)normalSkill.normalSkill.castEffect;
            normalSkill.flyEffectId  = (int)normalSkill.normalSkill.flyEffect;
            normalSkill.hitEffectId  = (int)normalSkill.normalSkill.hitEffect;
            normalSkill.mineUnit     = self;
            int LvUpId = normalSkillId * 100 + 1;
            normalSkill.normalSkillLvUp = Util.GetDic <MsgNormalSkillLvUp, NormalSkillLvUp>()[LvUpId];
            normalSkill.Init();
            MonsterSkill skillCondition = null;
            Util.GetDic <MsgMonsterSkill, MonsterSkill>().TryGetValue(normalSkillId, out skillCondition);
            SkillCondition condition    = SkillCondition.None;
            int            conditionVal = 0;
            float          minCd        = 0;
            float          maxCd        = 0;
            if (skillCondition != null)
            {
                JsonData dt = JsonMapper.ToObject(Util.GetConfigString(skillCondition.condition));
                if (dt.Count == 2)
                {
                    condition    = (SkillCondition)int.Parse(dt[0].ToString());
                    conditionVal = int.Parse(dt[1].ToString());
                }
                JsonData dt_1 = JsonMapper.ToObject(Util.GetConfigString(skillCondition.interval));
                minCd = float.Parse(dt_1[0].ToString());
                maxCd = float.Parse(dt_1[1].ToString());
            }
            ActiveSkillStruct activeSkillStruct = new ActiveSkillStruct();
            activeSkillStruct.autoSkill          = normalSkill;
            activeSkillStruct.autoSkillCondition = skillCondition;
            activeSkillStruct.condition          = condition;
            activeSkillStruct.conditionVal       = conditionVal;
            activeSkillStruct.minCd = minCd;
            activeSkillStruct.maxCd = maxCd;
            autoSkills.Add(activeSkillStruct);
        }
        enabled = false;
    }