Ejemplo n.º 1
0
    void LoadAvatar(int avatarResourceId)
    {
        if (role != null)
        {
            MonoBehaviour.Destroy(role.gameObject);
        }

        AvatarConfig.Avatar avatarCfg = ConfigDatabase.DefaultCfg.AvatarConfig.GetAvatarById(avatarResourceId);
        if (avatarCfg == null)
        {
            Debug.LogError(string.Format("Miss Avatar Setting : Id({0:X})", avatarResourceId));
        }

        Avatar avatar = Avatar.CreateAvatar(0x00000000);

        role = avatar.gameObject.AddComponent <BattleRole>();
        WeihuaGames.ClientClass.CombatAvatarData avatarData = new WeihuaGames.ClientClass.CombatAvatarData();
        avatarData.ResourceId = avatarResourceId;

        role.AvatarData = avatarData;
        role.Awake();
        role.AvatarAssetId = avatarCfg.breakThroughs[0].assetId;
        role.Avatar.Load(avatarCfg.breakThroughs[0].assetId, true, false);

        role.UseDefaultWeapons();
    }
Ejemplo n.º 2
0
    public static BattleRole Create(WeihuaGames.ClientClass.CombatAvatarData avatarData, int teamIndex, int avatarIndex)
    {
        Avatar     avatar = Avatar.CreateAvatar((teamIndex << 24 | avatarData.BattlePosition));
        BattleRole role   = avatar.GetComponent <BattleRole>();

        if (role == null)
        {
            role = avatar.gameObject.AddComponent <BattleRole>();
        }
        AvatarConfig.Avatar avatarCfg = ConfigDatabase.DefaultCfg.AvatarConfig.GetAvatarById(avatarData.ResourceId);
        int avatarAssetId             = avatarCfg.GetAvatarAssetId(avatarData.BreakThrough);

        role.AvatarAssetId = avatarAssetId;
        role.avatarData    = new WeihuaGames.ClientClass.CombatAvatarData();
        role.AvatarData.Copy(avatarData);

        role.teamIndex      = teamIndex;
        role.avatarIndex    = avatarIndex;
        role.battlePosition = avatarData.BattlePosition;
        role.AvatarHP       = avatarData.GetAttributeByType(_AvatarAttributeType.HP).Value;

        role.Awake();

        return(role);
    }
Ejemplo n.º 3
0
 public void ApplyBattleResults(BattleActionResult results, BattleRole role)
 {
     if (role == BattleRole.Defender)
     {
         TakeDamage(results.DefenderDmgTaken);
     }
     else
     {
         Debug.Log($"{name} attacked {results.DefenderName} and caused {results.AttackerDmgInflicted} dmg");
     }
 }
Ejemplo n.º 4
0
    public Member(int id, string name, string characterClass, TeamType team, IStats baseStats, BattleRole battleRole, int initialHp)
    {
        if (id > -1 && baseStats.Damagability() < 0.01)
        {
            throw new InvalidDataException($"Damagability of {name} is 0");
        }

        Id         = id;
        Name       = name;
        Class      = characterClass;
        TeamType   = team;
        BattleRole = battleRole;
        State      = new MemberState(id, baseStats, initialHp);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 范围伤害
    /// </summary>
    /// <param name="damage">伤害数值</param>
    private void rangeHurt(int damage)
    {
        if (this.targetList == null)
        {
            return;
        }
        int count = this.targetList.Count;

        for (int i = 0; i < count; ++i)
        {
            BattleRole br = this.targetList[i];
            br.hurt(damage);
        }
        this.targetList.Clear();
        this.targetList = null;
    }
Ejemplo n.º 6
0
    public static BattleRole Create(int avatarResourceId, float maxHP, float hp, float sp, string name, int weaponResourceId)
    {
        Avatar     avatar = Avatar.CreateAvatar(avatarResourceId);
        BattleRole role   = avatar.GetComponent <BattleRole>();

        if (role == null)
        {
            role = avatar.gameObject.AddComponent <BattleRole>();
        }
        AvatarConfig.Avatar avatarCfg = ConfigDatabase.DefaultCfg.AvatarConfig.GetAvatarById(avatarResourceId);
        int avatarAssetId             = avatarCfg.breakThroughs[0].assetId;

        role.AvatarAssetId = avatarAssetId;
        // Generate a CombatAvatarData
        WeihuaGames.ClientClass.CombatAvatarData bossAvatarData = new WeihuaGames.ClientClass.CombatAvatarData();
        bossAvatarData.ResourceId  = avatarResourceId;
        bossAvatarData.DisplayName = name;
        bossAvatarData.Attributes  = new List <WeihuaGames.ClientClass.Attribute>();
        WeihuaGames.ClientClass.Attribute maxHPAttr = new WeihuaGames.ClientClass.Attribute();
        maxHPAttr.Type  = _AvatarAttributeType.MaxHP;
        maxHPAttr.Value = maxHP;
        bossAvatarData.Attributes.Add(maxHPAttr);
        WeihuaGames.ClientClass.Attribute spAttr = new WeihuaGames.ClientClass.Attribute();
        spAttr.Type  = _AvatarAttributeType.SP;
        spAttr.Value = sp;
        bossAvatarData.Attributes.Add(spAttr);

        if (weaponResourceId != IDSeg.InvalidId)
        {
            WeihuaGames.ClientClass.EquipmentData edata = new WeihuaGames.ClientClass.EquipmentData();
            edata.BreakThrough = 0;
            edata.Id           = weaponResourceId;
            bossAvatarData.Equipments.Add(edata);
        }

        role.avatarData = bossAvatarData;
        role.AvatarHP   = hp;

        role.Awake();

        return(role);
    }
    /// <summary>
    /// 角色开始攻击
    /// </summary>
    /// <param name="param"></param>
    private void startRoleAttack(object param)
    {
        //MonoBehaviour.print("this.attackList.Count " + this.attackList.Count);
        if (this.attackList.Count == 0)
        {
            return;
        }
        this.isStartAttack = true;
        BattleRole br = this.attackList[0];

        br.attack();
        this.attackList.RemoveAt(0);
        bool autoDestroy = false;

        if (this.attackList.Count == 0)
        {
            autoDestroy = true;
        }
        Delay.setDelay(Layer.Instance.battleScene, 500, startRoleAttack, autoDestroy);
    }
    //人物死亡消息
    private void roleDeadHandler(object param)
    {
        //角色死亡消息
        BattleRole br    = (BattleRole)param;
        int        index = br.index;
        //从目标列表中删除此目标
        List <BattleRole> list;
        List <BattleRole> array;

        if (this.isMyTeam)
        {
            list  = this.targetTeam;
            array = this.targetTeamAry;
        }
        else
        {
            list  = this.myTeam;
            array = this.myTeamAry;
        }
        int length = list.Count;

        for (int i = 0; i < length; i++)
        {
            BattleRole battleRole = list[i];
            if (battleRole.index == index)
            {
                list.RemoveAt(i);
                break;
            }
        }
        length = array.Count;
        for (int i = 0; i < length; i++)
        {
            BattleRole battleRole = array[i];
            if (battleRole.index == index)
            {
                battleRole.isDeaded = true;
                break;
            }
        }
    }
    /// <summary>
    /// 初始化临时血量 用于判断 清空攻击目标数据
    /// </summary>
    /// <param name="isMyTeam">是否是我方队伍</param>
    private void initRoleAttackData(bool isMyTeam)
    {
        List <BattleRole> targetList;

        if (!isMyTeam)
        {
            targetList = this.targetTeam;
        }
        else
        {
            targetList = this.myTeam;
        }
        int count = targetList.Count;

        for (int i = 0; i < count; ++i)
        {
            BattleRole br = targetList[i];
            br.setAttackTarget(null);
            br.isAttacking   = false;
            br.heroVo.tempHp = br.heroVo.hp;
        }
    }
    /// <summary>
    /// 清空战斗数据
    /// </summary>
    public void clear()
    {
        int count = this.myTeam.Count;

        for (int i = 0; i < count; i++)
        {
            BattleRole br = this.myTeam[i];
            br.destroy();
            br = null;
        }
        this.myTeam.Clear();
        this.myTeamAry.Clear();

        count = this.targetTeam.Count;
        for (int i = 0; i < count; i++)
        {
            BattleRole br = this.targetTeam[i];
            br.destroy();
            br = null;
        }
        this.targetTeam.Clear();
        this.targetTeamAry.Clear();
    }
    /// <summary>
    /// 是否全部归位
    /// </summary>
    /// <param name="isMyTeam">是否是我方队伍</param>
    /// <returns></returns>
    private bool isAllBack(bool isMyTeam)
    {
        List <BattleRole> team = null;

        if (isMyTeam)
        {
            team = this.myTeam;
        }
        else
        {
            team = this.targetTeam;
        }
        int count = team.Count;

        for (int i = 0; i < count; i++)
        {
            BattleRole br = team[i];
            if (br.isAttacking)
            {
                return(false);
            }
        }
        return(true);
    }
Ejemplo n.º 12
0
 public DelayBattleRole(BattleRole role, DelayDelegate delayDelegate, object userData0, object userData1)
     : base(delayDelegate, userData0, userData0)
 {
     delayRole = role;
 }
Ejemplo n.º 13
0
 public Member(int id, string name, string characterClass, TeamType team, IStats baseStats, BattleRole battleRole)
     : this(id, name, characterClass, team, baseStats, battleRole, baseStats.MaxHp())
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 设置攻击者的目标对象
 /// </summary>
 /// <param name="br">目标对象</param>
 public void setAttackTarget(BattleRole br)
 {
     this.targetBr = br;
 }
    private void initTestData()
    {
        //此处为测试数据
        for (int i = 0; i < 6; ++i)
        {
            HeroVo hVo = new HeroVo();
            hVo.atk = RandomUtil.randint(15, 35);
            hVo.atk = 20;
            hVo.def = RandomUtil.randint(2, 5);
            hVo.hp = RandomUtil.randint(20, 50);
            hVo.attackType = RandomUtil.randint(1, 2);
            hVo.attackRangeType = RandomUtil.randint(0, 2);

            hVo.id = i + 1;
            if (i == 1)
            {
                hVo.hp = 5;
                hVo.attackType = 2;

            }
            if (i == 0)
            {
                hVo.hp = 200;
                hVo.attackType = 2;
            }
            if (i == 2)
            {
                hVo.hp = 200;
                hVo.attackType = 2;
            }

            BattleRole br = new BattleRole();
            br.index = i;
            br.create(Layer.Instance.battleScene.transform);
            br.createHpBar(Layer.Instance.battleUILayer.transform);
            br.initHpBarMax(hVo.hp);
            br.isMyTeam = true;
            br.heroVo = hVo;
            this.myTeam.Add(br);
            this.myTeamAry[i] = br;
        }

        for (int i = 0; i < 4; ++i)
        {
            HeroVo hVo = new HeroVo();
            hVo.atk = RandomUtil.randint(15, 35);
            hVo.def = RandomUtil.randint(2, 5);
            hVo.hp = RandomUtil.randint(20, 50);
            hVo.id = i + 6;
            hVo.attackType = RandomUtil.randint(1, 2);

            if (i == 3)
            {
                hVo.attackType = 1;
                hVo.atk = 80;
                hVo.hp = 300;
            }

            BattleRole br = new BattleRole();
            br.index = i;
            br.create(Layer.Instance.battleScene.transform);
            br.createHpBar(Layer.Instance.battleUILayer.transform);
            br.initHpBarMax(hVo.hp);

            br.isMyTeam = false;
            br.heroVo = hVo;
            this.targetTeam.Add(br);
            this.targetTeamAry[i] = br;
        }
        this.initTeamPos();
    }
Ejemplo n.º 16
0
 /// <summary>
 /// 设置攻击者的目标对象
 /// </summary>
 /// <param name="br">目标对象</param>
 public void setAttackTarget(BattleRole br)
 {
     this.targetBr = br;
 }
Ejemplo n.º 17
0
 public void ApplyBattleResults(BattleActionResult result, BattleRole role)
 {
     throw new NotImplementedException();
 }
    /// <summary>
    /// 获取被攻击目标(普通攻击)
    /// </summary>
    /// <param name="isMyTeam">是否是我方队伍攻击</param>
    private void getAttackTarget(bool isMyTeam)
    {
        List <BattleRole> targetList;
        List <BattleRole> targetAry;

        if (isMyTeam)
        {
            targetList = this.targetTeam;
            targetAry  = this.targetTeamAry;
        }
        else
        {
            targetList = this.myTeam;
            targetAry  = this.myTeamAry;
        }
        this.initRoleAttackData(isMyTeam);
        int count       = this.attackList.Count;
        int targetCount = targetList.Count;
        //关闭列表 存放一次进攻后血量为0的角色
        List <int> closeList = new List <int>();

        for (int i = 0; i < count; ++i)
        {
            BattleRole attackRole = this.attackList[i];
            float      dis        = float.MaxValue;
            int        index      = -1;
            //查找距离最近的对手
            for (int j = 0; j < targetCount; ++j)
            {
                BattleRole targetBr = targetList[j];
                if (closeList.IndexOf(targetBr.index) != -1)
                {
                    continue;
                }
                float curDis = (attackRole.posIndexVector - targetBr.posIndexVector).sqrMagnitude;
                if (curDis < dis)
                {
                    index = j;
                    dis   = curDis;
                }
            }
            //计算被攻击者剩余血量 如果进攻后血量为0 则放入关闭列表中
            if (index != -1)
            {
                BattleRole chooseBr = targetList[index];
                if (DamageUtils.checkRoleDead(attackRole.heroVo, chooseBr.heroVo))
                {
                    closeList.Add(chooseBr.index);
                }
                //将目标存放进去
                attackRole.setAttackTarget(chooseBr);
                if (attackRole.heroVo.attackRangeType != 0)
                {
                    List <BattleRole> rangeAttackRoleList = new List <BattleRole>();
                    bool   isHorizontal  = attackRole.heroVo.attackRangeType == BattleConstant.ATTACK_RANGE_HORIZONTAL;
                    int [] rangeIndexAry = BattleFormation.getPosIndexByDirection(isHorizontal, chooseBr.index);
                    //遍历posIndexAry 剔除 chooseBr.index 和 closeList中的索引
                    //判断checkRoleDead 将血为空的添加进col
                    int length = rangeIndexAry.Length;
                    for (int j = 0; j < length; j++)
                    {
                        int rangeIndex = rangeIndexAry[j];
                        if (rangeIndex == chooseBr.index ||
                            closeList.IndexOf(rangeIndex) != -1)
                        {
                            continue;
                        }
                        BattleRole rangeAttackRole = targetAry[rangeIndex];
                        if (rangeAttackRole != null && !rangeAttackRole.isDeaded)
                        {
                            if (DamageUtils.checkRoleDead(attackRole.heroVo, rangeAttackRole.heroVo))
                            {
                                closeList.Add(chooseBr.index);
                            }
                            rangeAttackRoleList.Add(rangeAttackRole);
                        }
                    }
                    attackRole.setAttackRangeTarget(rangeAttackRoleList);
                }
                attackRole.isAttacking = true;
            }
        }
    }
    /// <summary>
    /// 讲本轮出战的攻击者存入列表中
    /// </summary>
    /// <param name="isMyTeam">是否从我方队伍里获取</param>
    /// <param name="num">获取数量</param>
    private void getAttacker(bool isMyTeam, int num)
    {
        this.attackList.Clear();
        List <BattleRole> team = null;
        //选定角色的索引
        int teamIndex;

        if (isMyTeam)
        {
            teamIndex = this.myTeamIndex;
            team      = this.myTeamAry;
        }
        else
        {
            teamIndex = this.targetTeamIndex;
            team      = this.targetTeamAry;
        }
        //判断全部死亡
        if (this.allDead(isMyTeam))
        {
            return;
        }
        //人数不超过列表长度
        if (num > team.Count)
        {
            num = team.Count;
        }
        int count = team.Count;
        //选中的数量
        int selectCount = 0;

        for (int i = 0; i < count; ++i)
        {
            BattleRole br = team[teamIndex];
            if (br != null && !br.isDeaded)
            {
                MonoBehaviour.print(teamIndex + "号位置");
                MonoBehaviour.print("攻击类型:" + br.heroVo.attackType);
                this.attackList.Add(br);
                selectCount++;
            }
            teamIndex++;
            if (teamIndex > count - 1)
            {
                teamIndex = 0;
            }
            if (selectCount >= num)
            {
                break;
            }
        }
        //保存当前的队伍中选择的人物索引
        if (isMyTeam)
        {
            this.myTeamIndex = teamIndex;
        }
        else
        {
            this.targetTeamIndex = teamIndex;
        }
    }
    private void initTestData()
    {
        //此处为测试数据
        for (int i = 0; i < 6; ++i)
        {
            HeroVo hVo = new HeroVo();
            hVo.atk             = RandomUtil.randint(15, 35);
            hVo.atk             = 20;
            hVo.def             = RandomUtil.randint(2, 5);
            hVo.hp              = RandomUtil.randint(20, 50);
            hVo.attackType      = RandomUtil.randint(1, 2);
            hVo.attackRangeType = RandomUtil.randint(0, 2);

            hVo.id = i + 1;
            if (i == 1)
            {
                hVo.hp         = 5;
                hVo.attackType = 2;
            }
            if (i == 0)
            {
                hVo.hp         = 200;
                hVo.attackType = 2;
            }
            if (i == 2)
            {
                hVo.hp         = 200;
                hVo.attackType = 2;
            }

            BattleRole br = new BattleRole();
            br.index = i;
            br.create(Layer.Instance.battleScene.transform);
            br.createHpBar(Layer.Instance.battleUILayer.transform);
            br.initHpBarMax(hVo.hp);
            br.isMyTeam = true;
            br.heroVo   = hVo;
            this.myTeam.Add(br);
            this.myTeamAry[i] = br;
        }

        for (int i = 0; i < 4; ++i)
        {
            HeroVo hVo = new HeroVo();
            hVo.atk        = RandomUtil.randint(15, 35);
            hVo.def        = RandomUtil.randint(2, 5);
            hVo.hp         = RandomUtil.randint(20, 50);
            hVo.id         = i + 6;
            hVo.attackType = RandomUtil.randint(1, 2);

            if (i == 3)
            {
                hVo.attackType = 1;
                hVo.atk        = 80;
                hVo.hp         = 300;
            }

            BattleRole br = new BattleRole();
            br.index = i;
            br.create(Layer.Instance.battleScene.transform);
            br.createHpBar(Layer.Instance.battleUILayer.transform);
            br.initHpBarMax(hVo.hp);

            br.isMyTeam = false;
            br.heroVo   = hVo;
            this.targetTeam.Add(br);
            this.targetTeamAry[i] = br;
        }
        this.initTeamPos();
    }