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.
113 lines
4.1 KiB
113 lines
4.1 KiB
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Battle))] |
|
[FriendClass(typeof(Unit))] |
|
[FriendClass(typeof(Fighter))] |
|
public static class BattleOperate |
|
{ |
|
#if SERVER |
|
public static async ETTask<Battle> EnterBattle(Unit unit, long enemyId) |
|
{ |
|
Battle battle = unit.AddChild<Battle>(); |
|
UnitComponent uc = battle.GetOrAddComponent<UnitComponent>(); |
|
Unit enemyUnit = unit.GetParent<UnitComponent>().GetChild<Unit>(enemyId); |
|
if (enemyUnit == null) |
|
{ |
|
enemyUnit = await DBManagerComponent.Instance.GetZoneDB(unit.DomainZone()).Query<Unit>(enemyId); |
|
if (enemyUnit == null) |
|
{ |
|
return null; |
|
} |
|
|
|
uc.AddChild(enemyUnit); |
|
enemyUnit.InitPeopleNumberic(); |
|
} |
|
|
|
foreach (var v in unit.FighterDic) |
|
{ |
|
var people = unit.GetComponent<PeopleComponent>().GetChild<People>(v.Value); |
|
Fighter fighter = battle.AddChildWithId<Fighter>(v.Value); |
|
fighter.FromPeople(people); |
|
fighter.Pos = v.Key; |
|
battle.FighterDic[v.Value] = fighter; |
|
battle.FighterPosDic[v.Key] = fighter; |
|
fighter.Camp = 1; |
|
fighter.InitHp(); |
|
battle.AliveFightDic[fighter.Id] = fighter; |
|
} |
|
|
|
foreach (var v in enemyUnit.FighterDic) |
|
{ |
|
var people = enemyUnit.GetComponent<PeopleComponent>().GetChild<People>(v.Value); |
|
Fighter fighter = battle.AddChildWithId<Fighter>(v.Value); |
|
fighter.FromPeople(people); |
|
fighter.Pos = v.Key; |
|
battle.EnemyDic[v.Value] = fighter; |
|
battle.EnemyPosDic[v.Key] = fighter; |
|
fighter.Camp = 2; |
|
fighter.InitHp(); |
|
battle.AliveFightDic[fighter.Id] = fighter; |
|
} |
|
|
|
unit.BattleId = battle.Id; |
|
battle.BattleState = ConstBattleState.BATTLE_STATE_FIGHT; |
|
battle.BattleType = ConstBattleType.BATTLE_PVP; |
|
battle.EnemyId = enemyId; |
|
|
|
return battle; |
|
} |
|
|
|
public static Battle EnterPveBattle(Unit unit,long enemyId) |
|
{ |
|
Battle battle = unit.AddChild<Battle>(); |
|
UnitComponent uc = battle.GetOrAddComponent<UnitComponent>(); |
|
Unit enemyUnit = unit; |
|
|
|
|
|
foreach (var v in unit.FighterDic) |
|
{ |
|
var people = unit.GetComponent<PeopleComponent>().GetChild<People>(v.Value); |
|
Fighter fighter = battle.AddChildWithId<Fighter>(v.Value); |
|
fighter.FromPeople(people); |
|
fighter.Pos = v.Key; |
|
battle.FighterDic[v.Value] = fighter; |
|
battle.FighterPosDic[v.Key] = fighter; |
|
fighter.Camp = 1; |
|
fighter.FightType = ConstFightType.FIGHT_TYPE_PLAYER; |
|
fighter.InitHp(); |
|
battle.AliveFightDic[fighter.Id] = fighter; |
|
} |
|
|
|
var monsterGroup = unit.GetComponent<MonsterGroupComponent>().GetMonsterGroupById(enemyId); |
|
if (monsterGroup == null) |
|
{ |
|
battle.Dispose(); |
|
return null; |
|
} |
|
|
|
int pos = 0; |
|
foreach (var v in monsterGroup.Config.MonsterID) |
|
{ |
|
pos++; |
|
var config = MonsterConfigCategory.Instance.Get(v); |
|
Fighter fighter = battle.AddChild<Fighter>(); |
|
fighter.FromMonster(config); |
|
fighter.Pos = pos; |
|
battle.EnemyDic[pos] = fighter; |
|
battle.EnemyPosDic[pos] = fighter; |
|
fighter.Camp = 2; |
|
battle.AliveFightDic[fighter.Id] = fighter; |
|
} |
|
|
|
unit.BattleId = battle.Id; |
|
battle.BattleState = ConstBattleState.BATTLE_STATE_FIGHT; |
|
battle.BattleType = ConstBattleType.BATTLE_PVE; |
|
battle.EnemyId = enemyId; |
|
|
|
return battle; |
|
} |
|
#endif |
|
} |
|
} |