Ejemplo n.º 1
0
    public void AddNewHealthBar(FightUnit unit, Transform point, bool isEnemey)
    {
        if (HealthUIList.ContainsKey(unit))
        {
            return;
        }
        HealthUI healthUI = new HealthUI();

        healthUI.point = point;
        GameObject obj = Util.AddChild(isEnemey? enHealthBarObj:myHealthBarObj, mTrans);

        obj.SetActive(true);
        healthUI.displayHealthBar = obj.GetComponent <DisplayHealthBar>();
        UISprite background = obj.transform.GetChild(0).GetComponent <UISprite>();
        UISprite foreground = obj.transform.GetChild(0).GetChild(0).GetComponent <UISprite>();

        background.depth = depth++;
        foreground.depth = depth++;
        GameObject obj2 = Util.AddChild(hurtNumEmitter, mTrans);

        obj2.SetActive(true);
        healthUI.barTrans = obj.transform;
        UISlider slider = obj.GetComponentInChildren <UISlider>();

        healthUI.slider = slider;
        HurtNumEmitter emitter = obj2.GetComponent <HurtNumEmitter>();

        healthUI.emitter = emitter;
        HealthUIList.Add(unit, healthUI);
    }
Ejemplo n.º 2
0
    public void InitFightUnitInfo(List <FightUnit> allUnit)
    {
        List <FightUnit> _heros = new List <FightUnit>();

        for (int idx = 0; idx < allUnit.Count; ++idx)
        {
            FightUnit unit = allUnit[idx];
            AddFightUnitInfo(unit);

            if (!unit.IsEnemy)
            {
                _heros.Add(unit);
            }
        }

        _heros.Sort((FightUnit a, FightUnit b) => { return(a.StubPos.CompareTo(b.StubPos)); });

        for (int idx = 0; idx < _heros.Count; ++idx)
        {
            FightUnit  unit      = _heros[idx];
            GameObject fightHero = GameObject.Instantiate(fightHeroView.gameObject);
            fightHero.name = string.Format("FightHero_{0}", unit.UID);
            fightHero.transform.SetParent(this.hero_obj.transform, false);
            FightHeroView _fightHeroView = fightHero.GetComponent <FightHeroView>();
            _fightHeroView.Init();
            _fightHeroView.InitHero(unit);

            RectTransform fightHeroRect = fightHero.GetComponent <RectTransform>();
            fightHeroRect.anchoredPosition = new Vector2((idx - _heros.Count / 2.0f + 0.5f) * fightHeroRect.sizeDelta.x, 0);
            Heads.Add(unit.UID, _fightHeroView);
        }
    }
Ejemplo n.º 3
0
    //自己当前血量/最大血量变化
    public void OnFightUnitHpChange(FightUnit unit)
    {
        if (unit != this._unit)
        {
            return;
        }
        float hpPro = (float)unit.CurHP / unit.MaxHP;

        for (int idx = 0; idx < _allBuff.Count; ++idx)
        {
            Buff buff = _allBuff[idx];
            if (!buff.IsUsing)
            {
                continue;
            }
            if (buff.Type == BuffType.Trigger && buff.Trigger == (int)BuffTrigger.HpPro)
            {
                bool shouldTrigger = hpPro < buff.TriggerParam;
                if (buff.IsTriggered != shouldTrigger)
                {
                    TakeEffect(buff, !shouldTrigger);
                    buff.IsTriggered = shouldTrigger;
                }
            }
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// 战斗单位移动到targetpos事件,主要判断是不是所有单位都到位了
 /// </summary>
 /// <param name="unit"></param>
 public void OnUnitMoveOver(FightUnit unit)
 {
     if (unit == null)
     {
         EDebug.LogError("FightLogic.OnUnitOver failed, unit is null");
         return;
     }
     unit.State = FightUnitState.Idle;
     //如果所有的单位都移动到指定位置,移除事件,进入下一状态
     if (State == FightState.Prepare)
     {
         bool allUnitIdle = true;
         for (int idx = 0; idx < AllFighters.Count; ++idx)
         {
             FightUnit fightUnit = AllFighters[idx];
             if (fightUnit.IsDead)
             {
                 continue;
             }
             if (fightUnit.State != FightUnitState.Idle)
             {
                 allUnitIdle = false;
                 break;
             }
         }
         //所有单位都到达了指定位置
         if (allUnitIdle)
         {
             ZEventSystem.DeRegister(EventConst.OnUnitMoveOver, this);
             State = FightState.Fight;
         }
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// 为战斗单位创建VIew
    /// </summary>
    /// <param name="unit"></param>
    private void _createFightUnitView(FightUnit unit)
    {
        int resId   = 0;
        int horseId = 0;

        if (!unit.IsMonster)
        {
            Hero chero = JsonMgr.GetSingleton().GetHeroByID(unit.HeroId);
            resId   = chero.resid;
            horseId = chero.horseid;
        }
        else
        {
            Monster chero = JsonMgr.GetSingleton().GetMonsterByID(unit.HeroId);
            resId   = chero.resid;
            horseId = chero.horseid;
        }

        GameObject fighterObj = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(resId) as GameObject);
        GameObject horseObj   = null;

        if (horseId > 0)
        {
            horseObj = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(horseId) as GameObject);
            horseObj.transform.parent        = fighterObj.transform;
            horseObj.transform.localPosition = Vector3.zero;
        }
        FightUnitView fightUnitView = fighterObj.AddComponent <FightUnitView>();

        fightUnitView.unit  = unit;
        fightUnitView.Horse = horseObj;
        fightUnitView.Init(resId);
    }
Ejemplo n.º 6
0
 /// <summary>
 /// 进入战斗
 /// </summary>
 public override void DoAttack(FightUnit t)
 {
     //进入战斗才开始解锁技能
     if (!enabled)
     {
         enabled = true;
     }
     if (target != t)
     {
         target = t;
     }
     if (currentSkill != null)
     {
         return;
     }
     if (selectedSkill != null)
     {
         UseActiveSkill(selectedSkill);
         selectedSkill = null;
     }
     else
     {
         UseNormalAttack();
     }
 }
Ejemplo n.º 7
0
 public void Suffer(FightUnit fightUnit)
 {
     Console.WriteLine(fightUnit.name + "가 " + name + "을 공격합니다.");
     HP -= fightUnit.AT;
     Console.WriteLine(name + "의 체력이 " + HP + "가 되었습니다....");
     Console.WriteLine("");
 }
Ejemplo n.º 8
0
 public void OnFightTargetChange(FightUnit unit, FightUnit target)
 {
     if (unit != this.Unit && unit != this.Unit.FightTarget)
     {
         return;
     }
 }
Ejemplo n.º 9
0
    /// <summary>
    /// 当自己使用及技能时,检查有无根据技能id触发的buff
    /// </summary>
    /// <param name="unit"></param>
    /// <param name="cskill"></param>
    public void OnSkillTakeEffect(FightUnit unit, Skill cskill)
    {
        if (cskill == null)
        {
            return;
        }
        if (unit != this._unit)
        {
            return;
        }
        int sklId = cskill.ID;

        for (int idx = 0; idx < _allBuff.Count; ++idx)
        {
            Buff buff = _allBuff[idx];
            if (!buff.IsUsing)
            {
                continue;
            }
            if (buff.Type == BuffType.Trigger && buff.Trigger == (int)BuffTrigger.UseSkill)
            {
                if (sklId == (int)buff.TriggerParam)
                {
                    TakeEffect(buff);
                }
            }
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 算出修正距离
    /// </summary>
    public static float Distance(FightUnit from, FightUnit to)
    {
        float factor = DistanceFactorDic[(int)from.fightAttribute.elementType * 10 + (int)to.fightAttribute.elementType].factor;

        //float factor = 1;
        return(Util.Distance(from.transform.localPosition, to.transform.localPosition) * factor);
    }
Ejemplo n.º 11
0
 /// <summary>
 /// 进入战斗
 /// </summary>
 public override void DoAttack(FightUnit t)
 {
     if (target != t)
     {
         target = t;
     }
     if (currentSkill != null)
     {
         return;
     }
     if (isAutoUseSkill)
     {
         UseActiveSkill(normalSkill);
         isAutoUseSkill = false;
     }
     else if (isAutoUseUniqueSkill)
     {
         UseUniqueSkill();
         isAutoUseUniqueSkill = false;
     }
     else
     {
         UseNormalAttack();
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 技能附加buff
 /// </summary>
 public static void SkillAttachBuff(FightUnit attacker, FightUnit target, List <Skill.buffConfig> buffConfigList, HurtType hurtType)
 {
     if (buffConfigList.Count == 0)
     {
         return;
     }
     for (int i = 0; i < buffConfigList.Count; i++)
     {
         ActiveSkill.buffConfig buffConfig = buffConfigList[i];
         BuffData buffData = BuffDataDic[buffConfig.id];
         //判断免疫
         if (!IsBuffAttachable(target, buffData))
         {
             continue;
         }
         //判断控制buff的命中
         if (buffData.controlDebuff == 1 && Random.value > 1 - Mathf.Max(0, (target.fightAttribute.level - buffConfig.level)) * Const.CONST_RESIST_FACTOR)
         {
             continue;
         }
         float buffValue = Mathf.RoundToInt(attacker.fightAttribute.attack * buffConfig.percent) + buffConfig.value;
         Buff  buff      = Buff.AddNewBuff(target, attacker, buffData, buffValue, buffConfig.time, hurtType);
         buff.bindSkill = buffConfig.bindSkill;
     }
 }
Ejemplo n.º 13
0
    /// <summary>
    /// 使用绝技技能,HeroUnitUI调用
    /// </summary>
    /// <returns></returns>
    public void UI_UseUniqueSkill(params object[] objs)
    {
        UnAbleReason reason = UnAbleReason.None;

        if (self.state != FightUnit.UnitState.Fighting)
        {
            reason = UnAbleReason.NotFighting;
        }
        else if (self.isConfused)
        {
            reason = UnAbleReason.InSpecailState;
        }
        if (reason != UnAbleReason.None)
        {
            TipReason(reason);
            return;
        }
        else
        {
            if (target == null || target.state == FightUnit.UnitState.Dead)
            {
                target = FightRule.GetFightTarget(self, self.parentGroup.targetGroup);
                if (target == null)
                {
                    return;
                }
            }
            UseUniqueSkill();
        }
    }
Ejemplo n.º 14
0
    /// <summary>
    /// 展现魔法特效
    /// </summary>
    public virtual IEnumerator DisplaydmgEffect(FightUnit dmgEffectTarget)
    {
        if (dmgEffect != null && !string.IsNullOrEmpty(dmgEffectName))
        {
            EffectTarget effectTarget   = (EffectTarget)dmgEffect.target;
            Transform    dmgEffectTrans = null;
            Vector3      effectLocalPos = Vector3.zero;
            if (effectTarget == EffectTarget.Screen)
            {
                dmgEffectTrans = FightEffectManager.instance.transform;
            }
            else if (effectTarget == EffectTarget.MineCenter)
            {
                dmgEffectTrans = mineUnit.mTrans.parent;
                effectLocalPos = mineUnit.parentGroup.Center;
            }
            else if (effectTarget == EffectTarget.EnemyCenter)
            {
                dmgEffectTrans = mineUnit.mTrans.parent;
                effectLocalPos = targetUnit.parentGroup.Center;
            }
            else if (dmgEffectTarget != null)
            {
                dmgEffectTrans = dmgEffectTarget.GetEffectPoint((EffectPoint)dmgEffect.bone);
            }

            yield return(StartCoroutine(AssetManager.LoadAsset(dmgEffectName, AssetManager.AssetType.Effect, false)));

            GameObject obj = AssetManager.GetGameObject(dmgEffectName, dmgEffectTrans);
            obj.transform.localPosition = effectLocalPos;
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// 展现受击特效
    /// </summary>
    public IEnumerator DisplayHitEffect(FightUnit tg, SpecialEffect fx)
    {
        if (fx != null)
        {
            Transform hitEffectTrans = tg.GetEffectPoint((EffectPoint)fx.bone);
            Vector3   pos            = hitEffectTrans.position;
            hitEffectName       = Util.GetConfigString(fx.name);
            hitEffectAudioName  = Util.GetConfigString(fx.audio);
            hitEffectAudioDelay = fx.audioDelay;
            if (!string.IsNullOrEmpty(hitEffectName))
            {
                yield return(StartCoroutine(AssetManager.LoadAsset(hitEffectName, AssetManager.AssetType.Effect, false)));

                yield return(StartCoroutine(AssetManager.LoadAsset(hitEffectAudioName, AssetManager.AssetType.Audio, false)));

                GameObject obj = AssetManager.GetGameObject(hitEffectName);
                obj.transform.parent     = mineUnit.mTrans.parent;
                obj.transform.localScale = Vector3.one;
                obj.transform.position   = pos;
                AudioClip   audio      = AssetManager.GetAsset <AudioClip>(hitEffectAudioName);
                AudioSource audiosouce = obj.AddComponent <AudioSource> ();
                audiosouce.clip = audio;
                StartCoroutine(WaitAudioDelay(hitEffectAudioDelay));
                audiosouce.Play();
            }
        }
    }
Ejemplo n.º 16
0
    /// <summary>
    /// 选定目标的魔法
    /// </summary>
    public static IEnumerator AcitveSkillMagic_Single(FightUnit attacker, FightUnit target, ActiveSkill skill)
    {
        skill.StartCoroutine(skill.DisplaydmgEffect(target));
        if (skill.magicDelay.Length > 0)
        {
            for (int i = 0; i < skill.magicDelay.Length; i++)
            {
                yield return(new WaitForSeconds(skill.magicDelay[i]));

                if (skill.normalSkill.attackType == (int)SkillType.Hurt)
                {
                    ActiveSkillDamage(attacker, target, skill);
                }
                else
                {
                    FightCure(attacker, target, skill);
                }
            }
        }
        else
        {
            if (skill.normalSkill.attackType == (int)SkillType.Hurt)
            {
                ActiveSkillDamage(attacker, target, skill);
            }
            else
            {
                FightCure(attacker, target, skill);
            }
        }
    }
Ejemplo n.º 17
0
 public void OnHeadClick(FightUnit unit)
 {
     if (unit != null)
     {
         unit.UseActiveSkill();
     }
 }
Ejemplo n.º 18
0
    /// <summary>
    /// 字符串转换为具体属性值,返回结果x表示属性类型(0无类型1武力2策略),y表示属性值
    /// </summary>
    /// <param name="str"></param>
    /// <param name="user"></param>
    /// <param name="target"></param>
    /// <returns></returns>
    private static Vector2 expression2Attr(string str, FightUnit user, FightUnit target)
    {
        switch (str)
        {
        case "u_atk":
            return(new Vector2(1, user.Atk));

        case "t_atk":
            return(new Vector2(1, target.Atk));

        case "u_matk":
            return(new Vector2(2, user.Matk));

        case "t_matk":
            return(new Vector2(2, target.Matk));

        case "u_hp":
            return(new Vector2(0, user.MaxHP));

        case "t_hp":
            return(new Vector2(0, target.MaxHP));

        case "u_chp":
            return(new Vector2(0, user.CurHP));

        case "t_chp":
            return(new Vector2(0, target.CurHP));

        default:
        {
            EDebug.LogErrorFormat("expression2Attr failed, {0} is invalid", str);
            return(Vector2.zero);
        }
        }
    }
Ejemplo n.º 19
0
    /*
     * 修正暴击率=基础暴击率+(攻击方最终暴击值-被攻击方最终韧性值)*暴击系数
     *  其中基础暴击率和暴击系数为常数,由策划配置
     *  修正暴击率的值必须介于设定的5%和50%之间,这两个参数由策划配置
     *
     * 最终暴击率=修正暴击率+BUFF修正
     *  同类BUFF按加法计算
     *  最终暴击率必须介于0和100%之间
     *
     * 暴击伤害系数
     *  当发生暴击时,暴击伤害系数=基础暴击伤害系数+攻击方暴击伤害加成+BUFF加成
     *  未发生暴击时,暴击伤害系数=1
     *  基础暴击伤害系数为常数,由策划配置
     * */
    static bool IsCritical(FightUnit attacker, FightUnit target)
    {
        float criticalRate = Mathf.Clamp(Const.CONST_BASIC_CRIT_RATE + (target.fightAttribute.toughness - attacker.fightAttribute.critical) * Const.CONST_CRIT_FACTOR, Const.CONST_MIN_CRIT_RATE, Const.CONST_MAX_CRIT_RATE);

        criticalRate += attacker.fightAttribute.criticalRateBuff;
        criticalRate  = Mathf.Clamp01(criticalRate);
        return(Random.value <= criticalRate);
    }
Ejemplo n.º 20
0
    /* 修正Miss率=基础Miss率+(被攻击方最终闪避值-攻击方最终命中值)*闪避系数
     * 其中基础Miss率和闪避系数为常数,由策划配置
     * 修正Miss率的值必须介于0和60%之间,这两个参数由策划配置
     *
     * 最终Miss率=修正Miss率+闪避率BUFF修正-命中率BUFF修正
     * 同类BUFF效果按加法计算
     * 最终Miss率必须介于0和100%之间
     * */
    static bool IsMiss(FightUnit attacker, FightUnit target)
    {
        float missRate = Mathf.Clamp(Const.CONST_BASIC_MISS_RATE + (target.fightAttribute.dodge - attacker.fightAttribute.hit) * Const.CONST_DODGE_FACTOR, Const.CONST_MIN_MISS_RATE, Const.CONST_MAX_MISS_RATE);

        missRate += target.fightAttribute.dodgeRateBuff - attacker.fightAttribute.hitRateBuff;
        missRate  = Mathf.Clamp01(missRate);
        return(Random.value <= missRate);
    }
Ejemplo n.º 21
0
    public void Damage(FightUnit _OtherFightUnit)
    {
        //각자 플레이어의 것이 되어야한다
        int AT = _OtherFightUnit.GetAT();

        Console.WriteLine(AT + _OtherFightUnit.Name + "Damage");
        HP -= AT;
    }
Ejemplo n.º 22
0
 public void OnFightUnitHpChange(FightUnit unit)
 {
     if (unit != this.Unit)
     {
         return;
     }
     this.hp_img.fillAmount = unit.CurHP / (float)unit.MaxHP;
 }
Ejemplo n.º 23
0
 public void Use(FightUnit target)
 {
     if (targetUnit == null || targetUnit != target)
     {
         targetUnit = target;
     }
     DoSkill();
 }
Ejemplo n.º 24
0
 public void OnFightUnitDie(FightUnit unit)
 {
     if (unit != this.Unit)
     {
         return;
     }
     this.dead_img.SetActive(true);
 }
Ejemplo n.º 25
0
 public void DisplayHurtNum(FightUnit unit, string num, bool isHurt, bool isCrit)
 {
     if (HealthUIList.ContainsKey(unit))
     {
         HealthUIList[unit].displayHealthBar.GetHurtDisplay();
         HealthUIList[unit].emitter.AddHurtNum(num, isHurt, isCrit);
     }
 }
Ejemplo n.º 26
0
 public void ForceDestroyView(FightUnit unit)
 {
     if (this.unit != unit)
     {
         return;
     }
     _destroy();
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 结束寻路
 /// </summary>
 public void  StopFind()
 {
     this._mTarget        = null;
     this._mTargetPos     = -1;
     this._mFighter.State = FightUnitState.Idle;
     //最后发事件,因为FIghtLogic要读状态是不是Idle
     ZEventSystem.Dispatch(EventConst.OnUnitMoveOver, this._mFighter);
 }
Ejemplo n.º 28
0
    /// <summary>
    /// 计算下一个格子
    /// </summary>
    /// <param name="targetPos">目标格子位置</param>
    /// <returns></returns>
    public int NextGrid(int targetPos)
    {
        int curGrid = this._mFighter.GridPos;

        dirSortList.Clear();
        for (int idx = 0; idx < adjacentDirs.Length; ++idx)
        {
            int dirGrid = BorderGrid(targetPos, adjacentDirs[idx]);
            if (dirGrid > 0 && checkGrid(dirGrid))
            {
                float d = GridDis(curGrid, dirGrid);
                dirSortList.Add(new Vector2(dirGrid, d));
            }
        }
        dirSortList.Sort((Vector2 a, Vector2 b) =>
        {
            if (a.y < b.y)
            {
                return(-1);
            }
            else if (a.y > b.y)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        });
        List <int> obstacleList = new List <int>();

        for (int idx = 0; idx < FightLogic.Instance.AllFighters.Count; ++idx)
        {
            FightUnit unit = FightLogic.Instance.AllFighters[idx];
            if (unit.IsDead)
            {
                continue;
            }
            int gridPos = unit.GridPos;
            if (gridPos == curGrid)
            {
                continue;
            }
            obstacleList.Add(gridPos);
        }

        for (int idx = 0; idx < dirSortList.Count; ++idx)
        {
            List <int> path = null;
            FightLogic.Instance.aStarFinder.Clear();
            if (FightLogic.Instance.aStarFinder.Search(curGrid, (int)dirSortList[idx].x, obstacleList, out path))
            {
                return(path[path.Count - 2]);
            }
        }

        return(-1);
    }
Ejemplo n.º 29
0
    static int UpdateControlUnit(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        PlayerBehaviourFacade obj  = (PlayerBehaviourFacade)LuaScriptMgr.GetUnityObjectSelf(L, 1, "PlayerBehaviourFacade");
        FightUnit             arg0 = (FightUnit)LuaScriptMgr.GetUnityObject(L, 2, typeof(FightUnit));

        obj.UpdateControlUnit(arg0);
        return(0);
    }
Ejemplo n.º 30
0
    //持续伤害、治疗直接处理
    //控制状态直接加在本体
    #endregion

    public BuffMgr(FightUnit unit)
    {
        this._unit = unit;
        ZEventSystem.Register(EventConst.OnFightUnitDie, this, "OnFightUnitDie");
        ZEventSystem.Register(EventConst.OnFightUnitHit, this, "OnFightUnitHit");
        ZEventSystem.Register(EventConst.OnFightUnitHpChange, this, "OnFightUnitHpChange");
        ZEventSystem.Register(EventConst.OnSkillTakeEffect, this, "OnSkillTakeEffect");
        ZEventSystem.Register(EventConst.OnFightUnitBooster, this, "OnFightUnitBooster");
    }