This method shows a good example of a structured approach to handling complex game input logic, including distinguishing between different types of targets, checking ownership and conditions dynamically, and triggering game events based on those conditions. It encapsulates handling of skill targeting and activation in a turn-based game or a similar interactive system, ensuring clear pathways depending on the context (type of hero, type of target, etc.). Note, though, without the full context or related code (like definitions for GameMode, CGCastHeroSkillToCardEvent, etc.), some assumptions about functionality and purpose are necessarily speculative.
private void HandleInputSkill()
{
waitingForSkillInput = null;
MinionCardDisplayer otherMinion = arrowSkill.GetComponent<MouseHit>().FindClosestHit<MinionCardDisplayer>();
BattleFieldSlotDisplayer slotDisPlayer = arrowSkill.GetComponent<MouseHit>().FindClosestHit<BattleFieldSlotDisplayer>();
if (otherMinion == null && slotDisPlayer == null)
{
SetSkillOutcome(false);
return;
}
HeroTalent heroTalent = GameMode.GetActorObject(m_Player.GetHeroTalent());
ActorRef<Player> skillPlayer = m_HeroSkill.GetOwner();
if (otherMinion != null)
{
HandleMinionTarget(otherMinion, heroTalent, skillPlayer);
}
else
{
HandleSlotTarget(slotDisPlayer, skillPlayer);
}
}
private void HandleMinionTarget(MinionCardDisplayer minion, HeroTalent heroTalent, ActorRef<Player> skillPlayer)
{
Card card = minion.GetActorObject<Card>();
if (m_HeroSkill.type == HeroTypes.Mage && heroTalent.GetTalentIndex() == 1)
{
CastHeroSkillToCard(minion, skillPlayer);
return;
}
if (m_HeroSkill.type == HeroTypes.Rogue && !isChoosing)
{
ProcessRogueSkillSelection(minion, card, skillPlayer);
return;
}
CheckCardSelection(card, minion);
}
private void ProcessRogueSkillSelection(MinionCardDisplayer minion, Card card, ActorRef<Player> skillPlayer)
{
if (card.GetOwnerPlayer().IsSameWith(skillPlayer))
{
StartCoroutine(CoroutineDeploy(minion));
Debug.Log("StartCoroutine end");
isChoosing = true;
HighlightMinion(minion);
}
else
{
SetSkillOutcome(false);
}
}
private void CheckCardSelection(Card card, MinionCardDisplayer minion)
{
if (TargetCard.IsSameWith(card) || !card.GetOwnerPlayer().IsSameWith(m_HeroSkill.GetOwner()))
{
Debug.Log("choose same card");
SetSkillOutcome(false);
}
else
{
m_secondMinion = minion;
HighlightMinion(minion);
SetSkillOutcome(true);
}
}
private void HandleSlotTarget(BattleFieldSlotDisplayer slot, ActorRef<Player> skillPlayer)
{
if (!slot.AccurateBattleFieldPosition.PlayerPosition.Equals(m_Player.GetPlayerPosition()))
{
SetSkillOutcome(false);
return;
}
if (m_HeroSkill.type == HeroTypes.Mage)
{
CastSkillToSlot(slot, skillPlayer);
}
else
{
DestPosition = slot.AccurateBattleFieldPosition;
SetSkillOutcome(true);
}
}
private void CastHeroSkillToCard(MinionCardDisplayer minion, ActorRef<Player> skillPlayer)
{
CGCastHeroSkillToCardEvent castEvent = new CGCastHeroSkillToCardEvent()
{
TargetCard = minion.GetActor<Card>(),
Player = skillPlayer
};
GamePlayer.UpdateEvent(castEvent);
HandleArrowToSkill();
}
private void CastSkillToSlot(BattleFieldSlotDisplayer slot, ActorRef<Player> skillPlayer)
{
CGCastHeroSkillToCardEvent castEvent = new CGCastHeroSkillToCardEvent()
{
DestPosition = slot.AccurateBattleFieldPosition,
Player = skillPlayer
};
GamePlayer.UpdateEvent(castEvent);
HandleArrowToSkill();
}
private void SetSkillOutcome(bool isSuccess)
{
isSkillSuccessful = isSuccess;
if (!isSuccess)
{
isChoosing = false;
}
}
private void HighlightMinion(MinionCardDisplayer minion)
{
// Assume this method highlights the given minion.
HandleHighLight(minion);
}