using System; using System.Collections.Generic; namespace ET { [FriendClass(typeof(Unit))] [FriendClass(typeof(Battle))] public static class BattleHelper { public static async ETTask Embattle(Unit unit, Dictionary fighterDic) { try { C2M_Embattle msg = new C2M_Embattle() { }; foreach (var v in fighterDic) { msg.Ks.Add(v.Key); msg.Vs.Add(v.Value); } M2C_Embattle resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_Embattle; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } unit.SetEmbattle(fighterDic); } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } public static async ETTask EnterBattle(Unit unit, long enemyId,Int32 battleType) { try { C2M_EnterBattle msg = new C2M_EnterBattle() { EnemyId = enemyId,BattleType = battleType}; M2C_EnterBattle resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_EnterBattle; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } Battle battle = unit.AddChildWithId(resp.BattleId); battle.BattleType = battleType; battle.EnemyId = enemyId; unit.BattleId = resp.BattleId; battle.EnterBattle(resp.FighterList, resp.EnemyList); Game.EventSystem.Publish(new EventType.BattleStart(){CurrentScene = unit.ZoneScene().CurrentScene(), BattleInfo = battle}); // 启动战斗 battle.BattleAtk(); } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } public static async ETTask BattleAtkOver(Unit unit) { try { M2C_BattleAtkOver resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_BattleAtkOver()) as M2C_BattleAtkOver; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } var battle = unit.GetChild(unit.BattleId); battle.SetRandomSeed(resp.Seed); battle.BattleAtk(); } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } public static async ETTask ExitBattle(Unit unit) { try { M2C_ExitBattle resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_ExitBattle()) as M2C_ExitBattle; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } unit.ExitBattle(); } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } public static async ETTask UseSkill(Unit unit,long atkId, int skillId) { try { M2C_UseSkill resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_UseSkill(){AtkId=atkId,SkillId = skillId}) as M2C_UseSkill; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } var battle = unit.GetChild(unit.BattleId); if (battle != null) { battle.UseSkill(atkId, skillId,1); } } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } public static async ETTask TestReplaceSkill(Unit unit, long peopleId, int oldSkillId, int newSkillId) { try { M2C_TestReplaceSkill resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_TestReplaceSkill() { PeopleId = peopleId, OldSkillId = oldSkillId, NewSkillId = newSkillId }) as M2C_TestReplaceSkill; if (resp.Error != ErrorCode.ERR_Success) { Log.Error(resp.Error.ToString()); return resp.Error; } var peopleComp = unit.GetComponent(); var people = peopleComp.GetChild(peopleId); var skillComp = people.GetComponent(); if (skillComp != null) { skillComp.TestReplaceSkill(oldSkillId, newSkillId); } } catch (Exception e) { Log.Error(e); throw; } await ETTask.CompletedTask; return ErrorCode.ERR_Success; } } }