You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
6.0 KiB
181 lines
6.0 KiB
using System; |
|
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Unit))] |
|
[FriendClass(typeof(Battle))] |
|
public static class BattleHelper |
|
{ |
|
public static async ETTask<int> Embattle(Unit unit, Dictionary<int, long> 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<SessionComponent>().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<int> 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<SessionComponent>().Session.Call(msg) as M2C_EnterBattle; |
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
|
|
Battle battle = unit.AddChildWithId<Battle>(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<int> BattleAtkOver(Unit unit) |
|
{ |
|
try |
|
{ |
|
M2C_BattleAtkOver resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().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<Battle>(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<int> ExitBattle(Unit unit) |
|
{ |
|
try |
|
{ |
|
M2C_ExitBattle resp = await unit.ZoneScene().GetComponent<SessionComponent>().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<int> UseSkill(Unit unit,long atkId, int skillId) |
|
{ |
|
try |
|
{ |
|
M2C_UseSkill resp = await unit.ZoneScene().GetComponent<SessionComponent>().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<Battle>(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<int> TestReplaceSkill(Unit unit, long peopleId, int oldSkillId, int newSkillId) |
|
{ |
|
try |
|
{ |
|
M2C_TestReplaceSkill resp = await unit.ZoneScene().GetComponent<SessionComponent>().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<PeopleComponent>(); |
|
var people = peopleComp.GetChild<People>(peopleId); |
|
var skillComp = people.GetComponent<SkillComponent>(); |
|
if (skillComp != null) |
|
{ |
|
skillComp.TestReplaceSkill(oldSkillId, newSkillId); |
|
} |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
await ETTask.CompletedTask; |
|
return ErrorCode.ERR_Success; |
|
} |
|
} |
|
} |