Ejemplo n.º 1
0
    public void SkillAction(EntityBase caster, SkillCfg skillCfg, int index)
    {
        SkillActionCfg skillActionData = resSvc.GetSkillActionCfg(skillCfg.skillActionList[index]);
        int            damage          = skillCfg.skillDamageList[index];

        if (caster.entityType == EntityType.Player)
        {
            //获取场景中所有怪物实体
            List <EntityMonster> monsterList = caster.battleMgr.GetEntityMonster();

            for (int i = 0; i < monsterList.Count; i++)
            {
                EntityMonster target = monsterList[i];
                //判断距离和角度,对满足条件的怪物进行伤害运算
                if (InRange(caster.GetPos(), target.GetPos(), skillActionData.radius) && InAngle(caster.GetTrans(), target.GetPos(), skillActionData.angle))
                {
                    CalcDamage(caster, target, skillCfg, damage);
                }
            }
        }
        else if (caster.entityType == EntityType.Monster)
        {
            EntityPlayer entityPlayer = caster.battleMgr.GetEntityPlayer();
            if (entityPlayer == null)
            {
                return;
            }
            if (InRange(caster.GetPos(), entityPlayer.GetPos(), skillActionData.radius) && InAngle(caster.GetTrans(), entityPlayer.GetPos(), skillActionData.angle))
            {
                CalcDamage(caster, entityPlayer, skillCfg, damage);
            }
        }
    }
Ejemplo n.º 2
0
    public void Init()
    {
        _mainPlayer = CreatePlayer(EHeroType.Soldier, new Vector3(-6, 0, 5), Vector3.zero);
        if (_mainPlayer != null)
        {
            _entitys.Add(_mainPlayer);
        }

        EntityMonster monster1 = CreateMonster(1, new Vector3(-10, 0, 0), Vector3.zero);

        if (monster1 != null)
        {
            _entitys.Add(monster1);
        }

        EntityMonster monster2 = CreateMonster(2, new Vector3(-6, 0, 0), Vector3.zero);

        if (monster2 != null)
        {
            _entitys.Add(monster2);
        }

        EntityMonster monster3 = CreateMonster(3, new Vector3(-2, 0, 0), Vector3.zero);

        if (monster3 != null)
        {
            _entitys.Add(monster3);
        }

        _eventGroup.AddListener <BattleEvent.CharacterDead>(OnHandleBattleEvent);
        _eventGroup.AddListener <BattleEvent.DamageHurt>(OnHandleBattleEvent);
        _eventGroup.AddListener <BattleEvent.PlayerSpell>(OnHandleBattleEvent);
    }
Ejemplo n.º 3
0
    private void SelectDamageObj(EntityBase attacker, SkillDataCfg skillCfg, int skillIdx)
    {
        SkillActionCfg actionCfg = resSvc.GetSkillActionCfg(skillCfg.skillActionList[skillIdx]);
        int            damageVal = skillCfg.skillDamageList[skillIdx];

        if (attacker._entityType == Constants.EntityType.Monster)
        {
            EntityPlayer entityPlayer = attacker._battleMgr.GetEntityPlayer;
            if (entityPlayer == null)
            {
                return;
            }

            if (InRange(attacker.GetEntityPosition(), entityPlayer.GetEntityPosition(), actionCfg.radius) &&
                InAngle(attacker.GetEntityTransform(), entityPlayer.GetEntityPosition(), actionCfg.angle))
            {
                CalcDamage(attacker, entityPlayer, skillCfg, damageVal);
            }
        }
        else if (attacker._entityType == Constants.EntityType.Player)
        {
            //获取场景中所有的怪物
            List <EntityMonster> listMonster = attacker._battleMgr.GetAllEntityMonsters();
            for (int i = 0; i < listMonster.Count; i++)
            {
                EntityMonster monster = listMonster[i];
                //在攻击范围内
                if (InRange(attacker.GetEntityPosition(), monster.GetEntityPosition(), actionCfg.radius) &&
                    InAngle(attacker.GetEntityTransform(), monster.GetEntityPosition(), actionCfg.angle))
                {
                    CalcDamage(attacker, monster, skillCfg, damageVal);
                }
            }
        }
    }
Ejemplo n.º 4
0
 public void Process(EntityBase entity, params object[] args)
 {
     //判断是boss以后播放的是walk动画,因为血量降低到50%以后才播放run动画提速
     //这里的判断并不是真正的判断,是为了防止在boss提速以后第二次进入这个状态修改回walk
     if (entity is EntityMonster)
     {
         EntityMonster monster = (EntityMonster)entity;
         if (monster.md.mCfg.mType == MonsterType.Boss)
         {
             if (monster.speedUp)
             {
                 entity.SetBlend(Constants.blendRun);
             }
             else
             {
                 entity.SetBlend(Constants.blendWalk);
             }
         }
         else
         {
             entity.SetBlend(Constants.blendRun);
         }
     }
     else
     {
         entity.SetBlend(Constants.blendRun);
     }
 }
Ejemplo n.º 5
0
    public void LoadMonsterByWaveId(int wave)
    {
        var lst  = mapCfg.monsterLst;
        var mlst = lst[wave];

        for (int i = 0; i < mlst.Count; ++i)
        {
            MonsterCfg    mcfg    = resSev.GetMonsterCfg(mlst[i].id);
            GameObject    monster = resSev.LoadGoPrefab(mcfg.resPath, true, mlst[i].pos, Quaternion.Euler(0f, mlst[i].yAngle, 0f));
            StringBuilder sb      = "m".ConnectStr(mlst[i].wave).ConnectStr('_').ConnectStr(mlst[i].index);
            monster.name = sb.EndConnectStr();
            monster.transform.localScale = Vector3.one;
            monster.SetActive(false);

            int         lv    = mlst[i].lv;
            BattleProps props = mcfg.props * lv;

            EntityMonster entity = new EntityMonster();
            entity.SetBattleMgr(this);
            entity.SetLv(lv);
            entity.SetController(monster.GetComponent <MonsterController>());
            entity.SetStateMgr(stateMgr);
            entity.SetSkillMgr(skillMgr);
            entity.SetBattlePorps(props);
            entity.SetMonsterCfg(mcfg);

            monstersDic.Add(monster.name, entity);

            GameRoot.Instance.dynamicWindow.AddHpItem(monster.name, entity.Hp, entity.GetHpRoot());

            monster.SetActive(false);
            entity.RegisterAILogic();
        }
    }
Ejemplo n.º 6
0
    private EntityMonster FindNearestTarget()
    {
        List <EntityMonster> listMonster = _battleMgr.GetAllEntityMonsters();

        if (listMonster == null || listMonster.Count == 0)
        {
            return(null);
        }

        Vector3       vecSelf       = GetEntityPosition();
        EntityMonster targetMonster = null;
        float         distance      = 0.0f;

        for (int idx = 0; idx < listMonster.Count; idx++)
        {
            Vector3 vecMonster = listMonster[idx].GetEntityPosition();
            if (0 == idx)
            {
                distance      = Vector3.Distance(vecSelf, vecMonster);
                targetMonster = listMonster[0];
            }
            else
            {
                float val = Vector3.Distance(vecSelf, vecMonster);
                if (distance > val)
                {
                    distance      = val;
                    targetMonster = listMonster[idx];
                }
            }
        }

        return(targetMonster);
    }
Ejemplo n.º 7
0
    private EntityMonster FindClosedTarget()
    {
        List <EntityMonster> Lst = battleMgr.GetEntityMonster();

        if (Lst == null || Lst.Count == 0)
        {
            return(null);
        }
        Vector3       self          = GetPos();
        EntityMonster targetMonster = null;
        float         dis           = float.MaxValue;

        for (int i = 0; i < Lst.Count; i++)
        {
            var target  = Lst[i].GetPos();
            var disTemp = Vector3.Distance(self, target);
            if (dis > disTemp)
            {
                dis           = disTemp;
                targetMonster = Lst[i];
            }
        }

        return(targetMonster);
    }
Ejemplo n.º 8
0
    private void SkillAction(EntityBase entity, SkillCfg skillCfg, SkillActionCfg act, int actIndex)
    {
        int damage = skillCfg.damageLst[actIndex];
        int type   = skillCfg.dmgType;

        if (entity.entityType == EntityType.Player) // 怪物攻击
        {
            EntityMonster[] monsters = entity.BattleMgr.GetEntityMonsters();
            for (int i = 0; i < monsters.Length; ++i)
            {
                EntityMonster monster = monsters[i];
                if (InRange(entity.GetPos(), monster.GetPos(), act.radius) &&
                    InAngle(entity.GetTransform(), monster.GetPos(), act.angle))
                {
                    CalcDamage(entity, monster, damage, type);
                }
            }
        }
        else if (entity.entityType == EntityType.Monster)
        {
            EntityBase player = entity.BattleMgr.entityPlayer;
            if (InRange(entity.GetPos(), player.GetPos(), act.radius) &&
                InAngle(entity.GetTransform(), player.GetPos(), act.angle))
            {
                CalcDamage(entity, player, damage, type);
            }
        }
    }
Ejemplo n.º 9
0
    //加载怪物
    public void LoadMonster(int wave)
    {
        List <MonsterSpawnData> monsterLst = this.mapCfg.monsterLst;

        for (int i = 0; i < monsterLst.Count; i++)
        {
            if (monsterLst[i].mWave == wave)
            {
                MonsterSpawnData msd = monsterLst[i];
                GameObject       go  = resSvc.LoadPrefab(msd.mCfg.resPath);
                go.transform.localPosition    = msd.mBornpos;
                go.transform.localEulerAngles = msd.mBornRote;
                go.transform.name             = string.Format("{0}_{1}_{2}", msd.mCfg.id, msd.mWave, msd.mIndex);

                MonsterController monsterCtrl = go.GetComponent <MonsterController>();

                EntityMonster entityMonster = new EntityMonster();
                entityMonster.SetMonsterCfg(msd);
                entityMonster.Name = go.transform.name;
                entityMonster.SetBattleMgr(this);
                entityMonster.SetSkillMgr(this.skillMgr);
                entityMonster.SetStateMgr(this.stateMgr);
                entityMonster.SetBattleProps(msd.mCfg.bps);
                entityMonster.SetController(monsterCtrl);
                monsterDic.Add(go.name, entityMonster);
                entityMonster.SetActive(false);

                GameRoot.instance.dynamicWind.AddHpItemInfo(entityMonster.Name, entityMonster.HP, monsterCtrl.itemRoot);
            }
        }
    }
Ejemplo n.º 10
0
    //environment actions method depending on the player choice
    public static void eActions(int nAction, EntityPlayer p, EntityMonster m)
    {
        switch (nAction)
        {
        case 1: Battle.entitiesBattle(p, m);

        //Flee from battle
        case 2: PlayerState.flee(p);

        //Look at the battle
        case 3: PlayerState.look(p, null, null);

        //Eat and recover some health points
        case 4: PlayerState.eat(p, null);

        //Drink and recover some mana points
        case 5: PlayerState.drink(p, null);

        //Get drunk: provoke a random event
        case 6: PlayerState.getDrunk(p);

        //Sleep and recover some health and mana points
        case 7: PlayerState.sleep(p, null);
        }
    }
Ejemplo n.º 11
0
    public EntityMonster FindClosedMonster()
    {
        List <EntityMonster> list = battleMg.GetEntityMonsters();

        if (list == null || list.Count == 0)
        {
            return(null);
        }
        Vector3       self          = GetPos();
        EntityMonster targetMonster = null;
        float         dis           = 0;

        for (int i = 0; i < list.Count; i++)
        {
            Vector3 target = list[i].GetPos();
            if (i == 0)
            {
                dis           = Vector3.Distance(self, target);
                targetMonster = list[0];
            }
            else
            {
                float tempPos = Vector3.Distance(self, target);
                if (tempPos < dis)
                {
                    dis           = tempPos;
                    targetMonster = list[i];
                }
            }
        }
        return(targetMonster);
    }
Ejemplo n.º 12
0
    public void OnMonsterLoaded(GameObject m)
    {
        MonsterController controller = m.GetComponent <MonsterController>();
        MonsterData       md         = controller.MonsterEntityData.MD;//晚于OnShow执行
        EntityMonster     em         = new EntityMonster {
            BattleMgr = this,
            StateMgr  = m_StateMgr,
            SkillMgr  = m_SkillMgr
        };

        //设置初始属性
        em.Md = md;
        em.SetBattleProps(md.mCfg.bps);
        em.Name = "m" + md.mWave + "_" + md.mIndex;

        MonsterController mc = m.GetComponent <MonsterController>();

        mc.Init();
        em.SetCtrl(mc);

        mc.gameObject.SetActive(false);
        monsterDic.Add(m.name, em);
        if (md.mCfg.mType == MonsterType.Normal)
        {
            GameEntry.UI.AddHpItemInfo(m.name, mc.hpRoot, em.HP);
        }
        else if (md.mCfg.mType == MonsterType.Boss)
        {
            SetBossHPBarStateEventArgs stateEventArgs = ReferencePool.Acquire <SetBossHPBarStateEventArgs>();
            stateEventArgs.Fill(true);
            GameEntry.Event.Fire(this, stateEventArgs);
        }
    }
Ejemplo n.º 13
0
    private EntityMonster FindClosedTarget()
    {
        List <EntityMonster> lst = BattleMgr.GetEntityMonsters();

        if (lst == null || lst.Count == 0)
        {
            return(null);
        }

        Vector3       self          = GetPos();
        EntityMonster targetMonster = null;
        float         dis           = 0;

        for (int i = 0; i < lst.Count; i++)
        {
            Vector3 target = lst[i].GetPos();
            if (i == 0)
            {
                dis           = Vector3.Distance(self, target);
                targetMonster = lst[0];
            }
            else
            {
                float calcDis = Vector3.Distance(self, target);
                if (dis > calcDis)
                {
                    dis           = calcDis;
                    targetMonster = lst[i];
                }
            }
        }
        return(targetMonster);
    }
Ejemplo n.º 14
0
    private EntityMonster GetAtkRangeMonster()
    {
        List <EntityMonster> monsters = battleMgr.GetMonsters();

        if (monsters.Count <= 0)
        {
            return(null);
        }

        Vector3       selfPos    = GetPos();
        EntityMonster atkMonster = null;
        float         minDis     = 0f;

        for (int i = 0; i < monsters.Count; i++)
        {
            if (i == 0)
            {
                float dis = Vector3.Distance(selfPos, monsters[i].GetPos());
                minDis     = dis;
                atkMonster = monsters[i];
            }
            else
            {
                float dis = Vector3.Distance(selfPos, monsters[i].GetPos());
                if (dis < minDis)
                {
                    minDis     = dis;
                    atkMonster = monsters[i];
                }
            }
        }

        return(atkMonster);
    }
Ejemplo n.º 15
0
 public void Update()
 {/*这里的暂停时间是把时间变为0.1,需要注意的是timeSvc时间不受控制
   * 所以延迟释放的技能,包括其他技能特效存在时长不受这个影响*/
     if (isPaused)
     {
         Time.timeScale = 0.1f;
     }
     else
     {
         Time.timeScale = 1f;
     }
     foreach (var item in monsterDic)
     {
         EntityMonster em = item.Value;
         em.TickAILogic();
     }
     //当前批次怪物是否全部死亡
     if (mapMg != null)
     {
         if (triggerCheck && monsterDic.Count == 0)
         {
             bool isExist = mapMg.SetNextTriggerOn();
             triggerCheck = false;
             if (!isExist)
             {
                 //通关了,战斗结算
                 EndBattle(true, entitySelfPlayer.Hp);
             }
         }
     }
 }
Ejemplo n.º 16
0
 private void OnEnable()
 {
     TimeService.instance.AddTimeTask((int tid) =>
     {
         EntityMonster monster = BattleSys.Instance.battleMg.entitySelfPlayer.FindClosedMonster();
         //拿到当前攻击目标的位置,位置稍微上调一点,不然是射脚的
         //没有目标的时候,箭就向前飞
         Vector3 pos;
         if (monster == null)
         {
             isHaveTarget = false;
             pos          = Vector3.zero;
         }
         else
         {
             isHaveTarget = true;
             pos          = monster.GetPos();
         }
         monsterPos = new Vector3(pos.x, pos.y + 2f, pos.z);
         canFly     = true;
     }, 0.3f);
     TimeService.instance.AddTimeTask((int tid) =>
     {
         canFly = false;
         transform.localPosition = beginPos;
         transform.localRotation = beginRot;
     }, 0.6f);
 }
Ejemplo n.º 17
0
 private void OnDialogTrigger(int type, EntityMonster entityMonster, string arg)
 {
     if (type == 10 && InstanceManager.CurrentInstanceData != null && InstanceManager.CurrentInstanceData.waveShow > 0)
     {
         this.WaveText.set_text(arg);
     }
 }
Ejemplo n.º 18
0
    /// <summary>
    /// 添加一个新的精灵
    /// </summary>
    /// <param name="type"></param>
    public static void AddNewEntity(SpriteType type, EntityServerInfo info = null)
    {
        if (info == null)
        {
            info = new EntityServerInfo();
        }
        EntityParent entity = null;

        switch (type)
        {
        case SpriteType.NONE:

            break;

        case SpriteType.Myself:
            if (thePlayer == null)
            {
                entity        = new EntityMyself();
                info.id       = 1000;
                info.dataId   = 1;
                info.position = Vector3.zero;
                info.x        = 100;
                info.y        = 100;
            }
            else
            {
                info.id       = 1000;
                info.position = Vector3.zero;
                info.x        = 100;
                info.y        = 100;
                thePlayer.SetEntityServerInfo(info);
                thePlayer.UpdatePosition();
                return;
            }

            break;

        case SpriteType.Player:
            entity = new EntityPlayer();
            break;

        case SpriteType.Monster:
            entity = new EntityMonster();
            break;

        default:
            break;
        }
        if (entity == null)
        {
            return;
        }
        entity.SetEntityServerInfo(info);
        entity.CreateModel();
        entity.EnterWorld();
        OnEnterWorld(entity);
    }
Ejemplo n.º 19
0
 public override void BossInitEnd(EntityMonster boss)
 {
     base.BossInitEnd(boss);
     if (!UIManagerControl.Instance.IsOpen("TaskProgressUI"))
     {
         this.mProgressUI = (UIManagerControl.Instance.OpenUI("TaskProgressUI", UINodesManager.MiddleUIRoot, false, UIType.NonPush) as TaskProgressUI);
     }
     this.mProgressUI.SetLayout(boss.MonsterRank == EntityParent.MonsterRankType.Boss);
 }
    public void CreateMaster(MasterWave master)
    {
        EntityParent masterEntity = new EntityMonster();
        EntityInfo   info         = new EntityInfo(++CreateEntityIndex, (int)master.type, master.maxHp, master.demage, master.type.ToString(), master.speed);

        masterEntity.SetEntityInfo(info);
        masterEntity.EnterLevel();
        this.dicCreateEntitys.Add(masterEntity.EntityId, masterEntity);
    }
Ejemplo n.º 21
0
    public void RemoveMonster(string mName)
    {
        EntityMonster em = null;

        if (monsterDic.TryGetValue(mName, out em))
        {
            monsterDic.Remove(mName);
        }
    }
Ejemplo n.º 22
0
    public void RemoveMonsterData(string key)
    {
        EntityMonster monster = null;

        if (dictMonster.TryGetValue(key, out monster))
        {
            dictMonster.Remove(key);
            GameRoot.Instance._dynamicWnd.RemoveHpBarItem(key);
        }
    }
Ejemplo n.º 23
0
    public void RemoveMonster(string name)
    {
        EntityMonster entityMonster = null;

        if (monsterDicts.TryGetValue(name, out entityMonster))
        {
            monsterDicts.Remove(name);
            GameRoot.Instance.dynamicWindow.RemoveItemHp(name);
        }
    }
Ejemplo n.º 24
0
    public EntityMonster[] GetEntityMonsters()
    {
        EntityMonster[] monsters = new EntityMonster[monstersDic.Count];
        int             i        = 0;

        foreach (var pair in monstersDic)
        {
            monsters[i++] = pair.Value;
        }
        return(monsters);
    }
Ejemplo n.º 25
0
    public override void BossInitEnd(EntityMonster boss)
    {
        base.BossInitEnd(boss);
        BattleUI battleUI = UIManagerControl.Instance.GetUIIfExist("BattleUI") as BattleUI;

        if (battleUI == null)
        {
            return;
        }
        battleUI.ShowCallBoss(true);
    }
Ejemplo n.º 26
0
    public override Vector2 CalcTargetDir()
    {
        EntityMonster mtar = FindClosedTraget();

        if (mtar != null)
        {
            Vector3 target = mtar.GetPos();
            Vector3 self   = GetPos();
            Vector2 dir    = new Vector2(target.x - self.x, target.z - self.z);
            return(dir.normalized);
        }
        return(Vector2.zero);
    }
Ejemplo n.º 27
0
    public override Vector2 CalcTargetDirection()
    {
        EntityMonster monster = FindNearestTarget();

        if (monster != null)
        {
            Vector3 targetMonster = monster.GetEntityPosition();
            Vector3 vecSelf       = GetEntityPosition();
            Vector2 dir           = new Vector2(targetMonster.x - vecSelf.x, targetMonster.z - vecSelf.z);
            return(dir.normalized);
        }
        return(Vector2.zero);
    }
Ejemplo n.º 28
0
    public override Vector2 CalcTargetDir()
    {
        EntityMonster target = GetCloseTarget();

        if (target != null)
        {
            Vector3 targetPos = target.GetPos();
            Vector3 selfPos   = GetPos();
            Vector2 dir       = new Vector2(targetPos.x - selfPos.x, targetPos.z - selfPos.z);
            return(dir.normalized);
        }
        return(Vector2.zero);
    }
Ejemplo n.º 29
0
/**
 * Method that return the monster defense score<br/>
 * @param monster
 * @return monsterDefense
 */
    public int monsterDefense(EntityMonster monster)
    {
        int monsterDefense = 0;

        for (int i = 0; i != monster.getEntityDefense(); i++)
        {
            Random randomDice = new Random();
            if (heroquestDiceType[randomDice.Next(6)] == "Ennemy Shield")
            {
                monsterDefense++;
            }
        }
        return(monsterDefense);
    }
Ejemplo n.º 30
0
    private EntityMonster CreateMonster(int monsterID, Vector3 pos, Vector3 rot)
    {
        CfgMonsterTable monsterTable = CfgMonster.Instance.GetConfigTable(monsterID);

        if (monsterTable == null)
        {
            return(null);
        }

        EntityMonster monster = new EntityMonster(++EntityID, monsterID);

        monster.Create(this, monsterTable.AvatarID, pos, rot);
        return(monster);
    }