Exemplo n.º 1
0
    public void MouseToMove()
    {
        if (Input.GetKey(KeyCode.Mouse1) && MoveOrAttackSwitch)  //鼠标右键限定
        {
            //Debug.Log("MouseToMove()");
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;

            Physics.Raycast(ray, out hitInfo, 1 << LayerMask.NameToLayer("Terrain") | 1 << LayerMask.NameToLayer("Enemy"));
            //Debug.Log(hitInfo.point);
            if (hitInfo.collider.tag == "Terrain" &&
                Mathf.Abs(Vector3.Distance(GameObject.FindWithTag("Player").transform.position, hitInfo.point)) > 1)     //加限制
            {
                //Debug.Log("Terrain");
                Run.getInstance().RunToPos(hitInfo.point);              //坐标
                SmoothLookAt.getInstance().Init_Rotate(hitInfo.point);  //朝向

                NormalAttack.getInstance().attackTargetObj = null;
            }
            else if (hitInfo.collider.tag == "Enemy")
            {
                NormalAttack.getInstance().attackTargetObj = hitInfo.collider.GetComponentInParent <Enemy>().gameObject;
            }
            else
            {
                NormalAttack.getInstance().attackTargetObj = null;  //清空普攻目标
            }
        }
    }
Exemplo n.º 2
0
    private Goblin()
    {
        movingSpeed = 5.0f;
        movement    = new NormalMovement(gameObject, rigidbody, movingSpeed); //매개변수 고민
        attack1     = new NormalAttack();

        state = new Battle(); //이 스테이트를 각각 어떻게 선언해야 하는가 .....
    }
    public void AI()
    {
        List <GameObject> targets = new List <GameObject>();
        int targetIndex           = Random.Range(0, 2);

        targets.Add(GameObject.Find("BattleManager").GetComponent <BattleManager>().Party[targetIndex].gameObject);
        NormalAttack.Action(targets, gameObject);
    }
Exemplo n.º 4
0
    public override void Init()
    {
        self = GetComponent <HeroFightUnit>();
        /* 自动使用技能,当处于自动战斗或者混乱状态下 */
        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();
        /*主动技能初始化*/
        normalSkill             = NGUITools.AddChild <ActiveSkill>(gameObject);
        normalSkill.normalSkill = Util.GetDic <MsgNormalSkill, NormalSkill>()[normalSkillId];
        int LvUpId = normalSkillId * 100 + normalSkillLv;

        normalSkill.normalSkillLvUp = Util.GetDic <MsgNormalSkillLvUp, NormalSkillLvUp>()[LvUpId];
        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;
        normalSkill.Init();
        /*绝技初始化*/
        specailSkill = NGUITools.AddChild <UniqueSkill>(gameObject);
        specailSkill.specialSkill = Util.GetDic <MsgSpecialSkill, SpecialSkill>()[specailSkillId];
        int specailLvId = specailSkillId * 100 + specailSkillLv;

        specailSkill.specialSkillLvUp = Util.GetDic <MsgSpecialSkillLvUp, SpecialSkillLvUp>()[specailLvId];
        specailSkill.castEffectId     = (int)specailSkill.specialSkill.castEffect;
        specailSkill.dmgEffectId      = (int)specailSkill.specialSkill.dmgEffect;
        specailSkill.flyEffectId      = (int)specailSkill.specialSkill.flyEffect;
        specailSkill.hitEffectId      = (int)specailSkill.specialSkill.hitEffect;
        specailSkill.mineUnit         = self;
        specailSkill.Init();
        /*队长技能初始化*/

        CEventDispatcher.GetInstance().AddEventListener(CEventType.MOVE_TO_NEXT, ResetAutoState);
    }
Exemplo n.º 5
0
        public Warrior(string cName, string pClass, int bDamage, int maxHp) : base(cName, pClass, bDamage, maxHp)
        {
            characterName       = cName;
            baseDamage          = bDamage;
            currentHealthPoints = maxHp;
            maxHealthPoints     = maxHp;

            normalAttack  = new NormalAttack();
            specialAttack = new Berserk();
        }
Exemplo n.º 6
0
    IEnumerator InitActions()
    {
        yield return(new WaitForSeconds(0.01f));

        IdleInitAction = new IdleAction(this, "Idle", NV, mr, colliders, Ani);
        AttackAction   = new NormalAttack(this, new string[] { "劈砍1", "劈砍3" }, 0.44f, NV, Ani);
        BackAction     = new TakeBack(this, "", NV, transform);
        InjuredAction  = new InjuredAction(this, "GetHit", 1, NV, Ani);
        RunAction      = new RunAction(this, "Run", NV, Ani);
        DieAction      = new DieAction(this, "Die", mr, NV, transform, colliders, Ani, 0.2f);
    }
Exemplo n.º 7
0
        public void Use()
        {
            var sheets      = TableSheetsImporter.ImportSheets();
            var tableSheets = new TableSheets(sheets);

            Assert.True(tableSheets.SkillSheet.TryGetValue(100000, out var skillRow));
            var normalAttack = new NormalAttack(skillRow, 100, 100);

            var avatarState = new AvatarState(
                new PrivateKey().ToAddress(),
                new PrivateKey().ToAddress(),
                0,
                tableSheets.GetAvatarSheets(),
                new GameConfigState(),
                new PrivateKey().ToAddress());

            var worldRow = tableSheets.WorldSheet.First;

            Assert.NotNull(worldRow);

            var simulator = new StageSimulator(
                new TestRandom(),
                avatarState,
                null,
                worldRow.Id,
                worldRow.StageBegin,
                tableSheets.GetStageSimulatorSheets(),
                2,
                1);
            var player = new Player(avatarState, simulator);

            var enemyRow = tableSheets.CharacterSheet.OrderedList
                           .FirstOrDefault(e => e.Id > 200000);

            Assert.NotNull(enemyRow);

            var enemy = new Enemy(player, enemyRow, 1);

            player.Targets.Add(enemy);
            var battleStatusSkill = normalAttack.Use(
                player,
                0,
                new List <Buff>());

            Assert.NotNull(battleStatusSkill);
            Assert.Single(battleStatusSkill.SkillInfos);

            var skillInfo = battleStatusSkill.SkillInfos.FirstOrDefault();

            Assert.NotNull(skillInfo);
            Assert.Equal(enemy.Id, skillInfo.Target.Id);
        }
Exemplo n.º 8
0
    protected void AddTeam(int id, ETeamType type)
    {
        var team = new TeamController();

        team.TeamType = type;
        m_TeamList.Add(team);

        if (type == ETeamType.LeftSide)
        {
            var pupilId   = AdventureProxy.instance.GetData().PupilId;
            var pupilInfo = PupilProxy.instance.getPupilInfo(pupilId);
            var wuxue     = pupilInfo.GetEquipingWuXue();

            var character = team.AddCharacter(1, pupilId);
            character.TeamType = type;
            character.InitHp(200, 200);
            character.SkillId = wuxue != null ? wuxue.Id : 0;

            var normalAttack = new NormalAttack();
            normalAttack.AttackCount  = 1;
            normalAttack.AttackHurt   = 20;
            normalAttack.AttackTarget = null;
            character.InitNormalAttack(normalAttack);

            var skillAttack = new SkillAttack();
            skillAttack.AttackCount  = 4;
            skillAttack.AttackHurt   = 10;
            skillAttack.AttackTarget = null;
            skillAttack.SkillId      = character.SkillId;
            character.InitSkillAttack(skillAttack);
        }
        else
        {
            var character = team.AddCharacter(2, m_EnemyId);
            character.TeamType = type;
            character.InitHp(200, 200);
            character.SkillId = EnemyDeploy.GetInfo(m_EnemyId).SkillEffectId;

            var normalAttack = new NormalAttack();
            normalAttack.AttackCount  = 1;
            normalAttack.AttackHurt   = 10;
            normalAttack.AttackTarget = null;
            character.InitNormalAttack(normalAttack);

            var skillAttack = new SkillAttack();
            skillAttack.AttackCount  = 4;
            skillAttack.AttackHurt   = 5;
            skillAttack.AttackTarget = null;
            skillAttack.SkillId      = character.SkillId;
            character.InitSkillAttack(skillAttack);
        }
    }
Exemplo n.º 9
0
    public void ValidAttacks()
    {
        if (NormalAttack.getInstance().attackTargetObj)  //有效攻击
        {
            Debug.Log("ValidAttacks()");
            NormalAttack.getInstance().attackTargetObj.GetComponent <InjureSystem>().beInjured(100);

            //攻击特效
            var sfxAudio = GameObject.Find("SFX").GetComponent <AudioSource>();
            sfxAudio.clip = GameObject.FindWithTag("Player").GetComponentInChildren <HeroSounds>().normalAttackSFX[Random.Range(0, GameObject.FindWithTag("Player").GetComponentInChildren <HeroSounds>().normalAttackSFX.Length)];
            sfxAudio.Play();
        }
    }
Exemplo n.º 10
0
    /// <summary>
    /// 普通攻击的入口函数
    /// </summary>
    public static void NormalAttackWork(FightUnit attacker, FightUnit target, NormalAttack skill)
    {
        if (target == null || target.health == 0 || attacker == null || attacker.health == 0)
        {
            return;
        }
        switch ((SkillCurve)skill.attack.curve)
        {
        case SkillCurve.None:
        case SkillCurve.Melee:
            NormalAttackDamage(attacker, target, skill, skill.curHitEffect);
            break;

        case SkillCurve.Directional:
            GameObject obj = ProjectileMove.CreateProjectile(skill.name + "_" + attacker.mTrans.name, attacker.mTrans.parent, skill.flyEffectFromPos, skill.curFlyEffect.speed, target.Body, delegate(SpecialEffect fx)
            {
                if (attacker != null && target != null)
                {
                    NormalAttackDamage(attacker, target, skill, fx);
                }
            });
            obj.GetComponent <ProjectileMove>().hitEffect = skill.curHitEffect;
            skill.StartCoroutine(skill.DisplayFlyEffect(obj.transform));
            break;

        case SkillCurve.Parabola:
            Vector3 targetPos;
            bool    isHeroSkill = attacker.parentGroup.group == FightGroup.GroupType.Mine;
            if (skill.flyEffect.distance > 0)
            {
                targetPos = attacker.mTrans.localPosition + (isHeroSkill? -1 : 1) * Vector3.right * skill.flyEffect.distance;
            }
            else
            {
                targetPos = target.mTrans.localPosition + target.Body.localPosition;
            }
            GameObject obj_1 = ProjectileMove.CreateProjectile(skill.name, attacker.mTrans.parent, skill.flyEffectFromPos, skill.curFlyEffect.speed, skill.curFlyEffect.height, targetPos, delegate(SpecialEffect fx)
            {
                if (attacker != null && target != null)
                {
                    NormalAttackDamage(attacker, target, skill, fx);
                }
            });
            obj_1.GetComponent <ProjectileMove>().hitEffect = skill.curHitEffect;
            if (!isHeroSkill)
            {
                obj_1.AddComponent <DragRecord>();
            }
            break;
        }
    }
Exemplo n.º 11
0
 public override void Awake()
 {
     base.Awake();
     IdleInitAction = new IdleAction(this, "Idle", NV, mr, colliders, Ani);
     AttackAction   = new NormalAttack(this, new string[] { "attack1", "attack2" }, 0.44f, NV, Ani);
     BackAction     = new TakeBack(this, "", NV, transform);
     InjuredAction  = new InjuredAction(this, "GetHit", 1, NV, Ani);
     RunAction      = new RunAction(this, "Run", NV, Ani);
     DieAction      = new DieAction(this, "Die", mr, NV, transform, colliders, Ani, 0.2f);
     //技能节点初始化(skill1Action是AI中需要cd和weight控制的技能,而skill1Action是根据相应的触发条件触发的)
     skill1Action = new SYSkillAction(this, "skill1", 0.7f, 0.7f, NV, 10, Ani);
     skill2Action = new JumpAction(this, "skill2", 1.4f, 3f, NV, 3, Ani, 1.65f);
     //将通过冷却和权值的技能添加到总技能列表中(所以仅将skill1Action进行CD和Weight的封装并添加,而skill2Action在update中根据条件来单独控制技能的触发)
     SkillList.Add(new SkillCDAndWeight_New(skill1Action, 10, 20));
 }
Exemplo n.º 12
0
 public BaseMeleeClass()
 {
     CharacterClassName = "Warrior";
     Health             = 50;
     MaxHealth          = 50;
     Attack             = 20;
     Magicattack        = 0;
     Defense            = 5;
     Magicdefense       = 8;
     CurrentTech        = 100;
     MaxTech            = 100;
     MaxMana            = 0;
     ability1           = new NormalAttack();
     ability2           = new Swipe();
     ability3           = new Doping();
 }
Exemplo n.º 13
0
 public BaseMageClass()
 {
     CharacterClassName = "Mage";
     Health             = 25;
     MaxHealth          = 25;
     Attack             = 2;
     Magicattack        = 40;
     Defense            = 2;
     Magicdefense       = 5;
     MaxTech            = 0;
     CurrentMana        = 150;
     MaxMana            = 150;
     ability1           = new NormalAttack();
     ability2           = new Fire();
     ability3           = new Ice();
     ability4           = new NullAttack();
 }
Exemplo n.º 14
0
 public BaseHealerClass()
 {
     CharacterClassName = "Healer";
     Health             = 20;
     MaxHealth          = 20;
     Attack             = 5;
     Magicattack        = 20;
     Defense            = 5;
     Magicdefense       = 8;
     MaxTech            = 0;
     CurrentMana        = 250;
     MaxMana            = 250;
     ability1           = new NormalAttack();
     ability2           = new Heal();
     ability3           = new Sap();
     ability4           = new DivineLight();
     ability5           = new Salvation();
 }
Exemplo n.º 15
0
    public override void Turn(RoomType room)
    {
        Ability          selectedAbility  = new NormalAttack(this);//дописать логику выбора способности монстром
        List <Creatures> availableTargets = selectedAbility.GetAvailableTargets(room, this);
        Creatures        target           = availableTargets[0];

        foreach (Creatures c in availableTargets)
        {
            if (c.GetResultStat(Stats.Hp) < target.GetResultStat(Stats.Hp))
            {
                target = c;
            }
        }

        selectedAbility.UseAbility(target, this, room);
        Messenger <GameObject> .Broadcast(GameEvent.ENEMY_HIT, target.gameObject);

        this.gameObject.GetComponent <Animator>().SetTrigger("StartAttack");
    }
Exemplo n.º 16
0
    IEnumerator doSkill(int skillKind)
    {
        NormalAttack.getInstance().attackTargetObj = null;
        Run.getInstance().finishRun();
        m_animator.SetFloat("HeroSkillKind", skillKind);
        m_animator.SetBool("isHeroSkill", true);

        switch (skillKind)
        {
        case 0:
        {
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            Physics.Raycast(ray, out hitInfo, 1 << LayerMask.NameToLayer("Terrain") | 1 << LayerMask.NameToLayer("Enemy"));
            //SmoothLookAt.getInstance().Init_Rotate(hitInfo.point);
            gameObject.transform.LookAt(hitInfo.point);
            yield return(new WaitForSeconds(.1f));

            var prefabQ = Instantiate(Resources.Load("Prefab/BlindMonkQ"), GameObject.Find("Q_pos").transform.position, new Quaternion());

            var vec1        = new Vector3(hitInfo.point.x, GameObject.Find("Q_pos").transform.position.y, hitInfo.point.z);
            var vec2        = GameObject.Find("Q_pos").transform.position;
            var dir         = vec1 - vec2;
            Ray rayToTarget = new Ray(vec2, dir);

            ((GameObject)prefabQ).GetComponent <BlindMonkQ>().targetPos = rayToTarget.GetPoint(1000);
            break;
        }

        case 1:
        {
            Vector3 tarPos = new Vector3(Q_target.transform.position.x, GameObject.Find("Q_pos").transform.position.y, Q_target.transform.position.z);
            //SmoothLookAt.getInstance().Init_Rotate(tarPos);
            gameObject.transform.LookAt(tarPos);
            Run.getInstance().RunToPos(tarPos, true);
            Q_target = null;
            break;
        }

        default:
            break;
        }
    }
Exemplo n.º 17
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     NormalAttack.getInstance().AttackRateUpdate = Time.time - 1.2f;  //移动 => 缩短攻击间隔(走A)
 }
Exemplo n.º 18
0
    private void Update()
    {
        float empSpd = spd;

        if (hp <= 0)
        {
            hpFill.material.SetFloat("_Progress", 0);
        }
        else
        {
            hpFill.material.SetFloat("_Progress", hp / maxHP);
        }
        for (int i = 0; i < equipedItems.Count; i++)
        {
            switch (equipedItems[i])
            {
            case ItemType.Mask1:
                empSpd = empSpd + empSpd * 0.2f;
                break;

            case ItemType.Mask2:
                empSpd = empSpd + empSpd * 0.5f;
                break;

            case ItemType.Mask3:
                empSpd = empSpd + empSpd * 1f;
                break;

            case ItemType.Heart1:
                healElap1 += Time.deltaTime;
                if (healElap1 >= 1 && maxHP > hp * 0.005f)
                {
                    hp       += hp * 0.005f;
                    healElap1 = 0;
                }
                break;

            case ItemType.Heart2:
                healElap2 += Time.deltaTime;
                if (healElap2 >= 1 && maxHP > hp * 0.01f)
                {
                    hp       += hp * 0.01f;
                    healElap2 = 0;
                }
                break;

            case ItemType.Heart3:
                healElap2 += Time.deltaTime;
                if (healElap2 >= 1 && maxHP > hp * 0.03f)
                {
                    hp       += hp * 0.03f;
                    healElap3 = 0;
                }
                break;
            }
        }


        movementDir = new Vector2(jsMove.Direction.x, jsMove.Direction.z);
        // move anim
        if (Vector2.Distance(movementDir, Vector2.zero) > 0.01f)
        {
            if (Mathf.Abs(movementDir.x) > Mathf.Abs(movementDir.y))
            {
                if (movementDir.x > 0) // 오른쪽
                {
                    preDir = movementDir;
                    animator.SetBool("Idle", false);
                    animator.SetBool("DownMove", false);
                    animator.SetBool("LeftMove", false);
                    animator.SetBool("RightMove", true);
                    animator.SetBool("UpMove", false);
                }
                else if (movementDir.x <= 0) // 왼쪽
                {
                    preDir = movementDir;
                    animator.SetBool("Idle", false);
                    animator.SetBool("DownMove", false);
                    animator.SetBool("LeftMove", true);
                    animator.SetBool("RightMove", false);
                    animator.SetBool("UpMove", false);
                }
            }
            else
            {
                if (movementDir.y > 0) // 위쪽
                {
                    preDir = movementDir;
                    animator.SetBool("Idle", false);
                    animator.SetBool("DownMove", false);
                    animator.SetBool("LeftMove", false);
                    animator.SetBool("RightMove", false);
                    animator.SetBool("UpMove", true);
                }
                else if (movementDir.y <= 0)
                {
                    preDir = movementDir;
                    animator.SetBool("Idle", false);
                    animator.SetBool("DownMove", true);
                    animator.SetBool("LeftMove", false);
                    animator.SetBool("RightMove", false);
                    animator.SetBool("UpMove", false);
                }
            }
        }
        else
        {
            animator.SetBool("Idle", true);
            animator.SetBool("DownMove", false);
            animator.SetBool("LeftMove", false);
            animator.SetBool("RightMove", false);
            animator.SetBool("UpMove", false);
        }

        transform.Translate(movementDir.normalized * empSpd * Time.deltaTime);

        #region normalAttack
        // 기본공격
        if (attackSkills[(int)AttackType.DefaulAttack].isActive)
        {
            NormalAttack normalAttack = attackSkills[(int)AttackType.DefaulAttack].skill as NormalAttack;
            normalAttack.elapsedTime += Time.deltaTime;
            if (normalAttack.elapsedTime > normalAttack.attackDelay)
            {
                //Actor target=    Actor.FindActor((Actor actor) =>
                //{
                //    if (Vector2.Distance(actor.transform.position, transform.position) < normalAttack.attackRange)
                //    {
                //        return true;
                //    }
                //    return false;
                //});

                Actor target   = null;
                float bestDist = 100;
                foreach (var act in allActors)
                {
                    if (act.Value == this || act.Value.isActiveAndEnabled == false)
                    {
                        continue;
                    }
                    float dist = Vector2.Distance(transform.position, act.Value.transform.position);
                    if (dist < bestDist)
                    {
                        target   = act.Value;
                        bestDist = dist;
                    }
                }
                if (target != null && Vector2.Distance(target.transform.position, transform.position) < normalAttack.attackRange)
                {
                    normalAttack.Attack(target, firePos.position);
                    normalAttack.elapsedTime = 0;
                }
            }
        }
        #endregion
        if (attackSkills[(int)AttackType.FireBall].isActive)
        {
            FireBallAttack fireBallAttack = attackSkills[(int)AttackType.FireBall].skill as FireBallAttack;
            fireBallAttack.elapsedTime += Time.deltaTime;
            if (fireBallAttack.elapsedTime > fireBallAttack.AttackDelay)
            {
                fireBallAttack.Attack(firePos.position);
                fireBallAttack.elapsedTime = 0;
            }
        }
        if (attackSkills[(int)AttackType.MagicBall].isActive)
        {
            MagicBallAttack magicBallAttack = attackSkills[(int)AttackType.MagicBall].skill as MagicBallAttack;
            magicBallAttack.elapsedTime += Time.deltaTime;
            if (magicBallAttack.elapsedTime > magicBallAttack.AttackDelay)
            {
                Actor[] target     = new Actor[magicBallAttack.attackCount];
                float   bestDist   = 100;
                int     foundCnt   = 0;
                bool    isAttacked = false;
                foreach (var act in allActors)
                {
                    if (foundCnt >= magicBallAttack.attackCount)
                    {
                        break;
                    }
                    if (act.Value == this || act.Value.isActiveAndEnabled == false)
                    {
                        continue;
                    }
                    float dist = Vector2.Distance(transform.position, act.Value.transform.position);
                    if (dist < magicBallAttack.attackDistance)
                    {
                        target[foundCnt++] = act.Value;
                    }
                }
                for (int i = 0; i < target.Length; i++)
                {
                    if (target[i] != null)
                    {
                        magicBallAttack.Attack(target[i], firePos.position);
                        isAttacked = true;
                    }
                }
                if (isAttacked)
                {
                    magicBallAttack.elapsedTime = 0;
                }
            }
        }
        if (attackSkills[(int)AttackType.Cycle].isActive)
        {
            CycleMagic cycleMagic = attackSkills[(int)AttackType.Cycle].skill as CycleMagic;
            cycleMagic.Attack();
            //fireFallAttack.elapsedTime += Time.deltaTime;
            //if (fireFallAttack.elapsedTime > fireFallAttack.attackDelay)
            //{
            //    for (int i = 0; i < fireFallAttack.attackCount; i++)
            //    {
            //        int randX = UnityEngine.Random.Range(-2, 2);
            //        int randY = UnityEngine.Random.Range(-2, 2);
            //        Vector3 distPos = new Vector3(transform.position.x + randX, transform.position.y + randY);
            //        fireFallAttack.Attack(distPos);
            //    }
            //    fireFallAttack.elapsedTime = 0;
            //}
        }
    }
Exemplo n.º 19
0
    /// <summary>
    /// 普通攻击伤害
    /// 普通攻击伤害=攻击方最终攻击*防御效果*攻击方伤害加成效果系数*防御方对应属性免伤系数*防御方全免伤系数*属性相克系数*暴击伤害系数*random(0.95,1.05)
    /// 防御效果=1/(1+防御系数*防御方最终防御)
    /// 防御效果必须介于20%和100%之间,这两个参数由策划配置
    /// 防御常数为常量,由策划配置,下同
    /// 普通攻击的属性和单位自身的属性相同
    /// </summary>
    public static void NormalAttackDamage(FightUnit attacker, FightUnit target, NormalAttack skill, SpecialEffect hitEffect)
    {
        if (target == null || attacker == null || target.isInvincible)
        {
            return;
        }

        //判断命中
        if (IsMiss(attacker, target))
        {
            HealthUIManager.instance.DisplayHurtNum(target, "Miss", true, false);
            //触发闪避事件
            if (target.OnDodge != null)
            {
                target.OnDodge();
            }
            return;
        }

        //判断无敌
        if (target.isInvincible)
        {
            HealthUIManager.instance.DisplayHurtNum(target, "Invincible", true, false);
            return;
        }

        //判断暴击
        bool  isCrit    = false;
        float critScale = 1f;

        if (IsCritical(attacker, target))
        {
            isCrit    = true;
            critScale = Const.CONST_BASIC_CRIT_DMG + attacker.fightAttribute.criticalImprove;
            //当普通攻击暴击时
            if (attacker.OnNormalAttackCritil != null)
            {
                attacker.OnNormalAttackCritil(target);
            }
            //当被暴击时
            if (target.OnGotCritil != null)
            {
                attacker.OnGotCritil();
            }
        }

        //受击特效
        skill.StartCoroutine(skill.DisplayHitEffect(target, hitEffect));

        //计算数值
        float defense = (float)1 / (1 + Const.CONST_DEF_FACTOR * target.fightAttribute.Defence);//防御效果

        defense = Mathf.Clamp(defense, Const.CONST_MIN_DEF_EFFECT, Const.CONST_MAX_DEF_EFFECT);
        float    elementDefenseFactor = 0;
        HurtType hurtType             = (HurtType)attacker.fightAttribute.elementType;

        switch (hurtType)
        {
        case HurtType.Fire:
            elementDefenseFactor = target.fightAttribute.fireDefenseRate;
            break;

        case HurtType.Water:
            elementDefenseFactor = target.fightAttribute.waterDefenseRate;
            break;

        case HurtType.Earth:
            elementDefenseFactor = target.fightAttribute.eathDefenseRate;
            break;

        case HurtType.Light:
            elementDefenseFactor = target.fightAttribute.lightDefeneseRate;
            break;

        case HurtType.Dark:
            elementDefenseFactor = target.fightAttribute.darkDefenseRate;
            break;
        }
        float elementFactor = ElementFactorDic[(int)attacker.fightAttribute.elementType * 10 + (int)target.fightAttribute.elementType].factor;
        int   hurtNum       = Mathf.RoundToInt(attacker.fightAttribute.attack * defense
                                               * (1 + attacker.fightAttribute.allDamageRate) * (1 - elementDefenseFactor) * (1 - target.fightAttribute.allDefenseRate) * elementFactor * critScale * Random.Range(0.95f, 1.05f));

        hurtNum = Mathf.Max(0, hurtNum);

        //触发普通攻击命中事件
        if (attacker.OnNoramlAttackHit != null)
        {
            attacker.OnNoramlAttackHit(hurtNum);
        }
        //触发反弹事件
        if (target.OnFantan != null)
        {
            target.OnFantan(hurtNum, skill, hurtType);
        }
        //护盾计算
        hurtNum = CaculateHudun(hurtNum, target, hurtType);

        //伤血
        if (hurtNum == 0)
        {
            return;
        }
        HealthUIManager.instance.DisplayHurtNum(target, hurtNum.ToString(), true, isCrit);
        target.health -= hurtNum;
        if (target.health == 0)
        {
            FightManager.GetInstance().UnitDead(attacker, target);
        }
    }
Exemplo n.º 20
0
 public Character(int p, int p_2)
 {
     Hp            = p;
     BaseDamage    = p_2;
     vNormalAttack = new NormalAttack();
 }
Exemplo n.º 21
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;
    }
Exemplo n.º 22
0
 private void Awake()
 {
     instance   = this;
     m_animator = GetComponentInChildren <Animator>();
 }
Exemplo n.º 23
0
 // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
 override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     NormalAttack.getInstance().finishAttack();
 }