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.
 
 
 
 
 
 

232 lines
7.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using Org.BouncyCastle.Ocsp;
using ProtoCSStruct;
using Sog;
namespace Battle
{
public static class BattleHeroSvc
{
public static bool CheckIsFriend(BattleHero heroA, BattleHero heroB)
{
//自己是自己的友方
if (heroA.objId == heroB.objId)
{
return true;
}
////公共敌人没有友方
//if (heroA.fightSide == (int)BattleSide.AllEnemy)
//{
// return false;
//}
return heroA.fightSide == heroB.fightSide;
}
public static List<BattleHero> GetHeroBySide(BattleObj battle, BattleSide side)
{
return GetHeroBySideUnsafe(battle, side);
}
// 直接返回List, 任何增删改都会改变英雄列表, 后果自负
public static List<BattleHero> GetHeroBySideUnsafe(BattleObj battle, BattleSide side)
{
if (side == BattleSide.SideA)
return battle.herosA;
if (side == BattleSide.SideB)
return battle.herosB;
//if (side == (int)BattleSide.AllEnemy)
// return battle.pubEnemy;
return null;
}
// 返回只读的IEnumerable相对安全一些
/*public static List<BattleHero> GetFriend(BattleObj battle, BattleHero self)
{
return AIHeroTargetSelect.HeroSelectNearHero(self, false, false, true);
}*/
public static List<BattleHero> GetAliveFriend(BattleObj battle, BattleHero self)
{
var friends = GetHeroBySideUnsafe(battle, self.initSide);
return friends.Where(h => ! h.isDead).ToList();
}
public static List<BattleHero> GetAliveFriendNoSelf(BattleObj battle, BattleHero self)
{
var friends = GetHeroBySideUnsafe(battle, self.initSide);
return friends.Where(h => (!h.isDead && h.objId != self.objId)).ToList();
}
/*public static List<BattleHero> GetEnemy(BattleObj battle, BattleHero self)
{
return AIHeroTargetSelect.HeroSelectNearHero(self, true, false);
}*/
public static BattleSide GetEnemySide(BattleHero self)
{
return self.initSide == BattleSide.SideA ? BattleSide.SideB : BattleSide.SideA;
}
public static List<BattleHero> GetAliveEnemy(BattleObj battle, BattleHero self)
{
var enemy = GetHeroBySideUnsafe(battle, GetEnemySide(self));
return enemy.Where(h => !h.isDead).ToList();
}
public static BattleHero GetCommander(BattleObj battle, BattleHero self)
{
return null;
}
public static List<BattleHero> GetHeroByDescId(BattleObj battle, int descId)
{
return battle.allCreatures.Where(h => !h.isDead && h.DescId == descId).ToList();
}
public static bool IsHeroAllDead(BattleObj battle, BattleSide side)
{
foreach (var hero in GetHeroBySide(battle, side))
{
if (! hero.isDead)
{
return false;
}
}
return true;
}
public static BattleHero GetAliveBoss(BattleObj battle, BattleSide side)
{
foreach (var hero in GetHeroBySide(battle, side))
{
if (hero.isBoss && hero.isDead == false)
{
return hero;
}
}
return null;
}
// attackId不是caster.objId。例如A放闪电链顺序打到B、C、D
// 此时caster永远是A,但是对B而言attackId是A,对C而言attackId是B,对D而言attackId是C
// 表现层需要attackId来指示技能方向
public static void RemoveHero(BattleHero hero, HeroDieReson dieReson)
{
if (hero.isDead)
{
return;
}
}
public static ref HeroInfo GetHeroByBattleHero(BattleObj battle, BattleHero target)
{
ref HeroInfo _hero = ref battle.battleInfo.HerosA.List[0];
var tobjId = target.objId;
if(target.heroType == HeroType.Pet)
{
tobjId = target.masterObjId;
}
if (target.initSide == BattleSide.SideA)
{
// BattleHero 里没有HeroInfo 只能遍历了 后续添加了serialNum 就把descId换成serialNum 现在直接在战斗构造battlerhero时把objId存到serialNum
for (int i = 1; i < battle.battleInfo.HerosA.List.Count; i++)
{
if (battle.battleInfo.HerosA.List[i].Dbhero.SerialNum == tobjId)
{
return ref battle.battleInfo.HerosA.List[i];
}
}
}
if (target.initSide == BattleSide.SideB)
{
for (int i = 0; i < battle.battleInfo.HerosB.List.Count; i++)
{
if (battle.battleInfo.HerosB.List[i].Dbhero.SerialNum == tobjId)
{
return ref battle.battleInfo.HerosB.List[i];
}
}
}
return ref _hero;
}
//public static List<BattleHero> GetActionHero(BattleObj battle)
//{
// return battle.allCreatures.Where(h => !h.isDead)
// .OrderByDescending(h => h.prop.GetValueNoCheck(CSPropIDType.Speed))
// .ToList();
//}
public static BattleHero GetAttackTarget(BattleObj battle, BattleHero caster)
{
var enemy = BattleHeroSvc.GetHeroBySideUnsafe(battle, BattleHeroSvc.GetEnemySide(caster));
BattleHero target = null;
foreach (BattleHero hero in enemy)
{
if (!hero.isDead && (target == null || hero.pos < target.pos))
{
target = hero;
}
}
return target;
}
//获取敌方倒数第x名敌人
public static BattleHero GetAttackBackTarget(BattleObj battle, BattleHero caster, int backIdx)
{
var enemy = BattleHeroSvc.GetHeroBySideUnsafe(battle, BattleHeroSvc.GetEnemySide(caster)).Where(h => !h.isDead).OrderByDescending(h => h.pos).ToList();
BattleHero target = null;
for (int i = 0; i < enemy.Count; i++)
{
if (backIdx > 0)
{
target = enemy[i];
backIdx--;
}
}
return target;
}
//获取英雄主人
public static BattleHero GetAliveMasterHero(BattleObj battle, BattleSide side, int masterObjId)
{
var heroList = GetHeroBySideUnsafe(battle, side).Where(h => !h.isDead && h.objId == masterObjId).ToList();
if (heroList.Count > 0)
return heroList[0];
return null;
}
public static BattleHero GetAliveMate(BattleObj battle, BattleSide side)
{
var heroList = GetHeroBySideUnsafe(battle, side).Where(h => !h.isDead && h.heroType == HeroType.Pet).ToList();
if (heroList.Count > 0)
return heroList[0];
return null;
}
public static BattleHero GetAliveHeroByObjId(BattleObj battle, int objId)
{
var heroList = battle.allCreatures.Where(h => !h.isDead && h.objId == objId).ToList();
if (heroList.Count > 0)
return heroList[0];
return null;
}
}
}